예제 #1
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);
            }
        }
예제 #2
0
        private void AddAttribute(Attribute attribute)
        {
            if (!_allAttributes.TryAdd(attribute.ID, attribute))
            {
                return;
            }

            var att = new Bridge.Attribute
            {
                Id        = attribute.ID,
                CatalogId = _project.ID,
                Type      = (attribute.AttributeType == "Sku" ? "Product" : attribute.AttributeType).ToUpper(),
                Readonly  = attribute.Readonly,
                Name      =
                    new List <AttributeName>
                {
                    new AttributeName
                    {
                        lang  = EnUs,
                        Value =
                            attribute
                            .AttributeName
                    }
                }
            };

            att.SerializeObject(GetSaveFilePath("Attribute", att.Id.ToString()));
        }
        private void ProcessNodes()
        {
            StatusMessage = "Generating Node List";
            _args         = (InterchangeFormatExportArgs)Arguments;

            _globals =
                _args.GlobalAttributes.Select(att => Attribute.GetAttributeFromName(CurrentDb, att, false))
                .Where(att => att != null);

            var nodes         = (from tax in CurrentDb.TaxonomyInfos where _args.TaxonomyIds.Contains(tax.ID) select tax).ToList();
            var selectedNodes = nodes.SelectMany(p => p.AllChildren).Union(nodes).Distinct();

            var taxonomyEnrichmentImageAttributeId =
                Attribute.GetAttributeFromName(CurrentDb, Resources.TaxonomyEnrichmentImageAttributeName, false,
                                               AttributeTypeEnum.TaxonomyMeta).ID;

            var taxonomyEnrichmentCopyAttributeId =
                Attribute.GetAttributeFromName(CurrentDb, Resources.TaxonomyEnrichmentCopyAttributeName, false,
                                               AttributeTypeEnum.TaxonomyMeta).ID;

            foreach (var node in selectedNodes)
            {
                ProcessNode(node, taxonomyEnrichmentImageAttributeId, taxonomyEnrichmentCopyAttributeId);
            }
        }
예제 #4
0
        private SchemaAttribute GetMetaAttributeType(Attribute attribute)
        {
            var attributeName = attribute.AttributeName.ToLower();

            return(attributeName.StartsWith("is ") || attributeName.StartsWith("in ")
                       ? new SchemaAttribute(attribute, typeof(bool))
                       : new SchemaAttribute(attribute, typeof(string)));
        }
예제 #5
0
        private void CreateNewAttribute(AttributeInterchangeRecord attributeInterchangeRecord)
        {
            AttributeTypeEnum type;

            Enum.TryParse(attributeInterchangeRecord.AttributeType, out type);

            var newAttribute = Attribute.GetAttributeFromName(CurrentDbContext, attributeInterchangeRecord.AttributeName,
                                                              true, type, false);
            //CurrentDbContext.Attributes.InsertOnSubmit(newAttribute);
        }
예제 #6
0
        private Dictionary <string, string> GetTaxonomyEnrichmentImageGuid(
            Dictionary <string, string> taxonomyPathEnrichmentImages,
            Dictionary <string, TaxonomyPathAndId> existingTaxonomyPathId)
        {
            var enrichmentImageValueGuids    = new Dictionary <string, string>();
            var distinctEnrichmentImageValue = taxonomyPathEnrichmentImages.Values.Distinct();

            foreach (var enrichmentImageValue in distinctEnrichmentImageValue)
            {
                var success = false;

                //var isUri = Uri.IsWellFormedUriString(enrichmentImageValue, UriKind.Absolute);
                //var imageUri = isUri
                //                   ? new Uri(enrichmentImageValue)
                //                   : new Uri(Path.Combine(BaseImagePath, CurrentProjectId.ToString(), enrichmentImageValue));
                ////Success is for valid uri. If the image name only exist not the real file it will be false and added as warning
                success = _currentImageManager.UploadImage(enrichmentImageValue);
                var enrichmentImageGuid = _currentImageManager.RemoteImageGuid;

                //do necessary steps to
                var updatableTaxonomyPath =
                    taxonomyPathEnrichmentImages.FirstOrDefault(tpi => tpi.Value == enrichmentImageValue).Key;
                var updatableTaxonomyId = existingTaxonomyPathId[updatableTaxonomyPath].TaxonomyId.ToString();
                var newSku = _currentImageManager.ImageSku;
                newSku.EntityInfos.Add(new EntityInfo(CurrentDbContext)
                {
                    EntityDatas =
                    {
                        new EntityData(CurrentDbContext)
                        {
                            Attribute =
                                Attribute.GetAttributeFromName(CurrentDbContext,
                                                               Framework.Properties.Resources.
                                                               TaxonomyIdAttributeName,
                                                               true, useChache:false),
                            Value = updatableTaxonomyId
                        }
                    }
                });
                newSku.SkuInfos.Add(new SkuInfo(CurrentDbContext)
                {
                    TaxonomyID = new Guid(updatableTaxonomyId)
                });
                enrichmentImageValueGuids.Add(enrichmentImageValue, enrichmentImageGuid);

                if (!success)
                {
                    _noImageFileTaxEnrichementImage.Add(enrichmentImageValue);
                }
            }
            SaveDataChanges();
            return(enrichmentImageValueGuids);
        }
