Esempio n. 1
0
        /// <summary>
        /// Shuts down the specified presenter.
        /// </summary>
        /// <param name="presenter">The presenter.</param>
        /// <param name="completed">Called when the open action is finished.</param>
        public virtual void Shutdown(IPresenter presenter, Action <bool> completed)
        {
            if (presenter == null)
            {
                completed(true);
                return;
            }

            CanShutdownPresenter(
                presenter,
                isSuccess => {
                if (!isSuccess)
                {
                    completed(false);
                    return;
                }

                _presenters.Remove(presenter);

                presenter.Deactivate();
                presenter.Shutdown();

                var node = presenter as IPresenterNode;
                if (node != null)
                {
                    node.Parent = null;
                }

                completed(true);
            });
        }
Esempio n. 2
0
        private void SynchronizeSelectionCollections <TSource, TTarget>(IObservableCollection <TTarget> collection, Func <TSource, TTarget> getItem, NotifyCollectionChangedEventArgs e)
        {
            if (synchronizingSelection)
            {
                return;
            }

            synchronizingSelection = true;
            if (e.NewItems != null)
            {
                foreach (TSource newItem in e.NewItems)
                {
                    var targetItem = getItem(newItem);
                    collection.Add(targetItem);
                }
            }
            if (e.OldItems != null)
            {
                foreach (TSource oldItem in e.OldItems)
                {
                    var targetItem = getItem(oldItem);
                    collection.Remove(targetItem);
                }
            }
            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                collection.Clear();
            }
            synchronizingSelection = false;
        }
Esempio n. 3
0
        /// <summary>
        /// Shuts down the current presenter.
        /// </summary>
        /// <param name="completed">Called when the shutdown action is finished.</param>
        public virtual void ShutdownCurrent(Action <bool> completed)
        {
            if (_currentPresenter == null)
            {
                completed(true);
                return;
            }

            CanShutdownPresenter(
                _currentPresenter,
                isSuccess =>
            {
                if (!isSuccess)
                {
                    completed(false);
                    return;
                }

                var lastCurrent = _currentPresenter;
                int index       = _presenters.IndexOf(lastCurrent);
                var next        = DetermineNextPresenterToActivate(index);

                if (next != null)
                {
                    next = EnsurePresenter(next);

                    if (IsActive)
                    {
                        next.Activate();
                    }
                }

                ChangeCurrentPresenterCore(next);

                _presenters.Remove(lastCurrent);
                lastCurrent.Deactivate();
                lastCurrent.Shutdown();

                var node = lastCurrent as IPresenterNode;
                if (node != null)
                {
                    node.Parent = null;
                }

                completed(true);
            });
        }
Esempio n. 4
0
        internal void UserLeft(UserViewModel user)
        {
            RoomUserViewModel leftUser = _users.FirstOrDefault(x => x.User.Equals(user));

            if (leftUser != null)
            {
                _users.Remove(leftUser);
            }

            // TODO: Implement notification to the room of left user.
        }
        public void RemoveGetsRemovedFromDestination()
        {
            var person = new Person("Adult1", 50);

            _collection.Add(person);
            _collection.Remove(person);

            Assert.AreEqual(2, _results.Messages.Count, "Should be 1 updates");
            Assert.AreEqual(0, _results.Data.Count, "Should be nothing in the cache");
            Assert.AreEqual(1, _results.Messages.First().Adds, "First message should be an add");
            Assert.AreEqual(1, _results.Messages.Skip(1).First().Removes, "First message should be a remove");
        }
Esempio n. 6
0
        private void DoUpdate(IChangeSet <TObject, TKey> updates, IObservableCollection <TObject> list)
        {
            updates.ForEach(update =>
            {
                switch (update.Reason)
                {
                case ChangeReason.Add:
                    list.Add(update.Current);
                    break;

                case ChangeReason.Remove:
                    list.Remove(update.Current);
                    break;

                case ChangeReason.Update:
                    {
                        list.Remove(update.Previous.Value);
                        list.Add(update.Current);
                    }
                    break;
                }
            });
        }
        /// <summary>
        /// Função chamada quando a tela é exibida
        /// </summary>
        protected override void OnActivate()
        {
            _manipulacoes.Clear();

            // Recupera uma referência do banco
            using (var db = new DataBase.ManipulaImagemContext())
            {
                // Carrega as manipulações cadastradas
                _manipulacoes.AddRange(
                    db.Manipulacoes.ToArray().Select(m =>
                {
                    var i         = IoC.Get <ManipulacaoItemViewModel>();
                    i.Manipulacao = m;
                    i.Excluido   += (s, e) => _manipulacoes.Remove(i);
                    return(i);
                }));
            }
        }
