Revision a308d291

b/trunk/Pithos.Client.WPF/Converters/EnumTypeConverter.cs
8 8
{
9 9
    public class EnumTypeConverter : EnumConverter
10 10
    {
11
        public EnumTypeConverter(Type enumType) : base(enumType) { }
11
        public EnumTypeConverter(Type enumType) : base(enumType)
12
        {
13
        }
12 14

  
13
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
15
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
16
                                         Type destinationType)
14 17
        {
15
            if (destinationType == typeof(string) && value != null)
18
            if (destinationType == typeof (string) && value != null)
16 19
            {
17 20
                var enumType = value.GetType();
18 21
                if (enumType.IsEnum)
......
21 24

  
22 25
            return base.ConvertTo(context, culture, value, destinationType);
23 26
        }
27

  
24 28
        private string GetDisplayName(object enumValue)
25 29
        {
26 30
            var displayNameAttribute = EnumType.GetField(enumValue.ToString())
27
                                                                 .GetCustomAttributes(typeof(DescriptionAttribute), false)
28
                                                                 .FirstOrDefault() as DescriptionAttribute;
31
                                           .GetCustomAttributes(typeof (DescriptionAttribute), false)
32
                                           .FirstOrDefault() as DescriptionAttribute;
29 33
            if (displayNameAttribute != null)
30 34
                return displayNameAttribute.Description;
31 35

  
......
33 37
        }
34 38
    }
35 39

  
36
    [MarkupExtensionReturnType(typeof(object[]))]
40
    
37 41
    public class EnumValuesExtension : MarkupExtension
38 42
    {
39
        public EnumValuesExtension()
40
        {
41
        }
43

  
44
        private  Type _enumType;
45

  
42 46

  
43 47
        public EnumValuesExtension(Type enumType)
44 48
        {
49
            if (enumType == null)
50
                throw new ArgumentNullException("enumType");
51

  
45 52
            EnumType = enumType;
46 53
        }
47 54

  
48
        [ConstructorArgument("enumType")]
49
        public Type EnumType { get; set; }
55
        public Type EnumType
56
        {
57
            get { return _enumType; }
58
            private set 
59
            {
60
                if (_enumType == value)
61
                    return;
62

  
63
                var enumType = Nullable.GetUnderlyingType(value) ?? value;
64

  
65
                if (enumType.IsEnum == false)
66
                    throw new ArgumentException("Type must be an Enum.");
67

  
68
                _enumType = value;
69
            }
70
        }
71

  
72
        public override object ProvideValue (IServiceProvider serviceProvider)
73
        {
74
            var enumValues = Enum.GetValues(EnumType);
50 75

  
51
        public override object ProvideValue(IServiceProvider serviceProvider)
76
            return ( from object enumValue in enumValues
77
                       select new EnumerationMember
78
                                  {
79
                                      Value = enumValue,
80
                                      Description = GetDescription(enumValue)
81
                                  }).ToArray();
82
        }
83

  
84
        private string GetDescription (object enumValue)
52 85
        {
53
            if (EnumType == null)
54
                throw new ArgumentException("The enum type is not set");
55
            return Enum.GetValues(EnumType);
86
            var descriptionAttribute = EnumType
87
                                           .GetField(enumValue.ToString())
88
                                           .GetCustomAttributes(typeof (DescriptionAttribute), false)
89
                                           .FirstOrDefault() as DescriptionAttribute;
90

  
91

  
92
            return descriptionAttribute != null
93
                       ? descriptionAttribute.Description
94
                       : enumValue.ToString();
95
        }
96

  
97
        public class EnumerationMember
98
        {
99
            public string Description { get; set; }
100

  
101
            public object Value { get; set; }
56 102
        }
103

  
57 104
    }
58 105

  
59 106
}
b/trunk/Pithos.Client.WPF/FileProperties/ConflictResolver.cs
1 1
using System;
2 2
using System.Collections.Generic;
3
using System.ComponentModel.Composition;
3 4
using System.Linq;
4 5
using System.Text;
6
using Caliburn.Micro;
7
using Pithos.Core;
8
using Pithos.Core.Agents;
9
using Pithos.Interfaces;
10
using Pithos.Network;
5 11

  
6 12
namespace Pithos.Client.WPF.FileProperties
7 13
{
8
    public class ConflictResolver:IConflictResolver
14
    [Export(typeof(IConflictResolver))]
15
    public class ConflictResolver : IConflictResolver
9 16
    {
17
        [Import]
18
        public IStatusKeeper StatusAgent { get; set; }
19

  
20
        [Import]
21
        public NetworkAgent NetworkAgent { get; set; }
22

  
10 23
        public void Resolve(IEnumerable<ConflictFile> conflicts)
11 24
        {
12 25
            KeepServer(conflicts.Where(c => c.Action == ConflictAction.KeepServer));
......
21 34
        private void ClearLocal(IEnumerable<ConflictFile> conflicts)
22 35
        {
23 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, ""));    
39

  
24 40
        }
25 41

  
26 42

  
......
30 46
        {
31 47
            //This can be done either by scheduling the appropriate action, ignoring the hash
32 48
            //Or directly downloading the file.
49

  
33 50
            
51
            foreach (var conflict in conflicts)
52
            {
53
                //a.Post(new CloudDownloadAction());    
54
                PithosMonitor monitor;
55
/*
56
                var account = monitor.Account;
57
                var oi=monitor.GetObjectInfo(conflict.FilePath);                                
58
                NetworkAgent.Post(new CloudDownloadAction(account,oi,"Resolver"));
59
*/
60
            }
61
            
62

  
34 63
        }
35 64

  
36 65
        //Keeping the server version means that we need to 
......
39 68
        {
40 69
            //This can be done either by scheduling the appropriate action, ignoring the hash
41 70
            //Or directly uploading the file.
42
            
71
            foreach (var conflict in conflicts)
72
            {
73
                var info = FileInfoExtensions.FromPath(conflict.FilePath);
74
                var state=StatusAgent.GetStateByFilePath(conflict.FilePath);
75
                PithosMonitor monitor;
76

  
77
/*
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;
82
*/
83
/*
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.));
88
*/
89
            }
43 90
        }
44 91

  
45 92
        //Keeping both versions means that we need to copy one of them
b/trunk/Pithos.Client.WPF/FileProperties/ConflictsView.xaml
7 7
    <Window.Resources>
8 8
        <ResourceDictionary>
9 9
            <ContextMenu  x:Key="RowMenu" DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
10
            <MenuItem Header="{Binding FilePath}" cal:Message.Attach="GoToFile"/>
11
        </ContextMenu>
12
        <Style x:Key="DefaultRowStyle" TargetType="{x:Type DataGridRow}">
13
            <Setter Property="ContextMenu" Value="{StaticResource RowMenu}" />
14
        </Style>
10
                <MenuItem Header="{Binding FilePath}" cal:Message.Attach="GoToFile"/>
11
            </ContextMenu>
12
            <ObjectDataProvider x:Key="ActionsList" MethodName="GetValues" ObjectType="{x:Type model:ConflictAction}">
13
                <ObjectDataProvider.MethodParameters>
14
                    <x:Type TypeName="model:ConflictAction"/>
15
                </ObjectDataProvider.MethodParameters>
16
            </ObjectDataProvider>
17

  
18
            <Style x:Key="DefaultRowStyle" TargetType="{x:Type DataGridRow}">
19
                <Setter Property="ContextMenu" Value="{StaticResource RowMenu}" />
20
            </Style>
15 21
            <BooleanToVisibilityConverter x:Key="BoolToVisible" />
16 22
            <my:InverseBoolConverter x:Key="BoolToInvisible" />
17 23
            <ResourceDictionary.MergedDictionaries>
18 24
                    <ResourceDictionary Source="..\PithosStyles.xaml" />
19 25
                </ResourceDictionary.MergedDictionaries>
20
            </ResourceDictionary>
26

  
27
        </ResourceDictionary>
21 28
    </Window.Resources>
29
    
22 30
    <Grid>
23 31
        <Grid.RowDefinitions>
24 32
            <RowDefinition />
......
31 39
                  Visibility="{Binding Converter={StaticResource BoolToVisible}, Path=HasConflicts}"
32 40
                  >
33 41
            <DataGrid.Columns>
34
                <DataGridTextColumn x:Name="FilePath" Binding="{Binding FilePath}" Header="File" Width="*" />
35
                <DataGridTextColumn x:Name="LocalModified" Binding="{Binding LocalModified}" Header="Local Date" Width="Auto" />
36
                <DataGridTextColumn x:Name="Reason" Binding="{Binding Reason}" Header="Reason" Width="Auto" />
37
                <DataGridTemplateColumn x:Name="Action" Header="Action" Width="Auto">
38
                    <DataGridTemplateColumn.CellTemplate>
39
                        <DataTemplate>
40
                        <ComboBox x:Name="Action" ItemsSource="{cnv:EnumValues model:ConflictAction}" 
41
                                  SelectedValue="{Binding Action}" Grid.Column="2" 
42
                                  HorizontalAlignment="Right" 
43
                                  HorizontalContentAlignment="Left"
44
                                  Width="110" Margin="5" Padding="5,2"
45
                                  />
46
                        </DataTemplate>
47
                    </DataGridTemplateColumn.CellTemplate>
48
                </DataGridTemplateColumn>
42
                <DataGridTextColumn x:Name="FilePath" Binding="{Binding FilePath}" Header="File" Width="*" IsReadOnly="True" />
43
                <DataGridTextColumn x:Name="LocalModified" Binding="{Binding LocalModified}" Header="Local Date" Width="Auto" IsReadOnly="True"/>
44
                <DataGridTextColumn x:Name="Reason" Binding="{Binding Reason}" Header="Reason" Width="Auto" IsReadOnly="True"/>
45
                <DataGridComboBoxColumn x:Name="Action"  Header="Action" Width="Auto" 
46
                                    ItemsSource="{Binding Source={StaticResource ActionsList}}"                                                                                 
47
                                    SelectedValueBinding="{Binding Action}" >
48
                 <!--   <DataGridComboBoxColumn.CellStyle>
49
                        <Style  TargetType="{x:Type DataGridCell}">
50
                            <Style.Triggers>
51
                                <Trigger Property="IsSelected" Value="True">
52
                                    <Setter Property="IsEditing" Value="True" />
53
                                </Trigger>
54
                            </Style.Triggers>
55
                        </Style>
56
                    </DataGridComboBoxColumn.CellStyle>-->
57
                </DataGridComboBoxColumn>
49 58
            </DataGrid.Columns>
50 59
        </DataGrid>
51 60
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center" 
b/trunk/Pithos.Client.WPF/FileProperties/ConflictsViewModel.cs
88 88
        [Import]
89 89
        public IConflictResolver Resolver { get; set; }
90 90

  
91
        private readonly ObservableCollection<ConflictFile> _conflicts;
91
        private readonly ObservableCollection<ConflictFile> _conflicts=new ObservableCollection<ConflictFile>();
92 92

  
93 93
        public ObservableCollection<ConflictFile> Conflicts
94 94
        {
......
112 112

  
113 113
        public ConflictsViewModel()
114 114
        {
115
			this.DisplayName="Conflicts";
116
            var fileStates = from state in FileState.Queryable
117
                         where state.FileStatus == FileStatus.Conflict ||
118
                               state.OverlayStatus == FileOverlayStatus.Conflict
119
                         select state;
120
            var conflicts = from state in fileStates
121
                            let info=FileInfoExtensions.FromPath(state.FilePath)
122
                            select new ConflictFile
123
                                       {
124
                                           FilePath = state.FilePath,
125
                                           Reason=state.ConflictReason??state.FileStatus.Name() ,
126
                                           LocalModified = info.LastWriteTime
127
                                       };          
128
            _conflicts = new ObservableCollection<ConflictFile>(conflicts.ToList());
115
			this.DisplayName="Conflicts";            
129 116
            
130 117
        }
131 118

  
132 119
        protected override void OnViewLoaded(object view)
133 120
        {
134 121
            base.OnViewLoaded(view);
122
            var fileStates = from state in FileState.Queryable
123
                             where state.FileStatus == FileStatus.Conflict ||
124
                                   state.OverlayStatus == FileOverlayStatus.Conflict
125
                             select state;
126
            var conflicts = from state in fileStates
127
                            let info = FileInfoExtensions.FromPath(state.FilePath)
128
                            select new ConflictFile
129
                            {
130
                                FilePath = state.FilePath,
131
                                Reason = state.ConflictReason ?? state.FileStatus.Name(),
132
                                LocalModified = info.LastWriteTime
133
                            };
134
            Conflicts.Clear();
135
            foreach (var conflict in conflicts)
136
            {
137
                Conflicts.Add(conflict);
138
            }
139
            NotifyOfPropertyChange(()=>Conflicts);
140
            NotifyOfPropertyChange(() => HasConflicts);
141
            NotifyOfPropertyChange(() => HasNoConflicts);
135 142
            StatusKeeper.CleanupOrphanStates();
136 143
        }
137 144

  
......
170 177
        void Resolve(IEnumerable<ConflictFile> conflicts);
171 178
    }
172 179

  
173
    [Export(typeof(IConflictResolver))]
174 180
    public class DummyResolver:IConflictResolver
175 181
    {
182

  
183

  
176 184
        public void Resolve(IEnumerable<ConflictFile> conflicts)
177 185
        {
178 186
            
b/trunk/Pithos.Core/PithosMonitor.cs
148 148

  
149 149
        private AccountInfo _accountInfo;
150 150

  
151
        public AccountInfo Account
152
        {
153
            get { return _accountInfo; }
154
        }
155

  
151 156

  
152 157

  
153 158

  

Also available in: Unified diff