Exemple #1
0
        // ProgressBar for background
        private void backgroundWorkerProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            BackgroundWorker bw = sender as BackgroundWorker;

            if (activeKey != "" && bw.Equals(bgw[activeKey]) && bw.WorkerReportsProgress)
            {   // displayed process
                if (e.ProgressPercentage == 0)
                {
                    SetInfoForNewStep(activeStep);                                 // for new process display step
                }
                // update active step
                bgStep[activeKey] = activeStep;
                SetInfoForNewStep(activeStep);
                tsProgressBar.Value   = (e.ProgressPercentage > 100) ? 100 : e.ProgressPercentage;
                bgProgress[activeKey] = tsProgressBar.Value;
            }
            else
            {
                bgProgress[activeKey] = bgProgress[activeKey];
            }
        }
Exemple #2
0
        private void backgroundWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            bool             displayedProcess = false, deactivate = false;
            BackgroundWorker bw = sender as BackgroundWorker;

            if (activeKey != "" && bw.Equals(bgw[activeKey]))
            {
                displayedProcess = true;                                               // finish displayed process
            }
            // finish showed process
            bgProcesses[activeKey].LastRun = DateTime.Now;
            string ballonTextFirst = (activeKey.Substring(0, 6).Equals("DELETE") ? "" : "Import ") + activeKey;

            if (e.Cancelled)
            {
                deactivate = true;
                bgProcesses[activeKey].Status = "Cancel";
                notifyIcon.BalloonTipIcon     = ToolTipIcon.Warning;
                notifyIcon.BalloonTipText     = ballonTextFirst + " has been canceled";
            }
            else if (e.Error != null || (e.Result != null && e.Result.ToString().Substring(0, 6).Equals("ERROR:")))
            {
                deactivate = true;
                bgProcesses[activeKey].Status = "Error";
                notifyIcon.BalloonTipIcon     = ToolTipIcon.Error;
                notifyIcon.BalloonTipText     = ballonTextFirst + " has been broken due to ERROR";
            }
            else
            {
                deactivate = true;
                bgProcesses[activeKey].Status = "Success";
                notifyIcon.BalloonTipIcon     = ToolTipIcon.Info;
                notifyIcon.BalloonTipText     = ballonTextFirst + " completed";
            }
            // ShowBaloon for non-active process
            notifyIcon.ShowBalloonTip(15000);
            if (displayedProcess && deactivate)
            {
                if (bw.WorkerReportsProgress)
                {
                    // disable controls for displayed process
                    tsProgressBar.Enabled = false;
                    tsddButton.Enabled    = false;
                }
                // remove backgroundworker & alias of downloads
                bgw.Remove(activeKey);
                bgProcesses.Remove(activeKey);
                bgStep.Remove(activeKey);
                bgProgress.Remove(activeKey);
                // find another active process for displaying
                activeKey = "";
                foreach (string key in bgw.Keys)
                {
                    if (bgw[key].IsBusy)
                    {
                        activeKey = key;
                        break;
                    }
                }
                if (activeKey != "")
                {
                    ShiftStatusStripToActiveBackgroudWorker(bgw.Count, activeKey, bgStep[activeKey],
                                                            bgw[activeKey].IsBusy, bgProgress[activeKey]);
                }
                else
                {
                    ShiftStatusStripToActiveBackgroudWorker(0, activeKey, activeKey, false, 0);
                }
            }
            // set result of download
            try
            {
                context.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
            }

            BindData();
        }