예제 #7
0
        public string ProcessCalculatedAttribute(Attribute att, TaxonomyInfo tax,
                                                 bool getDefaultForNullTaxonomy = true)
        {
            if (tax == null)
            {
                var globalDerivedAttribute = att.DerivedAttributes.FirstOrDefault(p => p.TaxonomyID == Guid.Empty);

                if (globalDerivedAttribute != null)
                {
                    return(ProcessCalculatedAttribute(globalDerivedAttribute.Expression,
                                                      globalDerivedAttribute.MaxResultLength));
                }

                tax = _sku.Taxonomy;
                if (tax == null || !getDefaultForNullTaxonomy)
                {
                    return(String.Empty);
                }
            }

            var calculatedAttribute =
                att.DerivedAttributes.FirstOrDefault(da => da.TaxonomyInfo != null && da.TaxonomyID == tax.ID);

            if (calculatedAttribute == null && att.DerivedAttributes.Any(da => da.TaxonomyInfo == null))
            {
                calculatedAttribute = att.DerivedAttributes.First(da => da.TaxonomyInfo == null);
            }

            //I wonder why we are setting the calculatedAttribute to NULL if an Active InSchema SchemaData exists
            //if (calculatedAttribute != null)
            //{
            //    if (sourceTaxonomy != null)
            //    {
            //        var schemaInfo = sourceTaxonomy.SchemaInfos.SingleOrDefault(p => p.AttributeID == att.ID);
            //        if (schemaInfo != null && !schemaInfo.SchemaDatas.Any(sd => sd.Active && sd.InSchema))
            //            calculatedAttribute = null;
            //    }
            //}

            if (calculatedAttribute == null)
            {
                return(ProcessCalculatedAttribute(att, tax.TaxonomyData.ParentTaxonomyInfo, false));
            }

            return(ProcessCalculatedAttribute(calculatedAttribute.Expression, calculatedAttribute.MaxResultLength));
        }
예제 #8
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;
            }
        }
예제 #9
0
파일: Validate.cs 프로젝트: ewin66/Arya
        public IEnumerable <string> GetLovs(Attribute attribute, TaxonomyInfo taxonomy, Sku sku = null)
        {
            if (attribute == null || taxonomy == null)
            {
                return(null);
            }

            IEnumerable <string> lov;
            var node = taxonomy;

            do
            {
                lov  = GetLovsForNode(attribute, node, sku);
                node = node.TaxonomyData.ParentTaxonomyInfo;
            } while (lov == null && node != null);

            return(lov);
        }
예제 #10
0
파일: ImageManager.cs 프로젝트: ewin66/Arya
 public void AddAttributeValue(string attributeName, string value)
 {
     ImageSku.EntityInfos.Add(new EntityInfo(_db)
     {
         EntityDatas =
         {
             new EntityData(_db)
             {
                 Attribute =
                     Attribute
                     .GetAttributeFromName(
                         _db, attributeName,
                         true, AttributeTypeEnum.NonMeta, false),
                 Value = value
             }
         }
     });
     _db.SubmitChanges();
 }
예제 #11
0
파일: ImageManager.cs 프로젝트: ewin66/Arya
        private string GetLocalName(TaxonomyInfo taxonomy, Attribute attribute, ListOfValue lov)
        {
            // this is only a sketch
            var localName = new StringBuilder();

            localName.Append(CleanName(taxonomy.TaxonomyData.NodeName));
            if (attribute != null)
            {
                localName.Append("(" + CleanName(attribute.AttributeName) + ")");
            }

            if (lov != null)
            {
                localName.Append("[" + CleanName(lov.Value) + "]");
            }

            localName.Append(OriginalImageExtension);
            return(localName.ToString());
            //return OriginalFileName;
        }
예제 #12
0
        private SchemaInfo GetSchemaInfo(TaxonomyInfo currentTaxInfo, Attribute attributeName)
        {
            var schemaInfo =
                currentTaxInfo.SchemaInfos.FirstOrDefault(
                    si => si.Attribute.AttributeName == attributeName.AttributeName);

            if (schemaInfo != null)
            {
                return(schemaInfo);
            }

            var parentTaxonomyInfo = currentTaxInfo.TaxonomyData.ParentTaxonomyInfo;

            if (Args.ExportSuperSchema && parentTaxonomyInfo != null)
            {
                return(GetSchemaInfo(parentTaxonomyInfo, attributeName));
            }

            return(null);
        }
