{
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)
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;
}
}
- [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; }
}
+
}
}
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));
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, ""));
+
}
{
//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
{
//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
<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"
[Import]
public IConflictResolver Resolver { get; set; }
- private readonly ObservableCollection<ConflictFile> _conflicts;
+ private readonly ObservableCollection<ConflictFile> _conflicts=new ObservableCollection<ConflictFile>();
public ObservableCollection<ConflictFile> Conflicts
{
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();
}
void Resolve(IEnumerable<ConflictFile> conflicts);
}
- [Export(typeof(IConflictResolver))]
public class DummyResolver:IConflictResolver
{
+
+
public void Resolve(IEnumerable<ConflictFile> conflicts)
{
private AccountInfo _accountInfo;
+ public AccountInfo Account
+ {
+ get { return _accountInfo; }
+ }
+