Ejemplo n.º 1
0
        /// <summary>
        /// Gets the meta field values.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <returns></returns>
        public static Hashtable GetMetaFieldValues(DataRow row)
        {
            // Get meta class id
            int metaClassId = (int)row["MetaClassId"];

            if (metaClassId == 0)
            {
                return(null);
            }

            ItemAttributes attr      = new ItemAttributes();
            MetaClass      metaClass = MetaHelper.LoadMetaClassCached(CatalogContext.MetaDataContext, metaClassId);

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

            MetaFieldCollection mfs = metaClass.MetaFields;

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

            return(GetMetaFieldValues(row, metaClass, ref attr));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Binds the available fields.
        /// </summary>
        private void BindAvailableFields()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("MetaFieldId", typeof(int));
            dt.Columns.Add("FriendlyName", typeof(string));

            // Fields
            MetaFieldCollection mfc = MetaField.GetList(MDContext);

            foreach (MetaField field in mfc)
            {
                if (field.IsUser)
                {
                    DataRow row = dt.NewRow();
                    row["MetaFieldId"]  = field.Id;
                    row["FriendlyName"] = field.FriendlyName;
                    dt.Rows.Add(row);
                }
            }

            /*
             *          ItemsGrid.DataSource = new DataView(dt);
             *          ItemsGrid.DataBind();
             * */
        }
Ejemplo n.º 3
0
        // GET api/<controller>
        public IEnumerable <DataObjects.MetaField> Get()
        {
            MetaFieldCollection fieldCollection = Mediachase.MetaDataPlus.Configurator.MetaField.GetList(MetaDataContext.Instance);
            var mciList = from Mediachase.MetaDataPlus.Configurator.MetaField mc in fieldCollection
                          select new DataObjects.MetaField(mc);

            return(mciList.ToList());
        }
Ejemplo n.º 4
0
		private void BindAvailableFields()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("FieldId", typeof(int));
			dt.Columns.Add("FriendlyName", typeof(string));
			dt.Columns.Add("Description", typeof(string));
			dt.Columns.Add("DataType", typeof(string));
			dt.Columns.Add("DataTypeId", typeof(int));
			dt.Columns.Add("sortDataType", typeof(int));
			dt.Columns.Add("CanDelete", typeof(bool));

			MetaFieldCollection mfc = MetaField.GetList(MetaDataPlus.MetaNamespace.UserRoot, true);
			DataRow row;
			foreach (MetaField field in mfc)
			{
				bool fl = true;
				if (ddlShow.SelectedValue == "1" && field.OwnerMetaClassIdList.Count == 0)
					fl = false;
				if (ddlShow.SelectedValue == "-1" && field.OwnerMetaClassIdList.Count != 0)
					fl = false;
				if (fl)
				{
					row = dt.NewRow();
					row["FieldId"] = field.Id;
					row["FriendlyName"] = field.FriendlyName;
					row["Description"] = field.Description;
					MetaType mdType = MetaType.Load(field.DataType);
					row["DataType"] = mdType.FriendlyName;
					int iType = mdType.Id;
					if (mdType.MetaDataType == MetaDataType.DictionaryMultivalue ||
						mdType.MetaDataType == MetaDataType.DictionarySingleValue ||
						mdType.MetaDataType == MetaDataType.EnumMultivalue ||
						mdType.MetaDataType == MetaDataType.EnumSingleValue ||
						mdType.MetaDataType == MetaDataType.StringDictionary)
						iType = 0;
					row["DataTypeId"] = iType;
					row["sortDataType"] = GetSortDataType(mdType);
					row["CanDelete"] = (field.OwnerMetaClassIdList.Count == 0);
					dt.Rows.Add(row);
				}
			}

			DataView dv = dt.DefaultView;
			if (pc["Cust_AvailableFields_Sort"] == null)
				pc["Cust_AvailableFields_Sort"] = "sortDataType";
			dv.Sort = pc["Cust_AvailableFields_Sort"];
			if (int.Parse(ddlType.SelectedValue) >= 0)
				dv.RowFilter = "DataTypeId = " + ddlType.SelectedValue;
			dgAvailableFields.DataSource = dv;
			dgAvailableFields.DataBind();

			foreach (DataGridItem dgi in dgAvailableFields.Items)
			{
				ImageButton ib = (ImageButton)dgi.FindControl("ibDelete");
				if (ib != null)
					ib.Attributes.Add("onclick", "return confirm('" + LocRM.GetString("DeleteWarning") + "')");
			}
		}
Ejemplo n.º 5
0
        public IEnumerable <DataObjects.MetaField> GetAdvanced(string @namespace, bool isSystem)
        {
            MetaFieldCollection fieldCollection         = Mediachase.MetaDataPlus.Configurator.MetaField.GetList(MetaDataContext.Instance);
            IEnumerable <DataObjects.MetaField> mciList = from Mediachase.MetaDataPlus.Configurator.MetaField mc in fieldCollection
                                                          where mc.Namespace.CompareTo(@namespace) == 0 && mc.IsSystem == isSystem
                                                          select new DataObjects.MetaField(mc);

            return(mciList.ToList());
        }
Ejemplo n.º 6
0
        // GET api/<controller>
        public IEnumerable <DataObjects.MetaField> GetUnusedFields()
        {
            MetaFieldCollection fieldCollection = Mediachase.MetaDataPlus.Configurator.MetaField.GetList(MetaDataContext.Instance);
            var mciList = from Mediachase.MetaDataPlus.Configurator.MetaField mc in fieldCollection
                          where mc.OwnerMetaClassIdList.Count == 0
                          select new DataObjects.MetaField(mc);

            return(mciList.ToList());
        }
