Пример #1
0
        //Методот по события нажатия кнопки
        private void OneLinkEbay()
        {
            try
              {
            var id = Convert.ToInt64(Regex.Match(URLLink, "\\d{7,}").Value);
            var imgParser = new EbayLoadImage(new WebCl(), Properties.Default.PathToImg, mySqlDB, Properties.Default.FtpUsername, Properties.Default.FtpPassword);
            var parsedItems = SearchApi.ParseItems(new long[] { id });

            mySqlDB.InsertFctEbayGrabber(parsedItems, cbCategories.Text);
            var isAuction = true;

            ImageParsedCountHelper imageCount = null;

            if (parsedItems != null && parsedItems.Item != null && parsedItems.Item.Count() > 0)
            {
              imageCount = imgParser.LoadImages(parsedItems.Item[0].PictureURL);
              AddLog("Parser: " + imageCount.CountParsed + " images parsed", LogMessageColor.Information());
              AddLog("Parser: " + imageCount.CountDownloaded + " images downloaded", LogMessageColor.Information());
              foreach (var error in imageCount.ErrorList)
            AddLog(error.Key, error.Value == true ? LogMessageColor.Error() : LogMessageColor.Success());
              isAuction = (parsedItems.Item[0].TimeLeft != null && parsedItems.Item[0].ListingType != "FixedPriceItem");
            }

            var idResourceList = mySqlDB.ResourceListIDEbay();
            imageCount.ResourceId = idResourceList;
            if (imageCount != null)
            {
              foreach (var im in imageCount.Resources)
            mySqlDB.InsertassGrabberEbayResourceList(idResourceList, im);
              mySqlDB.UpdateFctEbayGrabberPhotoCount(idResourceList, imageCount.Resources.Count);
            }

            if (!isAuction)
              mySqlDB.ExecuteProcEBay(mySqlDB.ResourceListIDEbay());
              }
              catch (Exception ex)
              {
            AddLog("Parser: " + ex.Message, LogMessageColor.Error());
              }
        }
