Example #1
0
        private static void ExecuteLegrandOperations(string excelPath, int startIndex, int endIndex)
        {
            var wb            = ExcelUtilities.CreateWorkbook(excelPath);
            var excelSheet    = ExcelUtilities.SelectExcelSheet(wb, "Legrand");
            var eanDictionary = new Dictionary <string, string>();

            ExcelUtilities.ReadFromExcel(eanDictionary, excelSheet, startIndex, endIndex);
            var copiedDict = eanDictionary.ToDictionary(entry => entry.Key,
                                                        entry => entry.Value);
            var fieldsDict = new Dictionary <string, int>();

            foreach (var ean in eanDictionary.Keys)
            {
                var legrand         = new Legrand();
                var unprocessedHtml = HtmlHandler.GetUnprocessedHtml("Legrand", ean);
                List <Dictionary <string, string> > fieldCollections = new List <Dictionary <string, string> >();
                try
                {
                    copiedDict = legrand.GetMasterData(unprocessedHtml, ean).ToDictionary(k => k.Key, v => v.Value);
                }
                catch (Exception)
                {
                    startIndex++;
                    continue;
                }

                fieldCollections.Add(legrand.GetProductChars(unprocessedHtml, ean));
                fieldCollections.Add(legrand.GetGeneralChars(unprocessedHtml, ean));
                fieldCollections.Add(legrand.GetMoreInfo(unprocessedHtml, ean, 0));
                fieldCollections.Add(legrand.GetMoreInfo(unprocessedHtml, ean, 1));
                fieldCollections.Add(legrand.GetPicture(unprocessedHtml, ean));

                copiedDict = fieldCollections
                             .Where(fieldCollection => fieldCollection != null)
                             .Aggregate(copiedDict, (current, fieldCollection) => current.Union(fieldCollection).ToDictionary(k => k.Key, v => v.Value));

                Console.WriteLine(startIndex + ". " + ean + " downloaded");

                charDB.AddDic(copiedDict);

                foreach (var entry in copiedDict)
                {
                    var fieldIndex = 0;
                    if (!fieldsDict.ContainsKey(entry.Key))
                    {
                        fieldsDict.Add(entry.Key, 7 + fieldsDict.Count);
                    }

                    fieldIndex = fieldsDict[entry.Key];
                    excelSheet.Cells.WrapText                      = true;
                    excelSheet.Cells[1, fieldIndex].Value          = entry.Key;
                    excelSheet.Cells[startIndex, fieldIndex].Value = entry.Value;
                }
                Console.WriteLine(startIndex + ". " + ean + " written");
                startIndex++;
            }

            wb.Close();
        }
