Exemplo n.º 1
0
        public OnElementLoadedEvent(
            [Import(AllowDefault = true)] IPatternManager patternManager,
            [Import(AllowDefault = true)] IInstanceBase currentElement)
        {
            this.currentElement = currentElement;
            this.patternManager = patternManager;

            this.sourceEvent = WeakObservable.FromEvent <EventArgs>(
                handler => this.ElementLoaded += handler,
                handler => this.ElementLoaded -= handler);

            if (patternManager != null)
            {
                this.patternManager.IsOpenChanged += (sender, args) => this.OnOpenChanged();

                if (this.patternManager.IsOpen)
                {
                    this.storeEvent = WeakObservable.FromEvent <ValueEventArgs <IInstanceBase> >(
                        handler => this.patternManager.Store.ElementLoaded += handler,
                        handler => this.patternManager.Store.ElementLoaded -= handler);

                    this.storeEventSubscription = this.storeEvent.Subscribe(this.OnStoreElementLoaded);
                }
            }
        }
Exemplo n.º 2
0
        protected override IObservable <object> StartListeningCore(WeakReference reference)
        {
            var target = reference.Target;
            var incc   = target as INotifyCollectionChanged;
            var inpc   = target as INotifyPropertyChanged;
            var inputs = new List <IObservable <object> >();

            if (incc != null)
            {
                inputs.Add(WeakObservable.FromEventPattern <INotifyCollectionChanged, NotifyCollectionChangedEventArgs>(
                               incc,
                               nameof(incc.CollectionChanged))
                           .Where(x => ShouldUpdate(x.Sender, x.EventArgs))
                           .Select(_ => GetValue(target)));
            }

            if (inpc != null)
            {
                inputs.Add(WeakObservable.FromEventPattern <INotifyPropertyChanged, PropertyChangedEventArgs>(
                               inpc,
                               nameof(inpc.PropertyChanged))
                           .Where(x => ShouldUpdate(x.Sender, x.EventArgs))
                           .Select(_ => GetValue(target)));
            }

            return(Observable.Merge(inputs).StartWith(GetValue(target)));
        }
