Ejemplo n.º 1
0
        public void OnlyDisposeOnce()
        {
            var counter     = new DisposeCounter();
            var disposables = new Disposables();

            disposables.Add(counter);
            Assert.AreEqual(0, counter.DisposeCount);
            disposables.Dispose();
            Assert.AreEqual(1, counter.DisposeCount);
            disposables.Dispose();
            Assert.AreEqual(1, counter.DisposeCount);
        }
Ejemplo n.º 2
0
 private void OnDestroy()
 {
     if (!Disposables.IsDisposed)
     {
         Disposables.Dispose();
     }
 }
Ejemplo n.º 3
0
        public override void OnFrameworkInitializationCompleted()
        {
            UnhandledExceptionLogging();

            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
            {
                appState = new AppState().DisposeWith(Disposables);
                Locator.CurrentMutable.RegisterConstant(appState);

                desktop.MainWindow = new MainWindow()
                {
                    DataContext = new MainWindowViewModel().DisposeWith(Disposables)
                };

                // write setting to file after main window dispose
                ConfigurationHelper.SaveAppSettingsOnDispose().DisposeWith(Disposables);

                Locator.CurrentMutable.RegisterConstant(desktop.MainWindow);
                desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnMainWindowClose;

                Observable.FromEventPattern <ControlledApplicationLifetimeExitEventArgs>
                    (h => desktop.Exit += h, h => desktop.Exit -= h)
                .Subscribe(_ =>
                {
                    Disposables.Dispose();
                })
                .DisposeWith(Disposables);
            }

            base.OnFrameworkInitializationCompleted();
        }
Ejemplo n.º 4
0
        public void NoAddAfterDispose()
        {
            var disposables = new Disposables();

            disposables.Dispose();
            Assert.Throws <ObjectDisposedException>(() => disposables.Add(Scope.Create(() => { })));
        }
Ejemplo n.º 5
0
        public override bool OnClose()
        {
            Disposables.Dispose();
            Disposables = null;

            return(base.OnClose());
        }
Ejemplo n.º 6
0
        protected override void OnDetaching()
        {
            base.OnDetaching();

            Disposables?.Dispose();
            Disposables = null;
        }
Ejemplo n.º 7
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    if (!Disposables.IsDisposed)
                    {
                        Disposables.Dispose();
                    }

                    if (Bridge.Channel != null)
                    {
                        Bridge.Channel.Dispose();
                    }
                }

                if (eventSocket is OutboundSocket)
                {
                    // todo: should we close the socket associated with the channel here?
                    eventSocket.Dispose();
                }

                eventSocket = null;

                disposed = true;
            }
        }
Ejemplo n.º 8
0
        private unsafe void SignalWorkerThreadsToStop()
        {
            Observable.Interval(TimeSpan.FromMilliseconds(25))
            .TakeWhile(_ => _runningThreads > 0)
            .Select(_ =>
            {
                var result = new SwatcherAsyncResult {
                    Buffer = new byte[0]
                };
                var overlapped = new Overlapped {
                    AsyncResult = result
                };

                //the first parameter is null because we're not using IO completion callbacks; they're too slow.
                //we're taking the byte array from our empty byte array and passing that as user data to the overlapped.
                var overlappedPointer = overlapped.UnsafePack(null, result.Buffer);
                //when using IOCPs, we can send our own custom messages to the GetQueuedCompletionStatus
                //method by call PostQueuedCompletionStatus. In this case, we want to stop the threads that are
                //waiting on change events, so we will send a custom completion key "StopIocpThreads".
                WindowsFacade.PostQueuedCompletionStatus(CompletionPortHandle, 0, StopIocpThreads, overlappedPointer);
                return(Unit.Default);
            })
            .AsCompletion()
            .Where(_ => Config.LoggingEnabled)
            .Subscribe(_ =>
            {
                Disposables.Dispose();
                Logger.Info("Swatcher has stopped");
            });
        }
