示例#1
0
        private void ProcessCatalog()
        {
            _project = (from project in CurrentDb.Projects where project.ID == _args.ProjectId select project).First();
            var aryaUser             = CurrentDb.Users.First(u => u.ID == _project.CreatedBy);
            var lastUpdatedTimestamp = TimestampRecordType.FromValues(_project.CreatedOn,
                                                                      User.FromAryaUser(aryaUser));

            CurrentLogWriter.Debug("Processing " + _project);
            _productCatalog = new ProductCatalog
            {
                Id                  = _project.ID,
                Company             = _project.ClientDescription,
                Type                = "STANDARD",
                ProductCatalogNames =
                    ProductCatalogProductCatalogName.FromName(_project.SetName),
                TaxonomyMetaDataLanguageVersionss =
                    ProductCatalogTaxonomyMetaDataLanguageVersions.FromAryaProject(
                        _project),
                SchemaMetaDataLanguageVersionss =
                    ProductCatalogSchemaMetaDataLanguageVersions.FromAryaProject(
                        _project),
                LastUpdatedTimestamp = lastUpdatedTimestamp
            };

            var taxonomyNode = TaxonomyNode.FromValues(_project.CreatedOn, _project.ID, _project.ToString(),
                                                       Guid.Empty, _project.ID);

            taxonomyNode.IsRoot = true;
            taxonomyNode.SerializeObject(GetSaveFilePath("Node", _project.ID.ToString()));

            _productCatalog.SerializeObject(GetSaveFilePath("Catalog", _productCatalog.Id.ToString()));

            ProcessTaxonomyNodes();
        }