예제 #13
0
        private string GetColumnValue(AryaDbDataContext dc, SchemaInfo schema, string columnName)
        {
            var value = string.Empty;

            if (_taxColumns.Contains(columnName))
            {
                value = GetColumnValue(schema.TaxonomyInfo, columnName);
            }
            else if (String.CompareOrdinal("Attribute", columnName) == 0)
            {
                value = schema.Attribute.AttributeName;
            }
            else
            {
                value = SchemaAttribute.GetMetaAttributeValue(schema.Attribute,
                                                              Attribute.GetAttributeFromName(CurrentDb, columnName, false, AttributeTypeEnum.SchemaMeta),
                                                              schema.TaxonomyInfo);

                if (String.Compare(Resources.SchemaEnrichmentImageAttributeName, columnName,
                                   StringComparison.OrdinalIgnoreCase) == 0)
                {
                    var imageMgr = new ImageManager(dc, Args.ProjectId, value)
                    {
                        LocalDirectory  = ArgumentDirectoryPath,
                        RemoteImageGuid = value
                    };
                    //if (!Directory.Exists(imageMgr.LocalDirectory))
                    //    Directory.CreateDirectory(imageMgr.LocalDirectory);

                    if (Args.DownloadAssets)
                    {
                        imageMgr.DownloadImage(schema.TaxonomyInfo.ID, schema.Attribute.ID);
                    }

                    value = imageMgr.OriginalFileName;
                }
            }
            return(value);
        }
예제 #14
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;
        }
예제 #15
0
        private void ProcessEnrichmentImage(List <SchemaMetaDataInterchangeRecord> enrichmentImageRecords)
        {
            bool success;
            // build taxonomy dictionary
            var taxDict =
                CurrentDbContext.ExecuteQuery <TaxonomyPathAndId>(@"SELECT TaxonomyPath, TaxonomyId 
                                                FROM V_Taxonomy
                                                WHERE TaxonomyPath <> ''
                                                AND ProjectId = {0}",
                                                                  CurrentProjectId).ToDictionary(
                    key => key.TaxonomyPath, value => value.TaxonomyId,
                    StringComparer.OrdinalIgnoreCase);

            // var schemaMetaAttributes = CurrentDbContext.Attributes.Where(att => att.AttributeType.Contains("SchemaMeta")).Select(att=>att.AttributeName).ToList();
            var attDict = CurrentDbContext.Attributes.Where(at => Attribute.NonMetaAttributeTypes.Contains(at.AttributeType)).ToDictionary(key => key.AttributeName, value => value);



            foreach (var enrichmentImageRecord in enrichmentImageRecords)
            {
                //var isUri = Uri.IsWellFormedUriString(enrichmentImageRecord.SchemaMetaAttributeValue, UriKind.Absolute);
                //var imageUri = isUri
                //                   ? new Uri(enrichmentImageRecord.SchemaMetaAttributeValue)
                //                   : new Uri(Path.Combine(BaseImagePath,CurrentProjectId.ToString(),enrichmentImageRecord.SchemaMetaAttributeValue));
                //Success is for valid uri. If the image name only exist not the real file it will be false and added as warning
                success = _currentImageManager.UploadImage(enrichmentImageRecord.SchemaMetaAttributeValue);
                var enrichmentImageGuid = _currentImageManager.RemoteImageGuid;
                if (!taxDict.ContainsKey(enrichmentImageRecord.TaxonomyPath))
                {
                    _warnings.Add(new WorkerWarning()
                    {
                        LineData = enrichmentImageRecord.ToString(), ErrorMessage = Properties.Resources.TaxonomyDoesNotExistsWarningMessage
                    });
                    continue;
                }
                var taxonomy =
                    CurrentDbContext.TaxonomyInfos.FirstOrDefault(t => t.ID == taxDict[enrichmentImageRecord.TaxonomyPath]);
                if (taxonomy != null)
                {
                    if (!attDict.ContainsKey(enrichmentImageRecord.AttributeName))
                    {
                        _warnings.Add(new WorkerWarning()
                        {
                            LineData = enrichmentImageRecord.ToString(), ErrorMessage = Properties.Resources.AttributeDoesNotExistWarningMessage
                        });
                        continue;
                    }
                    var attribute = attDict[enrichmentImageRecord.AttributeName];

                    // get sku for the image
                    var newSku = _currentImageManager.ImageSku;

                    newSku.EntityInfos.Add(new EntityInfo(CurrentDbContext)
                    {
                        EntityDatas =
                        {
                            new EntityData(CurrentDbContext)
                            {
                                Attribute =
                                    Attribute.GetAttributeFromName(CurrentDbContext, Resources.AttributeIdAttributeName,
                                                                   true, AttributeTypeEnum.Sku, false),
                                Value = attribute.ID.ToString()
                            }
                        }
                    });

                    newSku.EntityInfos.Add(new EntityInfo(CurrentDbContext)
                    {
                        EntityDatas =
                        {
                            new EntityData(CurrentDbContext)
                            {
                                Attribute =
                                    Attribute.GetAttributeFromName(CurrentDbContext,
                                                                   Framework.Properties.Resources.
                                                                   TaxonomyIdAttributeName,
                                                                   true, AttributeTypeEnum.Sku, false),
                                Value = taxonomy.ID.ToString()
                            }
                        }
                    });
                    taxonomy.SkuInfos.Add(new SkuInfo(CurrentDbContext)
                    {
                        Sku = newSku
                    });
                    enrichmentImageRecord.SchemaMetaAttributeValue = enrichmentImageGuid;
                    if (!success)
                    {
                        _warnings.Add(new WorkerWarning
                        {
                            LineData     = enrichmentImageRecord.ToString(),
                            ErrorMessage = Properties.Resources.EnrichmentImageFileNotPresentWarningMessage
                        });
                    }
                } //end of if
                else
                {
                    _warnings.Add(new WorkerWarning()
                    {
                        LineData = enrichmentImageRecord.ToString(), ErrorMessage = Properties.Resources.TaxonomyDoesNotExistsWarningMessage
                    });
                }
            }  //end of for

            SaveDataChanges();
        }
