Exemplo n.º 1
0
        public void Create()
        {
            lines = new List <ImportLine>();

            partner = partnerRepository.GetByCode(feedImporter.PartnerCode);

            trends         = new List <Trend>(trendRepository.GetCurrentTrends());
            silouhettes    = new List <Silouhette>(silouhetteRepository.GetAll());
            patterns       = new List <Pattern>(patternRepository.GetAll());
            colorFamilies  = new List <ColorFamily>(colorFamilyRepository.GetAll());
            outfitUpdaters = new List <OutfitUpdater>(outfitUpdaterRepository.GetFor(partner));

            // Retrieve Keywords
            colorFamilyKeywords = colorFamilyRepository.GetKeywordsByPartner(partner);
            patternKeywords     = patternRepository.GetKeywordsByPartner(partner);
            silouhetteKeywords  = silouhetteRepository.GetKeywordsByPartner(partner);

            // Set discard words
            wordsForDiscard.Add("men");
            wordsForDiscard.Add("mens");
            wordsForDiscard.Add("men's");
            wordsForDiscard.Add("men´s");
            wordsForDiscard.Add("kid");
            wordsForDiscard.Add("kids");
            wordsForDiscard.Add("kid's");
            wordsForDiscard.Add("infant");
            wordsForDiscard.Add("girl");
            wordsForDiscard.Add("boy");
            wordsForDiscard.Add("girls");
            wordsForDiscard.Add("boys");
            wordsForDiscard.Add("girl’s");
            wordsForDiscard.Add("boy’s");
            wordsForDiscard.Add("girl's");
            wordsForDiscard.Add("boy's");
            wordsForDiscard.Add("Toddler");
            wordsForDiscard.Add("4-6X");
            wordsForDiscard.Add("Newborn");
            wordsForDiscard.Add("Bedding Collection");
            wordsForDiscard.Add("Sleep Sense");
            wordsForDiscard.Add("7-16");
            wordsForDiscard.Add("Pajamas");
            wordsForDiscard.Add("Bra");
            wordsForDiscard.Add("Hipster");
            wordsForDiscard.Add("8-20");
            wordsForDiscard.Add("swimsuit");
            wordsForDiscard.Add("luggage");
            wordsForDiscard.Add("table linens");
            wordsForDiscard.Add("2T-10");
            wordsForDiscard.Add("China");
            wordsForDiscard.Add("stemwear");
            wordsForDiscard.Add("cuff links");
            wordsForDiscard.Add("Noritake");
            wordsForDiscard.Add("Jasmine & Ginger");

            _logger.InfoFormat("Looping through file");
            feedImporter.FeedLineRead += new FeedLineReadEventHandler(ouImportationClassBuilder_FeedLineRead);
            feedImporter.ProcessFeed();

            CheckToSaveLines();
        }
        public void Create()
        {
            InitializePerformanceCounters();
            if (ramCounter.NextValue() < (ramTotal * MemorySafe))
            {
                WriteInfo(string.Format("Safe Memory Limit"), string.Format("Available = {0} < Safe Limit = {1}MB", getAvailableRAM(), ramTotal * MemorySafe));
                return;
            }

            DateTime startTime    = DateTime.Now;
            int      totalRecords = 0;

            lines = new List <OUImportationLine>();

            // TODO: Fetch keywords to make it faster on the loops.
            trends         = new List <Trend>(trendRepository.GetAll());
            silouhettes    = new List <Silouhette>(silouhetteRepository.GetAll());
            patterns       = new List <Pattern>(patternRepository.GetAll());
            colorFamilies  = new List <ColorFamily>(colorFamilyRepository.GetAll());
            outfitUpdaters = new List <OutfitUpdater>(outfitUpdaterRepository.GetFor(Partner));
            wordsForDiscard.Add(" men");
            wordsForDiscard.Add(" mens");
            wordsForDiscard.Add(" men's");
            wordsForDiscard.Add(" men´s");
            wordsForDiscard.Add("kid");
            wordsForDiscard.Add("kids");
            wordsForDiscard.Add("kid's");
            wordsForDiscard.Add("kid´s");

            // Retrieve Keywords
            // TODO: Limit by partner
            colorFamilyKeywords = new Repository <ColorFamilyKeywordsByPartner>().GetAll();
            patternKeywords     = new Repository <PatternKeywordsByPartner>().GetAll();
            silouhetteKeywords  = new Repository <SilouhetteKeywordsByPartner>().GetAll();

            Write("--------------------------------------------------------------------------------");
            Write(string.Format("{0} - {1}\t\t{2}\t\t{3}\t{4}\t{5}", "Time", "Process Type", "Action", "CPU Usage", "RAM Available(MB)", "Records OK"));
            WriteFullInfo("Start");

            //REVIEW: The ZapposClassBuilder should read the file and create an event for the loop, returning an
            //REVIEW: understandable object that we can interchange when we have another builder. This way we can not
            //REVIEW: change the builder in a truly manner. Right now, is kind of complex and not clear how to change it.
            //REVIEW: That way is simple to change from reading from a file or other providers.
            //REVIEW: This class should worry about checking if the line is valid and import it in our system.
            DelimitedClassBuilder cb = ouImportationClassBuilder.CreateClassBuilder(Separator, HaveHeader);

            //REVIEW: Why is these here? We always read line at line.
            if (Sync)
            {
                FileHelperEngine engine = new FileHelperEngine(cb.CreateRecordClass());
                object[]         items  = engine.ReadFile(path + Filename);
                totalRecords = items.Length;
                WriteFullInfo("Ready");

                for (int i = 0; i < items.Length; i++)
                {
                    actualLine = i;
                    if (HaveHeader)
                    {
                        actualLine++;
                    }

                    ProcessOUImportationLine(items[i]);

                    CheckLimits();
                }
            }
            else
            {
                FileHelperAsyncEngine engine = new FileHelperAsyncEngine(cb.CreateRecordClass());
                engine.BeginReadFile(path + Filename);
                WriteFullInfo("Ready");

                while (engine.ReadNext() != null)
                {
                    actualLine = totalRecords + 1;
                    if (HaveHeader)
                    {
                        actualLine++;
                    }

                    ProcessOUImportationLine(engine.LastRecord);

                    CheckLimits();
                    totalRecords++;
                }

                ProcessList();
            }

            DateTime endTime = DateTime.Now;
            TimeSpan span    = endTime - startTime;

            WriteFullInfo("Finish");
            Write("--------------------------------------------------------------------------------");
            Write(string.Format("{0} - {1} {2} {3} records in {4} seconds", endTime.ToLongTimeString(), Process, "Finish", totalRecords, span.TotalSeconds.ToString("0")));
            WriteInfo("Total lines added/modified", linesOk.Count.ToString());
            WriteInfo("Total errors", TotalErrors.ToString());
            //WriteInfo("Lines with errors", string.Join(",", linesWithErrors.ToArray()));
            Write("--------------------------------------------------------------------------------");
        }