2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using System.Collections.Specialized;
9 using Pithos.Client.WPF.Properties;
10 using Pithos.Interfaces;
13 namespace Pithos.Client.WPF.SelectiveSynch
15 class SelectiveSynchViewModel:Screen
17 private IEventAggregator _events ;
19 private string _rootPath;
20 private string _fragmentsPath;
21 public string RootPath
23 get { return _rootPath; }
27 _fragmentsPath = Path.Combine(_rootPath, FolderConstants.FragmentsFolder);
28 _pithosDirectory = new ObservableCollection<DirectoryRecord>{
29 new DirectoryRecord(_fragmentsPath) {Info = new DirectoryInfo(value)}};
30 NotifyOfPropertyChange(() => RootPath);
31 NotifyOfPropertyChange(()=>PithosDirectory);
35 private string _title;
38 get { return _title; }
42 NotifyOfPropertyChange(() => Title);
46 public AccountSettings Account { get; set; }
48 private ObservableCollection<DirectoryRecord> _pithosDirectory;
49 public ObservableCollection<DirectoryRecord> PithosDirectory
51 get { return _pithosDirectory; }
54 private ObservableCollection<DirectoryInfo> _checks;
55 public ObservableCollection<DirectoryInfo> Checks
57 get { return _checks; }
60 public void GetChecks()
62 var root = PithosDirectory[0];
63 _checks = new ObservableCollection<DirectoryInfo>(
65 where record.IsChecked==true
67 NotifyOfPropertyChange(() => Checks);
70 public SelectiveSynchViewModel(IEventAggregator events, AccountSettings account)
73 AccountName = account.AccountName;
74 Title = account.AccountName;
75 RootPath = account.RootPath;
77 SetInitialSelections(account);
80 private void SetInitialSelections(AccountSettings account)
82 var selections = account.SelectiveFolders;
83 if (selections.Count == 0)
85 var root = PithosDirectory[0];
86 var selects= from record in root
87 where selections.Contains(record.Info.FullName)
89 selects.Apply(record=>record.IsChecked=true);
92 protected string AccountName { get; set; }
94 public void SaveChanges()
96 var selections = GetSelectedFolderNames();
98 SaveSettings(selections);
99 var root = PithosDirectory[0];
101 var added= (from record in root
103 select record.Info.FullName.ToLower()).ToArray();
104 var removed= (from record in root
106 select record.Info.FullName.ToLower()).ToArray();
108 _events.Publish(new SelectiveSynchChanges{Account=Account,Added=added,Removed=removed});
117 private void SaveSettings(string[] selections)
119 Account.SelectiveFolders.Clear();
120 Account.SelectiveFolders.AddRange(selections);
121 Settings.Default.Save();
124 private string[] GetSelectedFolderNames()
126 var root = PithosDirectory[0];
127 var selections = from record in root
128 where record.IsChecked == true
129 select record.Info.FullName;
130 return selections.ToArray();
133 public void RejectChanges()