private string GetColumnValue(TaxonomyInfo taxonomy, string columnName) { if (columnName == "Taxonomy") { if (Args.IgnoreT1Taxonomy) { return(taxonomy.ToString(true)); } else { return(taxonomy.ToString()); } } if (columnName == "NodeType") { return((taxonomy.NodeType == "Derived") ? "Cross List" : TaxonomyInfo.NodeTypeRegular); } return(GetTn(taxonomy, columnName)); }
static void OpenInNewTab(TaxonomyInfo taxonomy) { var skuQuery = from si in AryaTools.Instance.InstanceData.Dc.SkuInfos let sku = si.Sku where si.Active && sku.Project.Equals(AryaTools.Instance.InstanceData.CurrentProject) && taxonomy.Equals(si.TaxonomyInfo) select sku; AryaTools.Instance.Forms.SkuForm.LoadTab( skuQuery, taxonomy, taxonomy.TaxonomyData.NodeName, taxonomy.ToString()); }
private string GetTaxPrefix(TaxonomyInfo tax) { var parts = tax.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.RemoveEmptyEntries).ToList(); var noOfLevels = GroupSkusBy == GroupSkusByNodeLevel.Level2 ? 2 : GroupSkusBy == GroupSkusByNodeLevel.Level2 ? 3 : 99; parts = parts.Take(noOfLevels).ToList(); var taxPrefix = parts.Aggregate((full, current) => full + TaxonomyInfo.Delimiter + current); return(taxPrefix); }
public void SetFormType(QueryFormType qft, TaxonomyInfo crossListNode = null) { _selectedCrossListNodeFromTreeView = crossListNode; switch (qft) { case QueryFormType.QueryView: Text = "Query View"; btnCrossList.Visible = false; txtBoxCrossListNode.Visible = false; break; case QueryFormType.CrossListDefinition: Text = "Cross List Definition"; btnCrossList.Visible = true; txtBoxCrossListNode.Visible = true; txtBoxCrossListNode.Text = _selectedCrossListNodeFromTreeView.ToString(); var derivedTaxonomy = _selectedCrossListNodeFromTreeView.DerivedTaxonomies.FirstOrDefault(); if (derivedTaxonomy != null) { PopulateQueryView(derivedTaxonomy.Expression.DeSerializeXElement()); } //if ( // AryaTools.Instance.InstanceData.Dc.DerivedTaxonomies.Any( // t => t.TaxonomyID == SelectedCrossListNodeFromTreeView.ID)) //{ // var cl = // AryaTools.Instance.InstanceData.Dc.DerivedTaxonomies.Where( // t => t.TaxonomyID == SelectedCrossListNodeFromTreeView.ID).Select(ex => ex.Expression). // Single().DeSerializeXElement(); // PopulateQueryView(cl); //} break; case QueryFormType.SkuGroup: Text = "Sku Group Definition"; btnCrossList.Visible = true; txtBoxCrossListNode.Visible = true; txtBoxCrossListNode.Text = SelectedSkuGroupForQueryView.Criterion.Name.ToString(); //var skuGroup = _selectedCrossListNodeFromTreeView.DerivedTaxonomies.FirstOrDefault(); if (SelectedSkuGroupForQueryView.Criterion != null) { PopulateQueryView(SelectedSkuGroupForQueryView.Criterion.DeSerializeXElement()); SelectedSkuGroupForQueryView = null; } break; } }
private string GetColumnValue(AryaDbDataContext dc, TaxonomyInfo taxonomyInfo, string columnName) { if (_taxColumns.Contains(columnName)) { if (columnName == "Taxonomy") { return(taxonomyInfo.ToString(Args.IgnoreT1Taxonomy)); } return(GetTn(taxonomyInfo, columnName)); } if (columnName == "NodeDescription") { return(taxonomyInfo.TaxonomyData.NodeDescription); } return(GetTaxMetaAttributeValue(dc, columnName, taxonomyInfo)); }
private void ProcessTaxonomySkus(TaxonomyInfo ti) { //Must use independent DataContext to conserve memory using (var dc = new AryaDbDataContext(Arguments.ProjectId, Arguments.UserId)) { var node = ItemNode.FromValues(ti.ID, ti.ProjectID, ti.ToString(((AdvancedExportArgs)Arguments).IgnoreT1Taxonomy), ti.NodeName); //var allSkus = from si in dc.SkuInfos // where si.Active && si.TaxonomyID == ti.ID // let sku = si.Sku // where sku.SkuType == Sku.ItemType.Product.ToString() // select sku; var allSkus = ti.GetSkus(_args.ExportCrossListNodes); var skus = ((AdvancedExportArgs)Arguments).GetFilteredSkuList(allSkus).ToList(); skus.AsParallel().ForAll(sku => ProcessSku(node, sku)); } }
private string GetTn(TaxonomyInfo taxonomy, string columnName) { if (columnName == "Taxonomy") { return(taxonomy.ToString(Args.IgnoreT1Taxonomy)); } if (!_rxCol.IsMatch(columnName)) { return(string.Empty); } var col = _rxCol.Match(columnName).Value; var resultInt = int.Parse(col); var taxParts = taxonomy.ToStringParts().ToList(); if (Args.IgnoreT1Taxonomy) { taxParts.RemoveAt(0); } return(taxParts.Count >= resultInt ? taxParts[resultInt - 1] : string.Empty); }
private void ProcessTaxonomySchemas(TaxonomyInfo ti) { //try //{ var taxonomyPaths = new List <string>(); var parts = ti.ToStringParts().ToList(); if (((AdvancedExportArgs)Arguments).IgnoreT1Taxonomy) { parts.RemoveAt(0); } for (var level = 1; level <= parts.Count; level++) { var taxPath = level.ToString(); for (var path = 0; path < level; path++) { taxPath += "/" + parts[path]; } taxonomyPaths.Add(taxPath); } var node = Node.FromValues(ti.ID, ti.ProjectID, ti.TaxonomyData.ParentTaxonomyID ?? Guid.Empty, ti.ToString(((AdvancedExportArgs)Arguments).IgnoreT1Taxonomy), taxonomyPaths.ToArray(), ti.NodeName); var taxonomyMetaDatas = from tmi in ti.TaxonomyMetaInfos from tmd in tmi.TaxonomyMetaDatas where tmd.Active select tmd; foreach (var tmd in taxonomyMetaDatas) { switch (tmd.TaxonomyMetaInfo.Attribute.AttributeName) { case "Taxonomy Enrichment Copy": if (node.Enrichment == null) { node.Enrichment = new Enrichment { lang = EnUs } } ; node.Enrichment.EnrichmentCopy = tmd.Value; break; case "Taxonomy Enrichment Image": if (node.Enrichment == null) { node.Enrichment = new Enrichment { lang = EnUs } } ; node.Enrichment.EnrichmentPrimaryImage = new EnrichmentFileResourceType { Filename = tmd.Value }; break; } } var schemas = from sch in ti.SchemaInfos where sch.SchemaDatas.Any(sd => sd.Active) orderby sch.Attribute.AttributeName select sch; node.SchemaAttribute = schemas.Select(ProcessSchema).ToArray(); node.SerializeObject(GetSaveFilePath("Node", ti.ID.ToString())); //} //catch (Exception ex) //{ // if (Summary.Warnings == null) // Summary.Warnings = new List<WorkerWarning>(); // Summary.Warnings.Add(new WorkerWarning // { // ErrorMessage = ex.Message, // ErrorDetails = ex.StackTrace, // LineData = ti.ToString() // }); //} }
private void WriteMetricsToFile(TaxonomyInfo taxonomy, int taxonomyMaxDepth) { // bool noRowIfNoSchema = true; var attributes = (from sci in _currentDb.SchemaInfos join scd in _currentDb.SchemaDatas on sci.ID equals scd.SchemaID join a in _currentDb.Attributes on sci.AttributeID equals a.ID where scd.Active && sci.TaxonomyID == taxonomy.ID && scd.InSchema select a).ToList().Where(p => !IgnoreAttributes.Contains(p.AttributeName)).OrderBy( p => p.AttributeName).ToList(); var taxonomyString = taxonomy.ToString(); if (IgnoreT1Taxonomy) { taxonomyString = taxonomyString.Substring(taxonomy.ToString().IndexOf('>') + 1); } if (string.IsNullOrEmpty(taxonomy.ToString())) { return; } var taxParts = taxonomyString.Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None); var taxonomyParts = new string[taxonomyMaxDepth]; StatusMessage = string.Format("{1}{0}Reading node", Environment.NewLine, taxonomy); IEnumerable <Sku> allSkus = (from sku in _currentDb.Skus join si in _currentDb.SkuInfos on sku.ID equals si.SkuID where si.TaxonomyID == taxonomy.ID && si.Active select sku).ToList(); StatusMessage = string.Format("{1}{0}Filtering SKUs", Environment.NewLine, taxonomy); IEnumerable <Sku> filteredSkus = GetFilteredSkuList(allSkus, true, _parsedSkuInclusions, _parsedSkuExclusions).ToList(); var filteredSkuCount = filteredSkus.Count(); if (!NoSchemaIfNoSku || filteredSkuCount != 0) { for (var i = 0; i < taxonomyMaxDepth; i++) { taxonomyParts[i] = i < taxParts.Length ? taxParts[i].Trim() : string.Empty; _attributeFile.Write(taxonomyParts[i] + "\t"); // valueFile.Write(taxonomyParts[i] + "\t"); // skuFile.Write(taxonomyParts[i] + "\t"); } } if (filteredSkuCount <= 0) { if (!NoSchemaIfNoSku) { _attributeFile.WriteLine(); } //print new line // valueFile.Write("{0}", Environment.NewLine); // skuFile.Write("{0}", Environment.NewLine); return; } // Even though we only export fill rates for filtered SKUs, we export all attributes in this node StatusMessage = string.Format("{1}{0}Fetching Attributes", Environment.NewLine, taxonomy); StatusMessage = string.Format("{1}{0}Reading values", Environment.NewLine, taxonomy); IEnumerable <EntityData> filteredEntityDatas = GetEntityDatas(filteredSkus).ToList(); if (!attributes.Any()) { //print new line //this line should be uncommented _attributeFile.WriteLine(); // valueFile.Write("{0}", Environment.NewLine); // skuFile.Write("{0}", Environment.NewLine); } else // taxonomy has attributes { for (var i = 0; i < attributes.Count(); i++) { if (i != 0) { //print taxonomy for (var j = 0; j < taxonomyMaxDepth; j++) { taxonomyParts[j] = j < taxParts.Length ? taxParts[j].Trim() : string.Empty; _attributeFile.Write(taxonomyParts[j] + "\t"); // valueFile.Write(taxonomyParts[j] + "\t"); // skuFile.Write(taxonomyParts[j] + "\t"); } } var currentAttribute = attributes[i]; StatusMessage = string.Format("{1}{0}Attribute {2}", Environment.NewLine, taxonomy, currentAttribute); var schemaData = taxonomy.SchemaInfos.Where(si => si.Attribute.Equals(currentAttribute)).Select( si => si.SchemaData).FirstOrDefault(); if (schemaData == null || !schemaData.InSchema) // Only export In Schema attributes { continue; } IEnumerable <EntityData> values = filteredEntityDatas.Where(ed => ed.Attribute.Equals(currentAttribute)).ToList(); var attrCount = values.Select(ed => ed.EntityInfo.SkuID).Distinct().Count(); _attributeFile.WriteLine("{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}", _delimiter, currentAttribute, filteredSkuCount, attrCount, filteredSkuCount == 0 ? 0 : attrCount * 100.00 / filteredSkuCount, schemaData.NavigationOrder, schemaData.DisplayOrder, currentAttribute.AttributeType); IEnumerable <string> distinctValues = values.Select(ed => ed.Value + _delimiter + (ed.Uom ?? string.Empty)).Distinct().OrderBy( val => val); var totalSkus = 0; if (distinctValues.Count() != 0) { for (var v = 0; v < distinctValues.Count(); v++) { var currentValue = distinctValues.ToList()[v]; var valueCount = values.Where( ed => (ed.Value + _delimiter + (ed.Uom ?? string.Empty)).Equals(currentValue)). Select(ed => ed.EntityInfo.SkuID).Distinct().Count(); totalSkus += valueCount; for (var j = 0; j < taxonomyMaxDepth; j++) { taxonomyParts[j] = j < taxParts.Length ? taxParts[j].Trim() : string.Empty; _valueFile.Write(taxonomyParts[j] + "\t"); } _valueFile.WriteLine( "{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}{0}{8}{0}{9}", _delimiter, currentAttribute, currentValue, filteredSkuCount, valueCount, filteredSkuCount == 0 ? 0 : valueCount * 100.00 / filteredSkuCount, filteredSkuCount == 0 ? 0 : attrCount * 100.00 / filteredSkuCount, schemaData.NavigationOrder, schemaData.DisplayOrder, currentAttribute.AttributeType); } //end of for } //end of if if (totalSkus < filteredSkuCount) { var currentValue = string.Empty + _delimiter + string.Empty; var valueCount = filteredSkuCount - totalSkus; for (var j = 0; j < taxonomyMaxDepth; j++) { taxonomyParts[j] = j < taxParts.Length ? taxParts[j].Trim() : string.Empty; _valueFile.Write(taxonomyParts[j] + "\t"); } _valueFile.WriteLine( "{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}{0}{8}{0}{9}", _delimiter, currentAttribute, currentValue, filteredSkuCount, valueCount, filteredSkuCount == 0 ? 0 : valueCount * 100.00 / filteredSkuCount, filteredSkuCount == 0 ? 0 : attrCount * 100.00 / filteredSkuCount, schemaData.NavigationOrder, schemaData.DisplayOrder, currentAttribute.AttributeType); } } //end of for } //end of else StatusMessage = string.Format("{1}{0}Fetching Navigation and Display attributes", Environment.NewLine, taxonomy); var navigationAttributes = taxonomy.SchemaInfos.Where(si => { var sd = si.SchemaData; return(sd != null && sd.NavigationOrder > 0); }).Select(si => si.Attribute).ToDictionary( att => att, att => att.AttributeName); var displayAttributes = taxonomy.SchemaInfos.Where(si => { var sd = si.SchemaData; return(sd != null && sd.DisplayOrder > 0); }).Select(si => si.Attribute).ToDictionary( att => att, att => att.AttributeName); var ctr = 0; for (var i = 0; i < filteredSkus.Count(); i++) { StatusMessage = string.Format("{1}{0}{2} Skus", Environment.NewLine, taxonomy, ++ctr); var currentSku = filteredSkus.ToList()[i]; IEnumerable <EntityData> skuEntityDatas = currentSku.EntityInfos.SelectMany(ei => ei.EntityDatas.Where(ed => ed.Active)).ToList(); var skuAttCount = skuEntityDatas.Where(ed => attributes.Contains(ed.Attribute)).Select(ed => ed.AttributeID). Distinct().Count(); var skuNavAttCount = skuEntityDatas.Where(ed => navigationAttributes.ContainsKey(ed.Attribute)).Select( ed => ed.AttributeID).Distinct().Count(); var skuDispAttCount = skuEntityDatas.Where(ed => displayAttributes.ContainsKey(ed.Attribute)).Select( ed => ed.AttributeID).Distinct().Count(); //print taxonomy for (var j = 0; j < taxonomyMaxDepth; j++) { taxonomyParts[j] = j < taxParts.Length ? taxParts[j].Trim() : string.Empty; _skuFile.Write(taxonomyParts[j] + "\t"); } _skuFile.WriteLine("{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}{0}{8}{0}{9}{0}{10}", _delimiter, currentSku.ItemID, attributes.Count, navigationAttributes.Count, displayAttributes.Count, skuAttCount, skuNavAttCount, skuDispAttCount, attributes.Count == 0 ? 0 : skuAttCount * 100.0 / attributes.Count, navigationAttributes.Count == 0 ? 0 : skuNavAttCount * 100.0 / navigationAttributes.Count, displayAttributes.Count == 0 ? 0 : skuDispAttCount * 100.0 / displayAttributes.Count); } }
private DataRow GetDataRow(DataRow dataRow, TaxonomyInfo node, IList <string> nodeParts, string attributeName, int nodeSkuCount, int attributeSkuCount, string value, string uom, int valueSkuCount, string itemId, int nodeAttributeCount, int nodeNavigationAttributeCount, int nodeDisplayAttributeCount, int skuAttributeCount, int skuNavigationAttributeCount, int skuDisplayAttributeCount) { foreach (DataColumn column in dataRow.Table.Columns) { switch (column.ColumnName) { case ColTaxonomyPath: dataRow[column.ColumnName] = node.ToString(_args.IgnoreT1Taxonomy); break; case ColItemId: dataRow[column.ColumnName] = itemId; break; case ColAttribute: dataRow[column.ColumnName] = attributeName; break; case ColValue: dataRow[column.ColumnName] = value; break; case ColUom: dataRow[column.ColumnName] = uom; break; case ColNavigationOrder: dataRow[column.ColumnName] = node.SchemaInfos.First(si => si.Attribute.AttributeName == attributeName) .SchemaData.NavigationOrder; break; case ColDisplayOrder: dataRow[column.ColumnName] = node.SchemaInfos.First(si => si.Attribute.AttributeName == attributeName) .SchemaData.DisplayOrder; break; case ColNodeFilteredSkuCount: dataRow[column.ColumnName] = nodeSkuCount; break; case ColAttributeSkuCount: dataRow[column.ColumnName] = attributeSkuCount; break; case ColValueSkuCount: dataRow[column.ColumnName] = valueSkuCount; break; case ColNodeAttributeCount: dataRow[column.ColumnName] = nodeAttributeCount; break; case ColNodeNavigationAttributeCount: dataRow[column.ColumnName] = nodeNavigationAttributeCount; break; case ColNodeDisplayAttributeCount: dataRow[column.ColumnName] = nodeDisplayAttributeCount; break; case ColSkuAttributeCount: dataRow[column.ColumnName] = skuAttributeCount; break; case ColSkuNavigationAttributeCount: dataRow[column.ColumnName] = skuNavigationAttributeCount; break; case ColSkuDisplayAttributeCount: dataRow[column.ColumnName] = skuDisplayAttributeCount; break; case ColAttributeFillRate: dataRow[column.ColumnName] = string.Format("{0:N2}%", attributeSkuCount * 100.00 / nodeSkuCount); break; case ColValueFillRate: dataRow[column.ColumnName] = string.Format("{0:N2}%", valueSkuCount * 100.00 / nodeSkuCount); break; case ColNodeAttributeFillRate: dataRow[column.ColumnName] = string.Format("{0:N2}%", skuAttributeCount * 100.00 / nodeAttributeCount); break; case ColNodeNavigationAttributeFillRate: dataRow[column.ColumnName] = string.Format("{0:N2}%", skuNavigationAttributeCount * 100.00 / nodeNavigationAttributeCount); break; case ColNodeDisplayAttributeFillRate: dataRow[column.ColumnName] = string.Format("{0:N2}%", skuDisplayAttributeCount * 100.00 / nodeDisplayAttributeCount); break; default: try { int level; if (!column.ColumnName.StartsWith("T") || !int.TryParse(column.ColumnName.Substring(1), out level)) { continue; } dataRow[column.ColumnName] = nodeParts.Count >= level ? nodeParts[level - 1] : string.Empty; } catch (Exception) { //Do Nothing - I wonder why control got here... } break; } } return(dataRow); }
private void ExportTaxonomyNode(NatalieTaxonomy selectedNode, TaxonomyInfo selectedTaxonomy) { StatusMessage = selectedTaxonomy.ToString(); //Export Schema var inSchemaAttributes = selectedTaxonomy.SchemaInfos.Where(si => si.SchemaData != null && si.SchemaData.InSchema).ToList(); var schemas = new List <NatalieSchema>(); foreach (var si in inSchemaAttributes) { var metaDatas = from mi in si.SchemaMetaInfos let md = mi.SchemaMetaData where md != null select md; var datas = metaDatas.Select( metaData => new NatalieSchemaData { MetaAttributeName = metaData.SchemaMetaInfo.Attribute.AttributeName, Value = metaData.Value }).ToArray(); var lovs = (from lov in si.ListOfValues select new NatalieLov { Value = lov.Value, DisplayOrder = lov.DisplayOrder.ToString(), Copy = lov.EnrichmentCopy, Image = lov.EnrichmentImage }).ToArray(); var schema = new NatalieSchema { AttributeName = si.Attribute.AttributeName, NavigationalOrder = si.SchemaData.NavigationOrder.ToString(), DisplayOrder = si.SchemaData.DisplayOrder.ToString(), DataType = si.SchemaData.DataType, SchemaDatas = datas, ListOfValues = lovs }; schemas.Add(schema); } selectedNode.Schemas = schemas.ToArray(); //Export Items var items = new List <NatalieItem>(); var allAttributes = inSchemaAttributes.Select(att => att.Attribute.AttributeName).ToList(); foreach (var sku in selectedTaxonomy.Skus) { var curentSku = sku; var entities = from attribute in allAttributes from value in curentSku.GetValuesForAttribute(attribute, false) select new NatalieItemData { AttributeName = attribute, Value = value.Value, Uom = value.Uom }; var skuNode = new NatalieItem { ItemId = sku.ItemID, ItemDatas = entities.ToArray() }; items.Add(skuNode); } selectedNode.Items = items.ToArray(); //Children var children = new List <NatalieTaxonomy>(); foreach (var childTaxonomy in selectedTaxonomy.AllChildren) { var childNode = new NatalieTaxonomy { NodeName = childTaxonomy.NodeName, Copy = childTaxonomy.EnrichmentCopy, Image = childTaxonomy.EnrichmentImage }; children.Add(childNode); ExportTaxonomyNode(childNode, childTaxonomy); } selectedNode.Taxonomies = children.ToArray(); CurrentProgress++; }
private List <Attribute> GetAttributes(AryaDbDataContext dc, TaxonomyInfo currentTaxonomyInfo) { var attributes = new List <Attribute>(); if (Args.LeafNodesOnly && !currentTaxonomyInfo.IsLeafNode) { return(attributes); } //if (!Args.ExportEmptyNodes && !currentTaxonomyInfo.GetSkus(Args.ExportCrossListNodes).Any()) //if (!(Args.ExportEmptyNodes || currentTaxonomyInfo.GetSkus(Args.ExportCrossListNodes).Any(t => t.SkuType == "Product"))) if (currentTaxonomyInfo.GetSkus(Args.ExportCrossListNodes).Any(t => t.SkuType == "Product") || Args.ExportEmptyNodes) { if (Args.ExportSuperSchema && !currentTaxonomyInfo.IsLeafNode) { var schemaInfos = new List <SchemaInfo>(); schemaInfos.AddRange( currentTaxonomyInfo.SchemaInfos.Where(si => si.SchemaDatas.Any(sd => sd.Active)).ToList()); if (Args.ExportSuperSchema) { foreach (var leaf in currentTaxonomyInfo.AllLeafChildren) { schemaInfos.AddRange(leaf.SchemaInfos.Where(si => si.SchemaDatas.Any(sd => sd.Active)).ToList()); } } var schemaAttributes = schemaInfos.Where(p => p.SchemaData.InSchema).Select(p => new { p.Attribute, p.SchemaData }).ToList(); attributes = (from att in schemaAttributes group att by att.Attribute into grp let minRank = grp.Min(p => GetRank(p.SchemaData, SortOrder.OrderbyDisplayNavigation)) orderby minRank select grp.Key).Distinct().ToList(); } else { attributes = (from si in dc.SchemaInfos where si.TaxonomyID == currentTaxonomyInfo.ID let sd = si.SchemaDatas.FirstOrDefault(sd => sd.Active) where sd != null let inSchema = sd.InSchema where inSchema let navRank = sd == null || sd.NavigationOrder == 0 ? decimal.MaxValue : sd.NavigationOrder let dispRank = sd == null || sd.DisplayOrder == 0 ? decimal.MaxValue : sd.DisplayOrder orderby navRank, dispRank select si.Attribute).ToList(); var currentTaxonomyString = currentTaxonomyInfo.ToString(); var possibleMissingAttributes = (from si in CurrentDb.SchemaInfos where si.TaxonomyID == currentTaxonomyInfo.ID let sd = si.SchemaDatas.FirstOrDefault(sd => sd.Active) where sd != null && !sd.InSchema && (sd.NavigationOrder > 0 || sd.DisplayOrder > 0) select si.Attribute.AttributeName).ToList().Select(p => currentTaxonomyString + "\t" + p).ToList(); _possibleMissingInSchemaAttributes.AddRange(possibleMissingAttributes); } return(attributes); } return(attributes); }
private void ProcessSkus(TaxonomyInfo node, IEnumerable <Sku> skus) { if (!_args.IncludeSkus) { return; } var skuList = skus.ToList(); // process deleted item/attribute pairs DeleteSkuAttributes(skuList); // start with listed globals var baseAttributes = _globals.ToList(); // add in-schema attributes, if requested if (_args.IncludeInSchemaValues) { var inSchemaAttributes = node.SchemaInfos.Select(si => si.SchemaData) .Where(sd => sd != null && sd.InSchema) .Select(sd => sd.SchemaInfo.Attribute) .ToList(); baseAttributes.AddRange(inSchemaAttributes); } foreach (var sku in skuList) { //Add to SkuTaxonomy records _data.SkuTaxonomies.Add(new SkuTaxonomyInterchangeRecord { ItemID = sku.ItemID, TaxonomyPath = node.ToString(_args.IgnoreT1Taxonomy), IsPrimary = node.NodeType == TaxonomyInfo.NodeTypeRegular }); if (node.NodeType != TaxonomyInfo.NodeTypeRegular) { _data.SkuTaxonomies.Add(new SkuTaxonomyInterchangeRecord { ItemID = sku.ItemID, TaxonomyPath = sku.Taxonomy.ToString(_args.IgnoreT1Taxonomy), IsPrimary = sku.Taxonomy.NodeType == TaxonomyInfo.NodeTypeRegular }); _data.Taxonomies.Add(new TaxonomyInterchangeRecord { TaxonomyPath = sku.Taxonomy.ToString(_args.IgnoreT1Taxonomy) }); } if (!_args.IncludeSkuValues || _processedSkus.Contains(sku)) { continue; } _processedSkus.Add(sku); var atts = baseAttributes.ToHashSet(); if (_args.ExportExtendedAttributes) { //Export all the extended attributes (that haven't been already exported) var ext = from ei in sku.EntityInfos from ed in ei.EntityDatas where ed.Active && !atts.Contains(ed.Attribute) select ed.Attribute; atts.AddRange(ext.Distinct()); } foreach (var att in atts) { // write an attribute record, just for completeness _data.Attributes.Add(new AttributeInterchangeRecord { AttributeName = att.AttributeName, AttributeType = att.AttributeType }); // get all values for this attribute var values = sku.GetValuesForAttribute(CurrentDb, att); // if there are no values for this attribute, assume that there may // be inactive records - write a delete record. if (values.Count == 0) { // if there are deleted values, write a blank record _data.SkuAttributeValues.Add(new SkuAttributeValueInterchangeRecord { ItemID = sku.ItemID, AttributeName = att.AttributeName, }); continue; } foreach (var ed in values) { if (_args.IgnoreEntityId) { _data.SkuAttributeValues.Add(new SkuAttributeValueInterchangeRecord { ItemID = sku.ItemID, AttributeName = att.AttributeName, Values = _sorter.GetLanguageValues(att.AttributeName, ed.Value, ed.Uom), Uom = ed.Uom, Field1 = ed.Field1, Field2 = ed.Field2, Field3 = ed.Field3, Field4 = ed.Field4, Field5 = ed.Field5 }); } else { _data.SkuAttributeValues.Add(new SkuAttributeValueInterchangeRecord { ItemID = sku.ItemID, AttributeName = att.AttributeName, Values = _sorter.GetLanguageValues(att.AttributeName, ed.Value, ed.Uom), Uom = ed.Uom, Field1 = ed.Field1, Field2 = ed.Field2, Field3 = ed.Field3, Field4 = ed.Field4, Field5 = ed.Field5, EntityID = ed.EntityID }); } } } } }
private void ProcessSchema(TaxonomyInfo node) { var schemata = node.SchemaInfos.Select(si => si.SchemaData).Where(sd => sd != null); var creationFilterDate = _args.CreationFilterDate; _sorter.ClearListOfValues(); foreach (var sd in schemata) { // create list of values for this schema data _sorter.MakeListOfValues(sd); //If ExportExtendedAttributes is TRUE, ignore attributes not InSchema unless it's a specified global if (!_args.ExportExtendedAttributes && !sd.InSchema && _args.GlobalAttributes != null && Array.IndexOf(_args.GlobalAttributes, sd.SchemaInfo.Attribute.AttributeName) == -1) { continue; } //Add Attribute var attribute = sd.SchemaInfo.Attribute; _data.Attributes.Add(new AttributeInterchangeRecord { AttributeName = attribute.AttributeName, AttributeType = attribute.AttributeType }); if (attribute.Type == AttributeTypeEnum.Derived) { //Add Derived Attribute Expression for Default Taxonomy and Current Taxonomy var expressions = attribute.DerivedAttributes.Where(de => de.TaxonomyInfo == null || de.TaxonomyInfo == node); var derivedExpressions = expressions.Select( de => new DerivedAttributeInterchangeRecord { DerivedAttributeName = attribute.AttributeName, TaxonomyPath = de.TaxonomyInfo == null ? null : de.TaxonomyInfo.ToString( _args.IgnoreT1Taxonomy), DerivedAttributeExpression = de.Expression, MaxResultLength = de.MaxResultLength }); _data.DerivedAttributes.AddRange(derivedExpressions); } //Add Schema Data _data.Schemas.Add(new SchemaInterchangeRecord { TaxonomyPath = node.ToString(_args.IgnoreT1Taxonomy), AttributeName = attribute.AttributeName, DataType = sd.DataType, NavigationOrder = sd.NavigationOrder, DisplayOrder = sd.DisplayOrder, InSchema = sd.InSchema }); //Add ListOfValues foreach (var lov in sd.SchemaInfo.ListOfValues.Where(v => v.Active)) { if (_args.IncludeLovEnrichments && creationFilterDate <= lov.CreatedOn) { _data.ListOfValues.Add(new ListOfValuesInterchangeRecord { TaxonomyPath = node.ToString(_args.IgnoreT1Taxonomy), AttributeName = attribute.AttributeName, Values = _sorter.GetLanguageValues(attribute.AttributeName, lov.Value, null), EnrichmentCopy = lov.EnrichmentCopy, EnrichmentImage = GetImageFileName(lov.EnrichmentImage) }); } else { _data.ListOfValues.Add(new ListOfValuesInterchangeRecord { TaxonomyPath = node.ToString(_args.IgnoreT1Taxonomy), AttributeName = attribute.AttributeName, Values = _sorter.GetLanguageValues(attribute.AttributeName, lov.Value, null) }); } } // process deleted enrichments if (_args.IncludeSchemaEnrichments) { var smdImage = (from smi in sd.SchemaInfo.SchemaMetaInfos where smi.Attribute.AttributeName == "Schema Enrichment Image" from smd in smi.SchemaMetaDatas where creationFilterDate <= smd.CreatedOn select smd).ToList(); if (smdImage.Any() && smdImage.All(s => !s.Active)) { _data.SchemaMetaDatas.Add(new SchemaMetaDataInterchangeRecord { TaxonomyPath = node.ToString(_args.IgnoreT1Taxonomy), AttributeName = attribute.AttributeName, SchemaMetaAttributeName = _args.UseOldFormat ? "EnrichmentImage" : "Schema Enrichment Image", // SchemaMetaAttributeValue = "" }); } var smdCopy = (from smi in sd.SchemaInfo.SchemaMetaInfos where smi.Attribute.AttributeName == "Schema Enrichment Copy" from smd in smi.SchemaMetaDatas where creationFilterDate <= smd.CreatedOn select smd).ToList(); if (smdCopy.Any() && smdCopy.All(s => !s.Active)) { _data.SchemaMetaDatas.Add(new SchemaMetaDataInterchangeRecord { TaxonomyPath = node.ToString(_args.IgnoreT1Taxonomy), AttributeName = attribute.AttributeName, SchemaMetaAttributeName = _args.UseOldFormat ? "EnrichmentCopy" : "Schema Enrichment Copy", // SchemaMetaAttributeValue = "" }); } } //Get Schema Meta Datas var smds = sd.SchemaInfo.SchemaMetaInfos.Select(smi => smi.SchemaMetaData).Where(smd => smd != null); foreach (var smd in smds) { if (smd.SchemaMetaInfo.Attribute.AttributeName == "Schema Enrichment Image") { if (_args.IncludeSchemaEnrichments && creationFilterDate <= smd.CreatedOn) { _data.SchemaMetaDatas.Add(new SchemaMetaDataInterchangeRecord { TaxonomyPath = node.ToString(_args.IgnoreT1Taxonomy), AttributeName = attribute.AttributeName, SchemaMetaAttributeName = _args.UseOldFormat ? "EnrichmentImage" : "Schema Enrichment Image", SchemaMetaAttributeValue = GetImageFileName(smd.Value) }); } } else if (smd.SchemaMetaInfo.Attribute.AttributeName == "Schema Enrichment Copy") { if (_args.IncludeSchemaEnrichments && creationFilterDate <= smd.CreatedOn) { _data.SchemaMetaDatas.Add(new SchemaMetaDataInterchangeRecord { TaxonomyPath = node.ToString(_args.IgnoreT1Taxonomy), AttributeName = attribute.AttributeName, SchemaMetaAttributeName = _args.UseOldFormat ? "EnrichmentCopy" : "Schema Enrichment Copy", SchemaMetaAttributeValue = smd.Value }); } } else { if (_args.IncludeSchemaMetadata) { _data.SchemaMetaDatas.Add(new SchemaMetaDataInterchangeRecord { TaxonomyPath = node.ToString(_args.IgnoreT1Taxonomy), AttributeName = attribute.AttributeName, SchemaMetaAttributeName = smd.SchemaMetaInfo.Attribute.AttributeName, SchemaMetaAttributeValue = smd.Value }); } } } } }
private void ProcessNode(TaxonomyInfo node, Guid taxonomyEnrichmentImageAttributeId, Guid taxonomyEnrichmentCopyAttributeId) { // skip over this node if the taxonomy path is blank if (String.IsNullOrEmpty(node.ToString(_args.IgnoreT1Taxonomy))) { return; } // skip over this node if it's derived and we aren't exporting them if (node.NodeType == TaxonomyInfo.NodeTypeDerived && !_args.ExportCrossListNodes) { return; } StatusMessage = string.Format("Processing {0}", node); _data.Taxonomies.Add(new TaxonomyInterchangeRecord { TaxonomyPath = node.ToString(_args.IgnoreT1Taxonomy) }); if (_args.IncludeTaxonomyEnrichments) { var creationFilterDate = _args.CreationFilterDate; var taxImageMd = (from tmi in node.TaxonomyMetaInfos where tmi.MetaAttributeID.Equals(taxonomyEnrichmentImageAttributeId) from tmd in tmi.TaxonomyMetaDatas where creationFilterDate <= tmd.CreatedOn select tmd).ToList(); if (taxImageMd.Any()) { if (taxImageMd.All(tmd => !tmd.Active)) { _data.TaxonomyMetaDatas.Add(new TaxonomyMetaDataInterchangeRecord { TaxonomyPath = node.ToString( _args.IgnoreT1Taxonomy), TaxonomyMetaAttributeName = _args.UseOldFormat ? "EnrichmentImage" : "Taxonomy Enrichment Image", // TaxonomyMetaAttributeValue = "" }); } else { var taxImageValue = taxImageMd.Where(tmd => tmd.Active).Select(tmd => tmd.Value).FirstOrDefault(); var taxImage = GetImageFileName(taxImageValue); if (!String.IsNullOrEmpty(taxImage)) { _data.TaxonomyMetaDatas.Add(new TaxonomyMetaDataInterchangeRecord { TaxonomyPath = node.ToString( _args.IgnoreT1Taxonomy), TaxonomyMetaAttributeName = _args.UseOldFormat ? "EnrichmentImage" : "Taxonomy Enrichment Image", TaxonomyMetaAttributeValue = taxImage }); } } } var taxCopyMd = (from tmi in node.TaxonomyMetaInfos where tmi.MetaAttributeID.Equals(taxonomyEnrichmentCopyAttributeId) from tmd in tmi.TaxonomyMetaDatas where creationFilterDate <= tmd.CreatedOn select tmd).ToList(); if (taxCopyMd.Any()) { if (taxCopyMd.All(tmd => !tmd.Active)) { _data.TaxonomyMetaDatas.Add(new TaxonomyMetaDataInterchangeRecord { TaxonomyPath = node.ToString( _args.IgnoreT1Taxonomy), TaxonomyMetaAttributeName = _args.UseOldFormat ? "EnrichmentCopy" : "Taxonomy Enrichment Copy", // TaxonomyMetaAttributeValue = "" }); } else { var taxCopyValue = taxCopyMd.Where(tmd => tmd.Active).Select(tmd => tmd.Value).FirstOrDefault(); if (!String.IsNullOrEmpty(taxCopyValue)) { _data.TaxonomyMetaDatas.Add(new TaxonomyMetaDataInterchangeRecord { TaxonomyPath = node.ToString( _args.IgnoreT1Taxonomy), TaxonomyMetaAttributeName = _args.UseOldFormat ? "EnrichmentCopy" : "Taxonomy Enrichment Copy", TaxonomyMetaAttributeValue = taxCopyValue }); } } } } ProcessNodeComponents(node); }
private void WriteTaxonomyToFile(TaxonomyInfo taxonomy) { StatusMessage = string.Format("{1}{0}Reading Node", Environment.NewLine, taxonomy); IQueryable <Sku> allSkus; if (taxonomy.NodeType == TaxonomyInfo.NodeTypeDerived) { if (!ExportCrossListNodes) { return; } var cl = Query.FetchCrossListObject(taxonomy); if (cl == null) { return; } allSkus = Query.GetFilteredSkus(cl.TaxonomyIDFilter, cl.ValueFilters, cl.AttributeTypeFilters, cl.MatchAllTerms).Distinct(); } else { allSkus = from sku in _currentDb.Skus where sku.SkuInfos.Any(si => si.Active && si.TaxonomyInfo == taxonomy) select sku; } StatusMessage = string.Format("{1}{0}Filtering SKUs", Environment.NewLine, taxonomy); var skus = GetFilteredSkuList(allSkus, true, _parsedSkuInclusions, _parsedSkuExclusions).ToList(); var iCtr = 0; var noOfSkus = skus.Count; var ignoreT1taxonomy = taxonomy.ToString(); if (IgnoreT1Taxonomy) { ignoreT1taxonomy = taxonomy.ToString().Substring(taxonomy.ToString().IndexOf('>') + 1); } skus.ForEach(sku => { StatusMessage = string.Format("{1}{0}{2} of {3} SKUs", Environment.NewLine, taxonomy, (++iCtr), noOfSkus); var taxonomies = sku.SkuInfos.Select( si => new { Taxonomy = si.TaxonomyInfo.OldString(), SkuAssignedOn = si.CreatedOn, SkuAssignedBy = si.User.FullName, SkuAssignRemark = (si.CreatedRemark == null) ? String.Empty : si.Remark.Remark1, TaxonomyCreatedOn = si.TaxonomyInfo.OldTaxonomyData == null ? string.Empty : si.TaxonomyInfo.OldTaxonomyData.CreatedOn.ToString(), TaxonomyCreatedBy = si.TaxonomyInfo.OldTaxonomyData == null ? string.Empty : si.TaxonomyInfo.OldTaxonomyData.User.FullName }) .Where(d => !string.IsNullOrWhiteSpace(d.Taxonomy)); if (taxonomy.NodeType == TaxonomyInfo.NodeTypeDerived) { var firstOrDefault = sku.SkuInfos.FirstOrDefault(a => a.Active); if (firstOrDefault != null) { var originalTaxonomy = firstOrDefault.TaxonomyInfo; _taxonomyFile.WriteLine(string.Format("{1}{0}{2}{0}{3}{0}{4}", _delimiter, sku.ItemID, ignoreT1taxonomy + TaxonomyInfo.CrossPrefix + originalTaxonomy.ToString(), "Cross List", ignoreT1taxonomy)); } } else { var firstOrDefault = taxonomies.FirstOrDefault(); if (firstOrDefault != null) { _taxonomyFile.WriteLine(string.Format("{1}{0}{2}{0}{3}{0}{4}", _delimiter, sku.ItemID, ignoreT1taxonomy, TaxonomyInfo.NodeTypeRegular, firstOrDefault.Taxonomy)); } } if (taxonomy.NodeType == TaxonomyInfo.NodeTypeDerived) { var firstOrDefault = sku.SkuInfos.FirstOrDefault(a => a.Active); if (firstOrDefault != null) { var originalTaxonomy = firstOrDefault.TaxonomyInfo; var attributes = GetExportAttributes(originalTaxonomy); WriteAttributeDataToFile(sku, originalTaxonomy, "Cross List", ignoreT1taxonomy + TaxonomyInfo.CrossPrefix + originalTaxonomy.ToString(), attributes); } } else { var attributes = GetExportAttributes(taxonomy); WriteAttributeDataToFile(sku, taxonomy, TaxonomyInfo.NodeTypeRegular, ignoreT1taxonomy, attributes); } }); StatusMessage = string.Format("{1}{0}({2} of {3}), Fetching Child Nodes", Environment.NewLine, taxonomy, iCtr, noOfSkus); //taxonomy.ChildTaxonomyDatas.Where(td => td.Active).Select(td => td.TaxonomyInfo).ForEach( // WriteTaxonomyToFile); //CurrentProgress++; }