Esempio n. 1
0
        public void ProcessFiles(List <string> files)
        {
            WorkAsync(new WorkAsyncInfo
            {
                Message          = "Analyzing file(s)...",
                AsyncArgument    = files,
                Work             = (bw, e) => { e.Result = EmailTemplateHelper.AnalyzeFiles((List <string>)e.Argument, Service); },
                PostWorkCallBack = evt =>
                {
                    var results = (List <EmailTemplateDefinition>)evt.Result;
                    if (results.Any(r => r.Errors.Count > 0))
                    {
                        // Display errors
                        var elForm = new ErrorsListForm(results);
                        elForm.ShowDialog(ParentForm);
                    }
                    else
                    {
                        if (results.Any(r => r.Exists))
                        {
                            // Display overwrite confirmation
                            var ocDialog = new OverwriteConfirmationDialog(results);
                            var result   = ocDialog.ShowDialog(ParentForm);
                            if (result == DialogResult.Cancel)
                            {
                                return;
                            }
                        }

                        WorkAsync(new WorkAsyncInfo("Importing file(s)...", (w, evt2) =>
                        {
                            EmailTemplateHelper.ImportFiles((List <EmailTemplateDefinition>)evt2.Argument, Service);

                            w.ReportProgress(0, "Publishing entities...");

                            Service.Execute(new PublishXmlRequest
                            {
                                ParameterXml = string.Format("<importexportxml><entities>{0}</entities><nodes/><securityroles/><settings/><workflows/></importexportxml>", string.Join("", results.Select(r => string.Format("<entity>{0}</entity>", r.Entity.GetAttributeValue <string>("primaryentitytypecode")))))
                            });
                        })
                        {
                            AsyncArgument    = results,
                            PostWorkCallBack = evt2 =>
                            {
                                if (evt2.Error != null)
                                {
                                    MessageBox.Show(ParentForm, evt2.Error.Message, "Error",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                                else
                                {
                                    MessageBox.Show(ParentForm, "EmailTemplate(s) imported!", "Information",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    lvEntities_SelectedIndexChanged(null, null);
                                }
                            },
                            ProgressChanged = evt2 =>
                            {
                                SetWorkingMessage(evt2.UserState.ToString());
                            }
                        });
                    }
                }
            });
        }