Example #1
0
        /// <summary>
        /// Accepts the changes.
        /// </summary>
        public virtual void AcceptChanges()
        {
            Logger.Debug(String.Format("Accepting changes with a following state {0}.", this.ObjectState.ToString()));
            using (TransactionScope scope = new TransactionScope())
            {
                switch (this.ObjectState)
                {
                case MetaObjectState.Added:
                    OnSaved(DataService.ExecuteNonExec(CreateInsertCommand()));
                    this._State = MetaObjectState.Unchanged;
                    break;

                case MetaObjectState.Modified:
                    OnSaved(DataService.ExecuteNonExec(CreateUpdateCommand()));
                    this._State = MetaObjectState.Unchanged;
                    break;

                case MetaObjectState.Deleted:
                    DataService.Run(CreateDeleteCommand());
                    // need to remove item from the collection
                    if (StorageCollection != null)
                    {
                        StorageCollection.RemovedDeletedItem(this);
                    }
                    break;

                case MetaObjectState.Unchanged:
                    break;
                }
                scope.Complete();
            }
        }
Example #2
0
 /// <summary>
 /// Marks current instance as new which will cause new record to be created in the database for the specified object.
 /// This is useful for creating duplicates of existing objects.
 /// </summary>
 internal virtual void MarkNew()
 {
     if (_State != MetaObjectState.Deleted)
     {
         _State = MetaObjectState.Added;
     }
 }
Example #3
0
        static M()
        {
            // Interfaces
            Object                          = MetaObject.Instance;
            Cachable                        = MetaCachable.Instance;
            Deletable                       = MetaDeletable.Instance;
            Enumeration                     = MetaEnumeration.Instance;
            UniquelyIdentifiable            = MetaUniquelyIdentifiable.Instance;
            Version                         = MetaVersion.Instance;
            Versioned                       = MetaVersioned.Instance;
            Printable                       = MetaPrintable.Instance;
            Localised                       = MetaLocalised.Instance;
            AccessControlledObject          = MetaAccessControlledObject.Instance;
            DelegatedAccessControlledObject = MetaDelegatedAccessControlledObject.Instance;
            SecurityTokenOwner              = MetaSecurityTokenOwner.Instance;
            ObjectState                     = MetaObjectState.Instance;
            Task                = MetaTask.Instance;
            Transitional        = MetaTransitional.Instance;
            TransitionalVersion = MetaTransitionalVersion.Instance;
            User                = MetaUser.Instance;
            WorkItem            = MetaWorkItem.Instance;

            // Classes
            Employment       = MetaEmployment.Instance;
            Organisation     = MetaOrganisation.Instance;
            Person           = MetaPerson.Instance;
            Settings         = MetaSettings.Instance;
            Singleton        = MetaSingleton.Instance;
            Counter          = MetaCounter.Instance;
            Media            = MetaMedia.Instance;
            MediaContent     = MetaMediaContent.Instance;
            PrintDocument    = MetaPrintDocument.Instance;
            Template         = MetaTemplate.Instance;
            TemplateType     = MetaTemplateType.Instance;
            PreparedExtent   = MetaPreparedExtent.Instance;
            PreparedFetch    = MetaPreparedFetch.Instance;
            Country          = MetaCountry.Instance;
            Currency         = MetaCurrency.Instance;
            Language         = MetaLanguage.Instance;
            Locale           = MetaLocale.Instance;
            LocalisedText    = MetaLocalisedText.Instance;
            AccessControl    = MetaAccessControl.Instance;
            Login            = MetaLogin.Instance;
            Permission       = MetaPermission.Instance;
            Role             = MetaRole.Instance;
            SecurityToken    = MetaSecurityToken.Instance;
            AutomatedAgent   = MetaAutomatedAgent.Instance;
            EmailMessage     = MetaEmailMessage.Instance;
            Notification     = MetaNotification.Instance;
            NotificationList = MetaNotificationList.Instance;
            TaskAssignment   = MetaTaskAssignment.Instance;
            TaskList         = MetaTaskList.Instance;
            UserGroup        = MetaUserGroup.Instance;
        }
