Exemple #1
0
        public void OrderByDisplay(TaxonomyInfo taxonomy)
        {
            if (taxonomy == null)
            {
                return;
            }

            Dictionary <SchemaData, decimal[]> sds = (from si in taxonomy.SchemaInfos
                                                      let sd = si.SchemaData
                                                               where sd != null && (sd.NavigationOrder > 0 || sd.DisplayOrder > 0)
                                                               select sd).ToDictionary(
                sd => sd, sd => new[] { sd.NavigationOrder, sd.DisplayOrder });

            if (!sds.Any())
            {
                return;
            }

            //int iCtr = 0;
            //foreach (SchemaData nav in
            //    (from sd in sds
            //     where sd.Value[0] > 0
            //     orderby sd.Value[0]
            //     select sd.Key).ToList())
            //{
            //    sds[nav][0] = ++iCtr;

            //    if (sds[nav][1] > 0) sds[nav][1] = iCtr;
            //}

            decimal iCtr = 0;

            foreach (SchemaData disp in
                     (from sd in sds
                      where sd.Value[1] > 0
                      orderby sd.Value[1]
                      select sd.Key).ToList())
            {
                if (sds[disp][0] > 0)
                {
                    sds[disp][1] = iCtr = sds[disp][0];
                }
                else
                {
                    sds[disp][1] = ++iCtr;
                }
            }


            foreach (var kvp in sds)
            {
                SchemaInfo schemaInfo = kvp.Key.SchemaInfo;
                SetValue(
                    schemaInfo.TaxonomyInfo, schemaInfo.Attribute, false, SchemaAttributeNavigationOrder, kvp.Value[0]);
                SetValue(
                    schemaInfo.TaxonomyInfo, schemaInfo.Attribute, false, SchemaAttributeDisplayOrder, kvp.Value[1]);
            }
        }
Exemple #2
0
 public List <Sku> this[TaxonomyInfo index]
 {
     get
     {
         return
             (SkuGroups.SelectMany(s => s.Sku.SkuInfos.Where(a => a.Active))
              .Where(t => t.TaxonomyInfo == index)
              .Select(s => s.Sku)
              .ToList());
     }
 }
Exemple #3
0
        public static void UnmapNodeAttribute(TaxonomyInfo taxonomy, Attribute attribute)
        {
            SchemaInfo schemaInfo = taxonomy.SchemaInfos.FirstOrDefault(si => si.Attribute.Equals(attribute));

            if (schemaInfo == null)
            {
                return;
            }

            schemaInfo.SchemaMetaInfos.SelectMany(smi => smi.SchemaMetaDatas).Where(md => md.Active).ForEach(
                md => md.Active = false);

            if (schemaInfo.SchemaData != null)
            {
                schemaInfo.SchemaData.Active = false;
            }
        }
Exemple #4
0
        public static int GetNodeCount(TaxonomyInfo taxonomy)
        {
            IEnumerable <TaxonomyInfo> childTaxonomyInfos;
            int count = 0;

            if (taxonomy != null)
            {
                childTaxonomyInfos = taxonomy.ChildTaxonomyDatas.Where(td => td.Active).Select(td => td.TaxonomyInfo).ToList();
                count = childTaxonomyInfos.Count();
            }
            //else
            //    childTaxonomyInfos = GetLevel1Nodes().ToList();

            //count += childTaxonomyInfos.Sum(childNode => GetNodeCount(childNode));

            return(count);
        }
Exemple #5
0
        private void ProcessTaxonomy(TaxonomyInfo taxonomy)
        {
            // set formatted taxonomy string
            var taxonomyString = taxonomy.ToString(_args.IgnoreT1Taxonomy);

            // get list of SKUs for this taxonomy
            var allSkus = taxonomy.GetSkus(_args.ExportCrossListNodes);

            if (!allSkus.Any())
            {
                return;
            }

            // filter skus based on sku inclusions and exclusions, then include only Product skus.
            var skus = _args.GetFilteredSkuList(allSkus).ToList();

            // process each sku...
            skus.ForEach(sku =>
            {
                // write line to attribute file
                if (taxonomy.NodeType == TaxonomyInfo.NodeTypeDerived)
                {
                    var firstOrDefault = sku.SkuInfos.FirstOrDefault(a => a.Active);
                    if (firstOrDefault != null)
                    {
                        var originalTaxonomy = firstOrDefault.TaxonomyInfo;
                        var attributes       = GetExportAttributes(originalTaxonomy);
                        ProcessAttributes(sku, "Cross List",
                                          taxonomyString + TaxonomyInfo.CROSS_PREFIX +
                                          originalTaxonomy.ToString(), attributes);
                    }
                }
                else
                {
                    var attributes = GetExportAttributes(taxonomy);
                    ProcessAttributes(sku, TaxonomyInfo.NodeTypeRegular, taxonomyString, attributes);
                }
            });
        }
