root / trunk / Pithos.Client.WPF / FileProperties / ConflictsViewModel.cs @ 21141c06
History | View | Annotate | Download (5.4 kB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Collections.ObjectModel; |
4 |
using System.ComponentModel; |
5 |
using System.ComponentModel.Composition; |
6 |
using System.Diagnostics; |
7 |
using System.IO; |
8 |
using System.Linq; |
9 |
using System.Text; |
10 |
using Caliburn.Micro; |
11 |
using Pithos.Client.WPF.Converters; |
12 |
using Pithos.Client.WPF.Utils; |
13 |
using Pithos.Core; |
14 |
using Pithos.Interfaces; |
15 |
|
16 |
namespace Pithos.Client.WPF.FileProperties |
17 |
{ |
18 |
[TypeConverter(typeof(EnumTypeConverter))] |
19 |
public enum ConflictAction |
20 |
{ |
21 |
[Description("Defer Decision")] |
22 |
Defer, |
23 |
[Description("Keep Local")] |
24 |
KeepLocal, |
25 |
[Description("Keep Server")] |
26 |
KeepServer, |
27 |
/* [Description("Keep Both")] |
28 |
KeepBoth,*/ |
29 |
[Description("Clear Record")] |
30 |
ClearLocal |
31 |
} |
32 |
|
33 |
public class ConflictFile:PropertyChangedBase |
34 |
{ |
35 |
private string _filePath; |
36 |
public string FilePath |
37 |
{ |
38 |
get { return _filePath; } |
39 |
set |
40 |
{ |
41 |
_filePath = value; |
42 |
NotifyOfPropertyChange(()=>FilePath); |
43 |
} |
44 |
} |
45 |
|
46 |
private string _reason; |
47 |
public string Reason |
48 |
{ |
49 |
get |
50 |
{ |
51 |
return _reason; |
52 |
} |
53 |
set |
54 |
{ |
55 |
_reason = value; |
56 |
NotifyOfPropertyChange(() => Reason); |
57 |
} |
58 |
} |
59 |
|
60 |
private ConflictAction _action; |
61 |
public ConflictAction Action |
62 |
{ |
63 |
get { return _action; } |
64 |
set |
65 |
{ |
66 |
_action = value; |
67 |
NotifyOfPropertyChange(()=>Action); |
68 |
} |
69 |
} |
70 |
|
71 |
public DateTime LocalModified { get; set; } |
72 |
|
73 |
public DateTime CloudModified { get; set; } |
74 |
|
75 |
public FileState State { get; set; } |
76 |
|
77 |
public void GoToFile() |
78 |
{ |
79 |
if (!File.Exists(FilePath) && !Directory.Exists(FilePath)) |
80 |
return; |
81 |
Process.Start("explorer.exe", "/select, " + FilePath); |
82 |
} |
83 |
} |
84 |
[Export(typeof(ConflictsViewModel))] |
85 |
class ConflictsViewModel:Screen |
86 |
{ |
87 |
[Import] |
88 |
public IStatusKeeper StatusKeeper { get; set; } |
89 |
|
90 |
[Import] |
91 |
public IConflictResolver Resolver { get; set; } |
92 |
|
93 |
private readonly ObservableCollection<ConflictFile> _conflicts=new ObservableCollection<ConflictFile>(); |
94 |
|
95 |
public ObservableCollection<ConflictFile> Conflicts |
96 |
{ |
97 |
get { return _conflicts; } |
98 |
} |
99 |
|
100 |
public bool HasConflicts |
101 |
{ |
102 |
get { return Conflicts!=null && Conflicts.Count > 0; } |
103 |
} |
104 |
|
105 |
public bool HasNoConflicts |
106 |
{ |
107 |
get { return !HasConflicts; } |
108 |
} |
109 |
|
110 |
public string[] Actions |
111 |
{ |
112 |
get { return new[] {"Keep Local", "Keep Server", "Keep Both"}; } |
113 |
} |
114 |
|
115 |
public ConflictsViewModel() |
116 |
{ |
117 |
this.DisplayName="Conflicts"; |
118 |
|
119 |
} |
120 |
|
121 |
protected override void OnViewLoaded(object view) |
122 |
{ |
123 |
base.OnViewLoaded(view); |
124 |
LoadConflicts(); |
125 |
} |
126 |
|
127 |
private void LoadConflicts() |
128 |
{ |
129 |
var fileStates = StatusKeeper.GetConflictStates(); |
130 |
var conflicts = from state in fileStates |
131 |
let info = FileInfoExtensions.FromPath(state.FilePath) |
132 |
select new ConflictFile |
133 |
{ |
134 |
FilePath = state.FilePath, |
135 |
State = state, |
136 |
Reason = state.ConflictReason ?? state.FileStatus.Name(), |
137 |
LocalModified = info.LastWriteTime |
138 |
}; |
139 |
Conflicts.Clear(); |
140 |
foreach (var conflict in conflicts) |
141 |
{ |
142 |
Conflicts.Add(conflict); |
143 |
} |
144 |
NotifyOfPropertyChange(() => Conflicts); |
145 |
NotifyOfPropertyChange(() => HasConflicts); |
146 |
NotifyOfPropertyChange(() => HasNoConflicts); |
147 |
StatusKeeper.CleanupOrphanStates(); |
148 |
} |
149 |
|
150 |
/// <summary> |
151 |
/// Open an explorer window to the target path's directory |
152 |
/// and select the file |
153 |
/// </summary> |
154 |
/// <param name="entry"></param> |
155 |
public void GoToFile(string fullPath) |
156 |
{ |
157 |
if (!File.Exists(fullPath) && !Directory.Exists(fullPath)) |
158 |
return; |
159 |
Process.Start("explorer.exe", "/select, " + fullPath); |
160 |
} |
161 |
|
162 |
public void Reload() |
163 |
{ |
164 |
LoadConflicts(); |
165 |
} |
166 |
|
167 |
public void Apply() |
168 |
{ |
169 |
/* var conflicts = from conflict in Conflicts |
170 |
where conflict.Action != ConflictAction.Defer |
171 |
select conflict; |
172 |
Resolver.Resolve(conflicts);*/ |
173 |
|
174 |
TryClose(); |
175 |
} |
176 |
|
177 |
public void Cancel() |
178 |
{ |
179 |
TryClose(); |
180 |
} |
181 |
|
182 |
|
183 |
} |
184 |
|
185 |
internal interface IConflictResolver |
186 |
{ |
187 |
void Resolve(IEnumerable<ConflictFile> conflicts); |
188 |
} |
189 |
|
190 |
public class DummyResolver:IConflictResolver |
191 |
{ |
192 |
|
193 |
|
194 |
public void Resolve(IEnumerable<ConflictFile> conflicts) |
195 |
{ |
196 |
|
197 |
} |
198 |
} |
199 |
} |