public override void Run()
        {
            State          = WorkerState.Working;
            StatusMessage  = "Init";
            fieldDelimiter = FieldDelimiter.GetValue().ToString();

            var fi           = new FileInfo(ExportFileName);
            var baseFileName = fi.FullName.Replace(fi.Extension, string.Empty);

            avfrFile = new StreamWriter(baseFileName + "_AVFR.txt", false, Encoding.UTF8);

            StatusMessage = "Generating Child node list ... ";

            var allChildren =
                Taxonomies.Cast <ExtendedTaxonomyInfo>().SelectMany(p => p.Taxonomy.AllLeafChildren).Distinct().ToList();

            CurrentProgress = 0;
            MaximumProgress = allChildren.Count;

            avfrFile.WriteLine(
                "T1{0}T2{0}T3{0}T4{0}T5{0}T6{0}T7{0}AttributeName{0}Value{0}NodeSkuCount{0}ValueSkuCount{0}AttributeSkuCount{0}NavigationOrder{0}DisplayOrder{0}Attribute FillRate{0}Value FillRate",
                fieldDelimiter);

            foreach (var taxonomyInfo in allChildren)
            {
                WriteAVFRData(taxonomyInfo);
                CurrentProgress++;
            }

            avfrFile.Close();
            avfrFile.Dispose();

            StatusMessage = "Done.";
            State         = WorkerState.Ready;
        }