Exemple #6
0
        // Public Methods (5) 

        public void GetAttributeOrders(
            Attribute attribute, TaxonomyInfo taxonomy,
            out decimal navAttOrder, out decimal dispAttOrder, out bool inSchema)
        {
            navAttOrder  = 0;
            dispAttOrder = 0;
            inSchema     = false;

            if (taxonomy == null || attribute == null)
            {
                return;
            }

            inSchema = GetValue(taxonomy, attribute, SchemaAttributeInSchema) != null;

            object nav = GetValue(taxonomy, attribute, SchemaAttributeNavigationOrder);

            navAttOrder = nav != null ? (decimal)nav : 0;

            object disp = GetValue(taxonomy, attribute, SchemaAttributeDisplayOrder);

            dispAttOrder = disp != null ? (decimal)disp : 0;
        }
        private void ProcessTaxonomy(TaxonomyInfo taxonomy)
        {
            // set formatted taxonomy string
            var taxonomyString = taxonomy.ToString(_args.IgnoreT1Taxonomy);

            // get list of SKUs for this taxonomy
            var allSkus = taxonomy.GetSkus(_args.ExportCrossListNodes);

            if (!allSkus.Any())
            {
                return;
            }

            // filter skus based on sku inclusions and exclusions, then include only Product skus.
            var skus = _args.GetFilteredSkuList(allSkus).ToList();

            // process each sku...
            skus.ForEach(sku =>
            {
                // get data on this sku's taxonomy history
                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(CultureInfo.InvariantCulture),
                    TaxonomyCreatedBy = si.TaxonomyInfo.OldTaxonomyData == null
                                ? string.Empty
                                : si.TaxonomyInfo.OldTaxonomyData.User.FullName
                }).Where(d => !string.IsNullOrWhiteSpace(d.Taxonomy));

                // write line to taxonomy file
                if (taxonomy.NodeType == TaxonomyInfo.NodeTypeDerived)
                {
                    var firstOrDefault = sku.SkuInfos.FirstOrDefault(a => a.Active);
                    if (firstOrDefault != null)
                    {
                        var originalTaxonomy = firstOrDefault.TaxonomyInfo;
                        WriteTaxonomyRow(sku.ItemID, taxonomyString + TaxonomyInfo.CROSS_PREFIX +
                                         originalTaxonomy.ToString(), "Cross List", taxonomyString);
                    }
                }
                else
                {
                    var firstOrDefault = taxonomies.FirstOrDefault();
                    if (firstOrDefault != null)
                    {
                        WriteTaxonomyRow(sku.ItemID, taxonomyString, TaxonomyInfo.NodeTypeRegular, firstOrDefault.Taxonomy);
                    }
                }

                // write line to attribute file
                if (taxonomy.NodeType == TaxonomyInfo.NodeTypeDerived)
                {
                    var firstOrDefault = sku.SkuInfos.FirstOrDefault(a => a.Active);
                    if (firstOrDefault != null)
                    {
                        var originalTaxonomy = firstOrDefault.TaxonomyInfo;
                        var attributes       = GetExportAttributes(originalTaxonomy);
                        ProcessAttributes(sku, originalTaxonomy, "Cross List",
                                          taxonomyString + TaxonomyInfo.CROSS_PREFIX +
                                          originalTaxonomy.ToString(), attributes);
                    }
                }
                else
                {
                    var attributes = GetExportAttributes(taxonomy);
                    ProcessAttributes(sku, taxonomy, TaxonomyInfo.NodeTypeRegular, taxonomyString, attributes);
                }
            });
        }
        private IEnumerable <Tuple <Attribute, decimal, decimal> > GetExportAttributes(TaxonomyInfo taxonomy)
        {
            if (_taxonomyAttributesCache.ContainsKey(taxonomy.ID))
            {
                return(_taxonomyAttributesCache[taxonomy.ID]);
            }
            var schemaInfos = new List <SchemaInfo>();

            schemaInfos.AddRange(taxonomy.SchemaInfos.Where(si => si.SchemaDatas.Any(sd => sd.Active)).ToList());

            if (_args.ExportSuperSchema)
            {
                foreach (var leaf in taxonomy.AllLeafChildren)
                {
                    schemaInfos.AddRange(leaf.SchemaInfos.Where(si => si.SchemaDatas.Any(sd => sd.Active)).ToList());
                }
            }

            var atts =
                schemaInfos.Where(p => p.SchemaData.InSchema).Select(p => new { p.Attribute, p.SchemaData }).ToList();

            List <Tuple <Attribute, decimal, decimal> > attributes;

            if (_args.Top6OnlyAttributes)
            {
                var attrs = (from att in atts.Where(att => att.SchemaData != null && att.SchemaData.NavigationOrder > 0)
                             let baseAttributeName = GetBaseAttributeName(att.Attribute.AttributeName)
                                                     group att by baseAttributeName
                                                     into grp
                                                     let minNavRank = grp.Min(g => g.SchemaData.NavigationOrder)
                                                                      orderby minNavRank
                                                                      select new { BaseAttributeName = grp.Key, Attributes = grp.Select(p => p.Attribute) }).Take(6)
                            .SelectMany(p => p.Attributes)
                            .Distinct()
                            .ToList();

                attributes = (from attribute1 in attrs
                              let schemaData = taxonomy.SchemaInfos.Single(si => si.AttributeID == attribute1.ID).SchemaData
                                               select
                                               schemaData == null
                                      ? new Tuple <Attribute, decimal, decimal>(attribute1, 0, 0)
                                      : new Tuple <Attribute, decimal, decimal>(attribute1, schemaData.NavigationOrder,
                                                                                schemaData.DisplayOrder)).ToList();
            }
            else
            {
                if (_args.ExportSuperSchema)
                {
                    attributes = (from att in atts
                                  group att by att.Attribute
                                  into grp
                                  let minRank = grp.Min(p => GetRank(p.SchemaData, SortOrder.OrderbyDisplayNavigation))
                                                orderby minRank
                                                select new Tuple <Attribute, decimal, decimal>(grp.Key, 0, minRank)).ToList();
                }
                else
                {
                    attributes = (from att in atts
                                  let rank = GetRank(att.SchemaData, _args.OrderAttributesBy)
                                             orderby rank, att.Attribute.AttributeName
                                  select
                                  new Tuple <Attribute, decimal, decimal>(att.Attribute,
                                                                          att.SchemaData == null ? 0 : att.SchemaData.NavigationOrder,
                                                                          att.SchemaData == null ? 0 : att.SchemaData.DisplayOrder)).ToList();
                }
            }

            //TODO: Check on whether Attribute Groups are needed.
//            if (AttributeGroupExclusions.Length > 0)
//            {
//                //exclude Attribute Groups
//                attributes =
//                    attributes.Where(
//                        p =>
//                        p.Item1.Group == null ||
//                        (!AttributeGroupExclusions.Contains(p.Item1.Group.ToLower()))).ToList();
//            }
//
//            if (AttributeGroupInclusions.Length > 0)
//            {
//                //include Attribute Groups
//                attributes =
//                    attributes.Where(
//                        p =>
//                        p.Item1.Group == null ||
//                        (AttributeGroupInclusions.Contains(p.Item1.Group.ToLower()))).ToList();
//            }
//
//            if ((AttributeGroupExclusions.Length > 0 && AttributeGroupExclusions.Contains("default")) ||
//                (AttributeGroupInclusions.Length > 0 && !AttributeGroupInclusions.Contains("default")))
//                attributes = attributes.Where(p => p.Item1.Group != null).ToList();

            _taxonomyAttributesCache.Add(taxonomy.ID, attributes);

            return(attributes);
        }
        private void ProcessAttributes(Sku sku, TaxonomyInfo taxonomy, string nodeType, string taxonomyString,
                                       IEnumerable <Tuple <Attribute, decimal, decimal> > attributeOrders)
        {
            // add static information to output lists
            var valueElements = new List <string>();

            valueElements.Add(sku.ItemID);
            valueElements.Add(taxonomyString);
            valueElements.Add(nodeType);

            var blankElements = new List <string>();

            if (_args.GenerateFileWithBlankValues)
            {
                blankElements.Add(sku.ItemID);
                blankElements.Add(taxonomyString);
                blankElements.Add(nodeType);
            }

            // add global attributes
            for (int i = 0; i < _globalAttributeNames.Count(); i++)
            {
                // get list of sub-attributes in this attribute, then collect their values
                var parts  = _globalAttributeNames[i].Split(new[] { ',' });
                var values = new List <EntityData>();
                foreach (var att in parts)
                {
                    values.AddRange(sku.GetValuesForAttribute(CurrentDb, att.Trim()));
                }

                if (_globalAttributeCount[i] == 0)
                {
                    // if there's no specified number of columns for this attribute, string the values together
                    var stringValue =
                        values.Select(val =>
                                      (val.Value + (_args.IncludeUoM ? " " + val.Uom : ""))
                                      .Trim())
                        .Distinct()
                        .OrderBy(val => val, new CompareForAlphaNumericSort())
                        .Aggregate(string.Empty, (current, val) => current + ((string.IsNullOrEmpty(current) ? string.Empty : ",") + val));
                    valueElements.Add(stringValue);
                    if (_args.GenerateFileWithBlankValues)
                    {
                        blankElements.Add(stringValue);
                    }
                }
                else
                {
                    // if there are multiple columns for this attribute, assign the values separately, limited by the count of collumns
                    var listStringValue =
                        values.Select(val =>
                                      (val.Value + (_args.IncludeUoM ? " " + val.Uom : ""))
                                      .Trim())
                        .Distinct()
                        .OrderBy(val => val, new CompareForAlphaNumericSort())
                        .Take(_globalAttributeCount[i])
                        .ToList();
                    for (int j = 0; j < _globalAttributeCount[i]; j++)
                    {
                        if (j < listStringValue.Count)
                        {
                            valueElements.Add(listStringValue[j]);
                            if (_args.GenerateFileWithBlankValues)
                            {
                                blankElements.Add(listStringValue[j]);
                            }
                        }
                        else
                        {
                            valueElements.Add("");
                            if (_args.GenerateFileWithBlankValues)
                            {
                                blankElements.Add("");
                            }
                        }
                    }
                }
            }

            // collect data for each attribute
            bool writeBlankRow = false;

            foreach (var att in attributeOrders)
            {
                //Attribute,NavOrder,DisplayOrder
                var attributeOrder = att;
                var navOrder       = att.Item2;
                var dispOrder      = att.Item3;

                if (((_args.ExportNavigationAttributes && navOrder > 0) || (_args.ExportDisplayAttributes && dispOrder > 0) ||
                     (_args.ExportUnRankedAttributes && navOrder == 0 && dispOrder == 0)))
                {
                    var entity = sku.GetValuesForAttribute(CurrentDb, attributeOrder.Item1.AttributeName);

                    // concatenate the values into a comma-delimited string
                    var value = entity.Aggregate(string.Empty,
                                                 (current, ed) =>
                                                 current + (string.IsNullOrEmpty(current) ? string.Empty : ", ") + ed.Value);

                    //display the uom once if there is one distinct uom, otherwise, output in the same order as the value (optional)
                    string uom = String.Empty;
                    if (_args.IncludeUoM)
                    {
                        var distinctUoms =
                            entity.Where(ed => !string.IsNullOrWhiteSpace(ed.Uom))
                            .Select(ed => ed.Uom)
                            .Distinct()
                            .ToList();
                        uom = distinctUoms.Aggregate(String.Empty, (current, next) => current + (string.IsNullOrEmpty(current) ? string.Empty : ", ") + next);
                    }

                    // concatenate field 1 into a comma-delimited string
                    string field1 = String.Empty;
                    if (_args.IncludeField1)
                    {
                        var distinctField1 =
                            entity.Where(ed => !string.IsNullOrWhiteSpace(ed.Field1))
                            .Select(ed => ed.Field1)
                            .Distinct()
                            .ToList();
                        field1 = distinctField1.Aggregate(String.Empty, (current, next) => current + (string.IsNullOrEmpty(current) ? string.Empty : ", ") + next);
                    }

                    // concatenate field 2 into a comma-delimited string
                    string field2 = String.Empty;
                    if (_args.IncludeField2)
                    {
                        var distinctField2 =
                            entity.Where(ed => !string.IsNullOrWhiteSpace(ed.Field2))
                            .Select(ed => ed.Field2)
                            .Distinct()
                            .ToList();
                        field2 = distinctField2.Aggregate(String.Empty, (current, next) => current + (string.IsNullOrEmpty(current) ? string.Empty : ", ") + next);
                    }

                    // concatenate field 3 into a comma-delimited string
                    string field3 = String.Empty;
                    if (_args.IncludeField3)
                    {
                        var distinctField3 =
                            entity.Where(ed => !string.IsNullOrWhiteSpace(ed.Field3))
                            .Select(ed => ed.Field3)
                            .Distinct()
                            .ToList();
                        field3 = distinctField3.Aggregate(String.Empty, (current, next) => current + (string.IsNullOrEmpty(current) ? string.Empty : ", ") + next);
                    }

                    // concatenate field 4 into a comma-delimited string
                    string field4 = String.Empty;
                    if (_args.IncludeField4)
                    {
                        var distinctField4 =
                            entity.Where(ed => !string.IsNullOrWhiteSpace(ed.Field4))
                            .Select(ed => ed.Field4)
                            .Distinct()
                            .ToList();
                        field4 = distinctField4.Aggregate(String.Empty, (current, next) => current + (string.IsNullOrEmpty(current) ? string.Empty : ", ") + next);
                    }

                    // concatenate field 5 into a comma-delimited string
                    string field5 = String.Empty;
                    if (_args.IncludeField5)
                    {
                        var distinctField5 =
                            entity.Where(ed => !string.IsNullOrWhiteSpace(ed.Field5OrStatus))
                            .Select(ed => ed.Field5OrStatus)
                            .Distinct()
                            .ToList();
                        field5 = distinctField5.Aggregate(String.Empty, (current, next) => current + (string.IsNullOrEmpty(current) ? string.Empty : ", ") + next);
                    }

                    // optionally, get the navigation data
                    var rank = string.Empty;
                    if (navOrder > 0 || dispOrder > 0)
                    {
                        if (_args.ExportNavigationAttributes)
                        {
                            rank = _args.ExportSuperSchema && taxonomy.IsLeafNode
                                       ? "S"
                                       : Decimal.Truncate(navOrder).ToString(CultureInfo.InvariantCulture);
                        }
                        if (_args.ExportDisplayAttributes)
                        {
                            if (_args.ExportNavigationAttributes)
                            {
                                rank += " • ";
                            }
                            rank += Decimal.Truncate(dispOrder).ToString(CultureInfo.InvariantCulture);
                        }
                    }

                    // add attribute data to output list
                    // append navigation data
                    if (_args.ExportRanks)
                    {
                        valueElements.Add(rank);
                    }

                    // append attribute name
                    valueElements.Add(attributeOrder.Item1.AttributeName);

                    if (_args.ExportNewValueColumn)
                    {
                        valueElements.Add("");
                    }

                    // append value data
                    valueElements.Add(value);

                    // append UoM data
                    if (_args.IncludeUoM)
                    {
                        valueElements.Add(uom);
                    }

                    // append field 1 data
                    if (_args.IncludeField1)
                    {
                        valueElements.Add(field1);
                    }

                    // append field 2 data
                    if (_args.IncludeField2)
                    {
                        valueElements.Add(field2);
                    }

                    // append field 3 data
                    if (_args.IncludeField3)
                    {
                        valueElements.Add(field3);
                    }

                    // append field 4 data
                    if (_args.IncludeField4)
                    {
                        valueElements.Add(field4);
                    }

                    // append field 5 data
                    if (_args.IncludeField5)
                    {
                        valueElements.Add(field5);
                    }

                    if (_args.GenerateFileWithBlankValues && string.IsNullOrWhiteSpace(value))
                    {
                        // signal that there are blank values to be written
                        writeBlankRow = true;

                        // append navigation data
                        if (_args.ExportRanks)
                        {
                            blankElements.Add(rank);
                        }

                        // append attribute name
                        blankElements.Add(attributeOrder.Item1.AttributeName);

                        if (_args.ExportNewValueColumn)
                        {
                            blankElements.Add("");
                        }

                        // append value data - should be blank
                        blankElements.Add("");

                        // append UoM data
                        if (_args.IncludeUoM)
                        {
                            blankElements.Add(uom);
                        }

                        // append field 1 data
                        if (_args.IncludeField1)
                        {
                            blankElements.Add(field1);
                        }

                        // append field 2 data
                        if (_args.IncludeField2)
                        {
                            blankElements.Add(field2);
                        }

                        // append field 3 data
                        if (_args.IncludeField3)
                        {
                            blankElements.Add(field3);
                        }

                        // append field 4 data
                        if (_args.IncludeField4)
                        {
                            blankElements.Add(field4);
                        }

                        // append field 5 data
                        if (_args.IncludeField5)
                        {
                            blankElements.Add(field5);
                        }
                    }
                }
            }

            _attributeTable.WriteDataRow(valueElements);
            if (_args.GenerateFileWithBlankValues && writeBlankRow)
            {
                _blankAttributeTable.WriteDataRow(blankElements);
            }
        }
