Esempio n. 1
0
        public IDisposable EnterMassUpdate()
        {
            _massUpdateScopeCount++;
            _waitingForMassUpdate = true;

            void DisposeAction()
            {
                _massUpdateScopeCount--;
                if (_massUpdateScopeCount == 0)
                {
                    _waitingForMassUpdate = false;

                    var args = GetChangeArguments();
                    if (args == null)
                    {
                        return;
                    }

                    OnCollectionChanged(args);
                    OnPropertyChanged(nameof(Count));

                    _reset    = false;
                    _newItems = null;
                    _oldItems = null;
                }
            }

            return(Disposable.FromAction(DisposeAction));
        }
Esempio n. 2
0
 internal IDisposable BeginEventAddMoratorium()
 {
     if (!this.eventAddAllowed)
     {
         ExceptionUtil.ThrowInvalidOperationException("An event add moratorium is already in effect");
     }
     this.eventAddAllowed = false;
     return(Disposable.FromAction(delegate {
         this.eventAddAllowed = true;
     }, false));
 }
Esempio n. 3
0
        public static IDisposable Initialize(IUpdatesServiceHost host)
        {
            object sync = UpdatesService.sync;

            lock (sync)
            {
                if (instance != null)
                {
                    ExceptionUtil.ThrowInvalidOperationException("Initialize has already been called");
                }
                instance = new UpdatesService(host);
                return(Disposable.FromAction(delegate {
                    Shutdown();
                }, false));
            }
        }
        public void TestAutoSubscription()
        {
            var testHub = new MessagesHub();

            var instance = new HandlerObject();

            var subscriptions = MessagesUtils.AutoSubscribe(instance, testHub);

            using (Disposable.FromAction(() =>
            {
                foreach (var s in subscriptions)
                {
                    s.Subscription.Dispose();
                }
            }))
            {
                string str1  = "value1";
                string str2  = "value2";
                int    ival1 = 77;

                Assert.AreEqual(instance.StrValue, string.Empty);
                Assert.AreEqual(instance.IntValue, 0);

                NotificationMessage1.Broadcast(str1, testHub);

                Assert.AreEqual(instance.StrValue, str1);

                NotificationMessage2.Broadcast(str2, ival1, testHub);

                Assert.AreEqual(instance.StrValue, str2);
                Assert.AreEqual(instance.IntValue, ival1);
            }

            Assert.Throws <Exception>(() =>
            {    // all subscriptions must gone after using (...) block
                NotificationMessage1.Broadcast(string.Empty, testHub);
            });
        }
Esempio n. 5
0
        internal IDisposable BeginEventAddMoratorium()
        {
            if (!this.eventAddAllowed)
            {
                ExceptionUtil.ThrowInvalidOperationException("An event add moratorium is already in effect");
            }
            List <IDisposable> second = new List <IDisposable>(this.properties.Count);

            using (Dictionary <string, Property> .ValueCollection.Enumerator enumerator = this.properties.Values.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    IDisposable item = enumerator.Current.BeginEventAddMoratorium();
                    second.Add(item);
                }
            }
            IDisposable tail = Disposable.FromAction(delegate {
                this.eventAddAllowed = true;
            }, false);

            this.eventAddAllowed = false;
            return(Disposable.Combine(Enumerable.Empty <IDisposable>().Concat <IDisposable>(tail).Concat <IDisposable>(second), false));
        }
Esempio n. 6
0
 private IDisposable NotifyMassSelection()
 {
     _relay.Send <MassSelectionStartingMessage>(this);
     return(Disposable.FromAction(() => _relay.Send <MassSelectionFinishedMessage>(this)));
 }