Пример #1
0
 private void toolStripDeleteProducts_Click(object sender, EventArgs e)
 {
     // background DELETING is locked for cancel and if during deleting user shift "ProgressBar" to another bg operation it is impossible to return to deleting progressbar.
     // after finish DELETING BalloonTip will be displayed
     try
     {
         DataGridViewRow selectedRow  = dataGridView1.SelectedRows[0];
         var             selectedFeed = selectedRow.DataBoundItem as Feed;
         var             vendorId     = selectedFeed.VendorId;
         string          keyDownload  = "DELETE_" + selectedFeed.Name;
         if (!bgw.Keys.Contains(keyDownload))
         {
             context = new SelectedHotelsEntities();
             feed    = context.Feeds.SingleOrDefault(f => f.Id == selectedFeed.Id);
             bgProcesses.Add(keyDownload, feed);
             workD     = new BackGroundWorkerDelegateWork(DeleteProducts);
             progressD = new BackGroundWorkerDelegateProgress(backgroundWorkerProgressChanged);
             completeD = new BackGroundWorkerDelegateCompleted(backgroundWorkerRunWorkerCompleted);
             bgw.Add(keyDownload, AddBackGroundWorker(workD, progressD, completeD));
             bgProgress.Add(keyDownload, 0);
             activeStep = "Deleting products...";
             bgStep.Add(keyDownload, activeStep);
             bgw[keyDownload].RunWorkerAsync(vendorId);
         }
         activeKey = keyDownload;
         // display status
         ShiftStatusStripToActiveBackgroudWorker(bgw.Count, activeKey, activeStep, bgw[activeKey].IsBusy, bgProgress[activeKey]);
     }
     catch (Exception exception)
     {
         activeStep = exception.Message;
     }
 }
Пример #2
0
        // Create new BackgroundWorker
        private BackgroundWorker AddBackGroundWorker(BackGroundWorkerDelegateWork bgwDoWork,
                                                     BackGroundWorkerDelegateProgress bgwProgressChanged,
                                                     BackGroundWorkerDelegateCompleted bgwRunWorkerCompleted)
        {
            BackgroundWorker backgroundWorker = new BackgroundWorker();

            backgroundWorker.DoWork                    += new DoWorkEventHandler(bgwDoWork);
            backgroundWorker.ProgressChanged           += new ProgressChangedEventHandler(bgwProgressChanged);
            backgroundWorker.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(bgwRunWorkerCompleted);
            backgroundWorker.WorkerReportsProgress      = true;
            backgroundWorker.WorkerSupportsCancellation = true;
            return(backgroundWorker);
        }
Пример #3
0
        private void StartWorkerProcess(int?stepImport = null, int?stepAddToCategories = null, int?stepAddImages = null)
        {
            string keyDownload;

            foreach (DataGridViewRow selectedRow in dataGridView1.SelectedRows)
            {
                var selectedFeed = selectedRow.DataBoundItem as Feed;
                keyDownload = selectedFeed.Name;
                if (!bgw.Keys.Contains(keyDownload))
                {
                    context = new SelectedHotelsEntities();
                    feed    = context.Feeds.SingleOrDefault(f => f.Id == selectedFeed.Id);
                    bgProcesses.Add(keyDownload, feed);
                    // set parameters for background process here if lists of parameters are the same for different rows in Feeds
                    // if it is necessary send different parameter`s list to background operation, assign parameters in block
                    // 'switch' as well as set 'BackGroundWorkerDelegateWork' for each row in Feeds
                    BackgroundWorkParameters bgParams = new BackgroundWorkParameters();
                    bgParams.Url = selectedFeed.URL;
                    if (!String.IsNullOrEmpty(selectedFeed.Category))
                    {
                        using (SelectedHotelsEntities db = new SelectedHotelsEntities())
                        {
                            var category = db.Categories.SingleOrDefault(c => c.Name == selectedFeed.Category);
                            if (category != null)
                            {
                                bgParams.CategoryId = category.Id;
                            }
                            else
                            {
                                category      = new Category();
                                category.Name = selectedFeed.Category;
                                db.Categories.Add(category);
                                db.SaveChanges();
                                bgParams.CategoryId = category.Id;
                            }
                        }
                    }
                    bgParams.PortalId             = selectedFeed.PortalId;
                    bgParams.VendorId             = selectedFeed.VendorId;
                    bgParams.AdvancedCategoryRoot = selectedFeed.AdvancedCategoryRoot;
                    bgParams.CountryFilter        = selectedFeed.CountryFilter;
                    bgParams.CityFilter           = selectedFeed.CityFilter;
                    bgParams.StepImport           = stepImport;
                    bgParams.StepAddToCategories  = stepAddToCategories;
                    bgParams.StepAddImages        = stepAddImages;
                    bgParams.FeedId = selectedFeed.Id;

                    switch (keyDownload)
                    {
                    case "Laterooms":
                    case "Laterooms (filtered)":
                        workD = ImportLaterooms.DoImport;
                        break;

                    case "Trade Doubler":
                    case "Home and garden":
                    case "Clothes":
                        workD = ImportTradeDoublerProducts.DoImport;
                        break;

                    case "Trade Doubler hotels.com EMEA2":
                    case "Trade Doubler hotels.com EMEA1":
                    case "Trade Doubler expedia":
                    case "Trade Doubler Hotels":
                        workD = ImportTradeDoublerHotels.DoImport;
                        break;

                    case "Productserve":
#if ImportProductserve
                        workD = ImportProductserve.DoImport;
#endif
                        break;

                    case "Webgains":
                        workD = ImportWebgainsProducts.DoImport;
                        break;

                    case "Excel":
                        workD = ImportExcelHotels.DoImport;
                        break;
                    }
                    progressD = backgroundWorkerProgressChanged;
                    completeD = backgroundWorkerRunWorkerCompleted;
                    bgw.Add(keyDownload, AddBackGroundWorker(workD, progressD, completeD));
                    bgProgress.Add(keyDownload, 0);
                    activeStep = "Start download";
                    bgStep.Add(keyDownload, activeStep);
                    bgw[keyDownload].RunWorkerAsync(bgParams);      // selectedFeed.URL
                }
                activeKey = keyDownload;
                // display status
                ShiftStatusStripToActiveBackgroudWorker(bgw.Count, activeKey, activeStep, bgw[activeKey].IsBusy, bgProgress[activeKey]);
            }
        }