Added Clear Conflict action to resolver
authorpkanavos <pkanavos@gmail.com>
Fri, 11 May 2012 20:26:14 +0000 (23:26 +0300)
committerpkanavos <pkanavos@gmail.com>
Fri, 11 May 2012 20:26:14 +0000 (23:26 +0300)
trunk/Pithos.Client.WPF/Converters/EnumTypeConverter.cs
trunk/Pithos.Client.WPF/FileProperties/ConflictResolver.cs
trunk/Pithos.Client.WPF/FileProperties/ConflictsView.xaml
trunk/Pithos.Client.WPF/FileProperties/ConflictsViewModel.cs
trunk/Pithos.Core/PithosMonitor.cs

index ee8ca84..26effb7 100644 (file)
@@ -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; }
         }
+
     }
 
 }
index 010e956..c38c7e3 100644 (file)
@@ -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<ConflictFile> conflicts)
         {
             KeepServer(conflicts.Where(c => c.Action == ConflictAction.KeepServer));
@@ -21,6 +34,9 @@ namespace Pithos.Client.WPF.FileProperties
         private void ClearLocal(IEnumerable<ConflictFile> 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
index acd9509..4cacf2a 100644 (file)
@@ -7,18 +7,26 @@
     <Window.Resources>
         <ResourceDictionary>
             <ContextMenu  x:Key="RowMenu" DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
-            <MenuItem Header="{Binding FilePath}" cal:Message.Attach="GoToFile"/>
-        </ContextMenu>
-        <Style x:Key="DefaultRowStyle" TargetType="{x:Type DataGridRow}">
-            <Setter Property="ContextMenu" Value="{StaticResource RowMenu}" />
-        </Style>
+                <MenuItem Header="{Binding FilePath}" cal:Message.Attach="GoToFile"/>
+            </ContextMenu>
+            <ObjectDataProvider x:Key="ActionsList" MethodName="GetValues" ObjectType="{x:Type model:ConflictAction}">
+                <ObjectDataProvider.MethodParameters>
+                    <x:Type TypeName="model:ConflictAction"/>
+                </ObjectDataProvider.MethodParameters>
+            </ObjectDataProvider>
+
+            <Style x:Key="DefaultRowStyle" TargetType="{x:Type DataGridRow}">
+                <Setter Property="ContextMenu" Value="{StaticResource RowMenu}" />
+            </Style>
             <BooleanToVisibilityConverter x:Key="BoolToVisible" />
             <my:InverseBoolConverter x:Key="BoolToInvisible" />
             <ResourceDictionary.MergedDictionaries>
                     <ResourceDictionary Source="..\PithosStyles.xaml" />
                 </ResourceDictionary.MergedDictionaries>
-            </ResourceDictionary>
+
+        </ResourceDictionary>
     </Window.Resources>
+    
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition />
                   Visibility="{Binding Converter={StaticResource BoolToVisible}, Path=HasConflicts}"
                   >
             <DataGrid.Columns>
-                <DataGridTextColumn x:Name="FilePath" Binding="{Binding FilePath}" Header="File" Width="*" />
-                <DataGridTextColumn x:Name="LocalModified" Binding="{Binding LocalModified}" Header="Local Date" Width="Auto" />
-                <DataGridTextColumn x:Name="Reason" Binding="{Binding Reason}" Header="Reason" Width="Auto" />
-                <DataGridTemplateColumn x:Name="Action" Header="Action" Width="Auto">
-                    <DataGridTemplateColumn.CellTemplate>
-                        <DataTemplate>
-                        <ComboBox x:Name="Action" ItemsSource="{cnv:EnumValues model:ConflictAction}" 
-                                  SelectedValue="{Binding Action}" Grid.Column="2" 
-                                  HorizontalAlignment="Right" 
-                                  HorizontalContentAlignment="Left"
-                                  Width="110" Margin="5" Padding="5,2"
-                                  />
-                        </DataTemplate>
-                    </DataGridTemplateColumn.CellTemplate>
-                </DataGridTemplateColumn>
+                <DataGridTextColumn x:Name="FilePath" Binding="{Binding FilePath}" Header="File" Width="*" IsReadOnly="True" />
+                <DataGridTextColumn x:Name="LocalModified" Binding="{Binding LocalModified}" Header="Local Date" Width="Auto" IsReadOnly="True"/>
+                <DataGridTextColumn x:Name="Reason" Binding="{Binding Reason}" Header="Reason" Width="Auto" IsReadOnly="True"/>
+                <DataGridComboBoxColumn x:Name="Action"  Header="Action" Width="Auto" 
+                                    ItemsSource="{Binding Source={StaticResource ActionsList}}"                                                                                 
+                                    SelectedValueBinding="{Binding Action}" >
+                 <!--   <DataGridComboBoxColumn.CellStyle>
+                        <Style  TargetType="{x:Type DataGridCell}">
+                            <Style.Triggers>
+                                <Trigger Property="IsSelected" Value="True">
+                                    <Setter Property="IsEditing" Value="True" />
+                                </Trigger>
+                            </Style.Triggers>
+                        </Style>
+                    </DataGridComboBoxColumn.CellStyle>-->
+                </DataGridComboBoxColumn>
             </DataGrid.Columns>
         </DataGrid>
         <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center" 
index 2ad1941..a1cb212 100644 (file)
@@ -88,7 +88,7 @@ namespace Pithos.Client.WPF.FileProperties
         [Import]
         public IConflictResolver Resolver { get; set; }
 
-        private readonly ObservableCollection<ConflictFile> _conflicts;
+        private readonly ObservableCollection<ConflictFile> _conflicts=new ObservableCollection<ConflictFile>();
 
         public ObservableCollection<ConflictFile> 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<ConflictFile>(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<ConflictFile> conflicts);
     }
 
-    [Export(typeof(IConflictResolver))]
     public class DummyResolver:IConflictResolver
     {
+
+
         public void Resolve(IEnumerable<ConflictFile> conflicts)
         {
             
index b5c250e..49bd13c 100644 (file)
@@ -148,6 +148,11 @@ namespace Pithos.Core
 
         private AccountInfo _accountInfo;
 
+        public AccountInfo Account
+        {
+            get { return _accountInfo; }
+        }
+