Beispiel #1
0
        private void InitEventsLogic()
        {
            EventPublisher = new EventPublisher();
            // klikniecie na kategorie
            EventPublisher.GetEvent <CollectionViewGroup>()
            .Subscribe(cvg => FilteredUsers = new ObservableCollection <User>(cvg.Items.Cast <User>()));
            // klikniecie na usera
            EventPublisher.GetEvent <User>()
            .Subscribe(user => SelectedUser = user);
            // inicjalizacja edycji usera
            EventPublisher.GetEvent <EditUserInitEvent>()
            .Subscribe(
                _ =>
            {
                EditUser =
                    new User
                {
                    Address   = SelectedUser.Address,
                    FirstName = SelectedUser.FirstName,
                    LastName  = SelectedUser.LastName,
                    BirthDate = SelectedUser.BirthDate,
                    Type      = SelectedUser.Type
                };
                EditModeNewUser = false;
            });
            EventPublisher.GetEvent <NewUserInitEvent>().Subscribe(_ =>
            {
                EditUser        = new User();
                EditModeNewUser = true;
            });
            // obsluga potwierdzenia edycji
            EventPublisher.GetEvent <EditUserFinishedEvent>().Subscribe(_ =>
            {
                User selected;
                if (EditModeNewUser)
                {
                    Users.Add(EditUser);
                    selected = EditUser;
                }
                else
                {
                    SelectedUser.FirstName = EditUser.FirstName;
                    SelectedUser.LastName  = EditUser.LastName;
                    SelectedUser.Address   = EditUser.Address;
                    SelectedUser.BirthDate = EditUser.BirthDate;
                    SelectedUser.Type      = EditUser.Type;
                    selected = SelectedUser;
                }

                //refresh powoduje wynullowanie SelectedUser, why?
                Cvs.View.Refresh();
                FilteredUsers = new ObservableCollection <User>(Users);
                SelectedUser  = selected;
            });
        }
        // ReSharper disable InconsistentNaming
        public void EventPublisherGetEvent_UnitTest_SecondTimeForType_Existing()
        // ReSharper restore InconsistentNaming
        {
            var publisher = new EventPublisher();
            Assert.AreEqual(0, publisher.Count);

            var first = publisher.GetEvent<object>();
            Assert.AreEqual(1, publisher.Count);
            Assert.IsNotNull(first);
            Assert.IsInstanceOfType(first, typeof(IObservable<object>));

            var second = publisher.GetEvent<object>();
            Assert.AreEqual(1, publisher.Count);
            Assert.IsNotNull(second);
            Assert.IsInstanceOfType(second, typeof(IObservable<object>));
        }
Beispiel #3
0
        public override void OnImportsSatisfied()
        {
            // subscribe to events
            var observable = EventPublisher.GetEvent <SelectedXmlDependencyChangedEvent>();

            observable.Subscribe(SelectedXmlDependencyChanged);
        }
 private void SubscribeToEvents()
 {
     _eventPublisher = new EventPublisher();
     var numberCountedObserver = Observer.Create<NumberCountedEvent>(new Action<NumberCountedEvent>(OnNumberCounted));
     _eventPublisher.GetEvent<NumberCountedEvent>()
         .ObserveOnDispatcher()
         .Subscribe(numberCountedObserver);
 }
