Example #1
0
        private void CheckOnStringDict(MyPackage currentContent)
        {
            var stuff = currentContent.GetPropertyValue("StringDictDemo"); // nope

            CatalogEntryDto dto = catSys.Service.GetCatalogEntryDto(currentContent.Code);

            var row = dto.CatalogEntry.FirstOrDefault();

            MetaObject metaObject = MetaObject.Load(MetaDataContext.Instance, row.CatalogEntryId, row.MetaClassId);
            var        x          = metaObject["StringDictDemo"];


            System.Collections.Hashtable hash          = ObjectHelper.GetMetaFieldValues(dto.CatalogEntry.FirstOrDefault());
            Dictionary <int, string>     keyValuePairs = new Dictionary <int, string>();

            if (hash.Contains("StringDictDemo"))
            {
                foreach (var item in hash.Keys)
                {
                }
            }

            foreach (var item in hash)
            {
            }
        }
Example #2
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);
        }
Example #3
0
 /// <summary>
 /// Handles the Load event of the Page control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected void Page_Load(object sender, System.EventArgs e)
 {
     if (!base.IsPostBack && (this.ClassId > 0))
     {
         MetaObject o = MetaObject.Load(CatalogContext.MetaDataContext, ObjectId, ClassId);
         if (o != null)
         {
             MetaFile metafile = (MetaFile)o[Name];
             if (metafile != null && metafile.Buffer != null && metafile.Buffer.Length > 0)
             {
                 base.Response.Clear();
                 Response.AddHeader("content-disposition", string.Format("attachment; filename=\"{0}\"", Server.UrlEncode(metafile.Name)));
                 Response.ContentType = metafile.ContentType + "; name=\"" + Server.UrlEncode(metafile.Name) + "\"";
                 //base.Response.ContentType = metafile.ContentType;
                 base.Response.BinaryWrite(metafile.Buffer);
                 //base.Response.Flush(); // seem to cause issue on some systems
                 base.Response.End();
             }
             else
             {
                 this.Visible = false;
             }
         }
         else
         {
             this.Visible = false;
         }
     }
 }
Example #4
0
        public virtual FillResult FillData(FillDataMode mode, DataTable rawData, Rule rule, int modifierId, DateTime modified)
        {
            if (rawData == null)
            {
                throw new ArgumentNullException("rawData");
            }

            FillResult retVal = new FillResult(rawData.Rows.Count);

            Validate(rule, rawData);

            int RowIndex = 0;

            foreach (DataRow Row in rawData.Rows)
            {
                try
                {
                    int ObjectId = CreateSystemRow(mode, FillItemList(SystemColumnInfos, Row, RowIndex, rule, retVal.warningList));

                    if (UserColumnInfos.Length != 0)
                    {
                        MetaObject Object = MetaObject.Load(ObjectId, _innerMetaClassName, modifierId, modified);
                        if (Object == null)
                        {
                            Object = MetaObject.NewObject(ObjectId, _innerMetaClassName, modifierId, modified);
                        }
                        CreateUserRow(Object, rule, FillItemList(UserColumnInfos, Row, RowIndex, rule, retVal.warningList));

                        Object.AcceptChanges();
                    }
                    else if (ObjectId == -1)
                    {
                        throw new IdleOperationException();
                    }

                    retVal.SuccessfulRow();
                }
                catch (AlreadyExistException)
                {
                }
                catch (MdpImportException ex)
                {
                    retVal.ErrorRow();
                    ex.setRowInfo(Row, RowIndex);
                    retVal.ErrorException(ex);
                }
                catch (Exception ex)
                {
                    retVal.ErrorRow();
                    retVal.ErrorException(ex);
                }
                RowIndex++;
            }
            return(retVal);
        }
        public ActionResult DoLowLevelDtoEdit(ShirtVariation currentContent, string newText)
        {
            //Old school way to change using Dtos directly
            var        catSystem  = ServiceLocator.Current.GetInstance <ICatalogSystem>();
            var        shirtDto   = catSystem.GetCatalogEntryDto(currentContent.Code);
            var        entryRow   = shirtDto.CatalogEntry.First();
            MetaObject metaObject = MetaObject.Load(MetaDataContext.Instance, entryRow.CatalogEntryId, entryRow.MetaClassId);

            metaObject["MainBody"] = newText;
            metaObject.AcceptChanges(MetaDataContext.Instance);

            return(RedirectToAction("Index"));
        }
