Пример #1
0
        public override bool CommitChanges(StepPartners step, Assistant assistant)
        {
            BackgroundJob job = new BackgroundJob(step);

            job.Action += () =>
            {
                PresentationDomain.Invoke(() => { step.Notebook.Sensitive = false; });
                IList <CustomerWrapper> allCustomers = GetAllCustomers();
                if (allCustomers.Count <= 0)
                {
                    return;
                }

                CustomerWrapper def = allCustomers [0];
                // Substitute the default customer
                def.Customer.Id = Partner.DefaultId;
                def.CommitChanges();

                foreach (CustomerWrapper customer in allCustomers)
                {
                    customer.CommitChanges();
                }
            };
            assistant.EnqueueBackgroundJob(job);

            return(true);
        }
        private bool ReLoadDatabases()
        {
            if (reloadingDatabases)
            {
                return(true);
            }

            dataBases = null;

            try {
                cboDatabase.Sensitive = false;
                btnOK.Sensitive       = false;
                reloadingDatabases    = true;
                cboDatabase.Load(new [] { Translator.GetString("Loading...") }, null, null, null);
                PresentationDomain.ProcessUIEvents();

                string dbProviderName = DbProvider;
                if (!BusinessDomain.TryConnect(dbProviderName, Server, SlaveServer, User, Password))
                {
                    cboDatabase.Load(new [] { Translator.GetString("None", "Database") }, null, null, null);
                    reloadingDatabases = false;
                    return(false);
                }

                DataHelper.FireAndForget(startedProvider =>
                {
                    try {
                        dataBases = BusinessDomain.GetDatabases();
                        // If the provider changed after we started to look for databases, don't show them
                        if (startedProvider != DbProvider)
                        {
                            return;
                        }

                        PresentationDomain.Invoke(() =>
                        {
                            bool hasDbs = dataBases.Length > 0;
                            if (hasDbs)
                            {
                                cboDatabase.Load(dataBases, null, null, BusinessDomain.AppConfiguration.DbDatabase);
                            }
                            else
                            {
                                cboDatabase.Load(new [] { Translator.GetString("None", "Database") }, null, null, null);
                            }
                            cboDatabase.Sensitive = hasDbs;
                            btnOK.Sensitive       = hasDbs;
                            reloadingDatabases    = false;
                        });
                    } catch {
                        cboDatabase.Load(new [] { Translator.GetString("None", "Database") }, null, null, null);
                        reloadingDatabases = false;
                    }
                }, dbProviderName);
                return(true);
            } catch (Exception ex) {
                ErrorHandling.LogException(ex);
                return(false);
            }
        }
Пример #3
0
        public override bool CommitChanges(StepLocations step, Assistant assistant)
        {
            BackgroundJob job = new BackgroundJob(step);

            job.Action += () =>
            {
                PresentationDomain.Invoke(() =>
                {
                    if (step.Notebook != null)
                    {
                        step.Notebook.Sensitive = false;
                    }
                    else
                    {
                        tbl.Sensitive = false;
                    }
                });
                // Substitute the default location
                if (locations.Count > 0)
                {
                    locations [0].Id = Location.DefaultId;
                }

                foreach (Location location in locations)
                {
                    location.CommitChanges();
                }
            };
            assistant.EnqueueBackgroundJob(job);

            return(true);
        }
Пример #4
0
        private void Assistant_StatusChanged(object sender, EventArgs e)
        {
            if (!AllStepsFinished())
            {
                UpdateStepStatuses();
                return;
            }

            PresentationDomain.Invoke(SetMessageCompleted);
        }
Пример #5
0
        public Assistant(AssistType assistType)
        {
            this.assistType = assistType;
            allSteps        = StepBase.GetAllSteps(assistType);

            Initialize();

            if (assistType == AssistType.ApplicationSetup)
            {
                AppendStep(new StepAppSetup());
            }
            else if (assistType == AssistType.DatabaseSetup)
            {
                AppendStep(new StepDBSetup());
            }
            else
            {
                throw new ArgumentOutOfRangeException("assistType");
            }


            backgroundWorker = new Thread(delegate()
            {
                while (true)
                {
                    if (backgroundJobs.Count > 0)
                    {
                        BackgroundJob job = backgroundJobs.Dequeue();
                        try {
                            PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.InProgress));
                            job.Action();
                            PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.Complete));
                        } catch (Exception ex) {
                            PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.Failed));
                            ErrorHandling.LogException(ex, ErrorSeverity.FatalError);
                        }
                    }
                    else
                    {
                        Thread.Sleep(100);
                    }

                    if (stopBackgroundWorker)
                    {
                        return;
                    }
                }
            })
            {
                IsBackground = true, Name = "Setup Assistant Worker"
            };
            backgroundWorker.Start();
        }
Пример #6
0
        public Assistant(StepBase step)
        {
            assistType = AssistType.ApplicationSetup;
            allSteps   = new List <StepBase> {
                step
            };

            Initialize();

            AppendStep(step);

            backgroundWorker = new Thread(delegate()
            {
                while (true)
                {
                    if (backgroundJobs.Count > 0)
                    {
                        BackgroundJob job = backgroundJobs.Dequeue();
                        try {
                            PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.InProgress));
                            job.Action();
                            PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.Complete));
                        } catch (Exception ex) {
                            PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.Failed));
                            ErrorHandling.LogException(ex, ErrorSeverity.FatalError);
                        }
                    }
                    else
                    {
                        Thread.Sleep(100);
                    }

                    if (stopBackgroundWorker)
                    {
                        return;
                    }
                }
            })
            {
                IsBackground = true, Name = "Setup Assistant Worker"
            };
            backgroundWorker.Start();
        }
Пример #7
0
 public void EnqueueBackgroundJob(BackgroundJob job)
 {
     PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.Waiting), false, true);
     backgroundJobs.Enqueue(job);
 }
Пример #8
0
 private void ShowProgress(double progress)
 {
     PresentationDomain.Invoke(() => exportProgress.Progress = progress, true);
 }