Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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;
        }
Beispiel #4
0
        /// <summary>
        /// Finds the application object by known maps.
        /// </summary>
        /// <param name="objectSpace">The object space.</param>
        /// <param name="reference">The reference.</param>
        /// <returns>Application object</returns>
        private static object findApplicationObjectByKnownMaps(IObjectSpace objectSpace, IObjectReference reference)
        {
            object result = null;

            // search using known mappings
            if (reference is IPackageObjectReference)
            {
                var objRef = (IPackageObjectReference)reference;
                if (!string.IsNullOrEmpty(objRef.KnownMapping))
                {
                    var typeInfo = objectSpace.TypesInfo.FindTypeInfo(objRef.ClassName);
                    if (typeInfo != null)
                    {
                        foreach (var mappingString in objRef.KnownMapping.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            var mapValues = mappingString.Split('\a');
                            if (mapValues.Length < 2)
                            {
                                continue;
                            }

                            var refNodeId = mapValues[0];

                            if (refNodeId == XafDeltaModule.Instance.CurrentNodeId)
                            {
                                // direct search by TargetId in current database
                                result = objectSpace.GetObjectByKey(typeInfo.Type,
                                                                    XPWeakReference.StringToKey(mapValues[1]));
                            }
                            else
                            {
                                // search similar mapping in existing OidMaps and return its target
                                var searchCriteria =
                                    CriteriaOperator.Parse("NodeId = ? And AssemblyName = ? And ClassName = ? And ObjectId = ?",
                                                           refNodeId, reference.AssemblyName, reference.ClassName, mapValues[1]);
                                var knownMap = objectSpace.FindObject <OidMap>(searchCriteria, true);
                                if (knownMap != null)
                                {
                                    result = knownMap.TargetObject;
                                }
                            }

                            if (result != null)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #5
0
 /// <summary>
 /// Convert NewObject reference to XPWeakReference after NewObject persist.
 /// </summary>
 internal void FixReference()
 {
     if (NewObject != null && NewObject is IXPObject)
     {
         var xpObj = (IXPObject)NewObject;
         if (!xpObj.Session.IsNewObject(xpObj))
         {
             xpObj     = (IXPObject)Session.GetObjectByKey(xpObj.ClassInfo, xpObj.Session.GetKeyValue(xpObj));
             Target    = new XPWeakReference(Session, xpObj);
             NewObject = null;
         }
     }
     Save();
 }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        /// <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);
        }
Beispiel #8
0
 /// <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 override object ConvertFromStorageType(object value)
 {
     return(XPWeakReference.StringToKey((string)value));
 }
Beispiel #11
0
 /// <summary>
 /// Convert NewObject reference to XPWeakReference after NewObject persist.
 /// </summary>
 internal void FixReference()
 {
     if (NewObject != null && NewObject is IXPObject)
     {
         var xpObj = (IXPObject)NewObject;
         if (!xpObj.Session.IsNewObject(xpObj))
         {
             xpObj = (IXPObject)Session.GetObjectByKey(xpObj.ClassInfo, xpObj.Session.GetKeyValue(xpObj));
             Target = new XPWeakReference(Session, xpObj);
             NewObject = null;
         }
     }
     Save();
 }
Beispiel #12
0
        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);
        }