Example #6
0
    /// <summary>
    /// Updates meta field
    /// </summary>
    /// <param name="item">The data item.</param>
    /// <returns></returns>
    private void UpdateMetaField(CatalogEntryDto.CatalogEntryRow item)
    {
        int             MetaClassId = item.MetaClassId;
        int             ObjectId    = item.CatalogEntryId;
        MetaDataContext MDContext   = CatalogContext.MetaDataContext;

        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;

            MDContext.Language = LanguageCode;

            MetaObject metaObj     = null;
            bool       saveChanges = true;

            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, LanguageCode, 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);
            }

            MDContext.UseCurrentUICulture = true;
        }
    }
Example #7
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);
        }
        /// <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();
            }
        }
        /// <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();
            }
        }
Example #10
0
    /// <summary>
    /// Binds the batch control.
    /// </summary>
    private void BindData()
    {
        CatalogEntryDto.VariationRow[] variationRows = null;

        CatalogEntryDto.CatalogEntryRow item = (CatalogEntryDto.CatalogEntryRow)DataItem;

        if (IsMetaField)
        {
            int             MetaClassId = item.MetaClassId;
            int             ObjectId    = item.CatalogEntryId;
            MetaDataContext MDContext   = CatalogContext.MetaDataContext;

            MetaControls.EnableViewState = false;
            if (MetaControls.Controls.Count > 0)
            {
                return;
            }

            MetaControls.Controls.Clear();

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

            if (mc == null)
            {
                return;
            }

            MDContext.UseCurrentUICulture = false;
            MDContext.Language            = LanguageCode;

            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);
                }
            }
            MDContext.UseCurrentUICulture = true;


            MetaField mf = MetaField.Load(MDContext, FieldName);
            if (mf.IsUser)
            {
                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 = MDContext;
                }

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

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

                ((IMetaControl)ctrl).LanguageCode    = LanguageCode;
                ((IMetaControl)ctrl).ValidationGroup = String.Empty;

                ctrl.DataBind();
            }
        }
        else
        {
            switch (FieldName)
            {
            case "Name":
            case "Code":
                tbItem.Visible = true;
                tbItem.Text    = (string)item[FieldName];
                break;

            case "StartDate":
            case "EndDate":
                cdpItem.Visible = true;
                cdpItem.Value   = (DateTime)item[FieldName];
                break;

            case "TemplateName":
                ddlItem.Visible = true;
                TemplateDto templates = DictionaryManager.GetTemplateDto();
                if (templates.main_Templates.Count > 0)
                {
                    DataView view = templates.main_Templates.DefaultView;
                    view.RowFilter         = "TemplateType = 'entry'";
                    ddlItem.DataTextField  = "FriendlyName";
                    ddlItem.DataValueField = "Name";
                    ddlItem.DataSource     = view;
                    ddlItem.DataBind();
                }
                ManagementHelper.SelectListItem2(ddlItem, item.TemplateName);
                break;

            case "SortOrder":
                tbItem.Visible = true;
                CatalogRelationDto relationDto = CatalogContext.Current.GetCatalogRelationDto(item.CatalogId, CatalogNodeId, item.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));
                if (relationDto.NodeEntryRelation.Count > 0)
                {
                    tbItem.Text = relationDto.NodeEntryRelation[0].SortOrder.ToString();
                }
                break;

            case "IsActive":
                becItem.Visible    = true;
                becItem.IsSelected = item.IsActive;
                break;

            case "ListPrice":
                tbItem.Visible = true;
                variationRows  = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    tbItem.Text = variationRows[0].ListPrice.ToString("#0.00");
                }
                break;

            case "TaxCategoryId":
                ddlItem.Visible = true;
                ddlItem.Items.Add(new ListItem(Resources.CatalogStrings.Entry_Select_Tax_Category, "0"));
                CatalogTaxDto taxes = CatalogTaxManager.GetTaxCategories();
                if (taxes.TaxCategory != null)
                {
                    foreach (CatalogTaxDto.TaxCategoryRow row in taxes.TaxCategory.Rows)
                    {
                        ddlItem.Items.Add(new ListItem(row.Name, row.TaxCategoryId.ToString()));
                    }
                }
                ddlItem.DataBind();
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    ManagementHelper.SelectListItem2(ddlItem, variationRows[0].TaxCategoryId);
                }
                break;

            case "TrackInventory":
                becItem.Visible = true;
                variationRows   = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    becItem.IsSelected = variationRows[0].TrackInventory;
                }
                break;

            case "MerchantId":
                ddlItem.Visible = true;
                ddlItem.Items.Insert(0, new ListItem(Resources.CatalogStrings.Entry_Select_Merchant, ""));
                CatalogEntryDto merchants = CatalogContext.Current.GetMerchantsDto();
                if (merchants.Merchant != null)
                {
                    foreach (CatalogEntryDto.MerchantRow row in merchants.Merchant.Rows)
                    {
                        ddlItem.Items.Add(new ListItem(row.Name, row.MerchantId.ToString()));
                    }
                }
                ddlItem.DataBind();
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0 && !variationRows[0].IsMerchantIdNull())
                {
                    ManagementHelper.SelectListItem2(ddlItem, variationRows[0].MerchantId);
                }
                break;

            case "WarehouseId":
                ddlItem.Visible = true;
                ddlItem.Items.Insert(0, new ListItem(Resources.CatalogStrings.Entry_Select_Warehouse, "0"));
                WarehouseDto warehouses = WarehouseManager.GetWarehouseDto();
                if (warehouses.Warehouse != null)
                {
                    foreach (WarehouseDto.WarehouseRow row in warehouses.Warehouse.Rows)
                    {
                        ddlItem.Items.Add(new ListItem(row.Name, row.WarehouseId.ToString()));
                    }
                }
                ddlItem.DataBind();
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    ManagementHelper.SelectListItem2(ddlItem, variationRows[0].WarehouseId);
                }
                break;

            case "PackageId":
                ddlItem.Visible = true;
                ddlItem.Items.Insert(0, new ListItem(Resources.CatalogStrings.Entry_Select_Package, "0"));
                ShippingMethodDto shippingDto = ShippingManager.GetShippingPackages();
                if (shippingDto.Package != null)
                {
                    foreach (ShippingMethodDto.PackageRow row in shippingDto.Package.Rows)
                    {
                        ddlItem.Items.Add(new ListItem(row.Name, row.PackageId.ToString()));
                    }
                }
                ddlItem.DataBind();
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    ManagementHelper.SelectListItem2(ddlItem, variationRows[0].PackageId);
                }
                break;

            case "Weight":
            case "MinQuantity":
            case "MaxQuantity":
                tbItem.Visible = true;
                variationRows  = item.GetVariationRows();
                if (variationRows.Length > 0 && variationRows[0][FieldName] != DBNull.Value)
                {
                    tbItem.Text = variationRows[0][FieldName].ToString();
                }
                break;

            case "InStockQuantity":
            case "ReservedQuantity":
            case "ReorderMinQuantity":
            case "PreorderQuantity":
            case "BackorderQuantity":
                tbItem.Visible = true;
                if (item.InventoryRow != null && item.InventoryRow[FieldName] != DBNull.Value)
                {
                    tbItem.Text = item.InventoryRow[FieldName].ToString();
                }
                break;

            case "AllowBackorder":
            case "AllowPreorder":
                becItem.Visible = true;
                if (item.InventoryRow != null)
                {
                    becItem.IsSelected = (bool)item.InventoryRow[FieldName];
                }
                break;

            case "InventoryStatus":
                ddlItem.Visible = true;
                ddlItem.Items.Insert(0, new ListItem(Resources.SharedStrings.Disabled, "0"));
                ddlItem.Items.Insert(0, new ListItem(Resources.SharedStrings.Enabled, "1"));
                ddlItem.Items.Insert(0, new ListItem(Resources.SharedStrings.Ignored, "2"));
                ddlItem.DataBind();
                if (item.InventoryRow != null)
                {
                    ManagementHelper.SelectListItem2(ddlItem, item.InventoryRow.InventoryStatus);
                }
                break;

            case "PreorderAvailabilityDate":
            case "BackorderAvailabilityDate":
                cdpItem.Visible = true;
                if (item.InventoryRow != null)
                {
                    cdpItem.Value = (DateTime)item.InventoryRow[FieldName];
                }
                break;
            }
        }
    }