Example #4
0
        /// <summary>
        /// Loads the specified row.
        /// </summary>
        /// <param name="row">The row.</param>
        public virtual void Load(DataRowView row)
        {
            if (row == null)
            {
                throw new ArgumentNullException("row");
            }

            foreach (DataColumn column in row.DataView.Table.Columns)
            {
                this[column.ColumnName] = row[column.ColumnName];
            }

            this._State = MetaObjectState.Unchanged;
        }
Example #5
0
        /// <summary>
        /// Loads the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public virtual void Load(IDataReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            for (int index = 0; index < reader.FieldCount; index++)
            {
                this[reader.GetName(index)] = reader[index];
            }

            this._State = MetaObjectState.Unchanged;
        }
Example #6
0
        /// <summary>
        /// Changes the state.
        /// </summary>
        protected void ChangeState()
        {
            switch (this.ObjectState)
            {
            case MetaObjectState.Added:
                break;

            case MetaObjectState.Deleted:
                throw new DeletedObjectInaccessibleException();

            case MetaObjectState.Modified:
                break;

            case MetaObjectState.Unchanged:
                this._State = MetaObjectState.Modified;
                break;
            }
        }
Example #7
0
        /// <summary>
        /// Deletes this instance.
        /// </summary>
        public virtual void Delete()
        {
            // If item has been just added, simply remove it from the collection
            if (this.ObjectState == MetaObjectState.Added)
            {
                if (StorageCollection != null)
                {
                    StorageCollection.Remove(this);
                }

                return;
            }

            this._State = MetaObjectState.Deleted;

            // need to remove item from the collection
            if (StorageCollection != null)
            {
                StorageCollection.DeleteItem(this);
            }
        }
Example #8
0
        /*
         *  //First we create an instance of this specific type.
         *  object newObject = new ClassInfo(GetType()).CreateInstance();
         *
         *  //We get the array of fields for the new type instance.
         *  FieldInfo[] fields = newObject.GetType().GetFields();
         *
         *  int i = 0;
         *
         *  foreach (FieldInfo fi in this.GetType().GetFields())
         *  {
         *      //We query if the fiels support the ICloneable interface.
         *      Type ICloneType = fi.FieldType.
         *                  GetInterface("ICloneable", true);
         *
         *      if (ICloneType != null)
         *      {
         *          //Getting the ICloneable interface from the object.
         *          ICloneable IClone = (ICloneable)fi.GetValue(this);
         *
         *          //We use the clone method to set the new value to the field.
         *          fields[i].SetValue(newObject, IClone.Clone());
         *      }
         *      else
         *      {
         *          // If the field doesn't support the ICloneable
         *          // interface then just set it.
         *          fields[i].SetValue(newObject, fi.GetValue(this));
         *      }
         *
         *      //Now we check if the object support the
         *      //IEnumerable interface, so if it does
         *      //we need to enumerate all its items and check if
         *      //they support the ICloneable interface.
         *      Type IEnumerableType = fi.FieldType.GetInterface
         *                      ("IEnumerable", true);
         *      if (IEnumerableType != null)
         *      {
         *          //Get the IEnumerable interface from the field.
         *          IEnumerable IEnum = (IEnumerable)fi.GetValue(this);
         *
         *          //This version support the IList and the
         *          //IDictionary interfaces to iterate on collections.
         *          Type IListType = fields[i].FieldType.GetInterface
         *                              ("IList", true);
         *          Type IDicType = fields[i].FieldType.GetInterface
         *                              ("IDictionary", true);
         *
         *          int j = 0;
         *          if (IListType != null)
         *          {
         *              //Getting the IList interface.
         *              IList list = (IList)fields[i].GetValue(newObject);
         *
         *              foreach (object obj in IEnum)
         *              {
         *                  //Checking to see if the current item
         *                  //support the ICloneable interface.
         *                  ICloneType = obj.GetType().
         *                      GetInterface("ICloneable", true);
         *
         *                  if (ICloneType != null)
         *                  {
         *                      //If it does support the ICloneable interface,
         *                      //we use it to set the clone of
         *                      //the object in the list.
         *                      ICloneable clone = (ICloneable)obj;
         *
         *                      list[j] = clone.Clone();
         *                  }
         *
         *                  //NOTE: If the item in the list is not
         *                  //support the ICloneable interface then in the
         *                  //cloned list this item will be the same
         *                  //item as in the original list
         *                  //(as long as this type is a reference type).
         *
         *                  j++;
         *              }
         *          }
         *          else if (IDicType != null)
         *          {
         *              //Getting the dictionary interface.
         *              IDictionary dic = (IDictionary)fields[i].
         *                                  GetValue(newObject);
         *              j = 0;
         *
         *              foreach (DictionaryEntry de in IEnum)
         *              {
         *                  //Checking to see if the item
         *                  //support the ICloneable interface.
         *                  ICloneType = de.Value.GetType().
         *                      GetInterface("ICloneable", true);
         *
         *                  if (ICloneType != null)
         *                  {
         *                      ICloneable clone = (ICloneable)de.Value;
         *
         *                      dic[de.Key] = clone.Clone();
         *                  }
         *                  j++;
         *              }
         *          }
         *      }
         *      i++;
         *  }
         *  return newObject;
         * */

        #region ISerializable Members
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleObject"/> class.
        /// </summary>
        /// <param name="info">The info.</param>
        /// <param name="context">The context.</param>
        protected SimpleObject(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            Logger = LogManager.GetLogger(GetType());
            _State = (MetaObjectState)info.GetValue("__State", typeof(MetaObjectState));

            // Save user fields
            foreach (SerializationEntry entry in info)
            {
                // skip system meta fields
                if (entry.Name.StartsWith("__"))
                {
                    continue;
                }

                // Load the value
                _FieldStorage[entry.Name] = entry.Value;
            }
        }
