Esempio n. 1
0
        public void Execute(object parameter)
        {
            combinationKeys = new List <string>();

            string inputFileChosenPath   = parent.InputFileProcessingLabelData;
            string proxiesFileChosenPath = parent.ProxiesFileProcessingLabelData;

            if (string.IsNullOrEmpty(inputFileChosenPath))
            {
                return;
            }
            inputFileChosenPath = inputFileChosenPath.Trim();

            Dispatcher.CurrentDispatcher.Invoke(() =>
            {
                parent.FileProcessingLabelData = StringConsts.FileProcessingLabelData_Processing;
            }, DispatcherPriority.DataBind);

            var titles = FilesHelper.ConvertCSVtoListofTitles(inputFileChosenPath);

            WebHelper.Proxies = FilesHelper.ConvertProxyFileToDictionary(proxiesFileChosenPath);
            var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();

            Task.Factory.StartNew(() =>
            {
                List <Task> TaskList = new List <Task>();
                foreach (var title in titles)
                {
                    var LastTask = new Task(() =>
                    {
                        scrapeDataFromMerchantWord(title);
                    });
                    LastTask.Start();
                    TaskList.Add(LastTask);
                }
                Task.WaitAll(TaskList.ToArray());
            }).ContinueWith((action) =>
            {
                ParallelQueue(combinationKeys).GetAwaiter().GetResult();
            }).ContinueWith((action) =>
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Combination;ASIN;Volume");
                foreach (var item in WebHelper.ResultList)
                {
                    sb.AppendLine(string.Format("{0};{1};{2}",
                                                item.Combination,
                                                item.ASIN,
                                                item.Price));
                }
                File.WriteAllText(Path.Combine(parent.ResultFolderLabelData, "AmazonData.csv"), sb.ToString());
                Dispatcher.CurrentDispatcher.Invoke(() =>
                {
                    parent.FileProcessingLabelData = StringConsts.FileProcessingLabelData_Finish;
                    Console.WriteLine(StringConsts.FileProcessingLabelData_Finish);
                }, DispatcherPriority.DataBind);
            }, uiScheduler);
        }