Beispiel #1
0
        void ExportCore(XPBaseObject selectedObject, IEnumerable <IClassInfoGraphNode> serializedClassInfoGraphNodes,
                        XElement root)
        {
            var objectInfo = new ObjectInfo(selectedObject.GetType(),
                                            selectedObject.ClassInfo.KeyProperty.GetValue(selectedObject));

            if (!(exportedObjecs.ContainsKey(objectInfo)))
            {
                exportedObjecs.Add(objectInfo, null);
                var serializedObjectElement = new XElement("SerializedObject");
                serializedObjectElement.Add(new XAttribute("type", selectedObject.GetType().Name));
                root.Add(serializedObjectElement);
                foreach (
                    var classInfoGraphNode in
                    serializedClassInfoGraphNodes.Where(
                        node => node.SerializationStrategy != SerializationStrategy.DoNotSerialize))
                {
                    XElement propertyElement = GetPropertyElement(serializedObjectElement, classInfoGraphNode);
                    switch (classInfoGraphNode.NodeType)
                    {
                    case NodeType.Simple:
                        SetMemberValue(selectedObject, classInfoGraphNode, propertyElement);
                        break;

                    case NodeType.Object:
                        CreateObjectProperty(selectedObject, propertyElement, classInfoGraphNode, root);
                        break;

                    case NodeType.Collection:
                        CreateCollectionProperty(selectedObject, classInfoGraphNode, root, propertyElement);
                        break;
                    }
                }
            }
        }
Beispiel #2
0
 void ExportCore(XPBaseObject selectedObject, IEnumerable<IClassInfoGraphNode> serializedClassInfoGraphNodes,
                 XElement root) {
     var objectInfo = new ObjectInfo(selectedObject.GetType(),
                                     selectedObject.ClassInfo.KeyProperty.GetValue(selectedObject));
     if (!(exportedObjecs.ContainsKey(objectInfo))) {
         exportedObjecs.Add(objectInfo, null);
         var serializedObjectElement = new XElement("SerializedObject");
         serializedObjectElement.Add(new XAttribute("type", selectedObject.GetType().Name));
         root.Add(serializedObjectElement);
         foreach (
             var classInfoGraphNode in
                 serializedClassInfoGraphNodes.Where(
                     node => node.SerializationStrategy != SerializationStrategy.DoNotSerialize)) {
             XElement propertyElement = GetPropertyElement(serializedObjectElement, classInfoGraphNode);
             switch (classInfoGraphNode.NodeType) {
                 case NodeType.Simple:
                     SetMemberValue(selectedObject, classInfoGraphNode, propertyElement);
                     break;
                 case NodeType.Object:
                     CreateObjectProperty(selectedObject, propertyElement, classInfoGraphNode, root);
                     break;
                 case NodeType.Collection:
                     CreateCollectionProperty(selectedObject, classInfoGraphNode, root, propertyElement);
                     break;
             }
         }
     }
 }
Beispiel #3
0
 public static bool IsOutdated(this XPBaseObject obj)
 {
     using (UnitOfWork uow = new UnitOfWork(obj.Session.DataLayer)) {
         XPBaseObject obj1 = (XPBaseObject)uow.GetObjectByKey(obj.GetType(), obj.Session.GetKeyValue(obj));
         return(!Equals(obj1.ClassInfo.OptimisticLockField.GetValue(obj1), obj.ClassInfo.OptimisticLockField.GetValue(obj)));
     }
 }
        /// <summary>
        /// Поиск записи из коллекции.
        /// </summary>
        public static int FindRecordPossition(System.ComponentModel.Component сollection, XPBaseObject record)
        {
            if (record == null)
            {
                return(0);
            }

            if (сollection is XPCollection)
            {
                XPCollection xpCollection = сollection as XPCollection;
                string       propertyName = DBAttribute.GetKey(record.GetType());
                int          idRecord     = (int)record.GetMemberValue(propertyName);

                for (int i = 0; i < xpCollection.Count; i++)
                {
                    XPBaseObject recordInt = (XPBaseObject)xpCollection[i];

                    int idRecordInt = (int)recordInt.GetMemberValue(propertyName);

                    if (idRecordInt == idRecord)
                    {
                        return(i);
                    }
                }
            }
            return(0);
        }