Example #11
0
 public static MetaObject LoadMetaObject(int ObjectId, string MetaClassName, int ModifierId, DateTime Modified)
 {
     return(MetaObject.Load(ObjectId, MetaClassName, ModifierId, Modified));
 }
Example #12
0
 public static MetaObject LoadMetaObject(int ObjectId, string MetaClassName)
 {
     return(MetaObject.Load(ObjectId, MetaClassName));
 }
Example #13
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public void ProcessRequest(HttpContext context)
        {
            if (_CachedVersionIsOkay(context.Request))
            {
                context.Response.StatusCode      = 304;
                context.Response.SuppressContent = true;
                return;
            }

            string file = context.Request.FilePath;

            file = file.Substring(file.LastIndexOf("/") + 1);
            file = file.Substring(0, file.IndexOf("."));
            string[] fileParams = file.Split(new char[] { '-' });

            if (fileParams.Length < 3)
            {
                return;
            }

            int    metaClassId   = Int32.Parse(fileParams[0]);
            int    objectId      = Int32.Parse(fileParams[1]);
            string metaFieldName = fileParams[2];

            bool thumbNail = false;

            if (fileParams.Length > 3)
            {
                if (fileParams[3] == "thumb")
                {
                    thumbNail = true;
                }
            }

            MetaObject o = MetaObject.Load(CatalogContext.MetaDataContext, objectId, metaClassId);

            if (o != null)
            {
                MetaField mf = MetaField.Load(CatalogContext.MetaDataContext, metaFieldName);

                if (mf == null)
                {
                    return;
                }

                MetaFile metafile = (MetaFile)o[mf];
                if (metafile != null && metafile.Buffer != null && metafile.Buffer.Length > 0)
                {
                    context.Response.Cache.SetExpires(DateTime.Now.Add(new TimeSpan(0, 1, 0)));
                    context.Response.Cache.SetCacheability(HttpCacheability.Public);
                    context.Response.Cache.SetLastModified(DateTime.Now);


                    context.Response.AddHeader("content-disposition", "inline; filename=" + metafile.Name);
                    context.Response.ContentType = metafile.ContentType;

                    if (!thumbNail)
                    {
                        context.Response.BinaryWrite(metafile.Buffer);
                    }
                    else // create thumbnail
                    {
                        if (!metafile.ContentType.Contains("gif")) // dont create thumbnails for gifs
                        {
                            int  thumbWidth   = 0;
                            int  thumbHeight  = 0;
                            bool thumbStretch = false;

                            object 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;
                                }
                            }

                            byte[] data = ImageGenerator.CreateImageThumbnail(metafile.Buffer, metafile.ContentType, thumbHeight, thumbWidth, thumbStretch);
                            context.Response.BinaryWrite(data);
                        }
                        else
                        {
                            context.Response.BinaryWrite(metafile.Buffer);
                        }
                    }
                }
                else
                {
                    context.Response.Cache.SetExpires(DateTime.Now.Add(new TimeSpan(1, 0, 0)));
                    context.Response.Cache.SetCacheability(HttpCacheability.Public);
                    context.Response.Cache.SetValidUntilExpires(false);

                    context.Response.AddHeader("content-disposition", "inline; filename=" + "nopic.png");
                    context.Response.ContentType = "image/png";
                    context.Response.WriteFile(context.Server.MapPath("~/images/nopic.png"));
                }
            }
        }
Example #14
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();
        }
Example #15
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++;
                        }
                    }
                }
            }
        }