2 using System.Collections.Generic;
\r
3 using System.Collections.ObjectModel;
\r
4 using System.ComponentModel;
\r
5 using System.ComponentModel.Composition;
\r
6 using System.Diagnostics;
\r
10 using Caliburn.Micro;
\r
11 using Pithos.Client.WPF.Converters;
\r
12 using Pithos.Client.WPF.Utils;
\r
14 using Pithos.Interfaces;
\r
16 namespace Pithos.Client.WPF.FileProperties
\r
18 [TypeConverter(typeof(EnumTypeConverter))]
\r
19 public enum ConflictAction
\r
21 [Description("Defer Decision")]
\r
23 [Description("Keep Local")]
\r
25 [Description("Keep Server")]
\r
27 /* [Description("Keep Both")]
\r
29 [Description("Clear Record")]
\r
33 public class ConflictFile:PropertyChangedBase
\r
35 private string _filePath;
\r
36 public string FilePath
\r
38 get { return _filePath; }
\r
42 NotifyOfPropertyChange(()=>FilePath);
\r
46 private string _reason;
\r
47 public string Reason
\r
56 NotifyOfPropertyChange(() => Reason);
\r
60 private ConflictAction _action;
\r
61 public ConflictAction Action
\r
63 get { return _action; }
\r
67 NotifyOfPropertyChange(()=>Action);
\r
71 public DateTime LocalModified { get; set; }
\r
73 public DateTime CloudModified { get; set; }
\r
75 public FileState State { get; set; }
\r
77 public void GoToFile()
\r
79 if (!File.Exists(FilePath) && !Directory.Exists(FilePath))
\r
81 Process.Start("explorer.exe", "/select, " + FilePath);
\r
84 [Export(typeof(ConflictsViewModel))]
\r
85 class ConflictsViewModel:Screen
\r
88 public IStatusKeeper StatusKeeper { get; set; }
\r
91 public IConflictResolver Resolver { get; set; }
\r
93 private readonly ObservableCollection<ConflictFile> _conflicts=new ObservableCollection<ConflictFile>();
\r
95 public ObservableCollection<ConflictFile> Conflicts
\r
97 get { return _conflicts; }
\r
100 public bool HasConflicts
\r
102 get { return Conflicts!=null && Conflicts.Count > 0; }
\r
105 public bool HasNoConflicts
\r
107 get { return !HasConflicts; }
\r
110 public string[] Actions
\r
112 get { return new[] {"Keep Local", "Keep Server", "Keep Both"}; }
\r
115 public ConflictsViewModel()
\r
117 this.DisplayName="Conflicts";
\r
121 protected override void OnViewLoaded(object view)
\r
123 base.OnViewLoaded(view);
\r
127 private void LoadConflicts()
\r
129 var fileStates = StatusKeeper.GetConflictStates();
\r
130 var conflicts = from state in fileStates
\r
131 let info = FileInfoExtensions.FromPath(state.FilePath)
\r
132 select new ConflictFile
\r
134 FilePath = state.FilePath,
\r
136 Reason = state.ConflictReason ?? state.FileStatus.Name(),
\r
137 LocalModified = info.LastWriteTime
\r
140 foreach (var conflict in conflicts)
\r
142 Conflicts.Add(conflict);
\r
144 NotifyOfPropertyChange(() => Conflicts);
\r
145 NotifyOfPropertyChange(() => HasConflicts);
\r
146 NotifyOfPropertyChange(() => HasNoConflicts);
\r
147 StatusKeeper.CleanupOrphanStates();
\r
151 /// Open an explorer window to the target path's directory
\r
152 /// and select the file
\r
154 /// <param name="entry"></param>
\r
155 public void GoToFile(string fullPath)
\r
157 if (!File.Exists(fullPath) && !Directory.Exists(fullPath))
\r
159 Process.Start("explorer.exe", "/select, " + fullPath);
\r
162 public void Reload()
\r
167 public void Apply()
\r
169 /* var conflicts = from conflict in Conflicts
\r
170 where conflict.Action != ConflictAction.Defer
\r
172 Resolver.Resolve(conflicts);*/
\r
177 public void Cancel()
\r
185 internal interface IConflictResolver
\r
187 void Resolve(IEnumerable<ConflictFile> conflicts);
\r
190 public class DummyResolver:IConflictResolver
\r
194 public void Resolve(IEnumerable<ConflictFile> conflicts)
\r