/// <summary> /// Overloading constructor to initialize the model /// </summary> public ChangeTrackingViewModel(ChangeTrackingKey changeTrackingKey) { this.changeTrackingKey = changeTrackingKey; Initialize(); model = new ChangeTracking(); }
public override void LoadData() { base.LoadData(); //Create a default change tracking insance var changeType = new ChangeType { Type = StaticProperties.TestString }; var changeTracking = new ChangeTracking { ChangeDate = DateTime.Now, ObjectChanged = StaticProperties.TestString, ObjectChangedID = StaticProperties.TestString, UserName = StaticProperties.TestString, ChangeType = changeType }; using (var ts = new TransactionScope()) { GenericBLL <ChangeType, int> .EnsurePersistent(changeType); GenericBLL <ChangeTracking, int> .EnsurePersistent(changeTracking); ts.CommitTransaction(); } }
public ObservableListViewModel(IViewInfo viewInfo, List <IViewModelEventSubscription <IViewModel, IEvent> > eventSubscriptions, List <IViewModelEventPublication <IViewModel, IEvent> > eventPublications, List <IViewModelEventCommand <IViewModel, IEvent> > commandInfo, ISystemProcess process, Type orientation, int priority) : base(process, viewInfo, eventSubscriptions, eventPublications, commandInfo, orientation, priority) { // Validator = new EntityValidator<TEntity>(); State.WhenAnyValue(x => x.Value).Subscribe(x => UpdateLocalState(x)); CurrentEntity.WhenAnyValue(x => x.Value).Subscribe(x => ChangeTracking.Clear()); _instance = this; }
/// <summary> /// Listens to the <see cref="OnPropertyChanged"/> to perform <see cref="ChangeTracking"/>. /// </summary> /// <param name="propertyName">The property name.</param> protected override void OnPropertyChanged(string propertyName) { base.OnPropertyChanged(propertyName); if (ChangeTracking != null && !ChangeTracking.Contains(propertyName)) { ChangeTracking.Add(propertyName); } }
public bool Save(ChangeTracking obj) { string sql = $"Insert into {TableName} ( JsonObject, DataGuid, CrudType, TableName, TimeStampChange, UserId, UserName)" + $"Values ( :JsonObject, :DataGuid, :CrudType, :TableName, :TimeStampChange, :UserId, :UserName) "; sqlService.OpenConnection((c) => { c.Execute(sql, new { JsonObject = obj.JsonObject, DataGuid = obj.DataGuid, CrudType = obj.CrudType, TableName = obj.TableName, TimeStampChange = obj.TimeStampChange, UserId = obj.UserId, UserName = obj.UserName }); }); return(true); }
public void SaveDeleteTest() { ChangeTracking tracking = new ChangeTracking(); ChangeType ctype = NHibernateHelper.DaoFactory.GetChangeTypeDao().GetById((int)ChangeTypes.Update, false); tracking.ObjectChanged = StaticProperties.TestString; tracking.ObjectChangedID = StaticProperties.ExistingProfileID.ToString(); tracking.ChangeType = ctype; Assert.IsTrue(ValidateBO <ChangeTracking> .isValid(tracking), "Tracking Object Not Valid"); Assert.IsTrue(tracking.IsTransient()); using (var ts = new TransactionScope()) { tracking = NHibernateHelper.DaoFactory.GetChangeTrackingDao().SaveOrUpdate(tracking); ts.CommitTransaction(); } Assert.IsFalse(tracking.IsTransient()); ChangeTracking trackingDB = NHibernateHelper.DaoFactory.GetChangeTrackingDao().GetById(tracking.ID, false); Assert.AreEqual <ChangeTracking>(tracking, trackingDB); this.TestContext.WriteLine("Tracking Created had ID = {0}", trackingDB.ID); using (var ts = new TransactionScope()) { NHibernateHelper.DaoFactory.GetChangeTrackingDao().Delete(tracking); ts.CommitTransaction(); } ////Make sure it is deleted bool isDeleted = false; try { tracking = NHibernateHelper.DaoFactory.GetChangeTrackingDao().GetById(trackingDB.ID, false); tracking.IsTransient(); } catch (NHibernate.ObjectNotFoundException) { isDeleted = true; } Assert.IsTrue(isDeleted); }
public Detection(ILogger log, EFClientStatistics clientStats) { Log = log; HitLocationCount = new Dictionary <IW4Info.HitLocation, HitInfo>(); foreach (var loc in Enum.GetValues(typeof(IW4Info.HitLocation))) { HitLocationCount.Add((IW4Info.HitLocation)loc, new HitInfo()); } ClientStats = clientStats; Strain = new Strain(); Tracker = new ChangeTracking <EFACSnapshot>(); TrackedHits = new List <EFClientKill>(); }
private void TrackChanges(List <ChangedProperty> changeList, object target, object id, ChangeTypes changeType) { ITrackable trackableObject = target as ITrackable; if (trackableObject == null || trackableObject.isTracked() == false) { return; } if (HttpContext.Current == null) { return; } ChangeTracking trackChange = new ChangeTracking(); if (trackableObject.arePropertiesTracked()) { trackChange.AppendProperties(changeList, trackChange); } trackChange.ChangeType = new NHibernateDaoFactory().GetChangeTypeDao().GetById((int)changeType, false); trackChange.UserName = HttpContext.Current.User.Identity.Name; trackChange.ObjectChanged = target.GetType().Name; trackChange.ObjectChangedID = id == null ? null : id.ToString(); //Now we have a tracking object with the changed properties added to its change list //Make sure it is valid if (ValidateBO <ChangeTracking> .isValid(trackChange)) { //Don't put this in a transaction becuase we are already in a transaction from the save/update/delete new NHibernateDaoFactory().GetChangeTrackingDao().SaveOrUpdate(trackChange); } //System.IO.StreamWriter writer = new System.IO.StreamWriter(HttpContext.Current.Server.MapPath("RecruitmentTracking.txt"),true); //writer.WriteLine("ChangeID {0} => Object type {1} with ID {2} was modified as follows", Guid.NewGuid(), target.GetType().Name, id.ToString()); //foreach (ChangedProperty change in changeList) //{ // //trackChange.PropertyChanged = change.type.Name; // //trackChange.PropertyChangedValue = change.NewValue; // writer.WriteLine("--- Property {0} was changed to {1}", change.PropertyChanged, change.PropertyChangedValue); //} //writer.Close(); }
public void CascadeSaveTest() { ChangeTracking target = NHibernateHelper.DaoFactory.GetChangeTrackingDao().GetById(StaticProperties.ExistingTrackingID, false); Assert.IsFalse(target.IsTransient()); if (target.ChangedProperties == null) { target.ChangedProperties = new List <ChangedProperty>(); } int numProperties = target.ChangedProperties.Count; //Now we'll add a few new properties to the target target.ChangedProperties.Add(new ChangedProperty(StaticProperties.TestString, StaticProperties.TestString, target)); target.ChangedProperties.Add(new ChangedProperty(StaticProperties.TestString, StaticProperties.TestString, target)); Assert.AreEqual <int>(numProperties + 2, target.ChangedProperties.Count); //make sure we have two new properties using (var ts = new TransactionScope()) { target = NHibernateHelper.DaoFactory.GetChangeTrackingDao().SaveOrUpdate(target); ts.CommitTransaction(); } foreach (ChangedProperty prop in target.ChangedProperties) { this.TestContext.WriteLine("Changed Property ID = {0} created: Property = {1}, new value = {2}", prop.ID, prop.PropertyChanged, prop.PropertyChangedValue); } Assert.IsFalse(target.IsTransient()); Assert.AreEqual <int>(numProperties + 2, target.ChangedProperties.Count); //make sure we STILL have two new properties //Delete the new properties target.ChangedProperties.RemoveAt(target.ChangedProperties.Count - 1); target.ChangedProperties.RemoveAt(target.ChangedProperties.Count - 1); using (var ts = new TransactionScope()) { target = NHibernateHelper.DaoFactory.GetChangeTrackingDao().SaveOrUpdate(target); ts.CommitTransaction(); } Assert.AreEqual <int>(numProperties, target.ChangedProperties.Count); //make sure we are back at the previous number of properties }
public dynamic GetValue([CallerMemberName] string property = "UnspecifiedProperty") { if (CurrentEntity.Value == null) { return(null); } var prop = CurrentEntity.Value.GetType().GetProperty(property, BindingFlags.Public | BindingFlags.Instance); if (prop == null) { return(null); } return(ChangeTracking.ContainsKey(property) ? ChangeTracking[property] : prop.GetValue(CurrentEntity.Value)); }
public void DoWork(string name, int age) { Queries queries = new Queries(); // queries.Start(); Projections projections = new Projections(); //projections.Start(); ChangeTracking changeTracking = new ChangeTracking(); //changeTracking.ContextLifeCycle(); DataLoading dataLoading = new DataLoading(); //dataLoading.Load(); ConnectedContext connected = new ConnectedContext(); //connected.CRUD_AutoDetectChanges(); connected.CRUD_DisableProxy(); }
/// <summary> /// Tracks the changes and saves them /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="obj"></param> /// <param name="crudType">Either insert/update or delete</param> /// <param name="tableName"></param> /// <param name="snapshot">a copy</param> public void TrackChange <TModel, TId>(object obj, CrudType crudType, string tableName, object snapshot, object primaryKey) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } ChangeTracking requestChange = new ChangeTracking { UserId = sessionService.CurrentSession.UserId, TableName = tableName, TimeStampChange = DateTime.Now, CrudType = crudType, }; requestChange = SetPrimaryKey <TModel, TId>(requestChange, primaryKey); if (obj is ITrackable trackable && trackable.Snapshot != null) { requestChange.JsonObject = DetailedCompare <TModel>((TModel)trackable.Snapshot, (TModel)obj); }
public void SetValue(dynamic value, [CallerMemberName] string property = "UnspecifiedProperty") { if (State.Value.Entity.GetType().GetProperty(property, BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance) == null) { return; } if (!ChangeTracking.ContainsKey(property)) { //Hack: fix this try { ChangeTracking.AddOrUpdate(property, value); } catch { } } else { ChangeTracking[property] = value; } this.RaisePropertyChanged(property); }
public void SetValue(dynamic value, [CallerMemberName] string property = "UnspecifiedProperty") { if (CurrentEntity.Value.GetType().GetProperty(property, BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance) == null) { return; } if (!ChangeTracking.ContainsKey(property)) { //HACK: doing this shit cuz jbcollection generating some error long after add no control to prevent error try { ChangeTracking.AddOrUpdate(property, value); } catch { } } else { ChangeTracking[property] = value; } this.RaisePropertyChanged(property); }
private void TrackChanges(List<ChangedProperty> changeList, object target, object id, ChangeTypes changeType) { ITrackable trackableObject = target as ITrackable; if (trackableObject == null || trackableObject.isTracked() == false) return; if (HttpContext.Current == null) return; ChangeTracking trackChange = new ChangeTracking(); if ( trackableObject.arePropertiesTracked() ) trackChange.AppendProperties(changeList, trackChange); trackChange.ChangeType = new NHibernateDaoFactory().GetChangeTypeDao().GetById((int)changeType, false); trackChange.UserName = HttpContext.Current.User.Identity.Name; trackChange.ObjectChanged = target.GetType().Name; trackChange.ObjectChangedID = id == null ? null : id.ToString(); //Now we have a tracking object with the changed properties added to its change list //Make sure it is valid if (ValidateBO<ChangeTracking>.isValid(trackChange)) { //Don't put this in a transaction becuase we are already in a transaction from the save/update/delete new NHibernateDaoFactory().GetChangeTrackingDao().SaveOrUpdate(trackChange); } //System.IO.StreamWriter writer = new System.IO.StreamWriter(HttpContext.Current.Server.MapPath("RecruitmentTracking.txt"),true); //writer.WriteLine("ChangeID {0} => Object type {1} with ID {2} was modified as follows", Guid.NewGuid(), target.GetType().Name, id.ToString()); //foreach (ChangedProperty change in changeList) //{ // //trackChange.PropertyChanged = change.type.Name; // //trackChange.PropertyChangedValue = change.NewValue; // writer.WriteLine("--- Property {0} was changed to {1}", change.PropertyChanged, change.PropertyChangedValue); //} //writer.Close(); }
/// <summary> /// Constructor to get the model /// </summary> /// <param name="model"></param> public ChangeTrackingViewModel(ChangeTracking model) { this.model = model; Initialize(); changeTrackingService.GetChanges(Guid.Parse("037AD2BD-E6C9-4247-B5AF-CE31509379DD")); }
/// <summary> /// Saves the request changes poco into database /// </summary> /// <param name="obj"></param> /// <returns></returns> public bool Save(ChangeTracking obj) { return(requestChangeRepository.Save(obj)); }
/// <summary> /// Constructor to get the model - type request change /// </summary> /// <param name="model"></param> public ChildViewModel(ChangeTracking model) { this.model = model; init(); }
/// <summary> /// Only to use it in this class /// </summary> private ChildViewModel() { model = new ChangeTracking(); init(); }
protected bool GetPropertyIsChanged([CallerMemberName] string property = "UnspecifiedProperty") { return(ChangeTracking.ContainsKey(property)); }
public void ConstructorTest() { ChangeTracking target = new ChangeTracking(); Assert.IsNotNull(target); }