Example #2
0
        private static void ExecuteKnipexOperations(string excelPath, int startIndex, int endIndex)
        {
            var wb            = ExcelUtilities.CreateWorkbook(excelPath);
            var excelSheet    = ExcelUtilities.SelectExcelSheet(wb, "Knipex");
            var eanDictionary = new Dictionary <string, string>();

            ExcelUtilities.ReadFromExcel(eanDictionary, excelSheet, startIndex, endIndex);
            var copiedDict = eanDictionary.ToDictionary(entry => entry.Key,
                                                        entry => entry.Value);
            var fieldsDict = new Dictionary <string, int>();

            foreach (var ean in eanDictionary.Keys)
            {
                var    knipex        = new Knipex();
                var    newEan        = ean.Remove(0, 1);
                string knipexFullUrl = knipex.GetProductUrl(newEan);
                if (string.IsNullOrEmpty(knipexFullUrl))
                {
                    copiedDict[ean] = null;
                    startIndex++;
                    continue;
                }
                var unprocessedHtml  = HtmlHandler.GetUnprocessedHtml("Knipex", knipexFullUrl);
                var unprocessedHtml2 = knipex.GetFinalSearchresult(unprocessedHtml, newEan);
                List <Dictionary <string, string> > fieldCollections = new List <Dictionary <string, string> >();
                if (unprocessedHtml2 == null)
                {
                    unprocessedHtml2 = unprocessedHtml;
                }
                copiedDict = knipex.GetTechData(unprocessedHtml2, ean).ToDictionary(k => k.Key, v => v.Value);

                fieldCollections.Add(knipex.GetDescription(unprocessedHtml2, ean));
                fieldCollections.Add(knipex.GetPicture(unprocessedHtml2, ean));
                //fieldCollections.Add(knipex.GetApplications(unprocessedHtml, ean));

                copiedDict = fieldCollections
                             .Where(fieldCollection => fieldCollection != null)
                             .Aggregate(copiedDict, (current, fieldCollection) => current.Union(fieldCollection).ToDictionary(k => k.Key, v => v.Value));

                Console.WriteLine(startIndex + ". " + ean + " downloaded");

                charDB.AddDic(copiedDict);

                foreach (var entry in copiedDict)
                {
                    var fieldIndex = 0;
                    if (!fieldsDict.ContainsKey(entry.Key))
                    {
                        fieldsDict.Add(entry.Key, 7 + fieldsDict.Count);
                    }

                    fieldIndex = fieldsDict[entry.Key];
                    excelSheet.Cells.WrapText                      = true;
                    excelSheet.Cells[1, fieldIndex].Value          = entry.Key;
                    excelSheet.Cells[startIndex, fieldIndex].Value = entry.Value;
                }
                Console.WriteLine(startIndex + ". " + ean + " written");
                startIndex++;
            }

            wb.Close();
        }
Example #3
0
        private static void ExecuteBsOperations(string path, int startIndex, int endIndex)
        {
            var wb            = ExcelUtilities.CreateWorkbook(path);
            var excelSheet    = ExcelUtilities.SelectExcelSheet(wb, "Brennenshtuhl");
            var eanDictionary = new Dictionary <string, string>();

            ExcelUtilities.ReadFromExcel(eanDictionary, excelSheet, startIndex, endIndex);
            var copiedDict = eanDictionary.ToDictionary(entry => entry.Key,
                                                        entry => entry.Value);
            var fieldsDict = new Dictionary <string, int>();

            foreach (var ean in eanDictionary.Keys)
            {
                var bs = new Brennenstuhl();

                //get link
                string bsFullUrl = bs.GetProductUrl(ean);
                if (string.IsNullOrEmpty(bsFullUrl))
                {
                    copiedDict[ean] = null;
                    startIndex++;
                    continue;
                }
                //get link end

                var unprocessedHtml = HtmlHandler.GetUnprocessedHtml("Brennenstuhl", bsFullUrl);
                List <Dictionary <string, string> > fieldCollections = new List <Dictionary <string, string> >();
                try
                {
                    copiedDict = bs.GetTechData(unprocessedHtml, ean).ToDictionary(k => k.Key, v => v.Value);
                }
                catch (Exception)
                {
                    startIndex++;
                    continue;
                }

                fieldCollections.Add(bs.GetDownloads(unprocessedHtml, ean));
                fieldCollections.Add(bs.GetPicture(unprocessedHtml, ean));

                copiedDict = fieldCollections
                             .Where(fieldCollection => fieldCollection != null)
                             .Aggregate(copiedDict, (current, fieldCollection) => current.Union(fieldCollection).ToDictionary(k => k.Key, v => v.Value));

                Console.WriteLine(startIndex + ". " + ean + " downloaded");

                charDB.AddDic(copiedDict);

                foreach (var entry in copiedDict)
                {
                    var fieldIndex = 0;
                    if (!fieldsDict.ContainsKey(entry.Key))
                    {
                        fieldsDict.Add(entry.Key, 7 + fieldsDict.Count);
                    }

                    fieldIndex = fieldsDict[entry.Key];
                    excelSheet.Cells.WrapText                      = true;
                    excelSheet.Cells[1, fieldIndex].Value          = entry.Key;
                    excelSheet.Cells[startIndex, fieldIndex].Value = entry.Value;
                }
                Console.WriteLine(startIndex + ". " + ean + " written");
                startIndex++;
            }

            wb.Close();
        }