Beispiel #5
0
        public static void SetXpMemberProperty(string propertyName, object value, XPBaseObject dbObject, bool save)
        {
            if (propertyName.IndexOf(".") > -1)
            {
                XPMemberInfo member = dbObject.ClassInfo.GetMember(propertyName.Split(".".ToCharArray())[0]);
                object       o      = member.GetValue(dbObject);
                if (typeof(XPBaseObject).IsAssignableFrom(member.MemberType))
                {
                    dbObject = o as XPBaseObject;
                    SetXpMemberProperty(propertyName.Substring(propertyName.IndexOf(".") + 1), value, dbObject, save);
                    return;
                }
                SetPropertyValue(o.GetType().GetProperty(propertyName.Substring(propertyName.IndexOf(".") + 1)), o,
                                 value);
                return;
            }
            XPMemberInfo xpMemberInfo = dbObject.ClassInfo.GetMember(propertyName);

            if (xpMemberInfo == null)
            {
                throw new PropertyMissingException(dbObject.GetType().FullName, propertyName);
            }
            xpMemberInfo.SetValue(dbObject,
                                  xpMemberInfo.Owner.ClassType.GetProperty(propertyName) == null
                                      ? value
                                      : ChangeType(value, xpMemberInfo.MemberType));
            if (save)
            {
                dbObject.Save();
            }
        }
Beispiel #6
0
        public static object GetXpMemberInfoValue(string propertyName, XPBaseObject o)
        {
            if (propertyName.IndexOf(".") > -1)
            {
                XPMemberInfo info  = o.ClassInfo.GetMember(propertyName.Split(".".ToCharArray())[0]);
                object       value = info.GetValue(o);
                if (typeof(XPBaseObject).IsAssignableFrom(info.MemberType))
                {
                    o = value as XPBaseObject;
                    return(o == null
                               ? null
                               : GetXpMemberInfoValue(propertyName.Substring(propertyName.IndexOf(".") + 1), o));
                }
                return
                    (value != null
                        ? GetPropertyInfoValue(propertyName.Substring(propertyName.IndexOf(".") + 1), info.GetValue(o))
                        : null);
            }
            XPMemberInfo xpMemberInfo = o.ClassInfo.GetMember(propertyName);

            if (xpMemberInfo == null)
            {
                throw new PropertyMissingException(o.GetType().FullName, propertyName);
            }
            return(xpMemberInfo.GetValue(o));
        }
        public static MemberProtectedInfo IsProtected(XPBaseObject baseObject, string propertyName){
            propertyName = propertyName.Replace("!", "");
            XPMemberInfo memberInfo = ReflectorHelper.GetXpMemberInfo(baseObject.Session, baseObject.GetType(),
                                                                      propertyName);

//            XPClassInfo xpClassInfo = memberInfo.ReferenceType;
//            FilterRecordAttribute attributeInfo = xpClassInfo != null
//                                                      ? (FilterRecordAttribute)
//                                                        xpClassInfo.FindAttributeInfo(
//                                                            typeof (FilterRecordAttribute))
//                                                      :
//                                                          null;

            if ( memberInfo.IsPersistent)
            {
//                if (attributeInfo != null &&attributeSatisfyUser(attributeInfo)&&
//                    criteriaSatisfyMember(propertyName, baseObject, xpClassInfo, attributeInfo))
//                    return new MemberProtectedInfo(true, true);
                var b = (bool?) ReflectorHelper.GetXpMemberInfoValue(propertyName +
                                                                     MemberLevelSecuritySuffix, baseObject);
                return new MemberProtectedInfo(false, b.HasValue && b.Value);
            }
            
            return new MemberProtectedInfo(false, false);
        }