예제 #16
0
            private void CalculateValue(IEnumerable <Token> existingTokens)
            {
                var token = _expression;

                if (_tokenType == TokenType.Attribute || _tokenType == TokenType.AttributeValueOnly)
                {
                    var entities =
                        Sku.EntityInfos.SelectMany(ei => ei.EntityDatas.Where(ed => ed.Active))
                        .Where(
                            ed =>
                            ed.Attribute.AttributeName != null &&
                            ed.Attribute.AttributeName.Equals(token, StringComparison.OrdinalIgnoreCase))
                        .OrderBy(ed => ed.Value)
                        .ToList();

                    if (entities.Count == 0)
                    {
                        var attribute = Attribute.GetAttributeFromName(_dc, token, false);
                        if (attribute != null && attribute.AttributeType == AttributeTypeEnum.Derived.ToString())
                        {
                            entities = new List <EntityData>
                            {
                                new EntityData
                                {
                                    Value =
                                        new TaxAttValueCalculator(Sku)
                                        .ProcessCalculatedAttribute(
                                            attribute, Sku.Taxonomy)
                                }
                            };
                        }
                    }

                    if (entities.Count == 0)
                    {
                        return;
                    }

                    if (entities.Count == 1)
                    {
                        var ed = entities[0];
                        _value = ed.Value ?? string.Empty;
                        if (_tokenType == TokenType.Attribute && !string.IsNullOrEmpty(ed.Uom))
                        {
                            Value += ed.Uom;
                        }
                        Uom = ed.Uom;
                        return;
                    }

                    var value   = string.Empty;
                    var allUoms = new HashSet <string>();
                    foreach (var entityData in entities)
                    {
                        value += (string.IsNullOrEmpty(value) ? string.Empty : ", ") + entityData.Value;
                        allUoms.Add(entityData.Uom);
                        if (!string.IsNullOrEmpty(entityData.Uom))
                        {
                            if (_tokenType == TokenType.Attribute)
                            {
                                value += entityData.Uom;
                            }
                        }
                    }

                    Value = value;

                    if (allUoms.Count == 1)
                    {
                        Uom = allUoms.First();
                    }

                    return;
                }

                if (_tokenType == TokenType.Uom)
                {
                    var allUomValues =
                        Sku.EntityInfos.SelectMany(ei => ei.EntityDatas.Where(ed => ed.Active))
                        .Where(
                            ed =>
                            ed.Attribute.AttributeName != null &&
                            ed.Attribute.AttributeName.Equals(token, StringComparison.OrdinalIgnoreCase))
                        .Select(p => p.Uom)
                        .Distinct()
                        .ToList();

                    Value = allUomValues.Count == 1 ? allUomValues[0] : string.Empty;
                    return;
                }

                if (_tokenType == TokenType.Constant)
                {
                    Value = token.Substring(1, token.Length - 2).Replace("\"\"", "\"");
                    return;
                }

                if (_tokenType == TokenType.Special)
                {
                    if (token.Equals(NewTaxonomyExpression))
                    {
                        var tax = Sku.Taxonomy;
                        Value = tax != null?tax.ToString() : string.Empty;

                        return;
                    }

                    if (token.Equals(OldTaxonomyExpression))
                    {
                        Value = Sku.OldTaxonomy;
                        return;
                    }

                    if (token.Equals(UomExpression))
                    {
                        var allUoms =
                            existingTokens.Where(
                                p =>
                                p._id != _id && p.CurrentTokenType == TokenType.Attribute &&
                                !string.IsNullOrEmpty(p.Value)).Select(p => p.Uom).Distinct().ToList();
                        Value = allUoms.Count == 1 ? allUoms[0] : null;
                        return;
                    }

                    if (token.Equals(NodeNameExpression))
                    {
                        var tax = Sku.Taxonomy;
                        Value = tax != null ? tax.TaxonomyData.NodeName : string.Empty;
                    }
                }
            }
