/// <summary> /// Creates the SnapshotOidMap for source object. /// </summary> /// <param name="sourceObject">The source object.</param> /// <param name="targetObject">The target object.</param> /// <returns></returns> public static SnapshotOidMap Create(object sourceObject, object targetObject) { var targetSession = ((ISessionProvider)targetObject).Session; var sourceSession = ((ISessionProvider)sourceObject).Session; /* 11.2.7 */ var modelClass = XafDeltaModule.XafApp.FindModelClass(targetObject.GetType()); var result = new SnapshotOidMap(targetSession) { Target = new XPWeakReference(targetSession, targetObject), // 11.2.7 StoredClassName = targetObject.GetType().FullName StoredClassName = modelClass.TypeInfo.FullName }; var sb = new StringBuilder(); sb.AppendFormat("{0}\a{1}\n", XafDeltaModule.Instance.CurrentNodeId, XPWeakReference.KeyToString(sourceSession.GetKeyValue(sourceObject))); var maps = OidMap.GetOidMaps((IXPObject)sourceObject); foreach (var oidMap in maps) { sb.AppendFormat("{0}\a{1}\n", oidMap.NodeId, oidMap.ObjectId); } result.KnownMapping = sb.ToString(); return(result); }
/// <summary> /// Gets the oid map for app object. /// </summary> /// <param name="appObject">The app object.</param> /// <param name="nodeId">The node id.</param> /// <returns>Oid map</returns> public static OidMap GetOidMap(object appObject, string nodeId) { if (appObject == null) { throw new ArgumentNullException("appObject"); } if (nodeId == null) { throw new ArgumentNullException("nodeId"); } var xpObj = (IXPObject)appObject; // search using OidMap var criteria = CriteriaOperator.Parse("NodeId = ? And AssemblyName = ? " + "And ClassName = ? And Not IsNull(Target) And Target.TargetKey_ = ?", nodeId, xpObj.ClassInfo.AssemblyName, xpObj.ClassInfo.FullName, XPWeakReference.KeyToString(xpObj.Session.GetKeyValue(xpObj))); var result = xpObj.Session.FindObject <OidMap>(PersistentCriteriaEvaluationBehavior.InTransaction, criteria); // search in new maps if (result == null) { var newMaps = xpObj.Session.GetObjectsToSave().Cast <object>().Where(x => x is OidMap).Cast <OidMap>(); foreach (var map in newMaps) { if (map.TargetObject == appObject) { result = map; break; } } } return(result); }
private void ShowNotesAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs args) { ListView lv = Application.CreateListView(Application.CreateObjectSpace(typeof(AuditDataItemPersistent)), typeof(AuditDataItemPersistent), true); GroupOperator criteria = new GroupOperator(GroupOperatorType.And); criteria.Operands.Add(new BinaryOperator("AuditedObject.TargetType", ((XPObjectSpace)ObjectSpace).Session.GetObjectType(View.CurrentObject))); criteria.Operands.Add(new BinaryOperator("AuditedObject.TargetKey", XPWeakReference.KeyToString(ObjectSpace.GetKeyValue(View.CurrentObject)))); lv.CollectionSource.Criteria["ByTargetObject"] = criteria; args.View = lv; }
XPBaseCollection GetAuditTrail(Session session, XPBaseObject xpBaseObject, Type auditedObjectWeakReferenceType) { var binaryOperator = new BinaryOperator("TargetType", session.GetObjectType(xpBaseObject)); var operands = new BinaryOperator("TargetKey", XPWeakReference.KeyToString(session.GetKeyValue(xpBaseObject))); var auditObjectWR = (XPWeakReference)session.FindObject(auditedObjectWeakReferenceType, new GroupOperator(binaryOperator, operands)); if (auditObjectWR != null) { var baseCollection = (XPBaseCollection)auditObjectWR.ClassInfo.GetMember("AuditDataItems").GetValue(auditObjectWR); baseCollection.BindingBehavior = CollectionBindingBehavior.AllowNone; return(baseCollection); } return(null); }
/// <summary> /// Gets the oid maps. /// </summary> /// <param name="source">The source.</param> /// <returns>Oid maps</returns> public static IEnumerable <OidMap> GetOidMaps(IXPObject source) { var className = source.ClassInfo.FullName; var modelClass = XafDeltaModule.XafApp.FindModelClass(source.GetType()); if (modelClass != null) { className = modelClass.Name; } var criteria = CriteriaOperator.Parse("ClassName = ? And Not IsNull(Target) And Target.TargetKey_ = ?", className /*source.ClassInfo.FullName*/, XPWeakReference.KeyToString(source.Session.GetKeyValue(source))); var result = new XPCollection <OidMap>(PersistentCriteriaEvaluationBehavior.InTransaction, source.Session, criteria); return(result); }
/// <summary> /// Store object data in reference. /// </summary> /// <param name="source">The source.</param> public virtual void Assign(object source) { if (source == null) { AssemblyName = ""; ClassName = ""; ObjectId = ""; AssemblyQualifiedName = ""; ReplicationKey = ""; } else { var modelClass = XafDeltaModule.XafApp.FindModelClass(source.GetType()); AssemblyName = modelClass.TypeInfo.AssemblyInfo.Assembly.GetName().Name; ClassName = modelClass.TypeInfo.FullName; ObjectId = XPWeakReference.KeyToString(modelClass.TypeInfo.KeyMember.GetValue(source)); AssemblyQualifiedName = modelClass.TypeInfo.Type.AssemblyQualifiedName; ReplicationKey = ExtensionsHelper.GetReplicationKey(source); } }
public override object ConvertToStorageType(object value) { return(XPWeakReference.KeyToString(value)); }
public void RestoreObject(AuditDataItemPersistent audit) { object currentobj = audit.AuditedObject.Target; if (!RestoredObjects.Contains(currentobj)) { RestoredObjects.Add(currentobj); } else { return; } ITypeInfo currenttypeinfo = XafTypesInfo.Instance.FindTypeInfo(currentobj.GetType()); foreach (AuditDataItemPersistent item in ObjectSpace.CreateCollection(typeof(AuditDataItemPersistent), CriteriaOperator.Parse("(AuditedObject = ? OR OldObject.TargetKey = ?) AND ModifiedOn >= ? AND (OperationType = 'ObjectDeleted' OR OperationType = 'RemovedFromCollection')", audit.AuditedObject, XPWeakReference.KeyToString(currenttypeinfo.KeyMember.GetValue(currentobj)), audit.ModifiedOn), new List <SortProperty>() { new SortProperty("ModifiedOn", DevExpress.Xpo.DB.SortingDirection.Ascending) })) { if (item.OperationType == "ObjectDeleted") { UndeleteObjectCore(currentobj, currenttypeinfo); } else if (item.OperationType == "RemovedFromCollection") { object oldobj = item.OldObject.Target; UndeleteObject(oldobj); object associatedobject = item.AuditedObject.Target; UndeleteObject(associatedobject); ITypeInfo associatedobjectinfo = XafTypesInfo.Instance.FindTypeInfo(associatedobject.GetType()); IList collection = associatedobjectinfo.FindMember(item.PropertyName).GetValue(associatedobject) as IList; collection.Add(oldobj); RestoreAggregateObjects(oldobj); RestoreAggregateObjects(associatedobject); } } RestoreAggregateObjects(currentobj); }