Example #9
0
 public void Delete()
 {
     this._state = MetaObjectState.Deleted;
 }
Example #10
0
        public void AcceptChanges()
        {
            switch (this.ObjectState)
            {
                case MetaObjectState.Added:
                case MetaObjectState.Modified:
                    // Insert or Update object [11/25/2004]
                    SqlParameter[] sqlParams = new SqlParameter[6 + 1 + this.FieldStorage.Keys.Count];

                    int Index = 0;
                    sqlParams[Index++] = new SqlParameter("@ObjectId", this.Id);

                    sqlParams[Index++] = new SqlParameter("@CreatorId", this.CreatorId);
                    sqlParams[Index++] = new SqlParameter("@Created", this.Created);

                    sqlParams[Index++] = new SqlParameter("@ModifierId", this.ModifierId);
                    sqlParams[Index++] = new SqlParameter("@Modified", this.Modified);

                    //if (MetaDataContext.Current.Language != null)
                    //{
                    //	sqlParams[Index++] = new SqlParameter("@Language", MetaDataContext.Current.Language);
                    //}
                    //else sqlParams[Index++] = new SqlParameter("@Language", DBNull.Value);

                    SqlParameter RetvalParam = new SqlParameter("@Retval", SqlDbType.Int);
                    RetvalParam.Direction = ParameterDirection.Output;
                    sqlParams[Index++] = RetvalParam;

                    foreach (string Key in this.FieldStorage.Keys)
                    {
                        object FieldValue = this.FieldStorage[Key] == null ? DBNull.Value : this.FieldStorage[Key];

                        // OZ: I changed lines to fix System and User field with same named problem.
                        //MetaField	metaField = this.MetaClass.MetaFields[Key];
                        MetaField metaField = this.MetaClass.UserMetaFields[Key];

                        //if(metaField.IsSystem)
                        //	continue;

                        if (FieldValue != DBNull.Value)
                        {
                            #region FieldValue!=DBNull.Value Section
                            if (metaField.DataType == MetaDataType.DictionarySingleValue ||
                                metaField.DataType == MetaDataType.EnumSingleValue)
                            {
                                FieldValue = ((MetaDictionaryItem)FieldValue).Id;
                            }
                            else if (metaField.DataType == MetaDataType.DictionaryMultivalue ||
                                metaField.DataType == MetaDataType.EnumMultivalue)
                            {
                                if (this.Id != -1)
                                {
                                    // Step 1. Resived Meta Key Value [11/30/2004]
                                    int MetaKey = SqlHelper.GetMetaKey(this.Id, this.MetaClass.Id, metaField.Id);

                                    // Step 2. Clear old value [11/30/2004]
                                    SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_ClearMultivalueDictionary"),
                                        new SqlParameter("@MetaKey", MetaKey));

                                    // Step 3. Save new values [11/30/2004]
                                    foreach (MetaDictionaryItem DicItem in (MetaDictionaryItem[])FieldValue)
                                    {
                                        SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_AddMultivalueDictionary"),
                                            new SqlParameter("@MetaKey", MetaKey),
                                            new SqlParameter("@MetaDictionaryId", DicItem.Id));
                                    }

                                    FieldValue = MetaKey;
                                }
                                else
                                {
                                    FieldValue = (int)-1;
                                }
                            }
                            else if (metaField.DataType == MetaDataType.File || metaField.DataType == MetaDataType.ImageFile)
                            {
                                if (this.Id != -1)
                                {
                                    MetaFile file = (MetaFile)FieldValue;

                                    // Step 1. Resived Meta Key Value [11/30/2004]
                                    int MetaKey = SqlHelper.GetMetaKey(this.Id, this.MetaClass.Id, metaField.Id);

                                    if (file.HasChanges)
                                    {
                                        SqlParameter spData = new SqlParameter("@Data", SqlDbType.Image);
                                        spData.Value = SqlHelper.Null2DBNull(MetaDataContext.Current.MetaFileDataStorageType == MetaFileDataStorageType.DataBase ? file.Buffer : null);

                                        // Step 3. Save new values [11/30/2004]
                                        SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_UpdateMetaFile"),
                                            new SqlParameter("@MetaKey", MetaKey),
                                            new SqlParameter("@FileName", file.Name),
                                            new SqlParameter("@ContentType", file.ContentType),
                                            new SqlParameter("@Size", file.Size),
                                            spData,
                                            new SqlParameter("@CreationTime", file.CreationTime),
                                            new SqlParameter("@LastReadTime", file.LastReadTime),
                                            new SqlParameter("@LastWriteTime", file.LastWriteTime));

                                        if (MetaDataContext.Current.MetaFileDataStorageType == MetaFileDataStorageType.LocalDisk)
                                        {
                                            using (FileStream stream = File.OpenWrite(Path.Combine(MetaDataContext.Current.LocalDiskStorage, string.Format("{0}.mdpdata", MetaKey))))
                                            {
                                                if (file.Buffer != null)
                                                    stream.Write(file.Buffer, 0, file.Size);
                                                stream.SetLength(file.Size);
                                                stream.Flush();
                                            }
                                        }

                                        file.HasChanges = false;
                                        file.SetId(MetaKey);
                                    }

                                    FieldValue = MetaKey;
                                }
                                else
                                {
                                    FieldValue = (int)-1;
                                }

                            }
                            else if (metaField.DataType == MetaDataType.StringDictionary)
                            {
                                if (this.Id != -1)
                                {
                                    MetaStringDictionary dic = (MetaStringDictionary)FieldValue;

                                    // Step 1. Resived Meta Key Value [11/30/2004]
                                    int MetaKey = SqlHelper.GetMetaKey(this.Id, this.MetaClass.Id, metaField.Id);

                                    // Step 2. Clear old value [11/30/2004]
                                    SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_ClearStringDictionary"),
                                        new SqlParameter("@MetaKey", MetaKey));

                                    // Step 3. Add new value [12/23/2004]
                                    foreach (string KeyValue in dic.Keys)
                                    {
                                        SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_AddMetaStringDictionary"),
                                            new SqlParameter("@MetaKey", MetaKey),
                                            new SqlParameter("@Key", KeyValue),
                                            new SqlParameter("@Value", dic[KeyValue]));
                                    }

                                    FieldValue = MetaKey;
                                }
                                else
                                {
                                    FieldValue = (int)-1;
                                }

                            }
                            else if (metaField.DataType == MetaDataType.MetaObject)
                            {
                                if (this.Id != -1)
                                {
                                    MetaObject mObject = (MetaObject)FieldValue;

                                    // Step 1. Resived Meta Key Value [11/30/2004]
                                    int MetaKey = SqlHelper.GetMetaKey(this.Id, this.MetaClass.Id, metaField.Id);

                                    // Step 2. Clear old value [11/30/2004]
                                    SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_DeleteMetaObjectValue"),
                                        new SqlParameter("@MetaKey", MetaKey));

                                    // Step 3. Add new value [12/23/2004]
                                    SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_UpdateMetaObjectValue"),
                                        new SqlParameter("@MetaKey", MetaKey),
                                        new SqlParameter("@MetaClassId", mObject.MetaClass.Id),
                                        new SqlParameter("@MetaObjectId", mObject.Id));
                                }
                                else
                                {
                                    FieldValue = (int)-1;
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            #region DBNull.Value Section
                            if (metaField.DataType == MetaDataType.DictionaryMultivalue ||
                                metaField.DataType == MetaDataType.EnumMultivalue)
                            {
                                // Step 1. Resived Meta Key Value [11/30/2004]
                                int MetaKey = SqlHelper.GetMetaKey(this.Id, this.MetaClass.Id, metaField.Id);

                                // Step 2. Clear old value [11/30/2004]
                                SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_ClearMultivalueDictionary"),
                                    new SqlParameter("@MetaKey", MetaKey));
                            }
                            else if (metaField.DataType == MetaDataType.File || metaField.DataType == MetaDataType.ImageFile)
                            {
                                // Step 1. Resived Meta Key Value [11/30/2004]
                                int MetaKey = SqlHelper.GetMetaKey(this.Id, this.MetaClass.Id, metaField.Id);
                                // Step 2. Clear old value [11/30/2004]
                                SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_DeleteMetaFile"),
                                    new SqlParameter("@MetaKey", MetaKey));
                            }
                            else if (metaField.DataType == MetaDataType.StringDictionary)
                            {
                                // Step 1. Resived Meta Key Value [11/30/2004]
                                int MetaKey = SqlHelper.GetMetaKey(this.Id, this.MetaClass.Id, metaField.Id);

                                // Step 2. Clear old value [11/30/2004]
                                SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_ClearStringDictionary"),
                                    new SqlParameter("@MetaKey", MetaKey));
                            }
                            else if (metaField.DataType == MetaDataType.MetaObject)
                            {
                                // Step 1. Resived Meta Key Value [11/30/2004]
                                int MetaKey = SqlHelper.GetMetaKey(this.Id, this.MetaClass.Id, metaField.Id);

                                // Step 2. Clear old value [11/30/2004]
                                SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_DeleteMetaObjectValue"),
                                    new SqlParameter("@MetaKey", MetaKey));
                            }

                            #endregion

                            //if (!metaField.AllowNulls && this.ObjectState == MetaObjectState.Added)
                            //{
                            //	FieldValue = MetaObject.GetDefaultValue(metaField.DataType);
                            //}
                        }

                        // Fix Problem: DbNull.Value in an image column [2/17/2005]
                        if (FieldValue == DBNull.Value && metaField.DataType == MetaDataType.Image)
                        {
                            SqlParameter tmpSqlPrm = new SqlParameter("@" + Key, SqlDbType.Image);
                            tmpSqlPrm.Value = DBNull.Value;
                            sqlParams[Index++] = tmpSqlPrm;
                        }
                        else if (FieldValue == DBNull.Value && metaField.DataType == MetaDataType.Binary)
                        {
                            SqlParameter tmpSqlPrm = new SqlParameter("@" + Key, SqlDbType.Binary);
                            tmpSqlPrm.Value = DBNull.Value;
                            sqlParams[Index++] = tmpSqlPrm;
                        }
                        else if (FieldValue == DBNull.Value && metaField.DataType == MetaDataType.Money)
                        {
                            SqlParameter tmpSqlPrm = new SqlParameter("@" + Key, SqlDbType.Money);
                            tmpSqlPrm.Value = DBNull.Value;
                            sqlParams[Index++] = tmpSqlPrm;
                        }
                        else if (metaField.DataType == MetaDataType.NText ||
                            metaField.DataType == MetaDataType.LongHtmlString ||
                            metaField.DataType == MetaDataType.LongString)
                        {
                            SqlParameter tmpSqlPrm = new SqlParameter("@" + Key, SqlDbType.NText);
                            tmpSqlPrm.Value = FieldValue;
                            sqlParams[Index++] = tmpSqlPrm;
                        }
                        else
                            sqlParams[Index++] = new SqlParameter("@" + Key, FieldValue);

                    }

                    SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, string.Format(AsyncResources.GetConstantValue("SPAT_TABLE_Update"), this.MetaClass.TableName), sqlParams);

                    if (this.Id == -1)
                    {
                        this._objectId = (int)RetvalParam.Value;
                        this.AcceptChanges();
                    }

                    this._state = MetaObjectState.Unchanged;
                    break;
                case MetaObjectState.Deleted:
                    // Delete File Item if MetaFileDataStorageType.LocalDisk
                    if (this.Context.MetaFileDataStorageType == MetaFileDataStorageType.LocalDisk)
                    {
                        foreach (object o in this.FieldStorage)
                        {
                            MetaFile mf = o as MetaFile;
                            if (mf != null)
                            {
                                try
                                {
                                    mf.Delete();
                                }
                                catch (Exception ex)
                                {
                                    System.Diagnostics.Trace.WriteLine(ex);
                                }
                            }
                        }
                    }

                    // Delete Object
                    SqlHelper.ExecuteNonQuery(MetaDataContext.Current, CommandType.StoredProcedure, string.Format(AsyncResources.GetConstantValue("SPAT_TABLE_Delete"), this.MetaClass.TableName),
                        new SqlParameter("@ObjectId", this.Id));
                    break;
                case MetaObjectState.Unchanged:
                    break;
            }
        }