예제 #17
0
        public override void Run()
        {
            //State = WorkerState.Working;
            try
            {
                //initialize the context
                using (CurrentDbContext = new AryaDbDataContext(CurrentProjectId, ImportRequestedBy))
                {
                    var imageMgr = new ImageManager(CurrentDbContext, CurrentProjectId);

                    List <ListOfValuesInterchangeRecord> allData = ImportData.ListOfValues;
                    //read all the data into a list<T>, change this as its not very efficient and scalable.
                    var invalidRecords = allData.GetInvalidRecords();
                    var listOfValuesInterchangeRecords = invalidRecords as IList <ListOfValuesInterchangeRecord> ?? invalidRecords.ToList();
                    listOfValuesInterchangeRecords.ToList().ForEach(ir => _warnings.Add(new WorkerWarning
                    {
                        LineData     = ir.ToString(),
                        ErrorMessage = Properties.Resources.RequiredValueNullWarningMessage
                    }));
                    var validImportRecords = allData.Except(listOfValuesInterchangeRecords.ToList()).ToList();
                    var newValueCount      = 0;
                    int ignoredCount       = 0;
                    int updatedCount       = 0;
                    // load a dictionary with taxonomy string / id pairs (taken from TaxonomyImport)
                    var taxDict =
                        CurrentDbContext.ExecuteQuery <TaxonomyPathAndId>(@"SELECT TaxonomyPath, TaxonomyId
                                                FROM V_Taxonomy
                                                WHERE TaxonomyPath <> ''
                                                AND ProjectId = {0}", CurrentProjectId).ToDictionary(
                            key => key.TaxonomyPath, value => value.TaxonomyId,
                            StringComparer.OrdinalIgnoreCase);

                    // load attribute and schema dictionaries
                    var attDict =
                        CurrentDbContext.Attributes.Where(
                            a => a.AttributeType == AttributeTypeEnum.Sku.ToString())
                        .Select(a => a)
                        .ToDictionary(key => key.AttributeName, value => value);
                    var schDict = new DoubleKeyDictionary <Guid, Guid, SchemaInfo>();
                    CurrentDbContext.SchemaInfos.ForEach(si => schDict.Add(si.TaxonomyID, si.AttributeID, si));

                    // iterate through the input records.
                    foreach (var csvRecord in validImportRecords)
                    {
                        var currentRecord = csvRecord;
                        // check for taxonomy - if it doesn't exist, give up.
                        if (!taxDict.ContainsKey(currentRecord.TaxonomyPath))
                        {
                            _warnings.Add(new WorkerWarning()
                            {
                                LineData = currentRecord.ToString(), ErrorMessage = Properties.Resources.TaxonomyDoesNotExistsWarningMessage
                            });
                            continue;
                        }
                        var taxId    = taxDict[currentRecord.TaxonomyPath];
                        var taxonomy = CurrentDbContext.TaxonomyInfos.First(ti => ti.ID == taxId);

                        // if attribute exists, get it, otherwise give up.
                        if (!attDict.ContainsKey(currentRecord.AttributeName))
                        {
                            _warnings.Add(new WorkerWarning()
                            {
                                LineData = currentRecord.ToString(), ErrorMessage = Properties.Resources.AttributeDoesNotExistWarningMessage
                            });
                            continue;
                        }
                        var att = attDict[currentRecord.AttributeName];

                        // if schema info exists, get it, otherwise create both it and schema data
                        SchemaInfo sch;
                        if (schDict.ContainsKeys(taxId, att.ID))
                        {
                            sch = schDict[taxId, att.ID];
                        }
                        else
                        {
                            sch = new SchemaInfo(CurrentDbContext)
                            {
                                TaxonomyID  = taxId,
                                Attribute   = att,
                                SchemaDatas =
                                {
                                    new SchemaData(CurrentDbContext)
                                    {
                                        InSchema = true, NavigationOrder = 0, DisplayOrder = 0
                                    }
                                }
                            };
                            att.SchemaInfos.Add(sch);
                            schDict.Add(taxId, att.ID, sch);
                        }
                        var    lov = sch.ListOfValues.FirstOrDefault(v => v.Value.ToLower() == currentRecord.Lov.ToLower() && v.Active);
                        string enrichmentImageGuid = null;
                        int    displayOrder;
                        if (lov != null || (lov == null && CurrentImportOptions.HasFlag(ImportOptions.CreateMissingLOVs)))
                        {
                            // if image url exists try to upload the image - "try" is used in case the url is badly formed.
                            // string enrichmentImage = null;

                            var success = false;
                            if (currentRecord.EnrichmentImage != null)
                            {
                                //Success is for valid uri. If the image name only exist not the real file it will be false and added as warning
                                success             = imageMgr.UploadImage(currentRecord.EnrichmentImage);
                                enrichmentImageGuid = imageMgr.RemoteImageGuid;
                                var newSku = imageMgr.ImageSku;

                                newSku.EntityInfos.Add(new EntityInfo(CurrentDbContext)
                                {
                                    EntityDatas =
                                    {
                                        new EntityData(CurrentDbContext)
                                        {
                                            Attribute =
                                                Attribute.GetAttributeFromName(CurrentDbContext,
                                                                               Framework.Properties.Resources.LovIdAttributeName, true, AttributeTypeEnum.Sku, false),
                                            Value = imageMgr.RemoteImageGuid
                                        }
                                    }
                                });

                                newSku.EntityInfos.Add(new EntityInfo(CurrentDbContext)
                                {
                                    EntityDatas =
                                    {
                                        new EntityData(CurrentDbContext)
                                        {
                                            Attribute =
                                                Attribute.GetAttributeFromName(CurrentDbContext,
                                                                               Framework.Properties.Resources.AttributeIdAttributeName,
                                                                               true, AttributeTypeEnum.Sku, false),
                                            Value = sch.AttributeID.ToString()
                                        }
                                    }
                                });

                                newSku.EntityInfos.Add(new EntityInfo(CurrentDbContext)
                                {
                                    EntityDatas =
                                    {
                                        new EntityData(CurrentDbContext)
                                        {
                                            Attribute =
                                                Attribute.GetAttributeFromName(CurrentDbContext, Framework.Properties.Resources.TaxonomyIdAttributeName,
                                                                               true, AttributeTypeEnum.Sku, false),
                                            Value = sch.TaxonomyID.ToString()
                                        }
                                    }
                                });

                                taxonomy.SkuInfos.Add(new SkuInfo(CurrentDbContext)
                                {
                                    Sku = newSku
                                });
                                if (!success)
                                {
                                    _warnings.Add(new WorkerWarning
                                    {
                                        LineData     = currentRecord.ToString(),
                                        ErrorMessage = Properties.Resources.EnrichmentImageFileNotPresentWarningMessage
                                    });
                                }
                            }

                            if (!string.IsNullOrEmpty(currentRecord.DisplayOrder) && !int.TryParse(currentRecord.DisplayOrder, out displayOrder))
                            {
                                _warnings.Add(new WorkerWarning()
                                {
                                    LineData = currentRecord.ToString(), ErrorMessage = Properties.Resources.DisplayOrderNotValidNumberWarningMessage
                                });
                                continue;
                            }
                        }


                        // if specific value record exists in this schema, get it, otherwise create it.
                        //var lov = sch.ListOfValues.FirstOrDefault(v => v.Value.ToLower() == currentRecord.Lov.ToLower() && v.Active);

                        if (lov == null)
                        {
                            if (CurrentImportOptions.HasFlag(ImportOptions.CreateMissingLOVs))
                            {
                                sch.ListOfValues.Add(entity: new ListOfValue(CurrentDbContext)
                                {
                                    Value           = currentRecord.Lov,
                                    EnrichmentImage = enrichmentImageGuid,
                                    EnrichmentCopy  = currentRecord.EnrichmentCopy,
                                    DisplayOrder    = int.TryParse(currentRecord.DisplayOrder, out displayOrder) ? displayOrder : (int?)null,
                                    CreatedOn       = DateTime.Now,
                                    CreatedBy       = ImportRequestedBy
                                });
                                newValueCount++;
                            }
                            else
                            {
                                _warnings.Add(new WorkerWarning
                                {
                                    LineData     = currentRecord.ToString(),
                                    ErrorMessage = Properties.Resources.CreateLovFlagOffWarningMessage
                                });
                                ProcessSummaryReport(0);
                            }
                        }
                        else
                        {
                            if (lov.Value == currentRecord.Lov && lov.EnrichmentCopy == currentRecord.EnrichmentCopy &&
                                lov.EnrichmentImage == currentRecord.EnrichmentImage && lov.DisplayOrder.ToString() == currentRecord.DisplayOrder)
                            {
                                ignoredCount++;
                                continue;
                            }
                            var updatedFlag = false;
                            if (!string.IsNullOrEmpty(enrichmentImageGuid))
                            {
                                lov.EnrichmentImage = enrichmentImageGuid;
                                updatedFlag         = true;
                            }
                            if (!string.IsNullOrEmpty(currentRecord.EnrichmentCopy))
                            {
                                lov.EnrichmentCopy = currentRecord.EnrichmentCopy;
                                updatedFlag        = true;
                            }
                            if (!string.IsNullOrEmpty(currentRecord.DisplayOrder))
                            {
                                lov.DisplayOrder = int.TryParse(currentRecord.DisplayOrder, out displayOrder)
                                                       ? displayOrder
                                                       : (int?)null;
                                updatedFlag = true;
                            }
                            if (updatedFlag)
                            {
                                lov.CreatedBy = ImportRequestedBy;
                                updatedCount++;
                                lov.CreatedOn = DateTime.Now;
                            }
                            else
                            {
                                ignoredCount++;
                            }
                        }
                    }
                    SaveDataChanges();
                    ProcessSummaryReport(newValueCount, updatedCount, ignoredCount);
                }
            }
            catch (IndexOutOfRangeException ex)
            {
                var newException = new Exception(Properties.Resources.InvalidRowInInputFileMessage, ex);
                Summary.SetError(newException);
            }
            catch (Exception ex)
            {
                Summary.SetError(ex);
            }
        }