Exemple #10
0
        private bool CreateTaxonomy(TaxonomyInterchangeRecord currentTaxonomyPath)
        {
            var isTaxonomyNew = false;

            //double check to make sure that this taxonomy doesn't already exist - should never be executed...
            if (currentTaxonomyPath == null ||
                _existingTaxonomyPathsAndIDs.ContainsKey(currentTaxonomyPath.TaxonomyPath.ToLower()))
            {
                return(false);
            }
            // split taxonomy into nodes
            var taxonomyParts = currentTaxonomyPath.TaxonomyPath.Split(new[] { '>' });

            var taxonomyPathPrefix = new StringBuilder();

            Guid?parentTaxonomyId = null;

            foreach (var taxNode in taxonomyParts)
            {
                // if this is the first node, don't add a delimiter
                if (taxonomyPathPrefix.Length > 0)
                {
                    taxonomyPathPrefix.Append(">");
                }
                taxonomyPathPrefix.Append(taxNode);

                var tempTaxonomyPathPrefix = taxonomyPathPrefix.ToString();

                // check to see if the taxonomy's parent is present - if so, get its id.
                // we keep iterating down the branch until we find a space for the taxonomy.
                // keep going until the entire taxonomy string is accounted for.
                if (_existingTaxonomyPathsAndIDs.ContainsKey(tempTaxonomyPathPrefix.ToLower()))
                {
                    parentTaxonomyId = _existingTaxonomyPathsAndIDs[tempTaxonomyPathPrefix.ToLower()];
                }
                else
                {
                    var newTaxonomyInfo = new TaxonomyInfo(CurrentDbContext)
                    {
                        ProjectID = CurrentProjectId, ShowInTree = false, NodeType = TaxonomyInfo.NodeTypeRegular
                    };
                    newTaxonomyInfo.TaxonomyDatas.Add(new TaxonomyData(CurrentDbContext)
                    {
                        TaxonomyID       = newTaxonomyInfo.ID,
                        ParentTaxonomyID = parentTaxonomyId,
                        NodeName         = taxNode,
                        CreatedBy        = ImportRequestedBy,
                        CreatedOn        = DateTime.Now,
                        CreatedRemark    = CurrentRemarkId
                    });

                    CurrentDbContext.TaxonomyInfos.InsertOnSubmit(newTaxonomyInfo);

                    //add it to the cache for future reuse
                    _existingTaxonomyPathsAndIDs.Add(tempTaxonomyPathPrefix.ToLower(), newTaxonomyInfo.ID);
                    parentTaxonomyId = newTaxonomyInfo.ID;
                    isTaxonomyNew    = true;
                }
            }
            return(isTaxonomyNew);
        }
