private void init() { changeTrackingService = CommonServiceLocator.ServiceLocator.Current.GetInstance <IChangeTrackingService>(); props = new ObservableCollection <ChildViewModel>(); variances = new List <Variance>(); this.isExpandable = true; }
public UnitOfWork(ApplicationDbContext dbContext, IChangeTrackingService changeTrackingService, IMediator mediator, ILoggerFactory loggerFactory) { _dbContext = dbContext; _changeTrackingService = changeTrackingService; _mediator = mediator; _loggerFactory = loggerFactory; }
public void bookmark_valid_owner_null_iChange_valid_transientEntities_iChangeTrackingService_ctor() { IChangeTrackingService mock = A.Fake <IChangeTrackingService>(); Bookmark bmk = new Bookmark(mock, (IChange)null, new Object[0]); bmk.Position.Should().Be.Null(); }
/// <summary> /// Initializes a new instance of the <see cref="Bookmark"/> class. /// </summary> /// <param name="owner">The owner.</param> /// <param name="position">The position.</param> /// <param name="transientEntities">The transient entities.</param> public Bookmark(IChangeTrackingService owner, IChange position, IEnumerable <Object> transientEntities) { Ensure.That(owner).Named("owner").IsNotNull(); this.Owner = owner; this.Position = position; this.TransientEntities = transientEntities ?? new ReadOnlyCollection <Object>(new Object[0]); }
protected virtual MementoEntity CreateMock( IChangeTrackingService memento, bool registerAsrTransient ) { MockRepository mocks = new MockRepository(); var entity = mocks.PartialMock<MementoEntity>( memento, registerAsrTransient ); entity.Replay(); return entity; }
/// <summary> /// Initializes a new instance of the <see cref="Bookmark"/> class. /// </summary> /// <param name="owner">The owner.</param> /// <param name="position">The position.</param> /// <param name="transientEntities">The transient entities.</param> public Bookmark( IChangeTrackingService owner, IChange position, IEnumerable<Object> transientEntities ) { Ensure.That( owner ).Named( "owner" ).IsNotNull(); this.Owner = owner; this.Position = position; this.TransientEntities = transientEntities ?? new ReadOnlyCollection<Object>( new Object[ 0 ] ); }
public void bookmark_valid_owner_null_change_null_transientEntities_iChangeTrackingService_ctor_valid_transientEntities() { IChangeTrackingService mock = A.Fake <IChangeTrackingService>(); Bookmark bmk = new Bookmark(mock, (IChange)null, (IEnumerable <Object>)null); bmk.TransientEntities.Should().Not.Be.Null(); bmk.TransientEntities.Count().Should().Be.EqualTo(0); }
protected override void OnMementoChanged(IChangeTrackingService newMemento, IChangeTrackingService oldMemento) { base.OnMementoChanged(newMemento, oldMemento); if (this.MementoChanged != null) { this.MementoChanged(this, new MementoChangedEventArgs(newMemento, oldMemento)); } }
public Person( IChangeTrackingService memento, Boolean registerAsTransient ) : base( memento, registerAsTransient ) { this.nameRejectCallback = ( pcr ) => { this.CacheChangeOnRejectCallback( "property-name", this.Name, nameRejectCallback, null, pcr ); this._name = pcr.CachedValue; }; }
public Person(IChangeTrackingService memento, bool registerAsTransient) : base(memento, registerAsTransient) { this.nameRejectCallback = (pcr) => { this.CacheChangeOnRejectCallback("property-name", this.Name, nameRejectCallback, null, pcr); this._name = pcr.CachedValue; }; }
/// <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); }
public Person(IChangeTrackingService memento, ChangeTrackingRegistration registration, TransientRegistration transientRegistration) : base(memento, registration) { this.transientRegistration = transientRegistration; this.nameRejectCallback = (pcr) => { this.CacheChangeOnRejectCallback("property-name", this.Name, nameRejectCallback, null, pcr); this._name = pcr.CachedValue; }; }
public Person( IChangeTrackingService memento, ChangeTrackingRegistration registration, TransientRegistration transientRegistration ) : base( memento, registration ) { this.transientRegistration = transientRegistration; this.nameRejectCallback = ( pcr ) => { this.CacheChangeOnRejectCallback( "property-name", this.Name, nameRejectCallback, null, pcr ); this._name = pcr.CachedValue; }; }
/// <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); }
static IEnumerable <T> GetItemsWhereActionIs <T>(this IChangeTrackingService service, ProposedActions filter) { var items = service.GetAdvisory() .Where(a => { return(a.Target.GetType().Is <T>() && a.Action == filter); }) .Select(a => a.Target) .Cast <T>(); return(items); }
/// <summary> /// Generates the advisory. /// </summary> /// <param name="svc">The service that holds the data to generate the advisory for.</param> /// <param name="changeSet">The subset of changes to generate the advisory for.</param> /// <returns>The generated advisory.</returns> public IAdvisory GenerateAdvisory(IChangeTrackingService svc, IChangeSet changeSet) { var result = new List <IAdvisedAction>(); var distinct = this.visitor.Visit(changeSet); foreach (var kvp in distinct) { ProposedActions proposedAction = kvp.Value.GetAdvisedAction(kvp.Key); EntityTrackingStates state = svc.GetEntityState(kvp.Key); bool isTransient = (state & EntityTrackingStates.IsTransient) == EntityTrackingStates.IsTransient; switch (proposedAction) { case ProposedActions.Create | ProposedActions.Update: proposedAction = isTransient ? ProposedActions.Create : ProposedActions.Update; break; case ProposedActions.Delete | ProposedActions.Dispose: proposedAction = isTransient ? ProposedActions.Dispose : ProposedActions.Delete; break; default: throw new NotSupportedException(); } var advisedAction = this.OnCreateAdvisedAction(kvp.Key, proposedAction); result.Add(advisedAction); } IEnumerable transientEntities = svc.GetEntities(EntityTrackingStates.IsTransient, true); foreach (Object te in transientEntities) { if (result.Any(a => a.Target == te)) { /* * An entity is created as Transient+Persistable, then is added to * a MementoEntityCollection that tracks a change as "item-added" thus * the advisory adds that entity (that is not AutoRemove) as something that * must be created. so if we arrive here and we already have the transient * entity in the advisory we skip it. */ continue; } var advisedAction = this.OnCreateAdvisedAction(te, ProposedActions.Create); result.Add(advisedAction); } return(new Advisory(result)); }
public void bookmark_valid_owner_valid_iChange_valid_transientEntities_iChangeTrackingService_ctor() { IChangeTrackingService owner = A.Fake <IChangeTrackingService>(); IChange expected = A.Fake <IChange>(); Object[] entities = new Object[] { new Object(), new Object() }; Bookmark bmk = new Bookmark(owner, expected, entities); bmk.Position.Should().Be.EqualTo(expected); bmk.TransientEntities.Should().Not.Be.Null(); bmk.TransientEntities.Should().Have.SameSequenceAs(entities); }
protected virtual void OnMementoChanged(IChangeTrackingService newMemento, IChangeTrackingService oldMemento) { this.EnsureNotDisposed(); this.ForEach(e => { IMemento memento = e as IMemento; if (memento != null) { memento.Memento = newMemento; } }); }
/// <summary> /// Init methode to encapsule same methods /// </summary> private void Initialize() { changeTrackingService = CommonServiceLocator.ServiceLocator.Current.GetInstance <IChangeTrackingService>(); var collection = changeTrackingService.GetChangesWithObject(changeTrackingKey.PrimaryKey); foreach (var item in collection) { var model = new ChildViewModel(item); model.ChangedOn = DateTime.Now; Changes.Add(model); } ; }
protected override void OnMementoChanged(IChangeTrackingService newMemento, IChangeTrackingService oldMemento) { base.OnMementoChanged(newMemento, oldMemento); if (oldMemento != null) { oldMemento.Detach(addressesDataSource); } if (newMemento != null) { newMemento.Attach(addressesDataSource); } }
/// <summary> /// Generates the advisory. /// </summary> /// <param name="svc">The service that holds the data to generate the advisory for.</param> /// <param name="changeSet">The subset of changes to generate the advisory for.</param> /// <returns>The generated advisory.</returns> public IAdvisory GenerateAdvisory( IChangeTrackingService svc, IChangeSet changeSet ) { var result = new List<IAdvisedAction>(); var distinct = this.visitor.Visit( changeSet ); foreach( var kvp in distinct ) { ProposedActions proposedAction = kvp.Value.GetAdvisedAction( kvp.Key ); EntityTrackingStates state = svc.GetEntityState( kvp.Key ); Boolean isTransient = ( state & EntityTrackingStates.IsTransient ) == EntityTrackingStates.IsTransient; switch( proposedAction ) { case ProposedActions.Create | ProposedActions.Update: proposedAction = isTransient ? ProposedActions.Create : ProposedActions.Update; break; case ProposedActions.Delete | ProposedActions.Dispose: proposedAction = isTransient ? ProposedActions.Dispose : ProposedActions.Delete; break; default: throw new NotSupportedException(); } var advisedAction = this.OnCreateAdvisedAction( kvp.Key, proposedAction ); result.Add( advisedAction ); } IEnumerable transientEntities = svc.GetEntities( EntityTrackingStates.IsTransient, true ); foreach( Object te in transientEntities ) { if ( result.Any( a => a.Target == te ) ) { /* * An entity is created as Transient+Persistable, then is added to * a MementoEntityCollection that tracks a change as "item-added" thus * the advisory adds that entity (that is not AutoRemove) as something that * must be created. so if we arrive here and we already have the transient * entity in the advisory we skip it. */ continue; } var advisedAction = this.OnCreateAdvisedAction( te, ProposedActions.Create ); result.Add( advisedAction ); } return new Advisory( result ); }
public void entityMemento_memento_changing_current_onMementoChanged_is_invoked_with_expected_values() { IChangeTrackingService expectedNew = new ChangeTrackingService(); IChangeTrackingService expectedOld = new ChangeTrackingService(); IChangeTrackingService actualNew = null; IChangeTrackingService actualOld = null; var target = new TestableMementoEntity(expectedOld); target.MementoChanged += (s, e) => { actualNew = e.NewMemento; actualOld = e.OldMemento; }; ((IMemento)target).Memento = expectedNew; actualNew.Should().Be.EqualTo(expectedNew); actualOld.Should().Be.EqualTo(expectedOld); }
/// <summary> /// Initialize GUI context objects. /// </summary> private void PrivateInit(string pszMkDocument) { _noScribbleMode = false; _loading = false; var outputWindowPaneLogger = new OutputWindowLogger(DevEnv); var settings = DependencyManagerSettings.Instance; var componentTargetsPath = pszMkDocument; ISettings <ServiceValidSettings> settingsToUse; try { settingsToUse = CreateSettingsToUse(settings, componentTargetsPath); } catch (Exception) { throw new ArgumentException(String.Format("Visual Editor could not open the local file {0}! (Local file must to be part of a TFS workspace)", componentTargetsPath)); } var teamProjectCollectionUrl = TeamFoundationServerExt.ActiveProjectContext.DomainUri; var dependencyService = new DependencyService(settingsToUse); // Reload the dependency management settings on each new editor window instance DependencyManagerSettings.Instance.Load(teamProjectCollectionUrl); // create view and connect to view model _editorBootstrapper = new Bootstrapper { DependencyService = dependencyService, Logger = outputWindowPaneLogger, LocalPath = componentTargetsPath, TeamProjectCollectionUrl = teamProjectCollectionUrl }; _editorBootstrapper.Initialize(); _trackingService = _editorBootstrapper.GetExportedValue <IChangeTrackingService>(); _trackingService.HasChangesChanged += TrackingService_HasChangesChanged; _fileName = pszMkDocument; }
/// <summary> /// Called when the <see cref="IChangeTrackingService"/> changes. /// </summary> /// <param name="newMemento">The new memento service.</param> /// <param name="oldMemento">The old memmento service.</param> protected override void OnMementoChanged(IChangeTrackingService newMemento, IChangeTrackingService oldMemento) { base.OnMementoChanged(newMemento, oldMemento); if (oldMemento != null && !oldMemento.IsDisposed) { oldMemento.AcceptingChanges -= new EventHandler <CancelEventArgs>(OnAcceptingChanges); oldMemento.RejectingChanges -= new EventHandler <CancelEventArgs>(OnRejectingChanges); oldMemento.ChangesAccepted -= new EventHandler(OnChangesAccepted); oldMemento.ChangesRejected -= new EventHandler(OnChangesRejected); } if (newMemento != null && !newMemento.IsDisposed) { newMemento.AcceptingChanges += new EventHandler <CancelEventArgs>(OnAcceptingChanges); newMemento.RejectingChanges += new EventHandler <CancelEventArgs>(OnRejectingChanges); newMemento.ChangesAccepted += new EventHandler(OnChangesAccepted); newMemento.ChangesRejected += new EventHandler(OnChangesRejected); } }
public Person( IChangeTrackingService memento ) : this( memento, true ) { }
public TestableMementoEntity(IChangeTrackingService memento) : base(memento, true) { }
/// <summary> /// Called when the <see cref="IChangeTrackingService"/> changes. /// </summary> /// <param name="newMemento">The new memento service.</param> /// <param name="oldMemento">The old memmento service.</param> protected virtual void OnMementoChanged(IChangeTrackingService newMemento, IChangeTrackingService oldMemento) { }
public FakeMementoEntity(IChangeTrackingService memento, ChangeTrackingRegistration registration) : base(memento, registration) { }
public FakeMementoEntity(IChangeTrackingService memento, bool registerAsTransient) : base(memento, registerAsTransient) { }
public FakeMementoEntity(IChangeTrackingService memento) : base(memento) { }
/// <summary> /// Initializes a new instance of the <see cref="MementoEntity"/> class. /// </summary> /// <param name="memento">The memento.</param> /// <param name="registerAsTransient">if set to <c>true</c> [register as transient].</param> protected MementoEntity(IChangeTrackingService memento, bool registerAsTransient) : this(memento, registerAsTransient ? ChangeTrackingRegistration.AsTransient : ChangeTrackingRegistration.AsPersistent) { }
public static MementoMonitor Monitor(IChangeTrackingService source, IDispatcher dispatcher) { return(new MementoMonitor(source, dispatcher)); }
internal MementoChangedEventArgs(IChangeTrackingService newMemento, IChangeTrackingService oldMemento) { this.NewMemento = newMemento; this.OldMemento = oldMemento; }
/// <summary> /// Initializes a new instance of the <see cref="MementoEntity" /> class. /// </summary> /// <param name="memento">The memento.</param> /// <param name="registration">The registration.</param> protected MementoEntity(IChangeTrackingService memento, ChangeTrackingRegistration registration) : base() { this.registration = registration; ((IMemento)this).Memento = memento; }
public static MementoMonitor Monitor(IChangeTrackingService source) { return(new MementoMonitor(source)); }
/// <summary> /// Initializes a new instance of the <see cref="MementoEntity"/> class. /// </summary> /// <param name="memento">The memento.</param> protected MementoEntity(IChangeTrackingService memento) : this(memento, ChangeTrackingRegistration.AsTransient) { }