Esempio n. 8
0
        public bool Remove(object a)
        {
            if (a is FloodRule rule)
            {
                return(rules.Remove(rule));
            }
            else if (a is string || a is ConcatenatedString)
            {
                int idx = rules.FindIndex((s) => s.Name == a.ToString());
                if (idx > -1)
                {
                    rules.RemoveAt(idx);
                    return(true);
                }
            }

            return(false);
        }
 protected virtual bool ValidateOrReplaceViewElementCollection(IObservableCollection <ViewElement> children, WindowProfileValidationContext context)
 {
     for (int index = 0; index < children.Count; ++index)
     {
         ViewElement element = children[index];
         using (element.PreventCollapse())
         {
             bool flag = this.ValidateOrReplaceViewElement(ref element, context);
             if (element != children[index])
             {
                 children[index] = element;
             }
             else if (!flag)
             {
                 children.Remove(element);
                 --index;
             }
         }
     }
     return(true);
 }
        private void UpdateTotalRecord()
        {
            _week.Remove(_week.SingleOrDefault(t => t.IsTotal));
            var total = new TimeSheetItem {
                IsTotal = true, Name = "TOTAL"
            };

            foreach (var item in _week)
            {
                total.WorkRemaining = total.WorkRemaining
                                      .AddHours(item.WorkRemaining.Hour)
                                      .AddMinutes(item.WorkRemaining.Minute)
                                      .AddSeconds(item.WorkRemaining.Second);
                total.Monday = total.Monday
                               .AddHours(item.Monday.Hour)
                               .AddMinutes(item.Monday.Minute)
                               .AddSeconds(item.Monday.Second);
                total.Tuesday = total.Tuesday
                                .AddHours(item.Tuesday.Hour)
                                .AddMinutes(item.Tuesday.Minute)
                                .AddSeconds(item.Tuesday.Second);
                total.Wednesday = total.Wednesday
                                  .AddHours(item.Wednesday.Hour)
                                  .AddMinutes(item.Wednesday.Minute)
                                  .AddSeconds(item.Wednesday.Second);
                total.Thursday = total.Thursday
                                 .AddHours(item.Thursday.Hour)
                                 .AddMinutes(item.Thursday.Minute)
                                 .AddSeconds(item.Thursday.Second);
                total.Friday = total.Friday
                               .AddHours(item.Friday.Hour)
                               .AddMinutes(item.Friday.Minute)
                               .AddSeconds(item.Friday.Second);
            }
            _week.Add(total);
        }
Esempio n. 11
0
        // add, 2014-04-14, rein
        // ref: http://social.msdn.microsoft.com/Forums/vstudio/en-US/2e278e3c-27ab-42b5-8a7b-6828ddbb9caf/how-to-sync-two-observable-collection-?forum=wpf
        // cannot use with Caliburn.Micro BindinableCollection
        public static void Sync <T>(this IObservableCollection <T> target, INotifyCollectionChanged source)
        {
            source.CollectionChanged += (sender, e) => {
//                target.CollectionChanged -= coll2_CollectionChanged;

                if (e.NewItems != null)
                {
                    foreach (var newItem in e.NewItems)
                    {
                        target.Add((T)newItem);
                    }
                }

                if (e.OldItems != null)
                {
                    foreach (var oldItem in e.OldItems)
                    {
                        target.Remove((T)oldItem);
                    }
                }

//                target.CollectionChanged += coll2_CollectionChanged;
            };
        }
Esempio n. 12
0
 private void RemoveFromAllFiles(IObservableCollection<FileViewModel> allFiles, ITreeNode treeNode)
 {
     FileViewModel fileViewModel = treeNode as FileViewModel;
       if (fileViewModel != null)
     allFiles.Remove(fileViewModel);
       else
       {
     DirectoryViewModel directoryViewModel = treeNode as DirectoryViewModel;
     if (directoryViewModel != null && directoryViewModel.Children != null)
     {
       foreach (ITreeNode child in directoryViewModel.Children)
       {
     RemoveFromAllFiles(allFiles, child);
       }
     }
       }
 }
 /// <summary>
 /// Remove o item informado.
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool Remove(T item)
 {
     return(_source.Remove(item));
 }
Esempio n. 14
0
 public bool Remove(TGlyphData item) => _collectionImplementation.Remove(item);
Esempio n. 15
0
 private ViewModelNode DeleteNode(MyPoint parameter, ViewModelNode result)
 {
     Nodes.Remove(result);
     return(result);
 }
