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;
13 using Pithos.Interfaces;
15 namespace Pithos.Client.WPF.FileProperties
17 [TypeConverter(typeof(EnumTypeConverter))]
18 public enum ConflictAction
20 [Description("Defer Decision")]
22 [Description("Keep Local")]
24 [Description("Keep Server")]
26 [Description("Keep Both")]
28 [Description("Clear Record")]
32 public class ConflictFile:PropertyChangedBase
34 private string _filePath;
35 public string FilePath
37 get { return _filePath; }
41 NotifyOfPropertyChange(()=>FilePath);
45 private string _reason;
48 get { return _reason; }
52 NotifyOfPropertyChange(() => Reason);
56 private ConflictAction _action;
57 public ConflictAction Action
59 get { return _action; }
63 NotifyOfPropertyChange(()=>Action);
67 public DateTime LocalModified { get; set; }
69 public DateTime CloudModified { get; set; }
71 public void GoToFile()
73 if (!File.Exists(FilePath) && !Directory.Exists(FilePath))
75 Process.Start("explorer.exe", "/select, " + FilePath);
78 [Export(typeof(ConflictsViewModel))]
79 class ConflictsViewModel:Screen
82 public IStatusKeeper StatusKeeper { get; set; }
85 public IConflictResolver Resolver { get; set; }
87 private readonly ObservableCollection<ConflictFile> _conflicts;
89 public ObservableCollection<ConflictFile> Conflicts
91 get { return _conflicts; }
94 public string[] Actions
96 get { return new[] {"Keep Local", "Keep Server", "Keep Both"}; }
99 public ConflictsViewModel()
101 this.DisplayName="Conflicts";
102 var conflicts = from state in FileState.Queryable
103 where state.FileStatus == FileStatus.Conflict ||
104 state.OverlayStatus == FileOverlayStatus.Conflict
105 let info=FileInfoExtensions.FromPath(state.FilePath)
106 select new ConflictFile {FilePath = state.FilePath,Reason=state.ConflictReason,LocalModified = info.LastWriteTime};
107 _conflicts = new ObservableCollection<ConflictFile>(conflicts.ToList());
112 /// Open an explorer window to the target path's directory
113 /// and select the file
115 /// <param name="entry"></param>
116 public void GoToFile(string fullPath)
118 if (!File.Exists(fullPath) && !Directory.Exists(fullPath))
120 Process.Start("explorer.exe", "/select, " + fullPath);
125 var conflicts = from conflict in Conflicts
126 where conflict.Action != ConflictAction.Defer
128 Resolver.Resolve(conflicts);
141 internal interface IConflictResolver
143 void Resolve(IEnumerable<ConflictFile> conflicts);