Example #11
0
        void LoadMetaFields2()
        {
            foreach (MetaField field in this.MetaClass.MetaFields)
            {
                if (field.IsSystem)
                    continue;

                object FieldValue = this[field.Name];

                if (FieldValue != null)
                {
                    if (field.DataType == MetaDataType.DictionarySingleValue ||
                        field.DataType == MetaDataType.EnumSingleValue)
                    {
                        //bool bFound = false;
                        //foreach (MetaDictionaryItem DicItem in field.Dictionary)
                        //{
                        //    if (DicItem.Id == (int)FieldValue)
                        //    {
                        //        bFound = true;
                        //        FieldValue = DicItem;
                        //        break;
                        //    }
                        //}

                        //if (!bFound)
                        //{
                        //    System.Diagnostics.Trace.WriteLine(string.Format("Couldn't find the MetaDictionaryItem (Id = {0}).", (int)FieldValue), "Mediachase.MetaDataPlus.MetaObject");
                        //    FieldValue = null;
                        //}
                    }
                    else if (field.DataType == MetaDataType.DictionaryMultivalue ||
                        field.DataType == MetaDataType.EnumMultivalue)
                    {
                        int MetaKey = (int)FieldValue;

                        // TODO: Move it in to the current transaction [12/1/2004]
                        using (SqlDataReader readerValue = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMultivalueDictionary"),
                                  new SqlParameter("@MetaKey", MetaKey)))
                        {
                            ArrayList MultuValues = new ArrayList();

                            while (readerValue.Read())
                            {
                                foreach (MetaDictionaryItem DicItem in field.Dictionary)
                                {
                                    if (DicItem.Id == (int)readerValue["MetaDictionaryId"])
                                    {
                                        MultuValues.Add(DicItem);
                                        break;
                                    }
                                }
                            }
                            readerValue.Close();

                            FieldValue = (MetaDictionaryItem[])MultuValues.ToArray(typeof(MetaDictionaryItem));
                        }
                    }
                    else if (field.DataType == MetaDataType.File || field.DataType == MetaDataType.ImageFile)
                    {
                        int MetaKey = (int)FieldValue;

                        // TODO: Move it in to the current transaction [12/1/2004]
                        using (SqlDataReader readerValue = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaFile"),
                                  new SqlParameter("@MetaKey", MetaKey)))
                        {
                            if (readerValue.Read())
                            {
                                MetaFile file = new MetaFile(readerValue);

                                FieldValue = file;
                            }
                            else
                                FieldValue = null;

                            readerValue.Close();
                        }

                    }
                    else if (field.DataType == MetaDataType.StringDictionary)
                    {
                        int MetaKey = (int)FieldValue;

                        // TODO: Move it in to the current transaction [12/1/2004]
                        using (SqlDataReader readerValue = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaStringDictionary"),
                                  new SqlParameter("@MetaKey", MetaKey)))
                        {
                            if (readerValue.Read())
                            {
                                MetaStringDictionary dic = new MetaStringDictionary();
                                dic.LoadDictionary(readerValue);
                                FieldValue = dic;
                            }
                            else
                                FieldValue = null;

                            readerValue.Close();
                        }
                    }
                    else if (field.DataType == MetaDataType.MetaObject)
                    {
                        using (SqlDataReader readerValue = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaObjectValue"),
                                  new SqlParameter("@MetaKey", (int)FieldValue)))
                        {
                            int MetaClassId = -1;
                            int MetaObjectId = -1;

                            if (readerValue.Read())
                            {
                                MetaClassId = (int)readerValue["MetaClassId"];
                                MetaObjectId = (int)readerValue["MetaObjectId"];

                                readerValue.Close();

                                try
                                {
                                    FieldValue = MetaObject.Load(MetaObjectId, MetaClassId);
                                }
                                catch (Exception ex)
                                {
                                    FieldValue = null;
                                    System.Diagnostics.Trace.WriteLine(ex, "Load MetaDataType.MetaObject");
                                }
                            }
                            else
                            {
                                FieldValue = null;
                                readerValue.Close();
                            }
                        }

                    }
                }

                _fieldStorage[field.Name] = FieldValue;
            }

            this._state = MetaObjectState.Unchanged;
        }
