root / trunk / Pithos.Client.WPF / FileProperties / ConflictsViewModel.cs @ 0a9d4d18
History | View | Annotate | Download (4.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.Core; |
13 |
using Pithos.Interfaces; |
14 |
|
15 |
namespace Pithos.Client.WPF.FileProperties |
16 |
{ |
17 |
[TypeConverter(typeof(EnumTypeConverter))] |
18 |
public enum ConflictAction |
19 |
{ |
20 |
[Description("Defer Decision")] |
21 |
Defer, |
22 |
[Description("Keep Local")] |
23 |
KeepLocal, |
24 |
[Description("Keep Server")] |
25 |
KeepServer, |
26 |
[Description("Keep Both")] |
27 |
KeepBoth, |
28 |
[Description("Clear Record")] |
29 |
ClearLocal |
30 |
} |
31 |
|
32 |
public class ConflictFile:PropertyChangedBase |
33 |
{ |
34 |
private string _filePath; |
35 |
public string FilePath |
36 |
{ |
37 |
get { return _filePath; } |
38 |
set |
39 |
{ |
40 |
_filePath = value; |
41 |
NotifyOfPropertyChange(()=>FilePath); |
42 |
} |
43 |
} |
44 |
|
45 |
private string _reason; |
46 |
public string Reason |
47 |
{ |
48 |
get { return _reason; } |
49 |
set |
50 |
{ |
51 |
_reason = value; |
52 |
NotifyOfPropertyChange(() => Reason); |
53 |
} |
54 |
} |
55 |
|
56 |
private ConflictAction _action; |
57 |
public ConflictAction Action |
58 |
{ |
59 |
get { return _action; } |
60 |
set |
61 |
{ |
62 |
_action = value; |
63 |
NotifyOfPropertyChange(()=>Action); |
64 |
} |
65 |
} |
66 |
|
67 |
public DateTime LocalModified { get; set; } |
68 |
|
69 |
public DateTime CloudModified { get; set; } |
70 |
|
71 |
public void GoToFile() |
72 |
{ |
73 |
if (!File.Exists(FilePath) && !Directory.Exists(FilePath)) |
74 |
return; |
75 |
Process.Start("explorer.exe", "/select, " + FilePath); |
76 |
} |
77 |
} |
78 |
[Export(typeof(ConflictsViewModel))] |
79 |
class ConflictsViewModel:Screen |
80 |
{ |
81 |
[Import] |
82 |
public IStatusKeeper StatusKeeper { get; set; } |
83 |
|
84 |
[Import] |
85 |
public IConflictResolver Resolver { get; set; } |
86 |
|
87 |
private readonly ObservableCollection<ConflictFile> _conflicts; |
88 |
|
89 |
public ObservableCollection<ConflictFile> Conflicts |
90 |
{ |
91 |
get { return _conflicts; } |
92 |
} |
93 |
|
94 |
public string[] Actions |
95 |
{ |
96 |
get { return new[] {"Keep Local", "Keep Server", "Keep Both"}; } |
97 |
} |
98 |
|
99 |
public ConflictsViewModel() |
100 |
{ |
101 |
this.DisplayName="Conflicts"; |
102 |
var fileStates = from state in FileState.Queryable |
103 |
where state.FileStatus == FileStatus.Conflict || |
104 |
state.OverlayStatus == FileOverlayStatus.Conflict |
105 |
select state; |
106 |
var conflicts = from state in fileStates |
107 |
let info=FileInfoExtensions.FromPath(state.FilePath) |
108 |
select new ConflictFile {FilePath = state.FilePath,Reason=state.ConflictReason,LocalModified = info.LastWriteTime}; |
109 |
_conflicts = new ObservableCollection<ConflictFile>(conflicts.ToList()); |
110 |
|
111 |
} |
112 |
|
113 |
protected override void OnViewLoaded(object view) |
114 |
{ |
115 |
base.OnViewLoaded(view); |
116 |
StatusKeeper.CleanupOrphanStates(); |
117 |
} |
118 |
|
119 |
/// <summary> |
120 |
/// Open an explorer window to the target path's directory |
121 |
/// and select the file |
122 |
/// </summary> |
123 |
/// <param name="entry"></param> |
124 |
public void GoToFile(string fullPath) |
125 |
{ |
126 |
if (!File.Exists(fullPath) && !Directory.Exists(fullPath)) |
127 |
return; |
128 |
Process.Start("explorer.exe", "/select, " + fullPath); |
129 |
} |
130 |
|
131 |
public void Apply() |
132 |
{ |
133 |
var conflicts = from conflict in Conflicts |
134 |
where conflict.Action != ConflictAction.Defer |
135 |
select conflict; |
136 |
Resolver.Resolve(conflicts); |
137 |
|
138 |
TryClose(); |
139 |
} |
140 |
|
141 |
public void Cancel() |
142 |
{ |
143 |
TryClose(); |
144 |
} |
145 |
|
146 |
|
147 |
} |
148 |
|
149 |
internal interface IConflictResolver |
150 |
{ |
151 |
void Resolve(IEnumerable<ConflictFile> conflicts); |
152 |
} |
153 |
|
154 |
[Export(typeof(IConflictResolver))] |
155 |
public class DummyResolver:IConflictResolver |
156 |
{ |
157 |
public void Resolve(IEnumerable<ConflictFile> conflicts) |
158 |
{ |
159 |
|
160 |
} |
161 |
} |
162 |
} |