2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using System.ComponentModel;
5 using System.ComponentModel.Composition;
6 using System.Diagnostics;
11 using Pithos.Client.WPF.Converters;
12 using Pithos.Client.WPF.Utils;
14 using Pithos.Interfaces;
16 namespace Pithos.Client.WPF.FileProperties
18 [TypeConverter(typeof(EnumTypeConverter))]
19 public enum ConflictAction
21 [Description("Defer Decision")]
23 [Description("Keep Local")]
25 [Description("Keep Server")]
27 [Description("Keep Both")]
29 [Description("Clear Record")]
33 public class ConflictFile:PropertyChangedBase
35 private string _filePath;
36 public string FilePath
38 get { return _filePath; }
42 NotifyOfPropertyChange(()=>FilePath);
46 private string _reason;
56 NotifyOfPropertyChange(() => Reason);
60 private ConflictAction _action;
61 public ConflictAction Action
63 get { return _action; }
67 NotifyOfPropertyChange(()=>Action);
71 public DateTime LocalModified { get; set; }
73 public DateTime CloudModified { get; set; }
75 public void GoToFile()
77 if (!File.Exists(FilePath) && !Directory.Exists(FilePath))
79 Process.Start("explorer.exe", "/select, " + FilePath);
82 [Export(typeof(ConflictsViewModel))]
83 class ConflictsViewModel:Screen
86 public IStatusKeeper StatusKeeper { get; set; }
89 public IConflictResolver Resolver { get; set; }
91 private readonly ObservableCollection<ConflictFile> _conflicts;
93 public ObservableCollection<ConflictFile> Conflicts
95 get { return _conflicts; }
98 public bool HasConflicts
100 get { return Conflicts!=null && Conflicts.Count > 0; }
103 public bool HasNoConflicts
105 get { return !HasConflicts; }
108 public string[] Actions
110 get { return new[] {"Keep Local", "Keep Server", "Keep Both"}; }
113 public ConflictsViewModel()
115 this.DisplayName="Conflicts";
116 var fileStates = from state in FileState.Queryable
117 where state.FileStatus == FileStatus.Conflict ||
118 state.OverlayStatus == FileOverlayStatus.Conflict
120 var conflicts = from state in fileStates
121 let info=FileInfoExtensions.FromPath(state.FilePath)
122 select new ConflictFile
124 FilePath = state.FilePath,
125 Reason=state.ConflictReason??state.FileStatus.Name() ,
126 LocalModified = info.LastWriteTime
128 _conflicts = new ObservableCollection<ConflictFile>(conflicts.ToList());
132 protected override void OnViewLoaded(object view)
134 base.OnViewLoaded(view);
135 StatusKeeper.CleanupOrphanStates();
139 /// Open an explorer window to the target path's directory
140 /// and select the file
142 /// <param name="entry"></param>
143 public void GoToFile(string fullPath)
145 if (!File.Exists(fullPath) && !Directory.Exists(fullPath))
147 Process.Start("explorer.exe", "/select, " + fullPath);
152 var conflicts = from conflict in Conflicts
153 where conflict.Action != ConflictAction.Defer
155 Resolver.Resolve(conflicts);
168 internal interface IConflictResolver
170 void Resolve(IEnumerable<ConflictFile> conflicts);
173 [Export(typeof(IConflictResolver))]
174 public class DummyResolver:IConflictResolver
176 public void Resolve(IEnumerable<ConflictFile> conflicts)