Example #12
0
        void LoadMetaFields(SqlDataReader reader)
        {
            _creatorId = (int)SqlHelper.DBNull2Null(reader["CreatorId"], -1);
            _created = (DateTime)SqlHelper.DBNull2Null(reader["Created"], DateTime.Now);

            _modifierId = (int)SqlHelper.DBNull2Null(reader["ModifierId"], -1);
            _modified = (DateTime)SqlHelper.DBNull2Null(reader["Modified"], DateTime.Now);

            foreach (MetaField field in this.MetaClass.MetaFields)
            {
                if (field.IsSystem)
                    continue;

                object FieldValue = SqlHelper.DBNull2Null(reader[field.Name]);

                if (FieldValue != null)
                {
                    if (field.DataType == MetaDataType.DictionarySingleValue ||
                        field.DataType == MetaDataType.EnumSingleValue)
                    {
                        bool bFound = false;
                        foreach (MetaDictionaryItem DicItem in field.Dictionary)
                        {
                            if (DicItem.Id == (int)FieldValue)
                            {
                                bFound = true;
                                FieldValue = DicItem;
                                break;
                            }
                        }

                        if (!bFound)
                        {
                            System.Diagnostics.Trace.WriteLine(string.Format("Couldn't find the MetaDictionaryItem (Id = {0}).", (int)FieldValue), "Mediachase.MetaDataPlus.MetaObject");
                            FieldValue = null;
                        }
                    }
                    else if (field.DataType == MetaDataType.DictionaryMultivalue ||
                        field.DataType == MetaDataType.EnumMultivalue)
                    {
                        //int MetaKey = (int)FieldValue;

                        //// TODO: Move it in to the current transaction [12/1/2004]
                        //using (SqlDataReader readerValue = SqlHelper.ExecuteReader(MetaDataContext.Current, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMultivalueDictionary"),
                        //          new SqlParameter("@MetaKey", MetaKey)))
                        //{
                        //    ArrayList MultuValues = new ArrayList();

                        //    while (readerValue.Read())
                        //    {
                        //        foreach (MetaDictionaryItem DicItem in field.Dictionary)
                        //        {
                        //            if (DicItem.Id == (int)readerValue["MetaDictionaryId"])
                        //            {
                        //                MultuValues.Add(DicItem);
                        //                break;
                        //            }
                        //        }
                        //    }
                        //    readerValue.Close();

                        //    FieldValue = (MetaDictionaryItem[])MultuValues.ToArray(typeof(MetaDictionaryItem));
                        //}
                    }
                    else if (field.DataType == MetaDataType.File || field.DataType == MetaDataType.ImageFile)
                    {
                        //int MetaKey = (int)FieldValue;

                        //// TODO: Move it in to the current transaction [12/1/2004]
                        //using (SqlDataReader readerValue = SqlHelper.ExecuteReader(MetaDataContext.Current.ConnectionString, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaFile"),
                        //          new SqlParameter("@MetaKey", MetaKey)))
                        //{
                        //    if (readerValue.Read())
                        //    {
                        //        MetaFile file = new MetaFile(readerValue);

                        //        FieldValue = file;
                        //    }
                        //    else
                        //        FieldValue = null;

                        //    readerValue.Close();
                        //}

                    }
                    else if (field.DataType == MetaDataType.StringDictionary)
                    {
                        //int MetaKey = (int)FieldValue;

                        //// TODO: Move it in to the current transaction [12/1/2004]
                        //using (SqlDataReader readerValue = SqlHelper.ExecuteReader(MetaDataContext.Current.ConnectionString, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaStringDictionary"),
                        //          new SqlParameter("@MetaKey", MetaKey)))
                        //{
                        //    if (readerValue.Read())
                        //    {
                        //        MetaStringDictionary dic = new MetaStringDictionary();
                        //        dic.LoadDictionary(readerValue);
                        //        FieldValue = dic;
                        //    }
                        //    else
                        //        FieldValue = null;

                        //    readerValue.Close();
                        //}
                    }
                    else if (field.DataType == MetaDataType.MetaObject)
                    {
                        //using (SqlDataReader readerValue = SqlHelper.ExecuteReader(MetaDataContext.Current.ConnectionString, CommandType.StoredProcedure, AsyncResources.GetConstantValue("SP_LoadMetaObjectValue"),
                        //          new SqlParameter("@MetaKey", (int)FieldValue)))
                        //{
                        //    int MetaClassId = -1;
                        //    int MetaObjectId = -1;

                        //    if (readerValue.Read())
                        //    {
                        //        MetaClassId = (int)readerValue["MetaClassId"];
                        //        MetaObjectId = (int)readerValue["MetaObjectId"];

                        //        readerValue.Close();

                        //        try
                        //        {
                        //            FieldValue = MetaObject.Load(MetaObjectId, MetaClassId);
                        //        }
                        //        catch (Exception ex)
                        //        {
                        //            FieldValue = null;
                        //            System.Diagnostics.Trace.WriteLine(ex, "Load MetaDataType.MetaObject");
                        //        }
                        //    }
                        //    else
                        //    {
                        //        FieldValue = null;
                        //        readerValue.Close();
                        //    }
                        //}

                    }
                }

                _fieldStorage[field.Name] = FieldValue;
            }

            this._state = MetaObjectState.Unchanged;
        }
Example #13
0
 protected void ChangeState()
 {
     switch (this.ObjectState)
     {
         case MetaObjectState.Added:
             break;
         case MetaObjectState.Deleted:
             throw new DeletedObjectInaccessibleException();
         case MetaObjectState.Modified:
             break;
         case MetaObjectState.Unchanged:
             this._state = MetaObjectState.Modified;
             break;
     }
 }
Example #14
0
 public void RejectChanges()
 {
     switch (this.ObjectState)
     {
         case MetaObjectState.Added:
             foreach (string FieldName in this.FieldStorage.Keys)
             {
                 this.FieldStorage[FieldName] = null;
             }
             break;
         case MetaObjectState.Deleted:
         case MetaObjectState.Modified:
             this._state = MetaObjectState.Unchanged;
             // Reload Settings [11/25/2004]
             ReloadMetaFields();
             break;
         case MetaObjectState.Unchanged:
             break;
     }
 }