Ejemplo n.º 9
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed != null && !disposed.EnsureCalledOnce())
            {
                if (disposing)
                {
                    if (!Disposables.IsDisposed)
                    {
                        Disposables.Dispose();
                    }

                    OtherLeg?.Dispose();
                    bridgedChannelsSubject.Dispose();
                }

                if (eventSocket != null && eventSocket is OutboundSocket)
                {
                    // todo: should we close the socket associated with the channel here?
                    eventSocket.Dispose();
                }

                eventSocket = null;

                Log.Debug(() => "Channel Disposed.");
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 10
0
        public override bool OnClose()
        {
            TabOpened = false;
            Disposables?.Dispose();
            Disposables = null;

            return(base.OnClose());
        }
Ejemplo n.º 11
0
 public void UnsubscribeEvents()
 {
     lock (DisposablesLock)
     {
         Disposables?.Dispose();
         Disposables = null;
     }
 }
Ejemplo n.º 12
0
        public override bool OnClose()
        {
            CoinsList.OnClose();

            Disposables?.Dispose();
            Disposables = null;

            return(base.OnClose());
        }
Ejemplo n.º 13
0
        public void WhenADisposablesIsDisposedMultipleTimesItShouldDisposeChildrenDisposablesOnce()
        {
            // Given
            var calls       = new List <string>();
            var disposables = new Disposables()
                              .Add(
                () => calls.Add("action1"),
                () => calls.Add("action2"),
                () => calls.Add("action3")
                );

            // When
            disposables.Dispose();
            disposables.Dispose();
            disposables.Dispose();

            // Then
            calls.Should().Equal("action1", "action2", "action3");
        }
Ejemplo n.º 14
0
        public void WhenADisposablesIsDisposedWithNoDisposablesItShouldNotFail()
        {
            // Given
            var disposables = new Disposables();

            // When
            disposables.Dispose();

            // Then
            // didn't failed
        }
        public void Dispose()
        {
            if (Disposables.IsDisposed)
            {
                return;
            }

            m_tokenSource.Dispose();

            Disposables.Dispose();
        }
Ejemplo n.º 16
0
        private volatile bool _disposedValue = false;         // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    Disposables?.Dispose();
                }

                _disposedValue = true;
            }
        }
Ejemplo n.º 17
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    disposables.Dispose();
                }

                disposedValue = true;
            }
        }
Ejemplo n.º 18
0
        public void CtorEnumerable()
        {
            var test        = "";
            var disposables = new Disposables(new List <IDisposable>
            {
                Scope.Create(() => test += "a"),
                Scope.Create(() => test += "b"),
                Scope.Create(() => test += "c"),
            });

            disposables.Dispose();
            Assert.AreEqual("cba", test);
        }
        public void ExplicitDispose()
        {
            TestDisposable o = new TestDisposable();

            Assert.IsFalse(o.IsDisposed);

            var disposer = new Disposables();

            disposer.Add(o);
            disposer.Dispose();

            Assert.IsTrue(o.IsDisposed);
        }
Ejemplo n.º 20
0
        public void WhenADisposablesIsDisposedItShouldDisposeChildDisposable()
        {
            // Given
            var calls       = new List <string>();
            var disposables = new Disposables()
                              .Add(() => calls.Add("action1"));

            // When
            disposables.Dispose();

            // Then
            calls.Should().Equal("action1");
        }
Ejemplo n.º 21
0
        public void CollectionInitialization()
        {
            var test        = "";
            var disposables = new Disposables
            {
                Scope.Create(() => test += "a"),
                Scope.Create(() => test += "b"),
                Scope.Create(() => test += "c"),
            };

            disposables.Dispose();
            Assert.AreEqual("cba", test);
        }
Ejemplo n.º 22
0
        public void WhenADisposablesWithDisposableArrayIsDisposedItShouldDisposeChildrenDisposables()
        {
            // Given
            var calls       = new List <string>();
            var disposables = new Disposables()
                              .Add(
                new Disposable(() => calls.Add("action1")),
                new Disposable(() => calls.Add("action2")),
                new Disposable(() => calls.Add("action3")));

            // When
            disposables.Dispose();

            // Then
            calls.Should().Equal("action1", "action2", "action3");
        }
Ejemplo n.º 23
0
        private volatile bool _disposedValue = false;         // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    Disposables?.Dispose();
                    if (Global.ChaumianClient != null)
                    {
                        Global.ChaumianClient.StateUpdated -= ChaumianClient_StateUpdated;
                    }
                }

                _disposedValue = true;
            }
        }