예제 #18
0
        private void ProcessAttributes(Sku sku, string nodeType, string taxonomyString, IEnumerable <KeyValuePair <Attribute, SchemaData> > attributeOrders)
        {
            // add static information to output lists
            var valueElements = new List <string> {
                sku.ItemID, taxonomyString, 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)
                        .Distinct()
                        .OrderBy(val => val, new CompareForAlphaNumericSort())
                        .Aggregate(string.Empty,
                                   (current, val) => current + ((string.IsNullOrEmpty(current) ? string.Empty : ",") + val));
                    valueElements.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)
                        .Distinct()
                        .OrderBy(val => val, new CompareForAlphaNumericSort())
                        .Take(_globalAttributeCount[i])
                        .ToList();
                    for (int j = 0; j < _globalAttributeCount[i]; j++)
                    {
                        valueElements.Add(j < listStringValue.Count ? listStringValue[j] : "");
                    }
                }
            }

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

            foreach (var att in attributeOrders)
            {
                Attribute  attribute  = att.Key;
                SchemaData schemaData = att.Value;

                var entity    = sku.GetValuesForAttribute(CurrentDb, attribute.AttributeName);
                var validator = new Validate(CurrentDb);
                IEnumerable <EntityData> invalidEntities = null;
                if (attribute.AttributeType != AttributeTypeEnum.Derived.ToString())
                {
                    invalidEntities = entity.Where(e => !validator.IsValidDataType(e, schemaData));
                }

                if (invalidEntities == null || !invalidEntities.Any())
                {
                    continue;
                }

                invalidValuesFound = true;
                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
                var    distinctUoms = entity.Where(ed => ed.Uom != null).Select(ed => ed.Uom).Distinct().ToList();
                string uom;
                switch (distinctUoms.Count)
                {
                case 0:
                {
                    uom = string.Empty;
                    break;
                }

                case 1:
                {
                    uom = distinctUoms.First();
                    break;
                }

                default:
                {
                    uom = entity.Aggregate(string.Empty,
                                           (current, u) => current + ((string.IsNullOrEmpty(current) ? string.Empty : ", ") + u.Uom));
                    break;
                }
                }

                var rank = Decimal.Truncate(schemaData.NavigationOrder) + " • " + Decimal.Truncate(schemaData.DisplayOrder);

                // add attribute data to output list
                // append navigation data
                valueElements.Add(rank);

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

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

                // append UoM data
                valueElements.Add(uom);
            }
            if (invalidValuesFound)
            {
                _attributeTable.WriteDataRow(valueElements);
            }
        }
