예제 #1
0
        public IArticle RefreshOrCreateEbayArticle(IArticle article, EbayArticleCSVWriter cswWriter, double amount, string template)
        {
            IArticle newArticle = null;

            currentAmount = amount;

            var availabilityMap = GetAvailabilityMap(article);

            foreach (var availabilityPair in availabilityMap)
            {
                if (article.EbayIds.ContainsKey(availabilityPair.Key))
                {
                    newArticle = ReviseEbayArticle(article, availabilityPair);
                    continue;
                }
                if (availabilityPair.Value == 0)
                {
                    continue;
                }
                newArticle = LoadUpNewSingleArticle(article, template, availabilityPair);
            }

            cswWriter.WriteToCSVFile(newArticle);
            return(newArticle);
        }
        private void UploadCurrentListToEbay()
        {
            double amount;

            if (!DoubleChecker.IsValidDouble(EbayArticleAmount, out amount))
            {
                MessageBox.Show("Bitte geben Sie einen gültigen Gewinn ein. In der Form 4,5");
                return;
            }

            IsUploadingToEbay = true;
            var bw = new BackgroundWorker();

            try
            {
                bw.DoWork += delegate
                {
                    string template = TemplateLoader.LoadTemplateFromUri(ConfigurationManager.AppSettings["Ebay.Template"]);
                    var    ebaySingleArticleCsvWriter = new EbayArticleCSVWriter(baseFileName + ".diffs");
                    CountOfCurrentUploadedItems = 0;
                    var allArticles = IterateThroughAllItemsAndUploadThem(GetOriginalArticles(), ebaySingleArticleCsvWriter, amount, template);
                    WriteAllArticlesBackToCSV(new List <IArticle>(allArticles));
                    IsUploadingToEbay = false;
                };
                bw.RunWorkerAsync();
            }
            catch (Exception e)
            {
                logger.Error("Schwerer Fehler beim Hochladen", e);
                MessageBox.Show("Es ist ein unbekannter Fehler beim Hochladen auf Ebay aufgetreten: " + e.Message);
            }
        }
        private static void WriteAllArticlesBackToCSV(List <IArticle> articles)
        {
            var ebayArticleCsvWriter = new EbayArticleCSVWriter(baseFileName);

            ebayArticleCsvWriter.WriteToCSVFile(articles);
        }
 private Dictionary <string, IArticle> .ValueCollection IterateThroughAllItemsAndUploadThem(Dictionary <string, IArticle> dictionary,
                                                                                            EbayArticleCSVWriter ebaySingleArticleCsvWriter, double amount,
                                                                                            string template)
 {
     foreach (var articleToUpload in WheelListFlat)
     {
         IArticle result = null;
         try
         {
             result = ebayUploader.RefreshOrCreateEbayArticle(articleToUpload,
                                                              ebaySingleArticleCsvWriter, amount,
                                                              template);
             var key = ArticleKeyGenerator.GetKeyFromArticle(articleToUpload);
             if (dictionary.ContainsKey(key))
             {
                 dictionary.Remove(key);
             }
             dictionary[key] = result;
         }
         catch (ApiException e)
         {
             logger.Warn(
                 "Fehler bei Ebay Kommunikation von Datensatz ID:" + articleToUpload.ArticleId, e);
         }
         catch (Exception e)
         {
             logger.Error("Unknown Exception On Uploading articles", e);
             break;
         }
         CountOfCurrentUploadedItems++;
     }
     return(dictionary.Values);
 }