Exemplo n.º 1
0
        /// <summary>
        /// Indexes the catalog entry dto.
        /// </summary>
        /// <param name="entryRow">The entry row.</param>
        /// <param name="languages">The languages.</param>
        private static int IndexCatalogEntryDto(CatalogEntryDto.CatalogEntryRow entryRow, string[] languages)
        {
            int indexCounter = 0;

            CatalogContext.MetaDataContext.UseCurrentUICulture = false;
            MetaObjectSerialized serialized = new MetaObjectSerialized();

            foreach (string language in languages)
            {
                CatalogContext.MetaDataContext.Language = language;
                MetaObject metaObj = null;
                metaObj = MetaObject.Load(CatalogContext.MetaDataContext, entryRow.CatalogEntryId, entryRow.MetaClassId);

                if (metaObj == null)
                {
                    continue;
                }

                serialized.AddMetaObject(language, metaObj);
                indexCounter++;
            }

            entryRow.SerializedData = serialized.BinaryValue;
            CatalogContext.MetaDataContext.UseCurrentUICulture = true;
            return(indexCounter);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the meta field values.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="metaAttributes">The meta attributes.</param>
        /// <returns></returns>
        private static Hashtable GetMetaFieldValues(DataRow row, MetaClass metaClass, ref ItemAttributes metaAttributes)
        {
            Hashtable hash = null;

            // try loading from serialized binary field first
            if (row.Table.Columns.Contains(MetaObjectSerialized.SerializedFieldName) && row[MetaObjectSerialized.SerializedFieldName] != DBNull.Value)
            {
                IFormatter formatter = null;
                try
                {
                    formatter = new BinaryFormatter();
                    MetaObjectSerialized metaObjSerialized = (MetaObjectSerialized)formatter.Deserialize(new MemoryStream((byte[])row[MetaObjectSerialized.SerializedFieldName]));
                    if (metaObjSerialized != null)
                    {
                        if (metaAttributes != null)
                        {
                            metaAttributes.CreatedBy    = metaObjSerialized.CreatorId;
                            metaAttributes.CreatedDate  = metaObjSerialized.Created;
                            metaAttributes.ModifiedBy   = metaObjSerialized.ModifierId;
                            metaAttributes.ModifiedDate = metaObjSerialized.Modified;
                        }
                        hash = metaObjSerialized.GetValues(CatalogContext.MetaDataContext.Language);
                    }
                }
                finally
                {
                    formatter = null;
                }
            }

            // Load from database
            if (hash == null)
            {
                MetaObject metaObj = MetaObject.Load(CatalogContext.MetaDataContext, (int)row[0], metaClass);
                if (metaObj != null)
                {
                    metaAttributes.CreatedBy    = metaObj.CreatorId;
                    metaAttributes.CreatedDate  = metaObj.Created;
                    metaAttributes.ModifiedBy   = metaObj.ModifierId;
                    metaAttributes.ModifiedDate = metaObj.Modified;
                    hash = metaObj.GetValues();
                }
            }

            if (hash == null)
            {
                return(null);
            }

            return(hash);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <param name="context">The context.</param>
        public void SaveChanges(IDictionary context)
        {
            if (ObjectId != 0)
            {
                // set username here, because calling FrameworkContext.Current.Profile causes MeteDataContext.Current to change (it's bug in ProfileContext class).
                string userName = FrameworkContext.Current.Profile.UserName;

                MDContext.UseCurrentUICulture = false;

                // make sure all the values are saved using transaction
                //using (TransactionScope scope = new TransactionScope())
                {
                    MetaObjectSerialized serialized = new MetaObjectSerialized();
                    //bool saveSerialized = false;
                    //string
                    foreach (string language in Languages)
                    {
                        MDContext.Language = language;

                        MetaObject metaObj     = null;
                        bool       saveChanges = true;

                        // Check if meta object contect exists
                        if (context != null && context.Contains(_MetaObjectContextKey + language))
                        {
                            saveChanges = false;
                            metaObj     = (MetaObject)context[_MetaObjectContextKey + language];
                        }
                        //if (context != null)
                        //{
                        //    if (context.Contains(_MetaObjectContextKey + language))
                        //    {
                        //        saveChanges = false;
                        //        saveSerialized = true;
                        //        metaObj = (MetaObject)context[_MetaObjectContextKey + language];
                        //    }
                        //    else if (context.Contains(_OrderMetaObjectContextKey + language))
                        //    {
                        //        metaObj = (MetaObject)context[_OrderMetaObjectContextKey + language];
                        //    }
                        //}

                        if (metaObj == null)
                        {
                            metaObj = MetaObject.Load(MDContext, ObjectId, MetaClassId);
                        }

                        if (metaObj == null)
                        {
                            metaObj = MetaObject.NewObject(MDContext, ObjectId, MetaClassId, userName);
                            //DataBind(); return;
                        }
                        else
                        {
                            metaObj.ModifierId = userName;
                            metaObj.Modified   = DateTime.UtcNow;
                        }

                        foreach (Control ctrl in MetaControls.Controls)
                        {
                            // Only update controls that belong to current language
                            if (String.Compare(((IMetaControl)ctrl).LanguageCode, language, true) == 0)
                            {
                                ((IMetaControl)ctrl).MetaObject = metaObj;
                                //((IMetaControl)ctrl).MetaField = metaObj;
                                ((IMetaControl)ctrl).Update();
                            }
                        }

                        // Only save changes when new object has been created
                        if (saveChanges)
                        {
                            metaObj.AcceptChanges(MDContext);
                        }
                        //else
                        if (context != null)
                        {
                            serialized.AddMetaObject(language, metaObj);
                        }
                    }

                    if (context != null)                     //&& saveSerialized)
                    {
                        context.Add("MetaObjectSerialized", serialized);
                    }
                    //scope.Complete();
                }

                MDContext.UseCurrentUICulture = true;
            }

            //DataBind();
        }