示例#2
0
        //private void ProcessSchemaTrails(TaxonomyInfo node)
        //{
        //    var schemaTrail = SchemaAuditTrail.FromValues(Guid.NewGuid());
        //    foreach (var si in node.SchemaInfos)
        //    {
        //        PopulatePrimarySchemaMetaDataTrail(si, schemaTrail);
        //        var smds = from smi in si.SchemaMetaInfos
        //                   from smd in smi.SchemaMetaDatas
        //                   select smd;
        //        foreach (var smd in smds)
        //        {
        //            var attribute = smd.SchemaMetaInfo.Attribute.AttributeName;
        //            var record = new SchemaAuditTrailRecord
        //            {
        //                Id = si.AttributeID,
        //                AuditTrailTimestamp =
        //                    TimestampRecordType.FromValues(smd.CreatedOn, User.FromAryaUser(smd.User)),
        //                LangDependentMetaData = new SchemaAuditTrailRecordLangDependentMetaData
        //                {
        //                    lang = EnUs,
        //                    SchemaAttributeName = attribute
        //                }
        //            };
        //            if (attribute == Resources.SchemaEnrichmentCopyAttributeName)
        //            {
        //                record.LangDependentMetaData.Enrichment = new Enrichment
        //                {
        //                    lang = EnUs,
        //                    EnrichmentCopy = smd.Value
        //                };
        //            }
        //            else if (attribute == Resources.SchemaEnrichmentImageAttributeName)
        //            {
        //                record.LangDependentMetaData.Enrichment = new Enrichment
        //                {
        //                    lang = EnUs,
        //                    EnrichmentPrimaryImage = new EnrichmentFileResourceType
        //                    {
        //                        Filename =
        //                            new ImageManager(CurrentDb, _project.ID).OriginalFileUri
        //                    }
        //                };
        //            }
        //            else
        //            {
        //                record.LangDependentMetaData.MetaDatums = new List<MetaDatumType>
        //                {
        //                    new MetaDatumType {Id = smd.MetaID, Name = attribute, Value = smd.Value}
        //                };
        //            }
        //            schemaTrail.SchemaAuditTrailRecords.Add(record);
        //        }
        //    }
        //    schemaTrail.SchemaAuditTrailRecords =
        //        schemaTrail.SchemaAuditTrailRecords
        //            .OrderBy(satr => satr.LangDependentMetaData.SchemaAttributeName)
        //            .ThenBy(satr => satr.AuditTrailTimestamp.Timestamp)
        //            .ToList();
        //    schemaTrail.SerializeObject(GetSaveFilePath("SchemaHistory", node.ID.ToString()));
        //}
        //private static void PopulatePrimarySchemaMetaDataTrail(SchemaInfo si, SchemaAuditTrail schemaTrail)
        //{
        //    var previousSd =
        //        Enumerable.Range(1, 1).Select(sd =>
        //            new
        //            {
        //                DataType = (string)null,
        //                DisplayOrder = (int?)null,
        //                NavigationOrder = (int?)null,
        //                InSchema = (bool?)null,
        //                Required = (bool?)null,
        //                Multivalue = (bool?)null
        //            }).First();
        //    foreach (var sd in si.SchemaDatas.OrderBy(s => s.CreatedOn))
        //    {
        //        var limd = new SchemaAuditTrailRecordLangIndependentMetaData();
        //        if (previousSd.InSchema == null || sd.InSchema != previousSd.InSchema)
        //        {
        //            limd.InSchema = sd.InSchema;
        //            limd.InSchemaSpecified = true;
        //        }
        //        if (previousSd.NavigationOrder == null || sd.NavigationOrder != previousSd.NavigationOrder)
        //        {
        //            limd.NavigationOrder = Convert.ToInt32(sd.NavigationOrder);
        //            limd.NavigationOrderSpecified = true;
        //        }
        //        if (previousSd.DisplayOrder == null || sd.DisplayOrder != previousSd.DisplayOrder)
        //        {
        //            limd.DisplayOrder = Convert.ToInt32(sd.DisplayOrder);
        //            limd.DisplayOrderSpecified = true;
        //        }
        //        if (previousSd.DataType == null || sd.DataType != previousSd.DataType)
        //            limd.DataType = sd.DataType;
        //        var record = new SchemaAuditTrailRecord
        //        {
        //            Id = si.AttributeID,
        //            AuditTrailTimestamp =
        //                TimestampRecordType.FromValues(sd.CreatedOn, User.FromAryaUser(sd.User)),
        //            LangDependentMetaData = new SchemaAuditTrailRecordLangDependentMetaData
        //            {
        //                lang = EnUs,
        //                SchemaAttributeName = si.Attribute.AttributeName
        //            },
        //            LangIndependentMetaData = limd
        //        };
        //        schemaTrail.SchemaAuditTrailRecords.Add(record);
        //        var oldSd = previousSd;
        //        previousSd = Enumerable.Range(1, 1).Select(r => new
        //        {
        //            DataType = limd.DataType ?? oldSd.DataType,
        //            DisplayOrder = limd.DisplayOrderSpecified ? limd.DisplayOrder : oldSd.DisplayOrder,
        //            NavigationOrder = limd.NavigationOrderSpecified ? limd.NavigationOrder : oldSd.NavigationOrder,
        //            InSchema = limd.InSchemaSpecified ? limd.InSchema : oldSd.InSchema,
        //            Required = limd.RequiredSpecified ? limd.Required : oldSd.Required,
        //            Multivalue = limd.MultivalueSpecified ? limd.Multivalue : oldSd.Multivalue
        //        }).First();
        //    }
        //}

        private void ProcessSku(Guid skuId)
        {
            try
            {
                //Must use independent DataContext to conserve memory
                using (var dc = new AryaDbDataContext(Arguments.ProjectId, Arguments.UserId))
                {
                    while (dc.Connection.State != ConnectionState.Open)
                    {
                        switch (dc.Connection.State)
                        {
                        case ConnectionState.Closed:
                            dc.Connection.Open();
                            break;

                        case ConnectionState.Connecting:
                            Thread.Sleep(100);
                            break;
                        }
                    }

                    var item     = dc.Skus.First(s => s.ID == skuId);
                    var filename = GetSaveFilePath("Sku", item.ItemID);
                    if (File.Exists(filename))
                    {
                        return;
                    }

                    var skuAttributes = new List <SkuAttribute>();
                    var psp           = (from ei in item.EntityInfos
                                         from ed in ei.EntityDatas
                                         where
                                         ed.Active &&
                                         (ed.Attribute.AttributeName.ToLower().Contains("primary keyword") ||
                                          ed.Attribute.AttributeName.ToLower().Contains("psp"))
                                         orderby ed.Attribute.AttributeName descending
                                         select ed.Value).FirstOrDefault() ?? "Item " + item.ItemID;

                    var sku = new Bridge.Sku
                    {
                        Id             = item.ID,
                        Classification = new List <CatalogRef>(),
                        Enrichments    = new List <Enrichment>(),
                        SkuAttributes  =
                            new SkuSkuAttributes
                        {
                            ItemId = item.ItemID,
                            PrimarySemanticPhrases =
                                SkuSkuAttributesPrimarySemanticPhrase.FromPsp(psp),
                            SkuAttributes = skuAttributes
                        },
                        LastUpdatedTimestamp =
                            TimestampRecordType.FromValues(item.CreatedOn, User.FromAryaUser(item.User))
                    };

                    var catalogRef = new CatalogRef
                    {
                        CatalogId      = _project.ID,
                        Primary        = true,
                        TaxonomyNodeId = item.Taxonomy.ID
                    };
                    sku.Classification.Add(catalogRef);

                    var edGroups = (from ei in dc.EntityInfos
                                    where ei.SkuID == item.ID
                                    from ed in ei.EntityDatas
                                    where ed.Active
                                    group ed by ed.Attribute.ID
                                    into grp
                                    select grp).ToList();

                    skuAttributes.AddRange(edGroups.Select(GetSkuAttribute));

                    var derivedAttributes =
                        dc.Attributes
                        .Where(att => att.AttributeType == AttributeTypeEnum.Derived.ToString() && _args.GlobalAttributes.Contains(att.AttributeName))
                        .ToList();

                    var derivedAttributeGroups = (from att in derivedAttributes
                                                  let value = item.GetValuesForAttribute(dc, att, false).First()
                                                              group value by att.ID
                                                              into grp
                                                              select grp).ToList();

                    skuAttributes.AddRange(derivedAttributeGroups.Select(GetSkuAttribute));

                    edGroups.Select(edg => edg.First().Attribute).ForEach(AddAttribute);

                    sku.SerializeObject(filename);
                }
            }
            catch (Exception ex)
            {
                if (Summary.Warnings == null)
                {
                    Summary.Warnings = new List <WorkerWarning>();
                }
                Summary.Warnings.Add(new WorkerWarning
                {
                    ErrorMessage = ex.Message,
                    ErrorDetails = ex.StackTrace,
                    LineData     = "SKU " + skuId
                });
            }
        }