Exemplo n.º 3
0
        protected override void StartListeningCore(WeakReference <object?> reference)
        {
            reference.TryGetTarget(out var target);

            var incc   = target as INotifyCollectionChanged;
            var inpc   = target as INotifyPropertyChanged;
            var inputs = new List <IObservable <object?> >();

            if (incc != null)
            {
                inputs.Add(WeakObservable.FromEventPattern <INotifyCollectionChanged, NotifyCollectionChangedEventArgs>(
                               incc,
                               nameof(incc.CollectionChanged))
                           .Where(x => ShouldUpdate(x.Sender, x.EventArgs))
                           .Select(_ => GetValue(target)));
            }

            if (inpc != null)
            {
                inputs.Add(WeakObservable.FromEventPattern <INotifyPropertyChanged, PropertyChangedEventArgs>(
                               inpc,
                               nameof(inpc.PropertyChanged))
                           .Where(x => ShouldUpdate(x.Sender, x.EventArgs))
                           .Select(_ => GetValue(target)));
            }

            _subscription = Observable.Merge(inputs).StartWith(GetValue(target)).Subscribe(ValueChanged);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OnSyncEvent"/> class.
 /// </summary>
 static OnSyncEvent()
 {
     if (sourceEvent == null)
     {
         sourceEvent = WeakObservable.FromEvent <EventArgs>(
             handler => SyncEvent += handler,
             handler => SyncEvent -= handler);
     }
 }
Exemplo n.º 5
0
        public EventPublisher(INotifyPropertyChanged eventSource)
        {
            //// this.eventSource = eventSource;

            this.observable = WeakObservable.FromEvent <PropertyChangedEventHandler, PropertyChangedEventArgs>(
                handler => new PropertyChangedEventHandler(handler.Invoke),
                handler => eventSource.PropertyChanged += handler,
                handler => eventSource.PropertyChanged -= handler);
        }
Exemplo n.º 6
0
        public OnBuildFinishedEvent([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
        {
            Guard.NotNull(() => serviceProvider, serviceProvider);

            this.dte = serviceProvider.GetService <EnvDTE.DTE>();
            this.dte.Events.BuildEvents.OnBuildDone += this.OnDteBuildDone;

            this.sourceEvent = WeakObservable.FromEvent <EventArgs>(
                handler => this.BuildFinished += handler,
                handler => this.BuildFinished -= handler);
        }
        public OnSolutionBuilderDragLeave([Import] SolutionBuilderView solutionBuilder)
        {
            Guard.NotNull(() => solutionBuilder, solutionBuilder);

            this.solutionBuilder = solutionBuilder;

            this.sourceEvent = WeakObservable.FromEvent <DragEventHandler, DragEventArgs>(
                handler => new DragEventHandler(handler),
                handler => this.solutionBuilder.ElementDragLeave += handler,
                handler => this.solutionBuilder.ElementDragLeave -= handler);
        }
        public OnElementPropertyChangedEvent([Import(AllowDefault = true)] IProductElement productElement)
        {
            // We get null when the event is being validated as it's constructed from the global
            // composition container to retrieve the event type.
            // See EventSettingsValidations constructor.
            if (productElement != null)
            {
                this.productElement = productElement;
                this.productElement.PropertyChanged += OnPropertyChanged;
            }

            this.localSourceEvent = WeakObservable.FromEvent <PropertyChangedEventArgs>(
                handler => this.ElementPropertyChanged += handler,
                handler => this.ElementPropertyChanged -= handler);
        }
Exemplo n.º 9
0
        private void OnOpenChanged()
        {
            if (this.storeEventSubscription != null)
            {
                this.storeEventSubscription.Dispose();
            }

            if (this.patternManager.IsOpen)
            {
                this.storeEvent = WeakObservable.FromEvent <ValueEventArgs <IInstanceBase> >(
                    handler => this.patternManager.Store.ElementInstantiated += handler,
                    handler => this.patternManager.Store.ElementInstantiated -= handler);

                this.storeEventSubscription = this.storeEvent.Subscribe(this.OnStoreElementInstantiated);
            }
        }
Exemplo n.º 10
0
        private void OnOpenChanged()
        {
            if (this.storeEventSubscription != null)
            {
                this.storeEventSubscription.Dispose();
            }

            if (this.patternManager.IsOpen)
            {
                this.storeEvent = WeakObservable.FromEvent <ValueEventArgs <IProductState> >(
                    handler => this.patternManager.StoreSaved += handler,
                    handler => this.patternManager.StoreSaved -= handler);

                this.storeEventSubscription = this.storeEvent.Subscribe(this.OnStoreProductStoreSaved);
            }
        }
Exemplo n.º 11
0
        public OnProductStoreSavedEvent(IPatternManager patternManager)
        {
            Guard.NotNull(() => patternManager, patternManager);

            this.patternManager = patternManager;
            this.patternManager.IsOpenChanged += (sender, args) => this.OnOpenChanged();

            this.sourceEvent = WeakObservable.FromEvent <EventArgs>(
                handler => this.ProductStoreSaved += handler,
                handler => this.ProductStoreSaved -= handler);

            if (this.patternManager.IsOpen)
            {
                this.storeEvent = WeakObservable.FromEvent <ValueEventArgs <IProductState> >(
                    handler => this.patternManager.StoreSaved += handler,
                    handler => this.patternManager.StoreSaved -= handler);

                this.storeEventSubscription = this.storeEvent.Subscribe(this.OnStoreProductStoreSaved);
            }
        }
Exemplo n.º 12
0
 public void WhenNullConversionHandler_ThenThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           WeakObservable.FromEvent <EventHandler, EventArgs>(null, handler => { }, handler => { }));
 }
Exemplo n.º 13
0
 public void WhenNullRemoveHandler_ThenThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           WeakObservable.FromEvent <EventArgs>(handler => { }, null));
 }