Exemple #11
0
        private IEnumerable <KeyValuePair <Attribute, SchemaData> > GetExportAttributes(TaxonomyInfo taxonomy)
        {
            if (_taxonomyAttributesCache.ContainsKey(taxonomy.ID))
            {
                return(_taxonomyAttributesCache[taxonomy.ID]);
            }
            var schemaInfos = new List <SchemaInfo>();

            schemaInfos.AddRange(taxonomy.SchemaInfos.Where(si => si.SchemaDatas.Any(sd => sd.Active)).ToList());

            var attributes = (from si in schemaInfos
                              let rank = GetRank(si.SchemaData, SortOrder.OrderbyNavigationDisplay)
                                         where si.SchemaData.InSchema
                                         orderby rank, si.Attribute.AttributeName
                              select new KeyValuePair <Attribute, SchemaData>(si.Attribute, si.SchemaData)).ToList();

            _taxonomyAttributesCache.Add(taxonomy.ID, attributes);

            return(attributes);
        }
Exemple #12
0
        public static string GetMetaAttributeValue(Attribute attribute, Attribute metaAttribute, TaxonomyInfo taxonomy)
        {
            try
            {
                var si = taxonomy.SchemaInfos.FirstOrDefault(a => a.Attribute == attribute);
                //var si = Arya.SchemaInfos.Where(t => t.TaxonomyID == Guid.Empty && t.Attribute == attribute ).FirstOrDefault();
                //if (si == null)
                //    return null;

                var smi = si.SchemaMetaInfos.FirstOrDefault(mi => mi.MetaAttributeID == metaAttribute.ID);

                //if (smi == null)
                //    return null;

                var smd = smi.SchemaMetaDatas.FirstOrDefault(a => a.Active);

                //if (smd == null)
                //    return null;
                //else
                return(smd.Value);
            }
            catch (NullReferenceException)
            {
                return(null);
            }
        }
