2 using System.Collections.Generic;
3 using System.ComponentModel.Composition;
8 using Pithos.Core.Agents;
9 using Pithos.Interfaces;
12 namespace Pithos.Client.WPF.FileProperties
14 [Export(typeof(IConflictResolver))]
15 public class ConflictResolver : IConflictResolver
18 public IStatusKeeper StatusAgent { get; set; }
21 public NetworkAgent NetworkAgent { get; set; }
23 public void Resolve(IEnumerable<ConflictFile> conflicts)
25 KeepServer(conflicts.Where(c => c.Action == ConflictAction.KeepServer));
26 KeepLocal(conflicts.Where(c => c.Action == ConflictAction.KeepLocal));
27 KeepBoth(conflicts.Where(c => c.Action == ConflictAction.KeepBoth));
28 ClearLocal(conflicts.Where(c => c.Action == ConflictAction.ClearLocal));
32 //Clearing the local state means that we clear the conflict state of the local file.
33 //This is needed to clear wrong conflicts
34 private void ClearLocal(IEnumerable<ConflictFile> conflicts)
36 //This can be done simply by changing the local Filestate status to normal
37 conflicts.Apply(clear =>
38 StatusAgent.SetFileState(clear.FilePath, FileStatus.Unchanged, FileOverlayStatus.Normal, ""));
43 //Keeping the server version means that we need to
44 //download the server's version of the file.
45 private void KeepServer(IEnumerable<ConflictFile> conflicts)
47 //This can be done either by scheduling the appropriate action, ignoring the hash
48 //Or directly downloading the file.
51 foreach (var conflict in conflicts)
53 //a.Post(new CloudDownloadAction());
54 PithosMonitor monitor;
56 var account = monitor.Account;
57 var oi=monitor.GetObjectInfo(conflict.FilePath);
58 NetworkAgent.Post(new CloudDownloadAction(account,oi,"Resolver"));
65 //Keeping the server version means that we need to
66 //upload the local version of the file to the server
67 private void KeepLocal(IEnumerable<ConflictFile> conflicts)
69 //This can be done either by scheduling the appropriate action, ignoring the hash
70 //Or directly uploading the file.
71 foreach (var conflict in conflicts)
73 var info = FileInfoExtensions.FromPath(conflict.FilePath);
74 var state=StatusAgent.GetStateByFilePath(conflict.FilePath);
75 PithosMonitor monitor;
78 var pair=(from monitor in Monitors
79 where conflict.FilePath.StartsWith(monitor.Value.RootPath, StringComparison.InvariantCultureIgnoreCase)
80 select monitor).FirstOrDefault();
81 var accountMonitor = pair.Value;
84 var account = monitor.Account;
85 //var oi=monitor.GetObjectInfo(conflict.FilePath);
86 NetworkAgent.Post(new CloudUploadAction(account,info,state,account.BlockSize,account.BlockHash,"Resolver"));
87 //NetworkAgent.Post(new CloudUploadAction(,info,conflict.FileState,NetworkAgent.));
92 //Keeping both versions means that we need to copy one of them
93 //somewhere and keep the other
94 private void KeepBoth(IEnumerable<ConflictFile> conflicts)
96 //We can copy the rename the local file to another name and download the server file
97 //Or rename the server file and upload the local file
99 //Downloading the server file is probably much faster with ADSL connections
101 //We could probably use the local file as a source of blocks to download fewer data,
102 //We create a hashmap of the local file, download the differences from the server
103 //and merge common and changed blocks to create the new file.