From a308d2918490f90b84b83d58d7b9c2fab31d0865 Mon Sep 17 00:00:00 2001 From: pkanavos Date: Fri, 11 May 2012 23:26:14 +0300 Subject: [PATCH] Added Clear Conflict action to resolver --- .../Converters/EnumTypeConverter.cs | 77 ++++++++++++++++---- .../FileProperties/ConflictResolver.cs | 51 ++++++++++++- .../FileProperties/ConflictsView.xaml | 51 +++++++------ .../FileProperties/ConflictsViewModel.cs | 40 ++++++---- trunk/Pithos.Core/PithosMonitor.cs | 5 ++ 5 files changed, 170 insertions(+), 54 deletions(-) diff --git a/trunk/Pithos.Client.WPF/Converters/EnumTypeConverter.cs b/trunk/Pithos.Client.WPF/Converters/EnumTypeConverter.cs index ee8ca84..26effb7 100644 --- a/trunk/Pithos.Client.WPF/Converters/EnumTypeConverter.cs +++ b/trunk/Pithos.Client.WPF/Converters/EnumTypeConverter.cs @@ -8,11 +8,14 @@ namespace Pithos.Client.WPF.Converters { public class EnumTypeConverter : EnumConverter { - public EnumTypeConverter(Type enumType) : base(enumType) { } + public EnumTypeConverter(Type enumType) : base(enumType) + { + } - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, + Type destinationType) { - if (destinationType == typeof(string) && value != null) + if (destinationType == typeof (string) && value != null) { var enumType = value.GetType(); if (enumType.IsEnum) @@ -21,11 +24,12 @@ namespace Pithos.Client.WPF.Converters return base.ConvertTo(context, culture, value, destinationType); } + private string GetDisplayName(object enumValue) { var displayNameAttribute = EnumType.GetField(enumValue.ToString()) - .GetCustomAttributes(typeof(DescriptionAttribute), false) - .FirstOrDefault() as DescriptionAttribute; + .GetCustomAttributes(typeof (DescriptionAttribute), false) + .FirstOrDefault() as DescriptionAttribute; if (displayNameAttribute != null) return displayNameAttribute.Description; @@ -33,27 +37,70 @@ namespace Pithos.Client.WPF.Converters } } - [MarkupExtensionReturnType(typeof(object[]))] + public class EnumValuesExtension : MarkupExtension { - public EnumValuesExtension() - { - } + + private Type _enumType; + public EnumValuesExtension(Type enumType) { + if (enumType == null) + throw new ArgumentNullException("enumType"); + EnumType = enumType; } - [ConstructorArgument("enumType")] - public Type EnumType { get; set; } + public Type EnumType + { + get { return _enumType; } + private set + { + if (_enumType == value) + return; + + var enumType = Nullable.GetUnderlyingType(value) ?? value; + + if (enumType.IsEnum == false) + throw new ArgumentException("Type must be an Enum."); + + _enumType = value; + } + } + + public override object ProvideValue (IServiceProvider serviceProvider) + { + var enumValues = Enum.GetValues(EnumType); - public override object ProvideValue(IServiceProvider serviceProvider) + return ( from object enumValue in enumValues + select new EnumerationMember + { + Value = enumValue, + Description = GetDescription(enumValue) + }).ToArray(); + } + + private string GetDescription (object enumValue) { - if (EnumType == null) - throw new ArgumentException("The enum type is not set"); - return Enum.GetValues(EnumType); + var descriptionAttribute = EnumType + .GetField(enumValue.ToString()) + .GetCustomAttributes(typeof (DescriptionAttribute), false) + .FirstOrDefault() as DescriptionAttribute; + + + return descriptionAttribute != null + ? descriptionAttribute.Description + : enumValue.ToString(); + } + + public class EnumerationMember + { + public string Description { get; set; } + + public object Value { get; set; } } + } } diff --git a/trunk/Pithos.Client.WPF/FileProperties/ConflictResolver.cs b/trunk/Pithos.Client.WPF/FileProperties/ConflictResolver.cs index 010e956..c38c7e3 100644 --- a/trunk/Pithos.Client.WPF/FileProperties/ConflictResolver.cs +++ b/trunk/Pithos.Client.WPF/FileProperties/ConflictResolver.cs @@ -1,12 +1,25 @@ using System; using System.Collections.Generic; +using System.ComponentModel.Composition; using System.Linq; using System.Text; +using Caliburn.Micro; +using Pithos.Core; +using Pithos.Core.Agents; +using Pithos.Interfaces; +using Pithos.Network; namespace Pithos.Client.WPF.FileProperties { - public class ConflictResolver:IConflictResolver + [Export(typeof(IConflictResolver))] + public class ConflictResolver : IConflictResolver { + [Import] + public IStatusKeeper StatusAgent { get; set; } + + [Import] + public NetworkAgent NetworkAgent { get; set; } + public void Resolve(IEnumerable conflicts) { KeepServer(conflicts.Where(c => c.Action == ConflictAction.KeepServer)); @@ -21,6 +34,9 @@ namespace Pithos.Client.WPF.FileProperties private void ClearLocal(IEnumerable conflicts) { //This can be done simply by changing the local Filestate status to normal + conflicts.Apply(clear => + StatusAgent.SetFileState(clear.FilePath, FileStatus.Unchanged, FileOverlayStatus.Normal, "")); + } @@ -30,7 +46,20 @@ namespace Pithos.Client.WPF.FileProperties { //This can be done either by scheduling the appropriate action, ignoring the hash //Or directly downloading the file. + + foreach (var conflict in conflicts) + { + //a.Post(new CloudDownloadAction()); + PithosMonitor monitor; +/* + var account = monitor.Account; + var oi=monitor.GetObjectInfo(conflict.FilePath); + NetworkAgent.Post(new CloudDownloadAction(account,oi,"Resolver")); +*/ + } + + } //Keeping the server version means that we need to @@ -39,7 +68,25 @@ namespace Pithos.Client.WPF.FileProperties { //This can be done either by scheduling the appropriate action, ignoring the hash //Or directly uploading the file. - + foreach (var conflict in conflicts) + { + var info = FileInfoExtensions.FromPath(conflict.FilePath); + var state=StatusAgent.GetStateByFilePath(conflict.FilePath); + PithosMonitor monitor; + +/* + var pair=(from monitor in Monitors + where conflict.FilePath.StartsWith(monitor.Value.RootPath, StringComparison.InvariantCultureIgnoreCase) + select monitor).FirstOrDefault(); + var accountMonitor = pair.Value; +*/ +/* + var account = monitor.Account; + //var oi=monitor.GetObjectInfo(conflict.FilePath); + NetworkAgent.Post(new CloudUploadAction(account,info,state,account.BlockSize,account.BlockHash,"Resolver")); + //NetworkAgent.Post(new CloudUploadAction(,info,conflict.FileState,NetworkAgent.)); +*/ + } } //Keeping both versions means that we need to copy one of them diff --git a/trunk/Pithos.Client.WPF/FileProperties/ConflictsView.xaml b/trunk/Pithos.Client.WPF/FileProperties/ConflictsView.xaml index acd9509..4cacf2a 100644 --- a/trunk/Pithos.Client.WPF/FileProperties/ConflictsView.xaml +++ b/trunk/Pithos.Client.WPF/FileProperties/ConflictsView.xaml @@ -7,18 +7,26 @@ - - - + + + + + + + + + - + + + @@ -31,21 +39,22 @@ Visibility="{Binding Converter={StaticResource BoolToVisible}, Path=HasConflicts}" > - - - - - - - - - - + + + + + + _conflicts; + private readonly ObservableCollection _conflicts=new ObservableCollection(); public ObservableCollection Conflicts { @@ -112,26 +112,33 @@ namespace Pithos.Client.WPF.FileProperties public ConflictsViewModel() { - this.DisplayName="Conflicts"; - var fileStates = from state in FileState.Queryable - where state.FileStatus == FileStatus.Conflict || - state.OverlayStatus == FileOverlayStatus.Conflict - select state; - var conflicts = from state in fileStates - let info=FileInfoExtensions.FromPath(state.FilePath) - select new ConflictFile - { - FilePath = state.FilePath, - Reason=state.ConflictReason??state.FileStatus.Name() , - LocalModified = info.LastWriteTime - }; - _conflicts = new ObservableCollection(conflicts.ToList()); + this.DisplayName="Conflicts"; } protected override void OnViewLoaded(object view) { base.OnViewLoaded(view); + var fileStates = from state in FileState.Queryable + where state.FileStatus == FileStatus.Conflict || + state.OverlayStatus == FileOverlayStatus.Conflict + select state; + var conflicts = from state in fileStates + let info = FileInfoExtensions.FromPath(state.FilePath) + select new ConflictFile + { + FilePath = state.FilePath, + Reason = state.ConflictReason ?? state.FileStatus.Name(), + LocalModified = info.LastWriteTime + }; + Conflicts.Clear(); + foreach (var conflict in conflicts) + { + Conflicts.Add(conflict); + } + NotifyOfPropertyChange(()=>Conflicts); + NotifyOfPropertyChange(() => HasConflicts); + NotifyOfPropertyChange(() => HasNoConflicts); StatusKeeper.CleanupOrphanStates(); } @@ -170,9 +177,10 @@ namespace Pithos.Client.WPF.FileProperties void Resolve(IEnumerable conflicts); } - [Export(typeof(IConflictResolver))] public class DummyResolver:IConflictResolver { + + public void Resolve(IEnumerable conflicts) { diff --git a/trunk/Pithos.Core/PithosMonitor.cs b/trunk/Pithos.Core/PithosMonitor.cs index b5c250e..49bd13c 100644 --- a/trunk/Pithos.Core/PithosMonitor.cs +++ b/trunk/Pithos.Core/PithosMonitor.cs @@ -148,6 +148,11 @@ namespace Pithos.Core private AccountInfo _accountInfo; + public AccountInfo Account + { + get { return _accountInfo; } + } + -- 1.7.10.4