/// <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)); }
/// <summary> /// Binds the data. /// </summary> private void BindData() { SearchFilter.Items.Clear(); SearchFilter.Items.Add(new ListItem(RM.GetString("GENERAL_ALL_PRODUCTS"), "")); string cacheKey = CatalogCache.CreateCacheKey("mc-catalogentry-list"); // check cache first object cachedObject = CatalogCache.Get(cacheKey); MetaClassCollection metaClasses = null; MetaClass catalogEntry = MetaHelper.LoadMetaClassCached(CatalogContext.MetaDataContext, "CatalogEntry"); if (catalogEntry != null) { metaClasses = catalogEntry.ChildClasses; } if (metaClasses != null) { foreach (MetaClass metaClass in metaClasses) { SearchFilter.Items.Add(new ListItem(metaClass.FriendlyName, metaClass.Name)); } } SearchFilter.DataBind(); Search.Text = Request.QueryString["search"]; CommonHelper.SelectListItem(SearchFilter, Request.QueryString["filter"]); }
/// <summary> /// Returns the MetaClass. /// </summary> public MetaClass GetEntryMetaClass() { if (_MetaClass == null) { _MetaClass = MetaHelper.LoadMetaClassCached(CatalogContext.MetaDataContext, MetaClassId); } return(_MetaClass); }
public MetaClassEx LoadMetaClassCached(int metaClassId, string language) { var context = CatalogContext.MetaDataContext; context.UseCurrentThreadCulture = false; context.Language = language; var metaClass = MetaHelper.LoadMetaClassCached(context, metaClassId); return(new MetaClassEx(metaClass)); }
/// <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)); }
public IEnumerable <IModelTransformContext> Execute(IEnumerable <IModelTransformContext> models) { var modelList = models.ToList(); foreach (var model in modelList) { var facetContent = model.Source as IFacetContent; if (facetContent != null) { var properties = model.Target.Properties; properties["MetaClassName"] = MetaHelper.LoadMetaClassCached(CatalogContext.MetaDataContext, facetContent.MetaClassId).FriendlyName; properties["StartPublish"] = facetContent.StartPublish; properties["StopPublish"] = facetContent.StopPublish; var contentType = _contentTypeRepository.Load(facetContent.ContentTypeID); var contentTypeModel = _contentTypeModelRepository.List() .FirstOrDefault(x => x.ExistingContentType == contentType); if (contentTypeModel == null) { continue; } if (typeof(EntryContentBase).IsAssignableFrom(contentTypeModel.ModelType)) { properties["Code"] = facetContent.Code; } if (typeof(VariationContent).IsAssignableFrom(contentTypeModel.ModelType)) { properties["Price"] = facetContent.DefaultPrice.ToString(); var instockQuantity = facetContent.Inventories.Sum(x => x.InStockQuantity); var reorderMinQuantity = facetContent.Inventories.Max(x => x.ReorderMinQuantity); string status; if (instockQuantity == 0) { status = "unavailable"; } else if (instockQuantity < reorderMinQuantity) { status = "low"; } else { status = "available"; } properties["InStockStatus"] = status; properties["InStockQuantity"] = instockQuantity.ToString(); } if (typeof(NodeContent).IsAssignableFrom(contentTypeModel.ModelType)) { properties["Code"] = facetContent.Code; } if (typeof(CatalogContent).IsAssignableFrom(contentTypeModel.ModelType)) { properties["WeightBase"] = facetContent.WeightBase; properties["DefaultCurrency"] = facetContent.DefaultCurrency; properties["LengthBase"] = facetContent.LengthBase; } if (typeof(IAssetContainer).IsAssignableFrom(contentTypeModel.ModelType)) { properties["Thumbnail"] = facetContent.ThumbnailPath; } model.Target.TypeIdentifier = contentTypeModel.ModelType.FullName.ToLowerInvariant(); SetCurrentCategoryRelation(model, properties, facetContent); SetHasChildrenForEntryContent(model, facetContent); // var catalogProperties = new Dictionary<string, Func<object, object>> // { // {CatalogProperty(c => c.DefaultLanguage), GetTranslatedLanguage}, // {CatalogProperty(c => c.Owner), getDefaultValue} // }; } } return(modelList); }
/// <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); }