예제 #19
0
        //This should be handles in the invalid value seperations
        //private void ReportNullAttributeValues(List<SkuAttributeValueInterchangeRecord> validImportRecords)
        //{
        //    var nullAttributeValueRecords = validImportRecords.Where(ad => ad.Value == null).ToList();
        //    nullAttributeValueRecords.ForEach(vr =>
        //                                          {
        //                                              _warnings.Add(new WorkerWarning
        //                                                                {
        //                                                                    LineData = vr.ToString(),
        //                                                                    ErrorMessage =
        //                                                                        "Attribute Value can not be null."
        //                                                                });
        //                                              validImportRecords.Remove(vr);
        //                                          });
        //}
        private void ProcessMultivalues(IEnumerable <SkuAttributeValueInterchangeRecord> multiValues)
        {
            CurrentLogWriter.DebugFormat("{0}: Processing Multi-Value records", Arguments.Id);
            var existingEntityInfos = new List <EntityInfo>();

            var results = multiValues.GroupBy(mv => new { mv.ItemID, mv.AttributeName },
                                              (key, group) => new { key.ItemID, key.AttributeName, Values = group.ToList() });

            foreach (var fileGroup in results)
            {
                var line    = fileGroup;
                var dbGroup = (from s in CurrentDbContext.Skus
                               where s.ItemID == line.ItemID
                               from ei in s.EntityInfos
                               from ed in ei.EntityDatas
                               where ed.Active && ed.Attribute.AttributeName.ToLower() == line.AttributeName.ToLower()
                               select ed).ToList();

                //if its an exact match on value+Uom
                var exactMatches = from fileLine in fileGroup.Values
                                   join dbLine in dbGroup on new { fileLine.Value, fileLine.Uom } equals new { dbLine.Value, dbLine.Uom }
                let ln = new { fileLine, dbLine }
                group ln by ln.fileLine
                into grp
                    select new { FileLine = grp.Key, DbLines = grp.Select(g => g.dbLine) };

                foreach (var exactMatch in exactMatches)
                {
                    //Processing general updates
                    if (!FieldsInFileAndDbFieldsMatches(exactMatch.DbLines, exactMatch.FileLine))
                    {
                        exactMatch.DbLines.ForEach(e => e.Active = false);
                        var ed = exactMatch.DbLines.First();
                        ed.EntityInfo.EntityDatas.Add(new EntityData(CurrentDbContext)
                        {
                            Attribute     = ed.Attribute,
                            Value         = ed.Value,
                            Uom           = ed.Uom,
                            Field1        = exactMatch.FileLine.Field1,
                            Field2        = exactMatch.FileLine.Field2,
                            Field3        = exactMatch.FileLine.Field3,
                            Field4        = exactMatch.FileLine.Field4,
                            Field5        = exactMatch.FileLine.Field5,
                            BeforeEntity  = false,
                            CreatedRemark = CurrentRemarkId
                        });
                    }
                    //remove the item from the eds
                    dbGroup.RemoveAll(exactMatch.DbLines);
                    //TODO: remove from file list??
                    _ignoredCountMultiValues++;
                    fileGroup.Values.Remove(exactMatch.FileLine);
                }

                //case 1
                if (_replaceExistingValues)
                {
                    //add to the entity info
                    existingEntityInfos = dbGroup.OrderBy(e => e.Value).Select(e => e.EntityInfo).ToList();
                    foreach (var entityData in dbGroup)
                    {
                        //deactivate all in dbs
                        entityData.Active = false;
                    }
                }
                if (existingEntityInfos.Count == 0 && !CurrentImportOptions.HasFlag(ImportOptions.CreateMissingValues))
                {
                    continue;
                }
                //case 2
                // var currentEntityInfoIndex = 0;
                foreach (var itemFromFile in fileGroup.Values)
                {
                    //create new entity data
                    if (itemFromFile == null)
                    {
                        continue;
                    }

                    EntityInfo currentEntityInfo;
                    if (existingEntityInfos.Count != 0)
                    {
                        currentEntityInfo = existingEntityInfos.First();
                    }
                    else
                    {
                        var currentSku = CurrentDbContext.Skus
                                         .FirstOrDefault(
                            s =>
                            s.ItemID == itemFromFile.ItemID);
                        if (currentSku == null)
                        {
                            _warnings.Add(new WorkerWarning
                            {
                                LineData     = itemFromFile.ToString(),
                                ErrorMessage = Resources.ItemDoesNotExistWarningMessage// Resources.AttributeDoesNotExistWarningMessage
                            });
                            continue;
                        }
                        else
                        {
                            currentEntityInfo = new EntityInfo(CurrentDbContext)
                            {
                                Sku = currentSku
                            };
                            CurrentDbContext.EntityInfos.InsertOnSubmit(currentEntityInfo);
                        }
                    }
                    var attributeFromName = Attribute.GetAttributeFromName(CurrentDbContext, itemFromFile.AttributeName, false, useChache: false);

                    if (attributeFromName == null)
                    {
                        _warnings.Add(new WorkerWarning
                        {
                            LineData     = itemFromFile.ToString(),
                            ErrorMessage = Resources.AttributeDoesNotExistWarningMessage
                        });
                        continue;
                    }

                    var attId = attributeFromName.ID;
                    currentEntityInfo.EntityDatas.Add(new EntityData(CurrentDbContext)
                    {
                        AttributeID   = attId,
                        Value         = itemFromFile.Value,
                        Uom           = itemFromFile.Uom,
                        Field1        = itemFromFile.Field1,
                        Field2        = itemFromFile.Field2,
                        Field3        = itemFromFile.Field3,
                        Field4        = itemFromFile.Field4,
                        Field5        = itemFromFile.Field5,
                        BeforeEntity  = false,
                        CreatedRemark = CurrentRemarkId
                    });

                    _successCountForMultiValues++;
                    if (existingEntityInfos.Contains(currentEntityInfo))
                    {
                        existingEntityInfos.Remove(currentEntityInfo);
                    }
                }
            }
            SaveDataChanges();
        }
