Ejemplo n.º 1
0
        /// <summary>
        /// Get Event as an Observable
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public IObservable <T> GetEvent <T>()
        {
            var defered = Observable.Defer(() =>
            {
                var tuple = _observablesByPayloadType.GetOrAdd(typeof(T), t =>
                {
                    var subject         = new Subject <T>();
                    var removeFromCache = Disposable.Create(() =>
                    {
                        Tuple <object, object> _; // throw away object!
                        _observablesByPayloadType.TryRemove(typeof(T), out _);
                    });

                    // because we are removing items from the cache to clean up on dispose,
                    // we need to publish then refcount the subject to ensure we only
                    // clean up when there are no subscribers left
                    var observable = subject.AddDisposable(removeFromCache)
                                     .Publish().RefCount().AsObservable();
                    return(new Tuple <object, object>(subject, observable));
                });

                return((IObservable <T>)tuple.Item2);
            });

            return(defered);
        }
Ejemplo n.º 2
0
        public ActivationStateViewModel(ILog log, IDispatcherSchedulerProvider scheduler)
        {
            _log = log;

            _isActive.ConnectINPCProperty(this, () => IsActive, scheduler).AddDisposable(Disposables);

            _onInitialise.AddDisposable(Disposables);
        }
Ejemplo n.º 3
0
        public ClosingStrategy(ILog log)
        {
            _log = log;

            _closing.AddDisposable(Disposables);
            _closed.AddDisposable(Disposables);

            CanCloseSetup = () => true;

            CloseCommand = new DelegateCommand(() => Close());
        }