示例#2
0
        public override void Run()
        {
            State = WorkerState.Working;
            _parsedSkuExclusions = ParseSkuInclusionAndExclusions(SkuExclusions);
            _parsedSkuInclusions = ParseSkuInclusionAndExclusions(SkuInclusions);

            _delimiter = FieldDelimiter.GetValue().ToString();
            _currentDb = new SkuDataDbDataContext();

            var dlo = new DataLoadOptions();

            dlo.LoadWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas);
            dlo.LoadWith <EntityInfo>(entityInfo => entityInfo.EntityDatas);
            dlo.LoadWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas);

            dlo.AssociateWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas.Where(p => p.Active));
            dlo.AssociateWith <EntityInfo>(entityInfo => entityInfo.EntityDatas.Where(p => p.Active || p.BeforeEntity));
            dlo.AssociateWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas.Where(p => p.Active));
            dlo.AssociateWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.SkuInfos.Where(p => p.Active));

            _currentDb.LoadOptions    = dlo;
            _currentDb.CommandTimeout = 2000;

            _currentDb.Connection.Open();
            _currentDb.Connection.ChangeDatabase(AryaTools.Instance.InstanceData.Dc.Connection.Database);


            var fi           = new FileInfo(ExportFileName);
            var baseFileName = fi.FullName.Replace(fi.Extension, string.Empty);

            _attributeFile = new StreamWriter(baseFileName + "_attributes.txt", false, Encoding.UTF8);
            _valueFile     = new StreamWriter(baseFileName + "_values.txt", false, Encoding.UTF8);
            _skuFile       = new StreamWriter(baseFileName + "_skus.txt", false, Encoding.UTF8);

            StatusMessage = "Init";
            var allExportTaxonomyIds =
                Taxonomies.Cast <ExtendedTaxonomyInfo>().Select(p => p.Taxonomy.ID).Distinct().ToList();
            var exportTaxonomies = _currentDb.TaxonomyInfos.Where(p => allExportTaxonomyIds.Contains(p.ID)).ToList();
            var allChildren      = exportTaxonomies.SelectMany(p => p.AllChildren).Distinct().ToList();
            var allLeafChildren  = exportTaxonomies.SelectMany(p => p.AllLeafChildren).Distinct().ToList();
            var maxDepth         = 0;

            if (allChildren.Count == 0 && allLeafChildren.Count != 0)
            {
                maxDepth =
                    allLeafChildren.Select(
                        child => child.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None).Length)
                    .Max();
            }

            else if (allLeafChildren.Count == 0 && allChildren.Count != 0)
            {
                maxDepth =
                    allChildren.Select(
                        child => child.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None).Length)
                    .Max();
            }

            else if (allLeafChildren.Count != 0 && allChildren.Count != 0)
            {
                if (allLeafChildren.Count >= allChildren.Count)
                {
                    maxDepth =
                        allLeafChildren.Select(
                            child =>
                            child.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None).Length).Max();
                }

                else
                {
                    maxDepth =
                        allChildren.Select(
                            child =>
                            child.ToString().Split(new[] { TaxonomyInfo.Delimiter }, StringSplitOptions.None).Length).Max();
                }
            }
            else
            {
                StatusMessage   = "There was no data to export.";
                MaximumProgress = 1;
                CurrentProgress = 1;
                State           = WorkerState.Ready;
            }

            if (IgnoreT1Taxonomy)
            {
                maxDepth--;
            }

            for (var i = 1; i <= maxDepth; i++)
            {
                _attributeFile.Write("T" + i + "\t");
                _valueFile.Write("T" + i + "\t");
                _skuFile.Write("T" + i + "\t");
            }
            _attributeFile.WriteLine(
                "Attribute{0}Node Sku Count{0}Attr. Sku Count{0}Fill Rate{0}Navigation Order{0}Display Order{0}Global",
                _delimiter);
            _valueFile.WriteLine(
                "Attribute{0}Value{0}Uom{0}Node Sku Count{0}Attr. Value Sku Count{0}Value Fill Rate{0}Attr. Fill Rate{0}Navigation Order{0}Display Order{0}Global",
                _delimiter);
            _skuFile.WriteLine(
                "Item Id{0}Node Attr. Count{0}Node Nav. Attr. Count{0}Node Disp. Attr. Count{0}Sku Attr. Count{0}Sku Nav. Attr. Count{0}Sku Disp. Attr. Count{0}Sku Attr. Fill Rate{0}Sku Nav. Attr. Fill Rate{0}Node Disp. Attr. Fill Rate",
                _delimiter);

            CurrentProgress = 0;

            if (allChildren.Count >= allLeafChildren.Count)
            {
                MaximumProgress = allChildren.Count;
                foreach (var child in allChildren)
                {
                    WriteMetricsToFile(child, maxDepth);
                    CurrentProgress++;
                }
            }
            else if (allChildren.Count < allLeafChildren.Count)
            {
                MaximumProgress = allLeafChildren.Count;

                foreach (var child in allLeafChildren)
                {
                    WriteMetricsToFile(child, maxDepth);
                    CurrentProgress++;
                }
            }

            _attributeFile.Close();
            _valueFile.Close();
            _skuFile.Close();

            StatusMessage = "Done!";
            State         = WorkerState.Ready;
        }
        public override void Run()
        {
            State = WorkerState.Working;
            _parsedSkuExclusions = ParseSkuInclusionAndExclusions(SkuExclusions);
            _parsedSkuInclusions = ParseSkuInclusionAndExclusions(SkuInclusions);

            _delimiter = FieldDelimiter.GetValue().ToString();

            //Create new context
            _currentDb = new SkuDataDbDataContext();
            var dlo = new DataLoadOptions();

            dlo.LoadWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas);
            dlo.LoadWith <EntityInfo>(entityInfo => entityInfo.EntityDatas);
            dlo.LoadWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas);

            //dlo.AssociateWith<TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas.Where(p => p.Active));
            dlo.AssociateWith <EntityInfo>(entityInfo => entityInfo.EntityDatas.Where(p => p.Active));
            dlo.AssociateWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas.Where(p => p.Active));
            //dlo.AssociateWith<TaxonomyInfo>(taxonomyInfo => taxonomyInfo.SkuInfos.Where(p => p.Active));

            _currentDb.LoadOptions    = dlo;
            _currentDb.CommandTimeout = 2000;

            _currentDb.Connection.Open();
            _currentDb.Connection.ChangeDatabase(AryaTools.Instance.InstanceData.Dc.Connection.Database);

            _separator = AryaTools.Instance.InstanceData.CurrentProject.ListSeparator;

            StatusMessage = "Init";

            var fi = new FileInfo(ExportFileName);

            _baseFileName = fi.FullName.Replace(fi.Extension, string.Empty);

            //_taxonomyFile = new StreamWriter(_baseFileName + "_Classification.txt", false, Encoding.UTF8);
            //_taxonomyFile.WriteLine("ItemId{0}New Taxonomy{0}Node Type{0}Old Taxonomy", _delimiter);

            var exportTaxonomyIds =
                Taxonomies.Cast <ExtendedTaxonomyInfo>().Select(p => p.Taxonomy.ID).Distinct().ToList();
            var exportTaxonomies = _currentDb.TaxonomyInfos.Where(p => exportTaxonomyIds.Contains(p.ID)).ToList();

            var allExportTaxonomies =
                exportTaxonomies.SelectMany(p => p.AllChildren2).Union(exportTaxonomies).Distinct().ToList();

            var exportGroups = allExportTaxonomies.GroupBy(GetTaxPrefix).ToList();

            CurrentProgress = 0;
            MaximumProgress = exportGroups.Count();

            foreach (var grp in exportGroups)
            {
                WriteTaxonomyToFile(grp.Select(g => g), grp.Key);
                CurrentProgress++;
            }

            //_taxonomyFile.Close();

            StatusMessage = "Done!";
            State         = WorkerState.Ready;
        }
        public override void Run()
        {
            State = WorkerState.Working;
            parsedSkuExclusions = ParseSkuInclusionAndExclusions(SkuExclusions);
            parsedSkuInclusions = ParseSkuInclusionAndExclusions(SkuInclusions);
            //parsedSkuValueInclusions = ParseSkuValueInclusions(SkuValueInclusions);

            taxonomyAttributesCache = new Dictionary <Guid, List <KeyValuePair <Attribute, SchemaData> > >();
            baseAttributeNames      = new Dictionary <string, string>();
            delimiter = FieldDelimiter.GetValue().ToString();

            //Create new context
            currentDb = new SkuDataDbDataContext();
            var dlo = new DataLoadOptions();

            projectField1Name = AryaTools.Instance.InstanceData.CurrentProject.EntityField1Name ?? string.Empty;
            dlo.LoadWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas);
            dlo.LoadWith <EntityInfo>(entityInfo => entityInfo.EntityDatas);
            dlo.LoadWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas);

            dlo.AssociateWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas.Where(p => p.Active));
            dlo.AssociateWith <EntityInfo>(entityInfo => entityInfo.EntityDatas.Where(p => p.Active));
            dlo.AssociateWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas.Where(p => p.Active));
            dlo.AssociateWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.SkuInfos.Where(p => p.Active));

            currentDb.LoadOptions    = dlo;
            currentDb.CommandTimeout = 2000;

            currentDb.Connection.Open();
            currentDb.Connection.ChangeDatabase(AryaTools.Instance.InstanceData.Dc.Connection.Database);

            InitGlobals(GlobalAttributes.ToList());

            StatusMessage = "Init";

            var fi           = new FileInfo(ExportFileName);
            var baseFileName = fi.FullName.Replace(fi.Extension, string.Empty);

            attributeDataFile = new StreamWriter(baseFileName + "_AttributeData.txt", false, Encoding.UTF8);

            attributeDataFile.Write("ItemId{0}Taxonomy{0}Node Type", delimiter);
            foreach (var attribute in globalAttributeHeaders)
            {
                string attributeHeader = null;
                var    parts           = attribute.Split(':');
                var    noOfHeaders     = 0;
                if (parts.Count() > 1)
                {
                    Int32.TryParse(parts[1].Trim(), out noOfHeaders);
                }
                if (parts.Count() == 2 && noOfHeaders > 0)
                {
                    for (var i = 0; i < noOfHeaders; i++)
                    {
                        if (attributeHeader == null)
                        {
                            attributeHeader += parts[0].Trim() + (i + 1);
                        }
                        else
                        {
                            attributeHeader += "\t" + parts[0].Trim() + (i + 1);
                        }
                    }
                }
                else
                {
                    attributeHeader = attribute;
                }
                attributeDataFile.Write("{0}{1}", delimiter, attributeHeader);
            }

            attributeDataFile.WriteLine("{0}Rank 1{0}Att 1{0}Val 1{0}Uom 1{0}[...]", delimiter);

            CurrentProgress = 0;

            if (SkuCollection != null && SkuCollection.Any())
            {
                var taxonomies =
                    (SkuCollection.Split(2000)
                     .SelectMany(skus => currentDb.Skus.Where(s => skus.Contains(s.ItemID)))
                     .GroupBy(s => s.Taxonomy)).ToList();

                MaximumProgress = taxonomies.Count;

                foreach (var st in taxonomies)
                {
                    WriteSkusToFile(st.Key, st.ToList());
                    CurrentProgress++;
                }
            }
            else
            {
                var allExportTaxonomyIds =
                    Taxonomies.Cast <ExtendedTaxonomyInfo>().Select(p => p.Taxonomy.ID).Distinct().ToList();
                var exportTaxonomies         = currentDb.TaxonomyInfos.Where(p => allExportTaxonomyIds.Contains(p.ID)).ToList();
                var allExportChildTaxonomies = exportTaxonomies.SelectMany(p => p.AllChildren2).Distinct().ToList();

                MaximumProgress = allExportChildTaxonomies.Count;

                foreach (var exportChildTaxonomy in allExportChildTaxonomies)
                {
                    WriteTaxonomyToFile(exportChildTaxonomy);
                    CurrentProgress++;
                }
            }

            attributeDataFile.Close();

            StatusMessage = "Done!";
            State         = WorkerState.Ready;
        }