예제 #20
0
파일: Validate.cs 프로젝트: ewin66/Arya
        private IEnumerable <string> GetLovsForNode(Attribute attribute, TaxonomyInfo taxonomy, Sku sku = null)
        {
            if (attribute == null || taxonomy == null)
            {
                return(null);
            }

            var si = taxonomy.SchemaInfos.FirstOrDefault(s => s.Attribute == attribute);

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

            var lovs = si.ListOfValues.Where(a => a.Active).ToList();

            if (lovs.Count == 0)
            {
                return(null);
            }

            if (sku == null)
            {
                return(lovs.Select(a => a.Value).Distinct());
            }

            //Get LOVs where parent Value is null
            var defaultLov =
                lovs.Where(a => a.ParentValue == null || a.ParentValue == "Ø").Select(v => v.Value).Distinct().ToList();

            // Combinations:
            // value: parentValue == x:null -- NA
            // value: parentValue == x:y --- if x is the cell value then y must be the parentValue -- check first
            // value: parentValue == x:* --- there must exist a parent value for cell value x -- check second
            // value: parentValue == x:Ø --- cell Value must be x when parentValue does not exist -- check third
            // value: parentValue == *:y --- Any/other cell value must have parentValue y  -- check fourth
            // value: parentValue == *:Ø --- No parent should exist for any/other value -- fifth check
            // value: parentValue == *:* --- all the values must have parent value -- sixth check
            // value: parentValue == Ø:y --- Does not make sense ..

            var parentEntities = GetParentAttributeValues(si, sku);

            if (parentEntities == null) //No Dependencies
            {
                return(defaultLov);
            }

            IEnumerable <string> parentAttributeValues = parentEntities.Select(v => v.Value).ToList();

            if (!parentAttributeValues.Any())
            {
                return(defaultLov);
            }

            var allowedLovs =
                lovs.Where(a => a.ParentValue == "✽" || parentAttributeValues.Contains(a.ParentValue))
                .Select(v => v.Value)
                .Distinct()
                .ToList();

            if (allowedLovs.Contains("Ø"))
            {
                return(new List <string>());
            }

            if (allowedLovs.Count == 0 || allowedLovs.Contains("✽"))
            {
                return(null);
            }

            return(allowedLovs);
        }
예제 #21
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);
            }
        }
예제 #22
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!!!");
            }
        }
예제 #23
0
 public ToleranceAttribute(Attribute attr, string tol, bool isOpt)
 {
     Attr       = attr;
     Tolerance  = tol;
     IsOptional = isOpt;
 }
예제 #24
0
 public SchemaAttribute(Attribute metaAttribute, Type dataType)
 {
     MetaSchemaAttribute = metaAttribute;
     DataType            = dataType;
 }