Exemple #13
0
        public string SetValue(
            TaxonomyInfo taxonomy, Attribute attribute, bool autoMapSchema, SchemaAttribute schematus, object value, bool suppressAutoMapMessage = false)
        {
            SchemaInfo schemaInfo    = taxonomy.SchemaInfos.FirstOrDefault(si => si.Attribute.Equals(attribute));
            bool       newSchemaInfo = false;

            if (schemaInfo == null)
            {
                if (suppressAutoMapMessage)
                {
                    return(null);
                }
                if (!autoMapSchema &&
                    MessageBox.Show(
                        String.Format(
                            "Attribute [{0}] is not mapped in Node [{1}]. Do you want to map it?", attribute,
                            taxonomy.TaxonomyData.NodeName), @"Add to Schema", MessageBoxButtons.YesNo) ==
                    DialogResult.No)
                {
                    return(null);
                }
                schemaInfo = new SchemaInfo {
                    Attribute = attribute
                };
                taxonomy.SchemaInfos.Add(schemaInfo);
                newSchemaInfo = true;
            }



            if (schematus == null)
            {
                //Create/Update Schema Info only
                SchemaData currentSchemaData = schemaInfo.SchemaData;
                var        newSchemaData     = new SchemaData();
                if (value != null && value is SchemaData)
                {
                    var fromSchemaData = (SchemaData)value;
                    if (currentSchemaData != null && currentSchemaData.Equals(fromSchemaData))
                    {
                        return(null);
                    }

                    newSchemaData.DataType        = fromSchemaData.DataType;
                    newSchemaData.DisplayOrder    = fromSchemaData.DisplayOrder;
                    newSchemaData.NavigationOrder = fromSchemaData.NavigationOrder;
                    newSchemaData.InSchema        = fromSchemaData.InSchema;
                }

                if (currentSchemaData != null)
                {
                    currentSchemaData.Active = false;
                }
                schemaInfo.SchemaDatas.Add(newSchemaData);
                return(null);
            }

            SchemaData activeSd = schemaInfo.SchemaData;

            switch (schematus.AttributeType)
            {
            case SchemaAttributeType.Primary:
                bool reallyNewSd  = false;
                bool reorderRanks = false;

                SchemaData newSchemaData;
                if (activeSd == null)
                {
                    reallyNewSd   = true;
                    newSchemaData = new SchemaData();
                }
                else
                {
                    //activeSd.DeletedBy = AryaTools.Instance.InstanceData.CurrentUser.ID;
                    activeSd.DeletedByUser = CurrentUser;     //fixes Object not found error
                    activeSd.DeletedOn     = DateTime.Now;
                    newSchemaData          = new SchemaData
                    {
                        DataType        = activeSd.DataType, InSchema = activeSd.InSchema,
                        NavigationOrder = activeSd.NavigationOrder,
                        DisplayOrder    = activeSd.DisplayOrder
                    };
                }

                string propertyName = schematus.PrimarySchemaAttribute.Replace(" ", String.Empty);

                PropertyInfo valueProperty = newSchemaData.GetType().GetProperty(propertyName);
                Type         propertyType  = valueProperty.PropertyType;


                if (propertyType == typeof(string))
                {
                    object stringValue = value ?? String.Empty;
                    if (propertyName == "DataType")
                    {
                        stringValue = ValidateDataType(stringValue);
                    }

                    if (!(valueProperty.GetValue(newSchemaData, null) ?? String.Empty).Equals(stringValue))
                    {
                        reallyNewSd = true;
                        valueProperty.SetValue(newSchemaData, stringValue.ToString(), null);
                    }
                }
                else if (propertyType == typeof(bool))
                {
                    object boolValue = value ?? false;
                    string firstCharacter;
                    try
                    {
                        firstCharacter = boolValue.ToString().Substring(0, 1).ToLower();
                    }
                    catch (Exception)
                    {
                        firstCharacter = "f";
                    }

                    bool newValue = firstCharacter.Equals("t") || firstCharacter.Equals("y") ||
                                    firstCharacter.Equals("1");

                    if (!((bool)valueProperty.GetValue(newSchemaData, null)).Equals(newValue))
                    {
                        reallyNewSd = true;
                        valueProperty.SetValue(newSchemaData, newValue, null);
                    }
                }
                //else if (propertyType == typeof (decimal))
                //{
                //    object decimalValue = value ?? 0.0;
                //    decimal newDecimalValue;
                //    if (Decimal.TryParse(decimalValue.ToString(), out newDecimalValue))
                //    {
                //        if (!((decimal) valueProperty.GetValue(newSchemaData, null)).Equals(newDecimalValue))
                //        {
                //            reallyNewSd = true;
                //            valueProperty.SetValue(newSchemaData, newDecimalValue, null);
                //            reorderRanks = SchemaDataGridView.AutoOrderRanks;
                //        }
                //    }
                //    else
                //        return String.Format(
                //            "Invalid value [{0}] for [{1}] - [{2}].{3}Expected a decimal value.", decimalValue,
                //            taxonomy.NodeName, attribute, Environment.NewLine);
                //}
                else
                {
                    return(String.Format(
                               "Unknown data type for value [{0}] for [{1}] - [{2}]", value ?? String.Empty,
                               taxonomy.NodeName, attribute));
                }

                if (reallyNewSd)
                {
                    if (activeSd != null)
                    {
                        activeSd.Active = false;
                    }
                    schemaInfo.SchemaDatas.Add(newSchemaData);

                    if (reorderRanks)
                    {
                        AutoOrderRanks(newSchemaData.SchemaInfo.TaxonomyInfo, newSchemaData);
                    }
                }

                return(null);

            case SchemaAttributeType.Meta:
                bool reallyNewSmd = false;

                if (schematus.DataType == typeof(bool))
                {
                    value = value.ToString().StartsWith("y", StringComparison.OrdinalIgnoreCase) ? "Yes" : "No";
                }
                //First check if there is an active SchemaData
                if (activeSd == null)
                {
                    if (suppressAutoMapMessage)
                    {
                        return(null);
                    }

                    if (!newSchemaInfo && !autoMapSchema &&
                        MessageBox.Show(
                            String.Format(
                                "Attribute [{0}] is not mapped in Node [{1}]. Do you want to map it?", attribute,
                                taxonomy.TaxonomyData.NodeName), "Add to Schema", MessageBoxButtons.YesNo) ==
                        DialogResult.No)
                    {
                        return(null);
                    }

                    schemaInfo.SchemaDatas.Add(new SchemaData());
                    reallyNewSmd = true;
                }

                SchemaMetaInfo activeSmi = (from mi in schemaInfo.SchemaMetaInfos
                                            where mi.Attribute.Equals(schematus.MetaSchemaAttribute)
                                            select mi).FirstOrDefault();

                if (activeSmi == null)
                {
                    activeSmi = new SchemaMetaInfo {
                        Attribute = schematus.MetaSchemaAttribute
                    };
                    schemaInfo.SchemaMetaInfos.Add(activeSmi);
                    reallyNewSmd = true;
                }

                SchemaMetaData activeSmd = activeSmi.SchemaMetaData;

                if (activeSmd == null)
                {
                    reallyNewSmd = true;
                }
                else if (value == null || !activeSmd.Value.Equals(value))
                {
                    reallyNewSmd     = true;
                    activeSmd.Active = false;
                }

                //if (reallyNewSmd && value != null && !String.IsNullOrEmpty(value.ToString()))
                //{
                //    activeSmi.SchemaMetaDatas.Add(new SchemaMetaData {Value = value.ToString()});
                //    SchemaDataGridView.UpdateAutoCompleteSource(schematus.MetaSchemaAttribute, value.ToString());
                //}

                return(null);

            default:
                return("Unknown Meta-attribute Type! Weird!!!");
            }
        }
