public SimpleGraphViewModel()
        {
            var observer = MementoObserver.Monitor(service);

            UndoCommand = DelegateCommand.Create()
                          .OnCanExecute(o => service.CanUndo)
                          .OnExecute(o => service.Undo())
                          .AddMonitor(observer);

            RedoCommand = DelegateCommand.Create()
                          .OnCanExecute(o => service.CanRedo)
                          .OnExecute(o => service.Redo())
                          .AddMonitor(observer);

            var person = new Person()
            {
                FirstName = "Mauro",
                LastName  = "Servienti"
            };

            var entity = new PersonViewModel();

            service.Attach(entity);

            entity.Initialize(person, false);

            Entity = entity;
        }
示例#2
0
        /// <summary>
        /// Attaches the specified list of entities to the change tracking service.
        /// </summary>
        /// <typeparam name="T">The type of the entity.</typeparam>
        /// <param name="service">The service to attach the entity to.</param>
        /// <param name="data">The source entity list.</param>
        /// <returns>The attached entity list.</returns>
        public static IEnumerable <T> Attach <T>(this IChangeTrackingService service, IEnumerable <T> data)
        {
            foreach (var element in data)
            {
                service.Attach(element);
            }

            return(data);
        }
示例#3
0
        /// <summary>
        /// Attaches the specified source entity to the change tracking service.
        /// </summary>
        /// <typeparam name="T">The type of the entity.</typeparam>
        /// <param name="service">The service to attach the entity to.</param>
        /// <param name="source">The source entity.</param>
        /// <returns>The attached entity.</returns>
        public static T Attach <T>(this IChangeTrackingService service, T source)
        {
            source.As <IMemento>(m =>
            {
                service.Attach(m);
            }, () =>
            {
                throw new NotSupportedException("Only IMemento enties can be attached to an IChangeTrackingService.");
            });

            return(source);
        }
        protected override void OnMementoChanged(IChangeTrackingService newMemento, IChangeTrackingService oldMemento)
        {
            base.OnMementoChanged(newMemento, oldMemento);

            if (oldMemento != null)
            {
                oldMemento.Detach(addressesDataSource);
            }

            if (newMemento != null)
            {
                newMemento.Attach(addressesDataSource);
            }
        }
示例#5
0
        public ComplexGraphViewModel()
        {
            var observer = MementoObserver.Monitor(service);

            UndoCommand = DelegateCommand.Create()
                          .OnCanExecute(o => service.CanUndo)
                          .OnExecute(o => service.Undo())
                          .AddMonitor(observer);

            RedoCommand = DelegateCommand.Create()
                          .OnCanExecute(o => service.CanRedo)
                          .OnExecute(o => service.Redo())
                          .AddMonitor(observer);

            CreateNewAddressCommand = DelegateCommand.Create()
                                      .OnExecute(o =>
            {
                var address     = Entity.Addresses.AddNew();
                SelectedAddress = address;
            });

            DeleteAddressCommand = DelegateCommand.Create()
                                   .OnCanExecute(o => SelectedAddress != null)
                                   .OnExecute(o =>
            {
                SelectedAddress.Delete();
                SelectedAddress = Entity.Addresses.FirstOrDefault();
            })
                                   .AddMonitor
                                   (
                PropertyObserver.For(this)
                .Observe(v => v.SelectedAddress)
                                   );

            var person = new Person()
            {
                FirstName = "Mauro",
                LastName  = "Servienti"
            };

            person.Addresses.Add(new Address(person)
            {
                City    = "Treviglio",
                Number  = "11",
                Street  = "Where I live",
                ZipCode = "20100"
            });

            person.Addresses.Add(new Address(person)
            {
                City    = "Daolasa",
                Number  = "2",
                Street  = "Pierino",
                ZipCode = "20100"
            });

            var entity = new PersonViewModel();

            entity.Initialize(person, false);

            service.Attach(entity);

            Entity = entity;
        }