Beispiel #5
0
        // ReSharper disable InconsistentNaming
        public void EventPublisherGetEvent_UnitTest_SecondTimeForType_Existing()
        // ReSharper restore InconsistentNaming
        {
            var publisher = new EventPublisher();

            Assert.AreEqual(0, publisher.Count);

            var first = publisher.GetEvent <object>();

            Assert.AreEqual(1, publisher.Count);
            Assert.IsNotNull(first);
            Assert.IsInstanceOfType(first, typeof(IObservable <object>));

            var second = publisher.GetEvent <object>();

            Assert.AreEqual(1, publisher.Count);
            Assert.IsNotNull(second);
            Assert.IsInstanceOfType(second, typeof(IObservable <object>));
        }
        // ReSharper disable InconsistentNaming
        public void EventPublisherPublish_UnitTest_RegisteredType_FindsSubjectAndInvokesOnNext()
        // ReSharper restore InconsistentNaming
        {
            var memo = new DesignValidationMemo();

            var publisher = new EventPublisher();
            var subscription = publisher.GetEvent<DesignValidationMemo>().Subscribe(m => Assert.AreSame(memo, m));

            publisher.Publish(memo);
            subscription.Dispose();
        }
        // ReSharper disable InconsistentNaming
        public void EventPublisherGetEvent_UnitTest_FirstTimeForType_New()
        // ReSharper restore InconsistentNaming
        {
            var publisher = new EventPublisher();
            Assert.AreEqual(0, publisher.Count);

            var actual = publisher.GetEvent<object>();
            Assert.AreEqual(1, publisher.Count);
            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(IObservable<object>));
        }
Beispiel #8
0
        // ReSharper disable InconsistentNaming
        public void EventPublisherPublish_UnitTest_RegisteredObjectType_FindsSubjectAndInvokesOnNext()
        // ReSharper restore InconsistentNaming
        {
            var memo = new DesignValidationMemo() as object;

            var publisher    = new EventPublisher();
            var subscription = publisher.GetEvent <DesignValidationMemo>().Subscribe(m => Assert.AreSame(memo, m));

            publisher.PublishObject(memo);
            subscription.Dispose();
        }
Beispiel #9
0
        public void EventPublisherPublish_UnitTest_RegisteredType_FindsSubjectAndInvokesOnNext()

        {
            var memo = new DesignValidationMemo();

            var publisher    = new EventPublisher();
            var subscription = publisher.GetEvent <DesignValidationMemo>().Subscribe(m => Assert.AreSame(memo, m));

            publisher.Publish(memo);
            subscription.Dispose();
        }
Beispiel #10
0
        // ReSharper disable InconsistentNaming
        public void EventPublisherGetEvent_UnitTest_FirstTimeForType_New()
        // ReSharper restore InconsistentNaming
        {
            var publisher = new EventPublisher();

            Assert.AreEqual(0, publisher.Count);

            var actual = publisher.GetEvent <object>();

            Assert.AreEqual(1, publisher.Count);
            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(IObservable <object>));
        }
Beispiel #11
0
        // ReSharper disable InconsistentNaming
        public void EventPublisherPublish_RemoveEvent_UnregisteredObjectType_NotRemoved()
        // ReSharper restore InconsistentNaming
        {
            var publisher    = new EventPublisher();
            var subscription = publisher.GetEvent <DesignValidationMemo>();

            Assert.AreEqual(1, publisher.Count);

            var result = publisher.RemoveEvent <Memo>();

            Assert.AreEqual(1, publisher.Count);
            Assert.IsFalse(result);
        }
Beispiel #12
0
        public void EventPublisherPublish_RemoveEvent_RegisteredObjectType_Removed()

        {
            var publisher    = new EventPublisher();
            var subscription = publisher.GetEvent <DesignValidationMemo>();

            Assert.AreEqual(1, publisher.Count);

            var result = publisher.RemoveEvent <DesignValidationMemo>();

            Assert.AreEqual(0, publisher.Count);
            Assert.IsTrue(result);
        }