Ejemplo n.º 7
0
        private void BindSelectedFields()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("FieldId", typeof(int));
            dt.Columns.Add("ClassId", typeof(int));
            dt.Columns.Add("FriendlyName", typeof(string));
            dt.Columns.Add("DataType", typeof(string));
            dt.Columns.Add("IsRequired", typeof(bool));
            dt.Columns.Add("CanChangeIsRequired", typeof(bool));

            MetaClass selectedMetaClass = GetSelectedMetaClass();

            if (selectedMetaClass != null)
            {
                MetaFieldCollection mfc = selectedMetaClass.MetaFields;
                foreach (MetaField field in mfc)
                {
                    if (field.IsUser)
                    {
                        DataRow row = dt.NewRow();
                        row["FieldId"]      = field.Id;
                        row["ClassId"]      = selectedMetaClass.Id;
                        row["FriendlyName"] = field.FriendlyName;
                        MetaType mdType = MetaType.Load(field.DataType);
                        row["DataType"] = mdType.FriendlyName;

                        row["CanChangeIsRequired"] = true;
                        if (!field.AllowNulls)
                        {
                            row["IsRequired"]          = true;
                            row["CanChangeIsRequired"] = false;
                        }
                        else
                        {
                            row["IsRequired"] = selectedMetaClass.GetFieldIsRequired(field);
                        }

                        dt.Rows.Add(row);
                    }
                }
                _pc["cust_SelectedElement"] = selectedMetaClass.Id.ToString();
            }

            dgSelectedFields.DataSource = new DataView(dt);
            dgSelectedFields.DataBind();

            foreach (DataGridItem dgi in dgSelectedFields.Items)
            {
                ImageButton ib = (ImageButton)dgi.FindControl("ibDelete");
                if (ib != null)
                {
                    ib.Attributes.Add("onclick", "return confirm('" + LocRM.GetString("DeleteWarning") + "')");
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes new instance of <see cref="MetaContentType"/>.
        /// </summary>
        /// <param name="list">Metadata of parent SP List.</param>
        /// <param name="entityType">Equivalent .NET type.</param>
        /// <param name="fieldProviders">Providers of <see cref="MetaField"/> that associated with current content type.</param>
        /// <exception cref="ArgumentNullException"><paramref name="list"/> or <paramref name="entityType"/> or <paramref name="fieldProviders"/> are null.</exception>
        public MetaContentType([NotNull] MetaList list, [NotNull] Type entityType,
                               [NotNull] IReadOnlyCollection <IMetaFieldProvider> fieldProviders)
        {
            Guard.CheckNotNull(nameof(list), list);
            Guard.CheckNotNull(nameof(entityType), entityType);
            Guard.CheckNotNull(nameof(fieldProviders), fieldProviders);

            List       = list;
            EntityType = entityType;

            Fields = new MetaFieldCollection(fieldProviders.Select(n => n.GetMetaField(this)));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Binds the items grid.
        /// </summary>
        /// <param name="id">The id.</param>
        private void BindItemsGrid(int id)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("MetaFieldId", typeof(int));
            dt.Columns.Add("FriendlyName", typeof(string));

            // Fields
            MetaFieldCollection mfc = MetaField.GetList(MDContext /*Namespace, true*/);            // allow sharing meta fields

            foreach (MetaField field in mfc)
            {
                if (field.IsUser)
                {
                    DataRow row = dt.NewRow();
                    row["MetaFieldId"]  = field.Id;
                    row["FriendlyName"] = field.FriendlyName;
                    dt.Rows.Add(row);
                }
            }

            ItemsGrid.DataSource = new DataView(dt);
            ItemsGrid.DataBind();

            if (id > 0)
            {
                ArrayList list = new ArrayList();

                MetaFieldCollection mfc2 = MetaField.GetList(MDContext, id);
                foreach (MetaField mf in mfc2)
                {
                    if (mf.IsUser)
                    {
                        for (int i = 0; i < ItemsGrid.Items.Count; i++)
                        {
                            if ((int)ItemsGrid.DataKeys[i] == mf.Id)
                            {
                                list.Add(i);
                                TextBox box = (TextBox)ItemsGrid.Items[i].FindControl("Weight");
                                box.Text = mf.Weight.ToString();
                            }
                        }
                    }
                }

                ((Mediachase.Web.Console.Controls.RowSelectorColumn)ItemsGrid.Columns[0]).SelectedIndexes = (int[])list.ToArray(typeof(int));
            }
        }
Ejemplo n.º 10
0
        private void BindSelectedFields()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("FieldId", typeof(int));
            dt.Columns.Add("FieldName", typeof(string));
            dt.Columns.Add("FriendlyName", typeof(string));
            dt.Columns.Add("DataType", typeof(string));
            dt.Columns.Add("Weight", typeof(string));

            MetaClass SelectedMetaClass = GetSelectedMetaClass();

            if (SelectedMetaClass != null)
            {
                ArrayList list = new ArrayList();
                list.AddRange(this.SelectedMetaFields);
                MetaFieldCollection mfc = SelectedMetaClass.MetaFields;
                foreach (MetaField field in mfc)
                {
                    if (field.IsUser && list.Contains(field.Name))
                    {
                        DataRow row = dt.NewRow();
                        row["FieldId"]      = field.Id;
                        row["FieldName"]    = field.Name;
                        row["FriendlyName"] = field.FriendlyName;
                        MetaType mdType = MetaType.Load(field.DataType);
                        row["DataType"] = mdType.FriendlyName;
                        row["Weight"]   = 1 + list.IndexOf(field.Name);
                        dt.Rows.Add(row);
                    }
                }
            }

            DataView dv = dt.DefaultView;

            dv.Sort = "Weight ASC";
            dgSelectedFields.DataSource = dv;
            dgSelectedFields.DataBind();

            foreach (DataGridItem dgi in dgSelectedFields.Items)
            {
                ImageButton ib = (ImageButton)dgi.FindControl("ibDelete");
                if (ib != null)
                {
                    ib.Attributes.Add("onclick", "return confirm('" + LocRM.GetString("DeleteWarning") + "')");
                }
            }
        }
Ejemplo n.º 11
0
        private static bool FieldDestinationIsMatch(MetaFieldCollection metaFields, MappingElement mapEl)
        {
            bool retVal = false;

            foreach (MappingRule mapRule in mapEl)
            {
                foreach (MetaField field in metaFields)
                {
                    if (mapRule.FieldName == field.Name)
                    {
                        retVal = true;
                        break;
                    }
                }

                if (retVal == false)
                {
                    break;
                }
            }
            return(retVal);
        }
Ejemplo n.º 12
0
        public IEnumerable <JObject> DeleteUnusedFields()
        {
            MetaFieldCollection fieldCollection = Mediachase.MetaDataPlus.Configurator.MetaField.GetList(MetaDataContext.Instance);
            var mciList = from Mediachase.MetaDataPlus.Configurator.MetaField mc in fieldCollection
                          where mc.OwnerMetaClassIdList.Count == 0
                          select new DataObjects.MetaField(mc);


            MetaDataContext context = MetaDataContext.Instance;

            List <JObject> result = new List <JObject>();

            foreach (DataObjects.MetaField field in mciList)
            {
                MetaField metaField = MetaField.Load(context, field.Id);
                if (metaField.IsSystem)
                {
                    result.Add(JObject.FromObject(
                                   new
                    {
                        Result  = "Failed",
                        Id      = metaField.Id,
                        Name    = metaField.Name,
                        Message = string.Format("Cannot delete system field {0} ({1})", metaField.Name, metaField.Id)
                    }));
                }
                else
                {
                    bool          isInUse = false;
                    List <string> usedBy  = new List <string>();
                    foreach (object ownerId in metaField.OwnerMetaClassIdList)
                    {
                        isInUse = true;
                        MetaClass ownerClass = MetaClass.Load(context, int.Parse(ownerId.ToString()));
                        usedBy.Add(string.Format("{0} ({1})", ownerClass.Name, ownerId.ToString()));
                    }

                    if (isInUse == false)
                    {
                        MetaField.Delete(context, metaField.Id);
                        result.Add(JObject.FromObject(
                                       new
                        {
                            Result  = "OK",
                            Message = "Deleted Meta Field",
                            Name    = metaField.Name,
                            Id      = metaField.Id
                        }));
                    }
                    else
                    {
                        result.Add(JObject.FromObject(
                                       new
                        {
                            Result  = "Failed",
                            Message = string.Format("Meta Field with id {0} is in use. Cannot delete.", metaField.Id),
                            Name    = metaField.Name,
                            Id      = metaField.Id,
                            UsedBy  = usedBy
                        }));
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 13
0
    /// <summary>
    /// Binds the data.
    /// </summary>
    public void BindData()
    {
        string[] mcs = CommonHelper.GetCompareMetaClasses();
        CompareGroupsRepeater.DataSource = mcs;
        CompareGroupsRepeater.DataBind();

        rptrHeaderImage.DataBind();
        rptrHeaderPurchaseLink.DataBind();

        List <CompareItem> listCompare = new List <CompareItem>();

        if (CurrentMetaClass != null)
        {
            MetaFieldCollection metaFields = CurrentMetaClass.UserMetaFields;
            if (metaFields != null && metaFields.Count > 0)
            {
                foreach (MetaField metaField in metaFields)
                {
                    string useInComparingAttribute = metaField.Attributes["UseInComparing"];
                    if (!string.IsNullOrEmpty(useInComparingAttribute) && bool.Parse(useInComparingAttribute))
                    {
                        CompareItem compareItem = new CompareItem();
                        compareItem.Title = metaField.FriendlyName;

                        List <string> items = new List <string>();
                        foreach (Entry product in ProductsToCompare)
                        {
                            string compareValue = String.Empty;

                            ItemAttribute item = product.ItemAttributes[metaField.Name];
                            if (item != null && item.Value != null && item.Value.Length > 0)
                            {
                                compareValue = item.Value[0];
                            }
                            items.Add(compareValue);
                        }

                        if (items.Count > 1)
                        {
                            for (int i = 1; i < items.Count; i++)
                            {
                                if (String.Compare(items[i - 1], items[i], true) != 0)
                                {
                                    break;
                                }

                                if (i == items.Count - 1)
                                {
                                    compareItem.EqualValues = true;
                                }
                            }
                        }

                        compareItem.Attributes = items.ToArray();
                        listCompare.Add(compareItem);
                    }
                }
            }
        }

        rptrMainTable.DataSource = listCompare;
        rptrMainTable.DataBind();
    }
Ejemplo n.º 14
0
        /// <summary>
        /// Indexes the catalog entry dto.
        /// </summary>
        /// <param name="indexer">The indexer.</param>
        /// <param name="entryRow">The entry row.</param>
        /// <param name="defaultCurrency">The default currency.</param>
        /// <param name="languages">The languages.</param>
        /// <returns></returns>
        private int IndexCatalogEntryDto(IndexBuilder indexer, CatalogEntryDto.CatalogEntryRow entryRow, string defaultCurrency, string[] languages)
        {
            int indexCounter = 0;

            CatalogContext.MetaDataContext.UseCurrentUICulture = false;

            // Import categories
            CatalogRelationDto relationDto = CatalogContext.Current.GetCatalogRelationDto(0, 0, entryRow.CatalogEntryId, "", new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));

            foreach (string language in languages)
            {
                Document doc = new Document();

                // Add constant fields
                doc.Add(new Field("_id", entryRow.CatalogEntryId.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
                doc.Add(new Field("Code", entryRow.Code, Field.Store.YES, Field.Index.UN_TOKENIZED));
                doc.Add(new Field("_content", entryRow.Code, Field.Store.NO, Field.Index.TOKENIZED));
                doc.Add(new Field("Name", entryRow.Name, Field.Store.YES, Field.Index.TOKENIZED));
                doc.Add(new Field("_content", entryRow.Name, Field.Store.NO, Field.Index.TOKENIZED));
                doc.Add(new Field("_lang", language, Field.Store.YES, Field.Index.UN_TOKENIZED));
                doc.Add(new Field("StartDate", entryRow.StartDate.ToString("s"), Field.Store.YES, Field.Index.UN_TOKENIZED));
                doc.Add(new Field("EndDate", entryRow.EndDate.ToString("s"), Field.Store.YES, Field.Index.UN_TOKENIZED));
                doc.Add(new Field("_classtype", entryRow.ClassTypeId, Field.Store.YES, Field.Index.UN_TOKENIZED));
                AddPriceFields(doc, entryRow, defaultCurrency);

                bool sortOrderAdded = false;
                foreach (CatalogRelationDto.NodeEntryRelationRow relation in relationDto.NodeEntryRelation)
                {
                    CatalogDto catalogDto  = CatalogContext.Current.GetCatalogDto(relation.CatalogId);
                    string     catalogName = String.Empty;
                    if (catalogDto != null && catalogDto.Catalog != null && catalogDto.Catalog.Count > 0)
                    {
                        catalogName = catalogDto.Catalog[0].Name;
                    }
                    else
                    {
                        continue;
                    }

                    CatalogNodeDto catalogNodeDto  = CatalogContext.Current.GetCatalogNodeDto(relation.CatalogNodeId);
                    string         catalogNodeCode = String.Empty;
                    if (catalogNodeDto != null && catalogNodeDto.CatalogNode != null && catalogNodeDto.CatalogNode.Count > 0)
                    {
                        catalogNodeCode = catalogNodeDto.CatalogNode[0].Code;
                    }
                    else
                    {
                        continue;
                    }

                    BuildPath(doc, catalogDto, catalogNodeDto, 0);

                    /*
                     * BuildPath(doc, entryRow.CatalogId, relation.CatalogNodeId);
                     * string path = BuildPath(entryRow.CatalogId, relation.CatalogNodeId);
                     * doc.Add(new Field(String.Format("_outline"), path, Field.Store.YES, Field.Index.UN_TOKENIZED));
                     * */
                    doc.Add(new Field(String.Format("_sortorder-{0}-{1}", catalogName, catalogNodeCode), relation.SortOrder.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
                    if (!sortOrderAdded && entryRow.CatalogId == relation.CatalogId) // add default sort order, which will be the first node added in the default catalog
                    {
                        doc.Add(new Field(String.Format("_sortorder"), relation.SortOrder.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
                        sortOrderAdded = true;
                    }
                }

                CatalogContext.MetaDataContext.Language = language;

                if (entryRow.MetaClassId != 0)
                {
                    // load list of MetaFields for MetaClass
                    MetaClass metaClass = MetaHelper.LoadMetaClassCached(CatalogContext.MetaDataContext, entryRow.MetaClassId);

                    if (metaClass != null)
                    {
                        MetaFieldCollection mfs = metaClass.MetaFields;
                        if (mfs != null)
                        {
                            //MetaObject metaObj = null;
                            //metaObj = MetaObject.Load(CatalogContext.MetaDataContext, entryRow.CatalogEntryId, entryRow.MetaClassId);

                            Hashtable hash = ObjectHelper.GetMetaFieldValues(entryRow);

                            if (hash != null)
                            {
                                foreach (MetaField field in mfs)
                                {
                                    AddField(doc, field, hash);
                                }
                            }
                        }
                    }

                    doc.Add(new Field("_metaclass", metaClass.Name, Field.Store.YES, Field.Index.UN_TOKENIZED));
                }
                indexer.AddDocument(doc);

                indexCounter++;
            }

            CatalogContext.MetaDataContext.UseCurrentUICulture = true;
            return(indexCounter);
        }
Ejemplo n.º 15
0
        private void DeleteAllMetaClasses(bool doDelete, ClearCatalogAndModelsResult result)
        {
            MetaDataContext     metaDataContext     = new MetaDataContext();
            MetaClassCollection metaClassCollection = MetaClass.GetList(metaDataContext);
            List <string>       logList             = new List <string>();

            foreach (MetaClass metaClass in metaClassCollection)
            {
                if (doDelete && metaClass.IsSystem == false)
                {
                    _log.DebugFormat("Deleting class: {0} - {1} (System: {2})",
                                     metaClass.Name,
                                     metaClass.Id,
                                     metaClass.IsSystem);
                    try
                    {
                        MetaClass.Delete(metaDataContext, metaClass.Id);
                        result.MetaClassesDeleted++;
                    }
                    catch (Exception ex)
                    {
                        result.MetaClassesSkipped++;
                        _log.Error(string.Format("Cannot delete Class: {0} - {1} ({2})", metaClass.Name,
                                                 metaClass.Id, ex.Message),
                                   ex);
                    }
                }
                else
                {
                    result.MetaClassesSkipped++;
                    _log.DebugFormat("NOT deleting system class: {0} - {1} (System: {2})",
                                     metaClass.Name,
                                     metaClass.Id,
                                     metaClass.IsSystem);
                }
            }

            // List of meta data fields to keep.
            List <string> filterFields = new List <string>()
            {
                "TrackingNumber",
                "AddYourOwn"
            };
            MetaFieldCollection fields = MetaField.GetList(metaDataContext);

            foreach (MetaField field in fields)
            {
                // Do not delete: System fields, filtered fields and fields starting with underscore
                if (doDelete &&
                    field.IsSystem == false &&
                    filterFields.Contains(field.Name) == false &&
                    field.Name.StartsWith("_") == false)
                {
                    _log.DebugFormat("Deleting field: {0} - {1} (System: {2})",
                                     field.Name,
                                     field.Id,
                                     field.IsSystem);
                    try
                    {
                        MetaField.Delete(metaDataContext, field.Id);
                        result.MetaFieldsDeleted++;
                    }
                    catch (Exception ex)
                    {
                        result.MetaFieldsSkipped++;
                        _log.Error(string.Format("Cannot delete Field: {0} - {1} ({2})",
                                                 field.Name,
                                                 field.Id, ex.Message),
                                   ex);
                    }
                }
                else
                {
                    result.MetaFieldsSkipped++;
                    _log.DebugFormat("NOT deleting field: {0} - {1} (System: {2})",
                                     field.Name,
                                     field.Id,
                                     field.IsSystem);
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates the attributes.
        /// </summary>
        /// <param name="metaAttributes">The meta attributes.</param>
        /// <param name="row">The row.</param>
        public static void CreateAttributes(ItemAttributes metaAttributes, DataRow row)
        {
            ArrayList attributes = new ArrayList();
            ArrayList files      = new ArrayList();
            ArrayList images     = new ArrayList();

            // Make sure we don't loose someone elses data
            if (metaAttributes != null && metaAttributes.Attribute != null)
            {
                foreach (ItemAttribute attr in metaAttributes.Attribute)
                {
                    attributes.Add(attr);
                }
            }

            // Make sure we don't loose someone elses data
            if (metaAttributes != null && metaAttributes.Files != null && metaAttributes.Files.File != null)
            {
                foreach (ItemFile file in metaAttributes.Files.File)
                {
                    files.Add(file);
                }
            }

            // Make sure we don't loose someone elses data
            if (metaAttributes != null && metaAttributes.Images != null)
            {
                //Changed this loop from a foreach to a for loop because metaAttributes.Image
                //was originally used but has been deprecated. metaAttributes.Images.Image
                //used instead
                for (int i = 0; i < metaAttributes.Images.Image.Length; i++)
                {
                    images.Add(metaAttributes.Images.Image[i]);
                }
            }


            // Get meta class id
            int metaClassId = (int)row["MetaClassId"];

            if (metaClassId == 0)
            {
                return;
            }



            // load list of MetaFields for MetaClass
            MetaClass metaClass = MetaHelper.LoadMetaClassCached(CatalogContext.MetaDataContext, metaClassId);

            if (metaClass == null)
            {
                return;
            }

            MetaFieldCollection mfs = metaClass.MetaFields;

            if (mfs == null)
            {
                return;
            }

            Hashtable hash = GetMetaFieldValues(row, metaClass, ref 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)
             *      {
             *          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;
            }

            // fill in MetaField DataSet
            foreach (MetaField mf in mfs)
            {
                // skip system MetaFields
                if (!mf.IsUser)
                {
                    continue;
                }

                // get meta field's value
                object value = null;
                if (hash.ContainsKey(mf.Name))
                {
                    value = MetaHelper.GetMetaFieldValue(mf, hash[mf.Name]);
                }

                // create row in dataset for current meta field
                switch (mf.DataType)
                {
                case MetaDataType.File:
                    MetaFile metaFile = value as MetaFile;

                    if (metaFile != null)
                    {
                        ItemFile file = new ItemFile();
                        file.ContentType  = metaFile.ContentType;
                        file.FileContents = metaFile.Buffer;
                        file.FileName     = metaFile.Name;
                        file.Name         = mf.Name;
                        file.Type         = mf.DataType.ToString();
                        file.FriendlyName = mf.FriendlyName;

                        files.Add(file);
                    }
                    break;

                case MetaDataType.Image:
                case MetaDataType.ImageFile:

                    string fileName = String.Format("{0}-{1}-{2}", metaClassId, (int)row[0], mf.Name);

                    bool createThumbnail = false;
                    int  imageWidth      = 0;
                    int  imageHeight     = 0;
                    int  thumbWidth      = 0;
                    int  thumbHeight     = 0;
                    bool thumbStretch    = false;

                    object createThumbnaleObj = mf.Attributes["CreateThumbnail"];
                    if (createThumbnaleObj != null && Boolean.Parse(createThumbnaleObj.ToString()))
                    {
                        createThumbnail = true;

                        object var = mf.Attributes["AutoResize"];

                        if (var != null && Boolean.Parse(var.ToString()))
                        {
                            var = mf.Attributes["ImageHeight"];
                            if (var != null)
                            {
                                imageHeight = Int32.Parse(var.ToString());
                            }

                            var = mf.Attributes["ImageWidth"];
                            if (var != null)
                            {
                                imageHeight = Int32.Parse(var.ToString());
                            }
                        }

                        var = mf.Attributes["CreateThumbnail"];

                        if (var != null && Boolean.Parse(var.ToString()))
                        {
                            var = mf.Attributes["ThumbnailHeight"];
                            if (var != null)
                            {
                                thumbHeight = Int32.Parse(var.ToString());
                            }

                            var = mf.Attributes["ThumbnailWidth"];
                            if (var != null)
                            {
                                thumbWidth = Int32.Parse(var.ToString());
                            }

                            var = mf.Attributes["StretchThumbnail"];
                            if (var != null && Boolean.Parse(var.ToString()))
                            {
                                thumbStretch = true;
                            }
                        }
                    }

                    //string[] val = MetaHelper.GetCachedImageUrl((MetaFile)hash[mf.Name], mf, fileName, createThumbnail, thumbHeight, thumbWidth, thumbStretch);

                    string imageUrl      = ImageService.RetrieveImageUrl(fileName);
                    string imageThumbUrl = ImageService.RetrieveThumbnailImageUrl(fileName);

                    //if (val != null)
                    {
                        Image attr = CreateImage(mf.Name, imageUrl);

                        if (createThumbnail)
                        {
                            attr.ThumbnailUrl = imageThumbUrl;
                        }

                        if (imageHeight != 0)
                        {
                            attr.Height = imageHeight.ToString();
                        }

                        if (imageWidth != 0)
                        {
                            attr.Width = imageWidth.ToString();
                        }

                        if (thumbHeight != 0)
                        {
                            attr.ThumbnailHeight = thumbHeight.ToString();
                        }

                        if (thumbWidth != 0)
                        {
                            attr.ThumbnailWidth = thumbWidth.ToString();
                        }

                        images.Add(attr);
                    }
                    break;

                case MetaDataType.BigInt:
                case MetaDataType.Bit:
                case MetaDataType.Boolean:
                case MetaDataType.Char:
                case MetaDataType.Date:
                case MetaDataType.DateTime:
                case MetaDataType.Decimal:
                case MetaDataType.Email:
                case MetaDataType.Float:
                case MetaDataType.Int:
                case MetaDataType.Integer:
                case MetaDataType.LongHtmlString:
                case MetaDataType.LongString:
                case MetaDataType.Money:
                case MetaDataType.NChar:
                case MetaDataType.NText:
                case MetaDataType.Numeric:
                case MetaDataType.NVarChar:
                case MetaDataType.Real:
                case MetaDataType.ShortString:
                case MetaDataType.SmallDateTime:
                case MetaDataType.SmallInt:
                case MetaDataType.SmallMoney:
                case MetaDataType.Sysname:
                case MetaDataType.Text:
                case MetaDataType.Timestamp:
                case MetaDataType.TinyInt:
                case MetaDataType.UniqueIdentifier:
                case MetaDataType.URL:
                case MetaDataType.VarChar:
                case MetaDataType.Variant:
                case MetaDataType.DictionarySingleValue:
                case MetaDataType.EnumSingleValue:
                    attributes.Add(ObjectHelper.CreateAttribute(mf.Name, mf.FriendlyName, mf.DataType.ToString(), new string[] { value == null ? String.Empty : value.ToString() }));
                    break;

                case MetaDataType.EnumMultiValue:
                case MetaDataType.DictionaryMultiValue:
                    attributes.Add(ObjectHelper.CreateAttribute(mf.Name, mf.FriendlyName, "string[]", (string[])value));
                    break;

                case MetaDataType.StringDictionary:
                    MetaStringDictionary stringDictionary = value as MetaStringDictionary;
                    ArrayList            strvals          = new ArrayList();
                    if (stringDictionary != null)
                    {
                        foreach (string key in stringDictionary.Keys)
                        {
                            strvals.Add(String.Format("{0};{1}", key, stringDictionary[key]));
                        }
                    }
                    attributes.Add(ObjectHelper.CreateAttribute(mf.Name, mf.FriendlyName, "string[]", stringDictionary == null ? null : (string[])strvals.ToArray(typeof(string))));
                    break;

                default:
                    break;
                }
            }

            metaAttributes.Attribute    = (ItemAttribute[])attributes.ToArray(typeof(ItemAttribute));
            metaAttributes.Files        = new ItemFiles();
            metaAttributes.Files.File   = (ItemFile[])files.ToArray(typeof(ItemFile));
            metaAttributes.Images       = new Images();
            metaAttributes.Images.Image = (Image[])images.ToArray(typeof(Image));
        }
Ejemplo n.º 17
0
        private static bool FieldDestinationIsMatch(MetaFieldCollection metaFields, MappingElement mapEl)
        {
            bool retVal = false;
            foreach (MappingRule mapRule in mapEl)
            {
                foreach (MetaField field in metaFields)
                {
                    if (mapRule.FieldName == field.Name)
                    {
                        retVal = true;
                        break;
                    }
                }

                if (retVal == false)
                    break;

            }
            return retVal;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Clones the node entry.
        /// </summary>
        /// <param name="catalogId">The catalog id.</param>
        /// <param name="catalogNodeId">The catalog node id.</param>
        /// <param name="catalogEntryId">The catalog entry id.</param>
        /// <param name="targetCatalogId">The target catalog id.</param>
        /// <param name="targetCatalogNodeId">The target catalog node id.</param>
        private void CloneNodeEntry(int catalogId, int catalogNodeId, int catalogEntryId, int targetCatalogId, int targetCatalogNodeId)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(catalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    if (catalogId <= 0)
                    {
                        catalogId = catalogEntryDto.CatalogEntry[0].CatalogId;
                    }

                    if (targetCatalogId <= 0)
                    {
                        targetCatalogId = catalogId;
                    }

                    CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(catalogId, catalogNodeId, catalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogEntry));

                    CatalogAssociationDto catalogAssociationDto = CatalogContext.Current.GetCatalogAssociationDtoByEntryId(catalogEntryId);

                    CatalogEntryDto newCatalogEntryDto = new CatalogEntryDto();
                    newCatalogEntryDto.CatalogEntry.ImportRow(catalogEntryDto.CatalogEntry[0]);
                    newCatalogEntryDto.CatalogEntry[0].SetAdded();
                    newCatalogEntryDto.CatalogEntry[0].Code = Guid.NewGuid().ToString();

                    if (catalogEntryDto.CatalogItemSeo.Count > 0)
                    {
                        foreach (CatalogEntryDto.CatalogItemSeoRow row in catalogEntryDto.CatalogItemSeo.Rows)
                        {
                            newCatalogEntryDto.CatalogItemSeo.ImportRow(row);
                            newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].SetAdded();
                            newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].Uri = Guid.NewGuid().ToString() + ".aspx";
                        }
                    }

                    if (catalogEntryDto.Variation.Count > 0)
                    {
                        foreach (CatalogEntryDto.VariationRow row in catalogEntryDto.Variation.Rows)
                        {
                            newCatalogEntryDto.Variation.ImportRow(row);
                            newCatalogEntryDto.Variation[newCatalogEntryDto.Variation.Count - 1].SetAdded();
                        }
                    }

                    if (catalogEntryDto.SalePrice.Count > 0)
                    {
                        foreach (CatalogEntryDto.SalePriceRow row in catalogEntryDto.SalePrice.Rows)
                        {
                            CatalogEntryDto.SalePriceRow newRow = newCatalogEntryDto.SalePrice.NewSalePriceRow();
                            newRow.ItemArray = row.ItemArray;
                            newRow.ItemCode  = newCatalogEntryDto.CatalogEntry[0].Code;
                            newCatalogEntryDto.SalePrice.Rows.Add(newRow);
                            //newCatalogEntryDto.SalePrice.ImportRow(row);
                            //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].ItemCode = newCatalogEntryDto.CatalogEntry[0].Code;
                            //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].SetAdded();
                        }
                    }

                    if (catalogEntryDto.Inventory.Count > 0)
                    {
                        foreach (CatalogEntryDto.InventoryRow row in catalogEntryDto.Inventory.Rows)
                        {
                            newCatalogEntryDto.Inventory.ImportRow(row);
                            newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SetAdded();
                            newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SkuId = newCatalogEntryDto.CatalogEntry[0].Code;
                        }
                    }

                    if (newCatalogEntryDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogEntry(newCatalogEntryDto);
                    }

                    if (newCatalogEntryDto.CatalogEntry.Count > 0)
                    {
                        CatalogEntryDto.CatalogEntryRow entry = newCatalogEntryDto.CatalogEntry[0];
                        int newCatalogEntryId = entry.CatalogEntryId;
                        int metaClassId       = entry.MetaClassId;

                        // load list of MetaFields for MetaClass
                        MetaClass           metaClass  = MetaClass.Load(CatalogContext.MetaDataContext, metaClassId);
                        MetaFieldCollection metaFields = metaClass.MetaFields;

                        // cycle through each language and get meta objects
                        CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                        string[] languages = GetCatalogLanguages(catalogId);
                        if (languages != null)
                        {
                            foreach (string language in languages)
                            {
                                CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                                CatalogContext.MetaDataContext.Language            = language;

                                MetaObject metaObject = MetaObject.Load(CatalogContext.MetaDataContext, catalogEntryDto.CatalogEntry[0].CatalogEntryId, metaClassId);

                                MetaObject newMetaObject = MetaObject.NewObject(CatalogContext.MetaDataContext, newCatalogEntryId, metaClassId, FrameworkContext.Current.Profile.UserName);

                                foreach (MetaField metaField in metaFields)
                                {
                                    // skip system MetaFields
                                    if (!metaField.IsUser)
                                    {
                                        continue;
                                    }

                                    switch (metaField.DataType)
                                    {
                                    case MetaDataType.File:
                                    case MetaDataType.Image:
                                    case MetaDataType.ImageFile:
                                        MetaFile metaFile = (MetaFile)metaObject[metaField];
                                        if (metaFile != null)
                                        {
                                            newMetaObject[metaField] = new MetaFile(metaFile.Name, metaFile.ContentType, metaFile.Buffer);
                                        }
                                        break;

                                    default:
                                        if (metaObject[metaField] != null)
                                        {
                                            newMetaObject[metaField] = metaObject[metaField];
                                        }
                                        break;
                                    }
                                }
                                newMetaObject.AcceptChanges(CatalogContext.MetaDataContext);
                            }
                        }
                        CatalogContext.MetaDataContext.UseCurrentUICulture = false;

                        CatalogRelationDto newCatalogRelationDto = new CatalogRelationDto();

                        foreach (CatalogRelationDto.CatalogEntryRelationRow row in catalogRelationDto.CatalogEntryRelation.Rows)
                        {
                            if (row.ParentEntryId == catalogEntryId)
                            {
                                newCatalogRelationDto.CatalogEntryRelation.ImportRow(row);
                                newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].SetAdded();
                                newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].ParentEntryId = newCatalogEntryId;
                            }
                        }

                        if (targetCatalogNodeId > 0)
                        {
                            foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows)
                            {
                                if (row.CatalogEntryId == catalogEntryId)
                                {
                                    newCatalogRelationDto.NodeEntryRelation.ImportRow(row);
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].SetAdded();
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogId      = targetCatalogId;
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogNodeId  = targetCatalogNodeId;
                                    newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogEntryId = newCatalogEntryId;
                                }
                            }
                        }

                        if (newCatalogRelationDto.HasChanges())
                        {
                            CatalogContext.Current.SaveCatalogRelationDto(newCatalogRelationDto);
                        }

                        CatalogAssociationDto newCatalogAssociationDto = new CatalogAssociationDto();

                        foreach (CatalogAssociationDto.CatalogAssociationRow row in catalogAssociationDto.CatalogAssociation.Rows)
                        {
                            newCatalogAssociationDto.CatalogAssociation.ImportRow(row);
                            newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].SetAdded();
                            newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].CatalogEntryId = newCatalogEntryId;
                        }

                        foreach (CatalogAssociationDto.CatalogEntryAssociationRow row in catalogAssociationDto.CatalogEntryAssociation.Rows)
                        {
                            newCatalogAssociationDto.CatalogEntryAssociation.ImportRow(row);
                            newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].SetAdded();
                            //newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].CatalogEntryId = newCatalogEntryId;
                        }

                        if (newCatalogAssociationDto.HasChanges())
                        {
                            CatalogContext.Current.SaveCatalogAssociation(newCatalogAssociationDto);
                        }
                    }
                }

                scope.Complete();
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Clones the catalog node.
        /// </summary>
        /// <param name="parentCatalogId">The parent catalog id.</param>
        /// <param name="parentCatalogNodeId">The parent catalog node id.</param>
        /// <param name="catalogNodeId">The catalog node id.</param>
        private void CloneCatalogNode(int parentCatalogId, int parentCatalogNodeId, int catalogNodeId)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                CatalogNodeDto catalogNodeDto = CatalogContext.Current.GetCatalogNodeDto(catalogNodeId);
                if (catalogNodeDto.CatalogNode.Count > 0)
                {
                    CatalogNodeDto newCatalogNodeDto = new CatalogNodeDto();
                    newCatalogNodeDto.CatalogNode.ImportRow(catalogNodeDto.CatalogNode[0]);
                    newCatalogNodeDto.CatalogNode[0].SetAdded();
                    newCatalogNodeDto.CatalogNode[0].ParentNodeId = parentCatalogNodeId;
                    newCatalogNodeDto.CatalogNode[0].Code         = Guid.NewGuid().ToString();

                    if (catalogNodeDto.CatalogItemSeo.Count > 0)
                    {
                        foreach (CatalogNodeDto.CatalogItemSeoRow row in catalogNodeDto.CatalogItemSeo.Rows)
                        {
                            newCatalogNodeDto.CatalogItemSeo.ImportRow(row);
                            newCatalogNodeDto.CatalogItemSeo[newCatalogNodeDto.CatalogItemSeo.Count - 1].SetAdded();
                            newCatalogNodeDto.CatalogItemSeo[newCatalogNodeDto.CatalogItemSeo.Count - 1].Uri = Guid.NewGuid().ToString() + ".aspx";
                        }
                    }

                    if (newCatalogNodeDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogNode(newCatalogNodeDto);
                    }

                    if (newCatalogNodeDto.CatalogNode.Count > 0)
                    {
                        CatalogNodeDto.CatalogNodeRow node = newCatalogNodeDto.CatalogNode[0];
                        int newCatalogNodeId = node.CatalogNodeId;
                        int metaClassId      = node.MetaClassId;

                        // load list of MetaFields for MetaClass
                        MetaClass           metaClass  = MetaClass.Load(CatalogContext.MetaDataContext, metaClassId);
                        MetaFieldCollection metaFields = metaClass.MetaFields;

                        // cycle through each language and get meta objects
                        CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                        string[] languages = GetCatalogLanguages(parentCatalogId);
                        if (languages != null)
                        {
                            foreach (string language in languages)
                            {
                                CatalogContext.MetaDataContext.UseCurrentUICulture = false;
                                CatalogContext.MetaDataContext.Language            = language;

                                MetaObject metaObject = MetaObject.Load(CatalogContext.MetaDataContext, catalogNodeDto.CatalogNode[0].CatalogNodeId, metaClassId);

                                MetaObject newMetaObject = MetaObject.NewObject(CatalogContext.MetaDataContext, newCatalogNodeId, metaClassId, FrameworkContext.Current.Profile.UserName);

                                foreach (MetaField metaField in metaFields)
                                {
                                    // skip system MetaFields
                                    if (!metaField.IsUser)
                                    {
                                        continue;
                                    }

                                    switch (metaField.DataType)
                                    {
                                    case MetaDataType.File:
                                    case MetaDataType.Image:
                                    case MetaDataType.ImageFile:
                                        MetaFile metaFile = (MetaFile)metaObject[metaField];
                                        if (metaFile != null)
                                        {
                                            newMetaObject[metaField] = new MetaFile(metaFile.Name, metaFile.ContentType, metaFile.Buffer);
                                        }
                                        break;

                                    default:
                                        if (metaObject[metaField] != null)
                                        {
                                            newMetaObject[metaField] = metaObject[metaField];
                                        }
                                        break;
                                    }
                                }
                                newMetaObject.AcceptChanges(CatalogContext.MetaDataContext);
                            }
                        }
                        CatalogContext.MetaDataContext.UseCurrentUICulture = false;

                        CatalogNodeDto childCatalogNodesDto = CatalogContext.Current.GetCatalogNodesDto(parentCatalogId, catalogNodeId);
                        if (childCatalogNodesDto.CatalogNode.Count > 0)
                        {
                            for (int i = 0; i < childCatalogNodesDto.CatalogNode.Count; i++)
                            {
                                CloneCatalogNode(parentCatalogId, newCatalogNodeDto.CatalogNode[0].CatalogNodeId, childCatalogNodesDto.CatalogNode[i].CatalogNodeId);
                            }
                        }

                        CatalogEntryDto catalogEntriesDto = CatalogContext.Current.GetCatalogEntriesDto(parentCatalogId, catalogNodeDto.CatalogNode[0].CatalogNodeId);
                        if (catalogEntriesDto.CatalogEntry.Count > 0)
                        {
                            for (int i = 0; i < catalogEntriesDto.CatalogEntry.Count; i++)
                            {
                                CloneNodeEntry(parentCatalogId, catalogNodeId, catalogEntriesDto.CatalogEntry[i].CatalogEntryId, parentCatalogId, newCatalogNodeDto.CatalogNode[0].CatalogNodeId);
                            }
                        }
                    }
                }

                scope.Complete();
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Creates the child controls internal.
        /// </summary>
        private void CreateChildControlsInternal()
        {
            //if (this.ObjectId > 0)
            {
                MetaControls.EnableViewState = false;
                if (MetaControls.Controls.Count > 0)
                {
                    return;
                }

                MetaControls.Controls.Clear();

                MetaClass mc = MetaClass.Load(this.MDContext, MetaClassId);

                if (mc == null)
                {
                    return;
                }

                Dictionary <string, MetaObject> metaObjects = new Dictionary <string, MetaObject>();

                if (_metaObjects != null)
                {
                    metaObjects = _metaObjects;
                }
                else
                {
                    // cycle through each language and get meta objects
                    MDContext.UseCurrentUICulture = false;
                    foreach (string language in Languages)
                    {
                        MDContext.UseCurrentUICulture = false;
                        MDContext.Language            = language;

                        MetaObject metaObj = null;
                        if (ObjectId > 0)
                        {
                            metaObj = MetaObject.Load(MDContext, ObjectId, mc);
                            if (metaObj == null)
                            {
                                metaObj = MetaObject.NewObject(MDContext, ObjectId, MetaClassId, FrameworkContext.Current.Profile.UserName);
                                metaObj.AcceptChanges(MDContext);
                            }
                        }

                        metaObjects[language] = metaObj;
                    }
                    MDContext.UseCurrentUICulture = true;
                }

                MetaFieldCollection metaFieldsColl = MetaField.GetList(MDContext, MetaClassId);
                foreach (MetaField mf in metaFieldsColl)
                {
                    if (mf.IsUser)
                    {
                        int index = 0;
                        foreach (string language in Languages)
                        {
                            string  controlName = ResolveMetaControl(mc, mf);
                            Control ctrl        = MetaControls.FindControl(mf.Name);

                            if (ctrl == null)
                            {
                                ctrl = Page.LoadControl(controlName);
                                MetaControls.Controls.Add(ctrl);
                            }


                            CoreBaseUserControl coreCtrl = ctrl as CoreBaseUserControl;
                            if (coreCtrl != null)
                            {
                                coreCtrl.MDContext = this.MDContext;
                            }

                            //ctrl.ID = String.Format("{0}-{1}", mf.Name, index.ToString());

                            ((IMetaControl)ctrl).MetaField = mf;
                            if (metaObjects[language] != null && metaObjects[language][mf] != null)
                            {
                                ((IMetaControl)ctrl).MetaObject = metaObjects[language];
                            }

                            ((IMetaControl)ctrl).LanguageCode    = language;
                            ((IMetaControl)ctrl).ValidationGroup = ValidationGroup;

                            ctrl.DataBind();

                            if (!mf.MultiLanguageValue)
                            {
                                break;
                            }

                            index++;
                        }
                    }
                }
            }
        }