Exemple #14
0
        public object GetValue(TaxonomyInfo taxonomy, Attribute attribute, SchemaAttribute schematus)
        {
            if (taxonomy == null && attribute == null)
            {
                return(schematus);
            }

            if (taxonomy == null)
            {
                return(attribute);
            }

            if (attribute == null)
            {
                return(taxonomy);
            }

            var schemaInfo = taxonomy.SchemaInfos.FirstOrDefault(si => si.Attribute != null && si.Attribute.Equals(attribute));

            if (schematus == null || schemaInfo == null)
            {
                return(null);
            }

            switch (schematus.AttributeType)
            {
            case SchemaAttributeType.Primary:
                SchemaData activeSchemaData = schemaInfo.SchemaDatas.FirstOrDefault(sd => sd.Active);
                if (activeSchemaData == null)
                {
                    return(null);
                }

                PropertyInfo valueProperty =
                    activeSchemaData.GetType().GetProperty(schematus.PrimarySchemaAttribute.Replace(" ", String.Empty));
                return(valueProperty.GetValue(activeSchemaData, null));

            case SchemaAttributeType.Meta:
                SchemaMetaData metaSchemaData = (from mi in schemaInfo.SchemaMetaInfos
                                                 where mi.Attribute.Equals(schematus.MetaSchemaAttribute) && mi.SchemaMetaData != null
                                                 select mi.SchemaMetaData).FirstOrDefault();
                return(metaSchemaData);

            case SchemaAttributeType.Special:
                if (schematus.SpecialSchemaAttribute.Equals(SpecialSchematusIsMapped))
                {
                    SchemaData activeSd = schemaInfo.SchemaDatas.FirstOrDefault(sd => sd.Active);
                    if (activeSd != null)
                    {
                        return("x");
                    }
                }

                if (schematus.SpecialSchemaAttribute.Equals(SpecialSchematusAttributeType))
                {
                    return(attribute.AttributeType);
                }

                if (schematus.SpecialSchemaAttribute.Equals(SpecialSchematusListOfValues))
                {
                    var listOfValues = schemaInfo.ListOfValues.Where(lov => lov.Active == true).Select(lov => lov).ToList();
                    if (listOfValues.Any())
                    {
                        string listSep = Currentproject.ProjPreferences.ListSeparator ?? "; ";
                        return(listOfValues.OrderBy(val => val.DisplayOrder).ThenBy(val => val.Value).Select(val => val.Value).Aggregate((current, lov) => current + listSep + lov));
                    }
                    else
                    {
                        return(null);
                    }
                }
                return(null);

            //case SchemaAttributeType.FillRate:
            //    double? fillRate = AryaTools.Instance.AllFillRates.GetFillRate(
            //        taxonomy, attribute, schematus.FillRateSchemaAttribute);
            //    if (fillRate == Double.MinValue)
            //    {
            //        SchemaDataGridView.RefreshGridView = true;
            //        return "Calculating...";
            //    }

            //    return fillRate;

            default:
                return(null);
            }
        }
