public virtual bool Add(RevisionedObject rdo_insert) { string idProperty_Name = null; object check_exist = ResolveRDO(rdo_insert, out idProperty_Name); if (check_exist == null) { // Reuse exist RevBase if exist object rdo_base_exist = ResolveCDO(rdo_insert.RevBase.GetType(), rdo_insert.RevBase.Name); if (rdo_base_exist != null) rdo_insert.RevBase = rdo_base_exist as RevisionBase; foreach (PropertyInfo pi in rdo_insert.GetType().GetProperties()) { if (pi.Name == idProperty_Name || pi.Name == "RevBase") continue; // do not update Primary Property and RevBase object v_changes = pi.GetValue(rdo_insert, null); if (v_changes != null && (pi.CanWrite || v_changes.GetType().IsGenericType)) SetProperty(rdo_insert, pi, v_changes); } ObjScope.Transaction.Begin(); ObjScope.Add(rdo_insert); ObjScope.Transaction.Commit(); return true; } else return false; }
protected override bool Update(RevisionedObject rdo_changes, out RevisionedObject to_change) { bool success = base.Update(rdo_changes, out to_change); if (true == success) { success = RecordHistory(to_change, ActionType.Update); } return success; }
public override bool Remove(RevisionedObject rdo_obj) { bool success = base.Remove(rdo_obj); if (true == success) { success = RecordHistory(rdo_obj, ActionType.Delete); } return success; }
public override bool Add(RevisionedObject rdo_obj) { bool success = base.Add(rdo_obj); if (true == success) { success = RecordHistory(rdo_obj, ActionType.Insert); } return success; }
public virtual bool Dump(RevisionedObject rdo_obj) { object dump_obj = ResolveRDO(rdo_obj); if (dump_obj != null) { DumpCDOObject(dump_obj); return true; } else return false; }
private bool RecordHistory(RevisionedObject rdo_obj, ActionType actionType) { Spec o = rdo_obj as Spec; SpecChangeHistory h; if (actionType == ActionType.Delete) h = new SpecChangeHistory(null, this.TxnDate, actionType); else h = new SpecChangeHistory(rdo_obj, this.TxnDate, actionType); o.AssignToSpecChangeHistory(h); ObjScope.Transaction.Begin(); ObjScope.Add(h); ObjScope.Transaction.Commit(); return true; }
public virtual bool Remove(RevisionedObject rdo_obj) { RevisionedObject to_delete = ResolveRDO(rdo_obj); if (to_delete != null) { ObjScope.Transaction.Begin(); if (1 == RDOBaseUsageCount(to_delete)) ObjScope.Remove(to_delete.RevBase); ObjScope.Remove(to_delete); ObjScope.Transaction.Commit(); return true; } else return false; }
protected virtual bool Update(RevisionedObject rdo_changes, out RevisionedObject to_change) { string idProperty_Name; to_change = ResolveRDO(rdo_changes, out idProperty_Name); if (to_change != null) { ObjScope.Transaction.Begin(); foreach (PropertyInfo pi in rdo_changes.GetType().GetProperties()) { if (pi.Name == idProperty_Name || pi.Name == "RevBase") continue; // do not update Primary Property and RevBase object v_changes = pi.GetValue(rdo_changes, null); if (v_changes != null && (pi.CanWrite || v_changes.GetType().IsGenericType)) SetProperty(to_change, pi, v_changes); } ObjScope.Transaction.Commit(); return true; } else return false; }
public SpecChangeHistory(RevisionedObject toChangeRDO, DateTime actionDate, ActionType actionType) : base(actionDate, actionType) { spec = toChangeRDO as Spec; }
protected RevisionedObject ResolveRDO(RevisionedObject rdo_changes, out string idProperty_Name) { object to_change = null; string idProperty_Value = Service.GetIdentityFieldValue(rdo_changes, out idProperty_Name); if (idProperty_Value == null || idProperty_Value == "0") to_change = ResolveCDO(rdo_changes.GetType(), rdo_changes.DisplayName); else to_change = ResolveCDOByID(rdo_changes.GetType(), idProperty_Value); return to_change as RevisionedObject; }
protected RevisionedObject ResolveRDO(RevisionedObject rdo_changes) { string idProperty_Name; return ResolveRDO(rdo_changes, out idProperty_Name); }
public bool Update(RevisionedObject rdo_changes) { RevisionedObject to_change = null; return Update(rdo_changes, out to_change); }
private int RDOBaseUsageCount(RevisionedObject rdo_obj) { const string queryRDOBaseUsageCount = "SELECT COUNT(*) FROM {0}Extent AS o WHERE o.RevBase = $1"; int count = 0; IQuery oqlQuery = ObjScope.GetOqlQuery(string.Format(queryRDOBaseUsageCount,rdo_obj.GetType().Name)); IQueryResult result = oqlQuery.Execute(rdo_obj.RevBase); if (result.Count > 0) count = (int)result[0]; result.Dispose(); return count; }