Esempio n. 1
0
 private void SettingsChangedMethod(object sender, NotifyCollectionChangedEventArgs e)
 {
     //different kind of changes that may have occurred in collection
     if (e.Action == NotifyCollectionChangedAction.Add)
     {
         foreach (Setting item in e.NewItems)
         {
             item.PropertyChanged += Setting_PropertyChanged;
             if (item.Scope == Setting.Scopes.DistributionSource.ToString() && item.Key != null)
             {
                 DistributionSourceMap[item.Key] = item.Value;
                 NotifyPropertyChanged("DistributionSourceMap");
             }
             if (item.Scope == Setting.Scopes.DistributionTarget.ToString() && item.Key != null)
             {
                 DistributionList.Add(new DistributionItem()
                 {
                     Folder = item.Key
                 });
                 DistributionTargetMap[item.Key] = item.Value;
                 NotifyPropertyChanged("DistributionTargetMap");
             }
             if (item.Scope == Setting.Scopes.DistributionExe.ToString() && item.Key != null)
             {
                 if (!Executables.Contains(item.Value))
                 {
                     Executables.Add(item.Value);
                 }
                 var distribution = DistributionList.FirstOrDefault(x => x.Folder == item.Key);
                 if (distribution != null)
                 {
                     distribution.Executable = item.Value;
                 }
             }
         }
     }
     if (e.Action == NotifyCollectionChangedAction.Replace)
     {
         foreach (Setting item in e.OldItems)
         {
             item.PropertyChanged -= Setting_PropertyChanged;
         }
         foreach (Setting item in e.NewItems)
         {
             item.PropertyChanged += Setting_PropertyChanged;
         }
     }
     if (e.Action == NotifyCollectionChangedAction.Remove)
     {
         foreach (Setting item in e.OldItems)
         {
             item.PropertyChanged -= Setting_PropertyChanged;
             if (item.Scope == Setting.Scopes.DistributionSource.ToString() && item.Key != null)
             {
                 DistributionSourceMap.Remove(item.Key);
             }
             if (item.Scope == Setting.Scopes.DistributionTarget.ToString() && item.Key != null)
             {
                 DistributionTargetMap.Remove(item.Key);
             }
             if (item.Scope == Setting.Scopes.DistributionExe.ToString() && item.Key != null)
             {
                 var setting = SettingsList.First(x => (x.Scope == item.Scope && x.Value == item.Value));
                 if (setting == null && Executables.Contains(item.Value))
                 {
                     Executables.Remove(item.Value);
                 }
                 var distribution = DistributionList.First(x => x.Folder == item.Key);
                 if (distribution != null)
                 {
                     distribution.Executable = "";
                 }
             }
         }
     }
     if (e.Action == NotifyCollectionChangedAction.Move)
     {
         //your code
     }
 }