コード例 #1
0
ファイル: DBObject.cs プロジェクト: aries544/eXpand
/*
        private XPMemberInfo GetCollectionProperty(string name)
        {
            XPMemberInfo info1 = ClassInfo.GetMember(name);
            if (info1 == null)
            {
                throw new PropertyMissingException(ClassInfo.FullName, name);
            }
            return info1;
        }
*/

//        /// <summary>
//        /// Stores all XPCollections marked with NoSaveAggregation
//        /// </summary>
//        private Hashtable CollectionsNoSaveAggregation
//        {
//            get
//            {
//                if (collectionsNoSaveAggregation == null)
//                    collectionsNoSaveAggregation = new Hashtable();
//
//                return collectionsNoSaveAggregation;
//            }
//        }

        public static XPCollection CreatePropertyCollectionNoSaveAggregation(DBObject owner,
                                                                             XPMemberInfo collectionProperty)
        {
            if (collectionProperty.IsManyToMany)
//                return new XPManyToManyNoSaveAggregation(owner, collectionProperty);
                throw new NotImplementedException("IsManyToMany on CreatePropertyCollectionNoSaveAggregation on " +
                                                  owner.GetType().FullName);
            return new XPCollection(owner.Session, owner, collectionProperty);
//            return new XPOneToManyCollectionNoSaveAggregation(owner, collectionProperty.Name);
//            AssociationAttribute attribute = (AssociationAttribute) collectionProperty.GetAttributeInfo(typeof(AssociationAttribute));
//
//            Type typeOfCollection = FindTypeOfCollection(attribute);
////            Type[] types = new Type[] {owner.GetType()};
////            Type builderType = GetBuilderType(typeOfCollection);
////            MethodInfo methodInfo = builderType.GetMethod("GetAll", types);
////            if (methodInfo == null)
////                throw new MethodNotFoundException(builderType, "GetAll", types);
//            XPOneToManyCollectionNoSaveAggregation xpOneToManyCollectionNoSaveAggregation = new XPOneToManyCollectionNoSaveAggregation(owner, collectionProperty.Name);
//            PropertyInfo[] propertyInfos = ReflectorHelper.GetDecoratedProperties(typeOfCollection, typeof(AssociationAttribute));
//            string propertyName = null;
//            foreach (PropertyInfo info in propertyInfos)
//                if (((AssociationAttribute) info.GetCustomAttributes(typeof (AssociationAttribute), true)[0]).Name ==
//                    attribute.Name)
//                    propertyName = info.Name;
//
//            DBCollection dbCollection = new DBCollection(owner.Session,typeOfCollection,new BinaryOperator(propertyName,owner));
//            foreach (DBObject dbObject in dbCollection)
//            {
//                if (xpOneToManyCollectionNoSaveAggregation.Lookup(dbObject.ClassInfo.KeyProperty.GetValue(dbObject)) ==null)
//                    xpOneToManyCollectionNoSaveAggregation.Add(dbObject);
//            }
//            
//            return xpOneToManyCollectionNoSaveAggregation;
        }
コード例 #2
0
ファイル: DBObject.cs プロジェクト: aries544/eXpand
//        public override void Save()
//        {
//            doEncryption();
//            EndEdit();
//            if (constrainsDisabled)
//            {
//                PropertyInfo[] propertyInfos = ReflectorHelper.GetPropertiesAssignAbleFrom(GetType(), typeof (DBObject));
//                foreach (PropertyInfo info in propertyInfos)
//                {
//                    DBObject value = (DBObject) info.GetValue(this, null);
//                    if (value != null) value.ConstrainsDisabled = true;
//                }
//            }
//            if (isDeleted)
//                base.Save();
//            else if (!constrainsDisabled && !HasErrors())
//            {
//                saveAggregated(this);
//                GetKey();
//                try
//                {
//                    base.Save();
//                }
//                catch (Exception e)
//                {
//                    throw new Exception("{" + ClassInfo.KeyProperty.GetValue(this) + "}" + GetType().FullName, e);
//                }
//                isChanged = false;
//            }
//            else if (constrainsDisabled)
//            {
//                GetKey();
//                base.Save();
//                isChanged = false;
//            }
//            else
//                throw new DALException(dataErrorInfoProvider.NoteError, GetType(), this);
////            if (dbObjectKey != null)
////            {
////                dbObjectKey.LastKey += 1;
////                dbObjectKey.Save();
////            }
//            DoDecryption();
//            AfterSave();
////            Reload();
//        }

        private void saveAggregated(DBObject dbObject)
        {
//            PropertyInfo[] properties =
//                ReflectorHelper.GetDecoratedProperties(dbObject.GetType(), typeof (MyAggregated));
//            foreach (PropertyInfo info in properties)
//            {
//                object value = info.GetValue(dbObject, null);
//                if (value != null)
//                {
//                    var dbObjectValue = (DBObject) value;
//                    saveAggregated(dbObjectValue);
//                    bool disabled = dbObjectValue.ConstrainsDisabled;
//                    dbObjectValue.ConstrainsDisabled = ConstrainsDisabled;
//                    dbObjectValue.Save();
//                    dbObjectValue.ConstrainsDisabled = disabled;
//                }
//            }
        }