Beispiel #13
0
        public override void OnImportsSatisfied()
        {
            // create the component view model
            try
            {
                _xmlComponent = XmlComponentRepository.GetXmlComponent(TargetsFileData);

                if (_xmlComponent == null)
                {
                    var initErrorEvent = new InitializationErrorEvent(new Exception(String.Format("Error while loading local file {0}!", TargetsFileData.LocalPath)));
                    EventPublisher.Publish(initErrorEvent);
                }
            }
            catch (XmlException xe)
            {
                var initErrorEvent = new InitializationErrorEvent(new Exception(String.Format("Error while loading local file {0} (Error while parsing XML: {1})!", TargetsFileData.LocalPath, xe.Message)));
                EventPublisher.Publish(initErrorEvent);
            }
            catch (DependencyServiceException dse)
            {
                var initErrorEvent = new InitializationErrorEvent(new Exception(String.Format("Error while loading local file {0} ({1})!", TargetsFileData.LocalPath, dse.Message)));
                EventPublisher.Publish(initErrorEvent);
            }

            _xmlComponentViewModel = new XmlComponentViewModel(_xmlComponent);

            // initialize the list of available Xml dependencies in the current targets file
            var dependencies = _xmlComponentViewModel.GetDependencies();

            foreach (var xmlDependencyViewModel in dependencies)
            {
                XmlDependencies.Add(xmlDependencyViewModel);
            }

            // add special view model for creation
            var createXmlDependencyViewModel = new CreateXmlDependencyViewModel();

            createXmlDependencyViewModel.XmlDependencyCreationRequest += CreateXmlDependencyViewModel_XmlDependencyCreationRequest;
            XmlDependencies.Add(createXmlDependencyViewModel);

            // hook events
            ChangeTrackingService.HasChangesChanged += ChangeTrackingService_HasChangesChanged;
            var saveAllChangesEvent = EventPublisher.GetEvent <SaveAllChangesEvent>();

            saveAllChangesEvent.Subscribe(o => Save(o.FileName));
        }
        // ReSharper disable InconsistentNaming
        public void EventPublisherPublish_RemoveEvent_UnregisteredObjectType_NotRemoved()
        // ReSharper restore InconsistentNaming
        {
            var publisher = new EventPublisher();
            var subscription = publisher.GetEvent<DesignValidationMemo>();
            Assert.AreEqual(1, publisher.Count);

            var result = publisher.RemoveEvent<Memo>();
            Assert.AreEqual(1, publisher.Count);
            Assert.IsFalse(result);
        }
Beispiel #15
0
        private void InitEventsLogic()
        {
            EventPublisher = new EventPublisher();
            // klikniecie na kategorie
            EventPublisher.GetEvent<CollectionViewGroup>()
                          .Subscribe(cvg => FilteredUsers = new ObservableCollection<User>(cvg.Items.Cast<User>()));
            // klikniecie na usera
            EventPublisher.GetEvent<User>()
                          .Subscribe(user => SelectedUser = user);
            // inicjalizacja edycji usera
            EventPublisher.GetEvent<EditUserInitEvent>()
                          .Subscribe(
                              _ =>
                                  {
                                      EditUser =
                                          new User
                                              {
                                                  Address = SelectedUser.Address,
                                                  FirstName = SelectedUser.FirstName,
                                                  LastName = SelectedUser.LastName,
                                                  BirthDate = SelectedUser.BirthDate,
                                                  Type = SelectedUser.Type
                                              };
                                      EditModeNewUser = false;
                                  });
            EventPublisher.GetEvent<NewUserInitEvent>().Subscribe(_ =>
                {
                    EditUser = new User();
                    EditModeNewUser = true;
                });
            // obsluga potwierdzenia edycji
            EventPublisher.GetEvent<EditUserFinishedEvent>().Subscribe(_ =>
                {
                    User selected;
                    if (EditModeNewUser)
                    {
                        Users.Add(EditUser);
                        selected = EditUser;
                    }
                    else
                    {
                        SelectedUser.FirstName = EditUser.FirstName;
                        SelectedUser.LastName = EditUser.LastName;
                        SelectedUser.Address = EditUser.Address;
                        SelectedUser.BirthDate = EditUser.BirthDate;
                        SelectedUser.Type = EditUser.Type;
                        selected = SelectedUser;
                    }

                    //refresh powoduje wynullowanie SelectedUser, why?
                    Cvs.View.Refresh();
                    FilteredUsers = new ObservableCollection<User>(Users);
                    SelectedUser = selected;
                });
        }