public static IListenerRegistration Subscribe <TModel, TViewModel, TKey>(IQuery query,
                                                                          SortedObservableCollection <TViewModel, TModel, TKey> viewModels,
                                                                          Func <TModel, TViewModel> getViewModel,
                                                                          Action?afterSnapshotProcessed = null)
     where TModel : BaseModel
     where TViewModel : IndexedCardViewModel <TModel>
 {
     viewModels.Clear();
     return(query.AddSnapshotListener((snapshot, ex) =>
     {
         if (snapshot is null)
         {
             viewModels.Clear();
         }
         else if (viewModels.Any())
         {
             foreach (var change in snapshot.DocumentChanges)
             {
                 var doc = change.Document;
                 if (change.Type == DocumentChangeType.Added)
                 {
                     viewModels.Add(getViewModel(doc.ToObject <TModel>() !));
                 }
                 else
                 {
                     var vm = viewModels.SingleOrDefault(x => x.UID == doc.Id);
                     if (vm is null)
                     {
                         return;
                     }
                     if (change.Type == DocumentChangeType.Modified)
                     {
                         viewModels.UpdateItem(vm, change.Document.ToObject <TModel>() !);
                     }
                     else
                     {
                         viewModels.Remove(vm);
                     }
                 }
             }
         }
         else if (!snapshot.IsEmpty)
         {
             snapshot.Documents.ForEach(x => viewModels.Add(getViewModel(x.ToObject <TModel>() !)));
         }
         afterSnapshotProcessed?.Invoke();
     }));
 }
Esempio n. 2
0
 public void Clear()
 {
     foreach (var d in Drives)
     {
         (d as DriveContainer).Dispose();
     }
     Drives.Clear();
 }
Esempio n. 3
0
 void pageGameSetup_Loaded(object sender, RoutedEventArgs e)
 {
     if (System.ComponentModel.DesignerProperties.IsInDesignTool)
     {
         return;                 //HACK BUG VS Designer
     }
     fTskHolders.Clear();
     foreach (TTskSet tsk in game.cfg.tskSets)
     {
         fTskHolders.Add(new TTskHolder(tsk));
     }
     fTskHolders.Add(new TTskHolder());
 }
Esempio n. 4
0
        public void Test_Clear()
        {
            var listener = new EventListener();
            var coll     = new SortedObservableCollection <int> {
                0, 1, 2
            };

            coll.PropertyChanged   += listener.Consume;
            coll.CollectionChanged += listener.Consume;

            listener.Expect <PropertyChangedEventArgs>(x => x.PropertyName == "Count");
            listener.Expect <NotifyCollectionChangedEventArgs>(x =>
                                                               ValidateCollectionEvent(x, NotifyCollectionChangedAction.Reset));

            coll.Clear();

            listener.MakeAssert();
            Assert.AreEqual(0, coll.Count);
        }
Esempio n. 5
0
        private async Task LoadServiceConfigurationAsync()
        {
            var predefinedNetworkServices = await GetPredefinedNetworkServicesAsync();

            foreach (var networkService in predefinedNetworkServices)
            {
                networkService.IsEnabledChanged += OnPredefinedServiceSelectionIsEnabledChanged;
            }
            PredefinedNetworkServices = predefinedNetworkServices;

            var userNetworkServices = await GetUserNetworkServicesAsync();

            m_userNetworkServices.Clear();
            foreach (var networkService in userNetworkServices)
            {
                networkService.IsEnabledChanged += OnUserServiceSelectionIsEnabledChanged;
                m_userNetworkServices.Add(networkService);
            }
        }
 public void Clear()
 {
     subGroups.Clear();
     Templates.Clear();
 }
Esempio n. 7
0
 /// <summary>
 /// Clears the items
 /// </summary>
 private void ClearItems()
 {
     _insertItems.Clear();
     OnItemsChanged();
 }