コード例 #3
0
ファイル: DBObject.cs プロジェクト: aries544/eXpand
 /// <summary>
 /// searches the persistent properties of a DBObject for a member that implements ICollection and has an Attribute of type Association
 /// </summary>
 /// <param name="associationName"></param>
 /// <param name="dbObject"></param>
 /// <returns></returns>
 public static string GetAssociatedCollection(string associationName, DBObject dbObject)
 {
     return getAssociatedCollection(associationName, dbObject.ClassInfo);
 }
コード例 #4
0
ファイル: DBObject.cs プロジェクト: aries544/eXpand
        public static string GetFileData(Session session, DBObject document, string propertyName)
        {
            #region getField name
            XPMemberInfo member = document.ClassInfo.GetMember(propertyName);
            if (member.HasAttribute(typeof (PersistentAttribute)))
            {
                var attribute =
                    (PersistentAttribute) member.GetAttributeInfo(typeof (PersistentAttribute));
                propertyName = attribute.MapTo;
            }
            #endregion
            #region getTableName
            string tableName = document.GetType().Name;
            object[] attributes = document.GetType().GetCustomAttributes(typeof (MapToAttribute), true);
            if (attributes.Length > 0)
                tableName = ((MapToAttribute) attributes[0]).MappingName;
            #endregion
            IDbCommand command = session.Connection.CreateCommand();
            command.CommandText = "SELECT " + propertyName + " FROM " + tableName + " WHERE " +
                                  document.ClassInfo.KeyProperty.Name + "=" +
                                  document.ClassInfo.KeyProperty.GetValue(document);
            object reader = command.ExecuteScalar();
            var fileData = reader as string;
            command.Dispose();

            //            session.Connection.Close();
            return fileData;
        }
コード例 #5
0
ファイル: DBObject.cs プロジェクト: aries544/eXpand
 public static object GetPropertyInfoValue(string propertyName, DBObject dbObject)
 {
     return ReflectorHelper.GetPropertyInfoValue(propertyName, dbObject);
 }
コード例 #6
0
ファイル: DBObject.cs プロジェクト: aries544/eXpand
 public static void SetProperty(string propertyName, object value, DBObject dbObject)
 {
     ReflectorHelper.SetProperty(propertyName, value, dbObject);
 }
コード例 #7
0
ファイル: DBObject.cs プロジェクト: aries544/eXpand
 public DBObject SetProperties(DBObject dbObject, Session session, bool m_disableKeySet, ArrayList hashtables)
 {
     var clone = (DBObject) dbObject.ClassInfo.CreateObject(session);
     foreach (XPMemberInfo m in dbObject.ClassInfo.PersistentProperties)
     {
         if (m is ServiceField || (m.IsKey && !m_disableKeySet))
             continue;
         object val = m.GetValue(dbObject);
         if (hashtables != null && typeof (DBObject).IsAssignableFrom(m.MemberType))
         {
             bool notFound = true;
             foreach (Hashtable hashtable in hashtables)
             {
                 if (val != null && hashtable.ContainsKey(val))
                 {
                     val = hashtable[val];
                     notFound = false;
                 }
             }
             if (val != null && notFound)
             {
                 //						if (!setSelfReferenceProperty((DBObject)val,session,m_disableKeySet,m,hashtables))
                 throw new ArgumentException("An object of type " + m.MemberType.Name + " not found for member " +
                                             m.Name +
                                             Environment.NewLine +
                                             "DbObjectType=" + dbObject.TypeNameString);
             }
         }
         m.SetValue(clone, val);
     }
     clone.disableKeySet = m_disableKeySet;
     return clone;
 }