Exemple #15
0
        public void AutoOrderRanks(TaxonomyInfo taxonomy, SchemaData schemaData)
        {
            if (taxonomy == null)
            {
                return;
            }

            Dictionary <SchemaData, decimal[]> sds = (from si in taxonomy.SchemaInfos
                                                      let sd = si.SchemaData
                                                               where sd != null && (sd.NavigationOrder > 0 || sd.DisplayOrder > 0)
                                                               select sd).ToDictionary(
                sd => sd, sd => new[] { sd.NavigationOrder, sd.DisplayOrder });

            if (!sds.Any())
            {
                return;
            }

            decimal baseNavOrder  = schemaData != null ? schemaData.NavigationOrder : 0;
            decimal baseDispOrder = schemaData != null ? schemaData.DisplayOrder : 0;

            List <SchemaData> navs = (from sd in sds
                                      where
                                      sd.Key.NavigationOrder > 0 && sd.Key.NavigationOrder >= baseNavOrder &&
                                      (schemaData == null || !sd.Key.Equals(schemaData))
                                      select sd.Key).ToList();

            foreach (SchemaData nav in navs)
            {
                sds[nav][0] = nav.NavigationOrder + 1;
            }

            int iCtr = 0;

            foreach (SchemaData nav in
                     (from sd in sds
                      where sd.Value[0] > 0
                      orderby sd.Value[0]
                      select sd.Key).ToList())
            {
                sds[nav][0] = ++iCtr;
            }

            List <SchemaData> disps = (from sd in sds
                                       where
                                       sd.Key.DisplayOrder > 0 && sd.Key.DisplayOrder >= baseDispOrder &&
                                       (schemaData == null || !sd.Key.Equals(schemaData))
                                       select sd.Key).ToList();

            foreach (SchemaData disp in disps)
            {
                sds[disp][1] = disp.DisplayOrder + 1;
            }

            iCtr = 0;
            foreach (SchemaData disp in
                     (from sd in sds
                      where sd.Value[1] > 0
                      orderby sd.Value[1]
                      select sd.Key).ToList())
            {
                sds[disp][1] = ++iCtr;
            }

            foreach (var kvp in sds)
            {
                SchemaInfo schemaInfo = kvp.Key.SchemaInfo;
                SetValue(
                    schemaInfo.TaxonomyInfo, schemaInfo.Attribute, false, SchemaAttributeNavigationOrder, kvp.Value[0]);
                SetValue(
                    schemaInfo.TaxonomyInfo, schemaInfo.Attribute, false, SchemaAttributeDisplayOrder, kvp.Value[1]);
            }
        }