Beispiel #8
0
 void ExportCore(XPBaseObject selectedObject, IEnumerable<IClassInfoGraphNode> serializedClassInfoGraphNodes, XElement root) {
     var serializedObjectElement = new XElement("SerializedObject");
     serializedObjectElement.Add(new XAttribute("type", selectedObject.GetType().Name));
     root.Add(serializedObjectElement);
     foreach (var classInfoGraphNode in serializedClassInfoGraphNodes) {
         XElement propertyElement = GetPropertyElement(serializedObjectElement, classInfoGraphNode);
         switch (classInfoGraphNode.NodeType) {
             case NodeType.Simple:
                 propertyElement.Value = GetMemberValue(selectedObject, classInfoGraphNode) + "";
                 break;
             case NodeType.Object:
                 createObjectProperty(selectedObject, propertyElement, classInfoGraphNode, root);
                 break;
             case NodeType.Collection:
                 createCollectionProperty(selectedObject, classInfoGraphNode, root, propertyElement);
                 break;
         }
     }
 }
 public IEnumerable<IClassInfoGraphNode> GetSerializedClassInfoGraphNodes(XPBaseObject baseObject) {
     var configuration = GetConfiguration(baseObject.Session, baseObject.GetType());
     return GetSerializedClassInfoGraphNodes(configuration);
 }
        public static void SetXpMemberProperty(string propertyName, object value, XPBaseObject dbObject, bool save) {
            if (propertyName.IndexOf(".", StringComparison.Ordinal) > -1) {
                XPMemberInfo member = dbObject.ClassInfo.GetMember(propertyName.Split(".".ToCharArray())[0]);
                object o = member.GetValue(dbObject);
                if (typeof(XPBaseObject).IsAssignableFrom(member.MemberType)) {
                    dbObject = o as XPBaseObject;
                    SetXpMemberProperty(propertyName.Substring(propertyName.IndexOf(".", StringComparison.Ordinal) + 1), value, dbObject, save);
                    return;
                }
                SetPropertyValue(o.GetType().GetProperty(propertyName.Substring(propertyName.IndexOf(".", StringComparison.Ordinal) + 1)), o,
                                 value);
                return;
            }
            XPMemberInfo xpMemberInfo = dbObject.ClassInfo.GetMember(propertyName);
            if (xpMemberInfo == null)
                throw new PropertyMissingException(dbObject.GetType().FullName, propertyName);
            xpMemberInfo.SetValue(dbObject,
                                  xpMemberInfo.Owner.ClassType.GetProperty(propertyName) == null
                                      ? value
                                      : ChangeType(value, xpMemberInfo.MemberType));
            if (save)
                dbObject.Save();

        }
 public static object GetXpMemberInfoValue(string propertyName, XPBaseObject o) {
     if (propertyName.IndexOf(".", StringComparison.Ordinal) > -1) {
         XPMemberInfo info = o.ClassInfo.GetMember(propertyName.Split(".".ToCharArray())[0]);
         object value = info.GetValue(o);
         if (typeof(XPBaseObject).IsAssignableFrom(info.MemberType)) {
             o = value as XPBaseObject;
             return o == null
                        ? null
                        : GetXpMemberInfoValue(propertyName.Substring(propertyName.IndexOf(".", StringComparison.Ordinal) + 1), o);
         }
         return
             value != null
                 ? GetPropertyInfoValue(propertyName.Substring(propertyName.IndexOf(".", StringComparison.Ordinal) + 1), info.GetValue(o))
                 : null;
     }
     XPMemberInfo xpMemberInfo = o.ClassInfo.GetMember(propertyName);
     if (xpMemberInfo == null)
         throw new PropertyMissingException(o.GetType().FullName, propertyName);
     return xpMemberInfo.GetValue(o);
 }
Beispiel #12
0
        public IEnumerable <IClassInfoGraphNode> GetSerializedClassInfoGraphNodes(XPBaseObject baseObject)
        {
            var configuration = GetConfiguration(baseObject.Session, baseObject.GetType());

            return(GetSerializedClassInfoGraphNodes(configuration));
        }
Beispiel #13
0
 IEnumerable<IClassInfoGraphNode> GetSerializedClassInfoGraphNodes(XPBaseObject baseObject, ISerializationConfiguration serializationConfiguration) {
     ISerializationConfiguration configuration = baseObject.GetType() ==serializationConfiguration.TypeToSerialize? serializationConfiguration
                                                     : SerializationConfigurationQuery.Find(baseObject.Session, baseObject.GetType());
     return GetSerializedClassInfoGraphNodes(configuration);
 }