Esempio n. 16
0
 private ViewModelConnect DeleteConnect(ViewModelConnect parameter, ViewModelConnect result)
 {
     Connects.Remove(parameter);
     parameter.FromConnector.CommandDelete.Execute();
     return(parameter);
 }
        private void TestEvents(IObservableCollection<string> instance)
        {
            var stringToAdd = "Adam is awesome";
            var addingCallCount = 0;
            var addedCallCount = 0;
            var removingCallCount = 0;
            var removedCallCount = 0;
            var clearingCallCount = 0;
            var clearedCallCount = 0;

            EventHandler<ObservableCollectionChangingEventArgs<string>> cancelAddHandler = (sender, eventArgs) =>
            {
                addingCallCount++;
                eventArgs.Items.Should().Contain(stringToAdd);
                eventArgs.Items.Count().Should().Be(1);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsAdded);
                eventArgs.CancelOperation.Should().BeFalse();
                eventArgs.CancelOperation = true;
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().NotContain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangingEventArgs<string>> allowAddHandler = (sender, eventArgs) =>
            {
                addingCallCount++;
                eventArgs.Items.Should().Contain(stringToAdd);
                eventArgs.Items.Count().Should().Be(1);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsAdded);
                eventArgs.CancelOperation.Should().BeFalse();
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().NotContain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangedEventArgs<string>> addChangedHandler = (sender, eventArgs) =>
            {
                addedCallCount++;
                eventArgs.Items.Should().Contain(stringToAdd);
                eventArgs.Items.Count().Should().Be(1);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsAdded);
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().Contain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangingEventArgs<string>> cancelRemoveHandler = (sender, eventArgs) =>
            {
                removingCallCount++;
                eventArgs.Items.Should().Contain(stringToAdd);
                eventArgs.Items.Count().Should().Be(1);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsRemoved);
                eventArgs.CancelOperation.Should().BeFalse();
                eventArgs.CancelOperation = true;
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().Contain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangingEventArgs<string>> allowRemoveHandler = (sender, eventArgs) =>
            {
                removingCallCount++;
                eventArgs.Items.Should().Contain(stringToAdd);
                eventArgs.Items.Count().Should().Be(1);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsRemoved);
                eventArgs.CancelOperation.Should().BeFalse();
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().Contain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangedEventArgs<string>> removeChangedHandler = (sender, eventArgs) =>
            {
                removedCallCount++;
                eventArgs.Items.Should().Contain(stringToAdd);
                eventArgs.Items.Count().Should().Be(1);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsRemoved);
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().NotContain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangingEventArgs<string>> cancelClearHandler = (sender, eventArgs) =>
            {
                clearingCallCount++;
                eventArgs.Items.Count().Should().Be(2);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsRemoved);
                eventArgs.CancelOperation.Should().BeFalse();
                eventArgs.CancelOperation = true;
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().Contain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangingEventArgs<string>> allowClearHandler = (sender, eventArgs) =>
            {
                clearingCallCount++;
                eventArgs.Items.Count().Should().Be(2);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsRemoved);
                eventArgs.CancelOperation.Should().BeFalse();
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().Contain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangedEventArgs<string>> clearChangedHandler = (sender, eventArgs) =>
            {
                clearedCallCount++;
                eventArgs.Items.Count().Should().Be(2);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsRemoved);
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().NotContain(x => eventArgs.Items.Contains(x));
            };

            // try to add with cancelAddHandler first, then with allowAddHandler, then remove with cancelRemoveHandler, then allowRemoveHandler

            instance.Clear();
            instance.Should().BeEmpty();
            instance.Changing += cancelAddHandler;
            instance.Changed += addChangedHandler;

            instance.Add(null);
            instance.Should().BeEmpty();
            addingCallCount.Should().Be(0);
            addedCallCount.Should().Be(0);

            instance.Add(stringToAdd);
            instance.Should().BeEmpty();
            addingCallCount.Should().Be(1);
            addedCallCount.Should().Be(0);

            instance.Changing -= cancelAddHandler;
            instance.Changing += allowAddHandler;

            instance.Add(stringToAdd);
            instance.Should().Contain(stringToAdd);
            instance.Count.Should().Be(1);
            addingCallCount.Should().Be(2);
            addedCallCount.Should().Be(1);

            instance.Changing -= allowAddHandler;
            instance.Changed -= addChangedHandler;
            instance.Changing += cancelRemoveHandler;
            instance.Changed += removeChangedHandler;

            instance.Remove(null);
            instance.Count.Should().Be(1);
            removingCallCount.Should().Be(0);
            removedCallCount.Should().Be(0);

            instance.Remove(stringToAdd);
            instance.Should().Contain(stringToAdd);
            instance.Count.Should().Be(1);
            removingCallCount.Should().Be(1);
            removedCallCount.Should().Be(0);

            instance.Changing -= cancelRemoveHandler;
            instance.Changing += allowRemoveHandler;
            instance.Remove(stringToAdd);
            instance.Should().BeEmpty();
            removingCallCount.Should().Be(2);
            removedCallCount.Should().Be(1);

            instance.Changing -= allowRemoveHandler;
            instance.Changed -= removeChangedHandler;

            instance.Changing += cancelClearHandler;
            instance.Changed += clearChangedHandler;
            instance.Clear();
            clearingCallCount.Should().Be(0);
            clearedCallCount.Should().Be(0);

            instance.Changing -= cancelClearHandler;
            instance.Changed -= clearChangedHandler;
            instance.Add("a");
            instance.Add("b");
            instance.Count.Should().Be(2);
            instance.Changing += cancelClearHandler;
            instance.Changed += clearChangedHandler;
            instance.Clear();
            instance.Count.Should().Be(2);
            clearingCallCount.Should().Be(1);
            clearedCallCount.Should().Be(0);
            instance.Changing -= cancelClearHandler;
            instance.Changing += allowClearHandler;
            instance.Clear();
            instance.Should().BeEmpty();
            clearingCallCount.Should().Be(2);
            clearedCallCount.Should().Be(1);
            instance.Changing -= allowClearHandler;
            instance.Changed -= clearChangedHandler;
        }