Beispiel #1
0
        //static string sampleOGRN = "1026104027388"; // сбивающие <>
        //static string sampleOGRN = "1027700132195"; // СБЕР
        //static string sampleOGRN = "1025300780295"; // Контур
        //static string sampleOGRN = "1077763213000"; // мало информации
        //static string sampleOGRN = "1097760000458"; // мало инфы
        //static string sampleOGRN = "1037739872939"; // с предыдущими адресами
        //static string sampleOGRN = "1057747421247"; // полная история
        //static string sampleOGRN = "1022501302834"; // с ОФИСОМ!
        //static string sampleOGRN = "1022501302966"; //  два директора

        private static void getOneCompanyInfo()
        {
            var page        = WebWorker.GetPage(sampleOGRN /*, ProxyProvider.GetRandomProxy()*/);
            var companyInfo = Parser.Parse(page);

            //DataBaseManager.InsertData(companyInfo);
            showResult(companyInfo);
        }
Beispiel #2
0
        static void collectData()
        {
            string ogrn;

            while (!string.IsNullOrEmpty(ogrn = inputDataManager.GetNextLine()))
            {
                int      errorsCount = 0;
                var      nextStep    = NeedTo.Download;
                bool     isComplete  = false;
                WebProxy proxy       = new WebProxy();
                var      companyInfo = new CompanyInfo();
                string   page        = default(string);

                while (!isComplete)
                {
                    try
                    {
                        if (nextStep == NeedTo.Download)
                        {
                            proxy    = ProxyProvider.GetProxy();
                            page     = WebWorker.GetPage(ogrn, proxy);
                            nextStep = NeedTo.Parse;
                        }

                        if (nextStep == NeedTo.Parse)
                        {
                            companyInfo = Parser.Parse(page);
                            nextStep    = NeedTo.Insert;
                        }

                        if (nextStep == NeedTo.Insert)
                        {
                            DataBaseManager.InsertData(companyInfo);
                        }

                        isComplete = inputDataManager.Log(ogrn, InputDataManager.Status.Succes);
                    }
                    catch (Exception ex)
                    {
                        errorsCount++;

                        if (errorsCount > maxErrors)
                        {
                            isComplete = inputDataManager.Log(ogrn, InputDataManager.Status.Error, ex);
                        }
                        else
                        {
                            if (ex.Message.Contains("String or binary data would be truncated.")) // слишком длинное значение (обычно, названия)
                            {
                                isComplete = inputDataManager.Log(ogrn, InputDataManager.Status.Error, ex);
                            }
                            else if (ex.Message.Contains("Слишком много запросов к серверу.")) // TODO: обработать бан
                            {
                                //ProxyProvider.MarkAsBanned(proxy);
                                Console.WriteLine(ex.Message + "Меняем прокси и пробуем ещё.");
                            }
                            else if (ex.Message.Contains("Не найдена организация или индивидуальный предприниматель"))
                            {
                                isComplete = inputDataManager.Log(ogrn, InputDataManager.Status.NotFound);
                            }
                            else if (ex.Message.Contains("Невозможно разрешить удаленное имя:")) // TODO: обработать отсутствие интернета
                            {
                                Console.WriteLine(errorsCount + " " + ogrn + " " + ex.Message + " " + ex.StackTrace + Environment.NewLine);
                            }
                            else if (ex.StackTrace.Contains("строка 31"))
                            {
                                Console.WriteLine(errorsCount + " " + ogrn + " " + "WW" + " " + ex.Message);
                            }
                            else
                            {
                                Console.WriteLine(errorsCount + " " + ogrn + " " + ex.Message + " " + ex.StackTrace + Environment.NewLine);
                            }
                        }
                    }

                    delay(1, 2, ValueOfTime.Seconds, errorsCount);
                }
            }
        }