示例#5
0
        public override void Run()
        {
            State = WorkerState.Working;
            _parsedSkuExclusions = ParseSkuInclusionAndExclusions(SkuExclusions);
            _parsedSkuInclusions = ParseSkuInclusionAndExclusions(SkuInclusions);
            //parsedSkuValueInclusions = ParseSkuValueInclusions(SkuValueInclusions);

            _taxonomyAttributesCache = new Dictionary <Guid, List <Tuple <Attribute, decimal, decimal> > >();
            _baseAttributeNames      = new Dictionary <string, string>();
            _delimiter = FieldDelimiter.GetValue().ToString();

            //Create new context
            _currentDb = new SkuDataDbDataContext();
            var dlo = new DataLoadOptions();

            _projectField1Name = AryaTools.Instance.InstanceData.CurrentProject.EntityField1Name ?? string.Empty;
            dlo.LoadWith <TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas);
            dlo.LoadWith <EntityInfo>(entityInfo => entityInfo.EntityDatas);
            dlo.LoadWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas);

            //dlo.AssociateWith<TaxonomyInfo>(taxonomyInfo => taxonomyInfo.TaxonomyDatas.Where(p => p.Active));
            //dlo.AssociateWith<EntityInfo>(entityInfo => entityInfo.EntityDatas.Where(p => p.Active));
            dlo.AssociateWith <SchemaInfo>(schemaInfo => schemaInfo.SchemaDatas.Where(p => p.Active));
            //dlo.AssociateWith<TaxonomyInfo>(taxonomyInfo => taxonomyInfo.SkuInfos.Where(p => p.Active));

            _currentDb.LoadOptions    = dlo;
            _currentDb.CommandTimeout = 2000;

            _currentDb.Connection.Open();
            _currentDb.Connection.ChangeDatabase(AryaTools.Instance.InstanceData.Dc.Connection.Database);

            InitGlobals(GlobalAttributes);

            StatusMessage = "Init";

            var fi           = new FileInfo(ExportFileName);
            var baseFileName = fi.FullName.Replace(fi.Extension, string.Empty);

            _taxonomyFile = new StreamWriter(baseFileName + "_Classification.txt", false, Encoding.UTF8);
            _taxonomyFile.WriteLine("ItemId{0}New Taxonomy{0}Node Type{0}Old Taxonomy", _delimiter);

            _attributeDataFile = new StreamWriter(baseFileName + "_AttributeData.txt", false, Encoding.UTF8);
            if (GenerateFileWithBlankValues)
            {
                _blankValuesAttributeDataFile = new StreamWriter(baseFileName + "_AttributeBlanks.txt", false,
                                                                 Encoding.UTF8);
            }

            _attributeDataFile.Write("ItemId{0}Taxonomy{0}Node Type", _delimiter);
            if (GenerateFileWithBlankValues)
            {
                _blankValuesAttributeDataFile.Write("ItemId{0}Taxonomy{0}Node Type", _delimiter);
            }
            foreach (var attribute in _globalAttributeHeaders)
            {
                string attributeHeader = null;
                var    parts           = attribute.Split(':');
                var    noOfHeaders     = 0;
                if (parts.Count() > 1)
                {
                    Int32.TryParse(parts[1].Trim(), out noOfHeaders);
                }
                if (parts.Count() == 2 && noOfHeaders > 0)
                {
                    for (var i = 0; i < noOfHeaders; i++)
                    {
                        if (attributeHeader == null)
                        {
                            attributeHeader += parts[0].Trim() + (i + 1);
                        }
                        else
                        {
                            attributeHeader += "\t" + parts[0].Trim() + (i + 1);
                        }
                    }
                }
                else
                {
                    attributeHeader = attribute;
                }
                _attributeDataFile.Write("{0}{1}", _delimiter, attributeHeader);
                if (GenerateFileWithBlankValues)
                {
                    _blankValuesAttributeDataFile.Write("{0}{1}", _delimiter, attributeHeader);
                }
            }
            if (ExportRanks)
            {
                _attributeDataFile.Write("{0}Rank 1", _delimiter);
                if (GenerateFileWithBlankValues)
                {
                    _blankValuesAttributeDataFile.Write("{0}Rank 1", _delimiter);
                }
            }

            _attributeDataFile.Write("{0}Att 1", _delimiter);
            if (GenerateFileWithBlankValues)
            {
                _blankValuesAttributeDataFile.Write("{0}Att 1", _delimiter);
            }

            if (ExportNewValueColumn)
            {
                _attributeDataFile.Write("{0}New Value 1", _delimiter);
                if (GenerateFileWithBlankValues)
                {
                    _blankValuesAttributeDataFile.Write("{0}New Value 1", _delimiter);
                }
            }

            _attributeDataFile.Write("{0}Val 1", _delimiter);
            if (IncludeUoM)
            {
                _attributeDataFile.Write("{0}Uom 1", _delimiter);
            }
            if (IncludeField1)
            {
                _attributeDataFile.Write("{0}Field 1 1", _delimiter);
            }
            if (IncludeField2)
            {
                _attributeDataFile.Write("{0}Field 2 1", _delimiter);
            }
            if (IncludeField3)
            {
                _attributeDataFile.Write("{0}Field 3 1", _delimiter);
            }
            if (IncludeField4)
            {
                _attributeDataFile.Write("{0}Field 4 1", _delimiter);
            }
            if (IncludeField5)
            {
                _attributeDataFile.Write("{0}Field 5 1", _delimiter);
            }
            _attributeDataFile.WriteLine("{0}[...]", _delimiter);

            if (GenerateFileWithBlankValues)
            {
                _blankValuesAttributeDataFile.Write("{0}Val 1", _delimiter);
                if (IncludeUoM)
                {
                    _blankValuesAttributeDataFile.Write("{0}Uom 1", _delimiter);
                }
                if (IncludeField1)
                {
                    _blankValuesAttributeDataFile.Write("{0}Field 1 1", _delimiter);
                }
                if (IncludeField2)
                {
                    _blankValuesAttributeDataFile.Write("{0}Field 2 1", _delimiter);
                }
                if (IncludeField3)
                {
                    _blankValuesAttributeDataFile.Write("{0}Field 3 1", _delimiter);
                }
                if (IncludeField4)
                {
                    _blankValuesAttributeDataFile.Write("{0}Field 4 1", _delimiter);
                }
                if (IncludeField5)
                {
                    _blankValuesAttributeDataFile.Write("{0}Field 5 1", _delimiter);
                }
                _blankValuesAttributeDataFile.WriteLine("{0}[...]", _delimiter);
            }

            var exportTaxonomyIds =
                Taxonomies.Cast <ExtendedTaxonomyInfo>().Select(p => p.Taxonomy.ID).Distinct().ToList();
            var exportTaxonomies = _currentDb.TaxonomyInfos.Where(p => exportTaxonomyIds.Contains(p.ID)).ToList();

            var allExportTaxonomies =
                exportTaxonomies.SelectMany(p => p.AllChildren2).Union(exportTaxonomies).Distinct().ToList();

            CurrentProgress = 0;
            MaximumProgress = allExportTaxonomies.Count;

            foreach (var exportChildTaxonomy in allExportTaxonomies)
            {
                WriteTaxonomyToFile(exportChildTaxonomy);
                CurrentProgress++;
            }

            _taxonomyFile.Close();
            _attributeDataFile.Close();
            if (GenerateFileWithBlankValues)
            {
                _blankValuesAttributeDataFile.Close();
            }

            StatusMessage = "Done!";
            State         = WorkerState.Ready;
        }