Ejemplo n.º 24
0
        protected Workspace(ILog log, IDispatcherSchedulerProvider scheduler, IStandardDialog standardDialog)
        {
            _log            = log;
            _scheduler      = scheduler;
            _standardDialog = standardDialog;

            ClosingStrategy = new ClosingStrategy(log);
            ClosingStrategy.AddDisposable(Disposables);

            ClosingStrategy.Closing
            .TakeUntil(ClosingStrategy.Closed)
            .Subscribe(_ =>
            {
                Closing();

                CleanUp();
            });

            this.ExecuteOnClosed(() => Disposables.Dispose());

            BusyViewModel = new BusyViewModel(scheduler);
            BusyViewModel.AddDisposable(Disposables);

            ActivationStateViewModel = new ActivationStateViewModel(log, scheduler);
            ActivationStateViewModel.AddDisposable(Disposables);

            ActivationStateViewModel.OnInitialise
            .SelectMany(_ => OnInitialise().ToObservable()
                        .TakeUntil(BusyViewModel.BusyLatch))
            .TakeUntil(ClosingStrategy.Closed)
            .Subscribe(_ => { });

            ActivationStateViewModel.ActivationStateChanged
            .ObserveOn(scheduler.Dispatcher.RX)
            .Where(isActive => isActive)
            .TakeUntil(ClosingStrategy.Closed)
            .Subscribe(_ => OnActivate());

            ActivationStateViewModel.ActivationStateChanged
            .ObserveOn(scheduler.Dispatcher.RX)
            .Where(isActive => !isActive)
            .TakeUntil(ClosingStrategy.Closed)
            .Subscribe(_ => OnDeActivate());

            Show();
        }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            var container    = (IContainer)null;
            var workRegistry = new WorkManagerRegistry();
            var notifier     = new ServiceLogNotification();
            var disposables  = new Disposables();
            var builder      = new ContainerBuilder();

            builder.RegisterModule(new ServiceModule(workRegistry, notifier, disposables, () => new DependencyFactory(container)));
            container = builder.Build();

            using (var workManager = new WorkManager(workRegistry, new WorkManagerDependencyResolver(container), notifier))
            {
                workManager.OnRuntimeState += (state) =>
                {
                    switch (state)
                    {
                    case ManagerRuntimeStates.Stopped:
                        disposables.Dispose();
                        break;
                    }
                };


                if (!Environment.UserInteractive)
                {
                    var servicesToRun = new ServiceBase[]
                    {
                        new WindowsService(workManager)
                    };

                    ServiceBase.Run(servicesToRun);
                }
                else
                {
                    workManager.Start();

                    Console.WriteLine($"WorkManager '{WorkManagerConfig.ApplicationName}' has started.");
                    Console.WriteLine("Press any key to terminate...");
                    Console.ReadKey();

                    workManager.Stop();
                }
            }
        }
Ejemplo n.º 26
0
        protected override void OnAttached()
        {
            Disposables?.Dispose();

            Disposables = new CompositeDisposable
            {
                AssociatedObject.GetObservable(InputElement.IsEnabledProperty).Subscribe(enabled =>
                {
                    if (enabled)
                    {
                        AssociatedObject.Opacity = OriginalOpacity.HasValue ? OriginalOpacity.Value : 1;
                    }
                    else
                    {
                        OriginalOpacity          = AssociatedObject.Opacity;
                        AssociatedObject.Opacity = 0.5;
                    }
                })
            };
        }
Ejemplo n.º 27
0
        public void Dispose()
        {
            if (wasDisposed || Kernel.applicationQuitting || this == null)
            {
                return;
            }
            wasDisposed = true;


            Disposables.Dispose();
            DisposablesProperty.Dispose();
            DisposablesProperty = null;

            OnDispose();

            OnDisposing.Execute();

            OnDisposing.Dispose();
            OnDisposing = null;

            OnAfterBind.Dispose();
            OnAfterBind = null;

            //If an error is thrown here, you are trying to dispose a model that was not bound. This should never happen/you should always bind your models and this comment is just here so you know whats wrong :)
            //_dManager.Remove(this);
            //If an error is thrown here, you are trying to dispose a model that was not bound. This should never happen/you should always bind your models and this comment is just here so you know whats wrong :)
            try {
                _dManager.Remove(this);
            }
            catch (Exception e) {
                if (!skipWarning)   // sry, but I have some cases(in my NPC-Nodes) where I have a Model but unbound. I shouldn't have used MVC-Model in the first place....
                {
                    UnityEngine.Debug.LogError("Tried to dispose unbound MVC-Model:" + GetType().ToString());
                    UnityEngine.Debug.LogException(e);
                }
            }
        }
Ejemplo n.º 28
0
        public void Dispose()
        {
            if (wasDisposed || Kernel.applicationQuitting || this == null)
            {
                return;
            }
            wasDisposed = true;

            Disposables.Dispose();
            DisposablesProperty.Dispose();
            DisposablesProperty = null;

            OnDispose();

            OnDisposing.Execute();

            OnDisposing.Dispose();
            OnDisposing = null;

            OnAfterBind.Dispose();
            OnAfterBind = null;

            _dManager.Remove(this);
        }
Ejemplo n.º 29
0
 public void Dispose()
 {
     Disposables.Dispose();
 }
Ejemplo n.º 30
0
 public virtual void Dispose()
 {
     Debug.WriteLine("Disposing");
     Disposables.Dispose();
 }