Пример #2
0
        private void LoadSectionEbay(SectionItem sectionItem)
        {
            while (EbayState.Pausing || EbayState.Paused)
              {
            if (EbayState.Pausing)
            {
              AddLog(string.Empty, LogMessageColor.Information());
              AddLog("Paused", LogMessageColor.Information());
              AddLog(string.Empty, LogMessageColor.Information());
            }
            EbayState.SetPaused();
            if (AvitoState.Pausing || AvitoState.Paused)
            {
              btnParsingAvitoEbayStart.SetPropertyThreadSafe(() => btnParsingAvitoEbayStart.Enabled, true);
              btnParsingAvitoEbayPause.SetPropertyThreadSafe(() => btnParsingAvitoEbayPause.Enabled, false);
              btnParsingAvitoEbayStop.SetPropertyThreadSafe(() => btnParsingAvitoEbayStop.Enabled, true);
            }
            else
            {
              btnParsingEbayStart.SetPropertyThreadSafe(() => btnParsingEbayStart.Enabled, true);
              btnParsingEbayPause.SetPropertyThreadSafe(() => btnParsingEbayPause.Enabled, false);
              btnParsingEbayStop.SetPropertyThreadSafe(() => btnParsingEbayStop.Enabled, true);
            }
            Thread.Sleep(1000);
              }

              if (EbayState.Stopping || EbayState.Stopped)
            return;

              var cryticalCount = 8;
              var searchApi = new SearchApi();
              searchApi.PerPage = 100;
              searchApi.Section = sectionItem.Link;

              AddLog("Parser: " + sectionItem.CategoryName, LogMessageColor.Information());

              try
              {
            var ids = searchApi.SearchLinks();
            AddLog("Parser: Count new ad: " + ids.Count().ToString(), LogMessageColor.Information());
            IList<long> newIds = new List<long>();
            var countCurrentRepeat = 0;

            foreach (var item in ids)
            {
              if (countCurrentRepeat > cryticalCount)
            break;
              if (mySqlDB.IsNewAdEbay(item))
            newIds.Add(item);
              else
            countCurrentRepeat++;
            }

            var partsIdsCollection = Helpful.Partition(newIds, 1);
            AddLog("Parser: Prepared insert to db", LogMessageColor.Information());

            var imgParser = new EbayLoadImage(new WebCl(), Properties.Default.PathToImg, mySqlDB, Properties.Default.FtpUsername, Properties.Default.FtpPassword);

            foreach (var item in partsIdsCollection)
            {
              while (EbayState.Pausing || EbayState.Paused)
              {
            if (EbayState.Pausing)
            {
              AddLog(string.Empty, LogMessageColor.Information());
              AddLog("Paused", LogMessageColor.Information());
              AddLog(string.Empty, LogMessageColor.Information());
            }
            EbayState.SetPaused();
            if (AvitoState.Pausing || AvitoState.Paused)
            {
              btnParsingAvitoEbayStart.SetPropertyThreadSafe(() => btnParsingAvitoEbayStart.Enabled, true);
              btnParsingAvitoEbayPause.SetPropertyThreadSafe(() => btnParsingAvitoEbayPause.Enabled, false);
              btnParsingAvitoEbayStop.SetPropertyThreadSafe(() => btnParsingAvitoEbayStop.Enabled, true);
            }
            else
            {
              btnParsingEbayStart.SetPropertyThreadSafe(() => btnParsingEbayStart.Enabled, true);
              btnParsingEbayPause.SetPropertyThreadSafe(() => btnParsingEbayPause.Enabled, false);
              btnParsingEbayStop.SetPropertyThreadSafe(() => btnParsingEbayStop.Enabled, true);
            }
            Thread.Sleep(1000);
              }

              if (EbayState.Stopping || EbayState.Stopped)
            break;

              AddLog("Parser: Begin parsing ad", LogMessageColor.Information());
              var parsedItems = SearchApi.ParseItems(item);
              foreach (var unit in parsedItems.Item)
              {
            AddLog(string.Format("{0,-15} - {1}", "url: ", unit.ViewItemURLForNaturalSearch), LogMessageColor.Information());
            AddLog(string.Format("{0,-15} - {1}", "title: ", unit.Title), LogMessageColor.Information());
            AddLog(string.Format("{0,-15} - {1}", "cost: ", unit.CurrentPrice.Value.ToString()), LogMessageColor.Information());
            AddLog(string.Format("{0,-15} - {1}", "country: ", unit.Country), LogMessageColor.Information());
            AddLog(string.Format("{0,-15} - {1}", "city: ", unit.Location), LogMessageColor.Information());
            AddLog(string.Format("{0,-15} - {1}", "author: ", unit.Seller.UserID), LogMessageColor.Information());
            AddLog(string.Format("{0,-15} - {1}", "ebay section: ", unit.PrimaryCategoryName), LogMessageColor.Information());
              }
              var isAuction = true;
              ImageParsedCountHelper imageCount = null;
              if (parsedItems != null && parsedItems.Item != null && parsedItems.Item.Count() > 0)
              {
            if (Properties.Default.PublishParsedData)
            {
              AddLog("Parser: Begin loading images", LogMessageColor.Information());
              try
              {
                imageCount = imgParser.LoadImages(parsedItems.Item[0].PictureURL);
                AddLog("Parser: " + imageCount.CountParsed + " images parsed", LogMessageColor.Information());
                AddLog("Parser: " + imageCount.CountDownloaded + " images downloaded", LogMessageColor.Information());
                foreach (var error in imageCount.ErrorList)
                  AddLog(error.Key, error.Value == true ? LogMessageColor.Error() : LogMessageColor.Success());
              }
              catch (Exception ex)
              {
                AddLog("Parser: " + ex.Message, LogMessageColor.Error());
              }
              AddLog("Parser: End loading images", LogMessageColor.Information());
            }
            isAuction = (parsedItems.Item[0].TimeLeft != null && parsedItems.Item[0].ListingType != "FixedPriceItem");
            if (isAuction)
              AddLog("Parser: It is auction", LogMessageColor.Information());
            else
              AddLog("Parser: It is advertisement", LogMessageColor.Information());
              }
              AddLog("Parser: End parsing ad", LogMessageColor.Information());
              IncParsed();

              AddLog("Parser: sleep after parse on. " + Properties.Default.SleepAfterParseSec + " sec", LogMessageColor.Information());
              Thread.Sleep(Properties.Default.SleepAfterParseSec * 1000);
              AddLog("Parser: sleep after parse off", LogMessageColor.Information());

              AddLog("Parser: preparing ad to insert to db", LogMessageColor.Information());
              var idResourceList = mySqlDB.ResourceListIDEbay();
              imageCount.ResourceId = idResourceList;
              try
              {
            mySqlDB.InsertFctEbayGrabber(parsedItems, sectionItem.CategoryName);
            if (imageCount != null)
            {
              foreach (var im in imageCount.Resources)
                mySqlDB.InsertassGrabberEbayResourceList(idResourceList, im);
              mySqlDB.UpdateFctEbayGrabberPhotoCount(idResourceList, imageCount.Resources.Count);
            }
            if (Properties.Default.PublishParsedData && !isAuction)
            {
              AddLog("Parser: Begin publishing ad", LogMessageColor.Information());
              mySqlDB.ExecuteProcEBay(idResourceList);
              AddLog("Parser: End publishing ad", LogMessageColor.Information());

              AddLog("Parser: sleep after publication on. " + Properties.Default.SleepSecAfterPublicationSec + " sec", LogMessageColor.Information());
              Thread.Sleep(Properties.Default.SleepSecAfterPublicationSec * 1000);
              AddLog("Parser: sleep after publication off", LogMessageColor.Information());
            }
            AddLog("Parser: ad inserted", LogMessageColor.Information());
            incInserted();
              }
              catch (Exception ex)
              {
            AddLog("Parser: " + ex.Message, LogMessageColor.Error());
              }
              AddLog(string.Empty, LogMessageColor.Information());
            }

            AddLog("Parser: End pasring section " + sectionItem.CategoryName, LogMessageColor.Information());
            AddLog("Parser: Inserted: " + newIds.Count().ToString(), LogMessageColor.Information());
              }
              catch (Exception ex)
              {
            AddLog("Parser: " + ex.Message, LogMessageColor.Error());
              }
        }