コード例 #1
0
        private async Task GenerateSelectionAsync() {
            ToggleUI(false);

            using (new Wait()) {
                Dictionary<Template, List<TemplateOutputDefinitionFilenameResult>> templateOutputs = (from li in outputsListView.CheckedItems.Cast<ListViewItem>()
                                                                                                      group (TemplateOutputDefinitionFilenameResult)li.Tag by (Template)li.Group.Tag into g
                                                                                                      select new {
                                                                                                          Template = g.Key,
                                                                                                          Outputs = g.ToList()
                                                                                                      }).ToDictionary(o => o.Template, o => o.Outputs);

                if (templateOutputs.IsNullOrEmpty()) {
                    MessageBox.Show("You must select one or more template you wish to generate.", "Generate", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ToggleUI(true);
                    return;
                }

                outputsListView.CheckedItems.Cast<ListViewItem>().ForEach(o => {
                    o.SubItems[statusColumn.Index].Text = null;
                    o.SubItems[messageColumn.Index].Text = null;
                });

                progressBar.Value = 0;
                progressBar.Maximum = templateOutputs.SelectMany(o => o.Value).Count();
                progressBar.Visible = true;

                this.Generator = new Generator(ProjectContext.Project, templateOutputs);
                this.Generator.GenerationStatus += new Generator.GenerationStatusEventHandler(Generator_GenerationStatus);
                this.Generator.TemplateGenerationStatus += new Generator.TemplateGenerationStatusEventHandler(Generator_TemplateGenerationStatus);
                this.Generator.ItemGenerationStatus += new Generator.ItemGenerationStatusEventHandler(Generator_ItemGenerationStatus);

                await this.Generator.GenerateAsync();
            }
        }
コード例 #2
0
        void Generator_TemplateGenerationStatus(Generator generator, TemplateGenerationStatusEventArgs e) {
            this.Invoke(new GenericDelegate<TemplateGenerationStatusEventArgs>(x => {
                ListViewGroup group = outputsListView.Groups.Cast<ListViewGroup>().Single(o => o.Tag == e.Template);

                foreach (ListViewItem item in group.Items)
                    UpdateListViewItemStatus(item, e.Status, e.Error);
            }), e);
        }
コード例 #3
0
        private void Generator_ItemGenerationStatus(Generator generator, ItemGenerationStatusEventArgs e) {
            this.Invoke(new GenericDelegate<ItemGenerationStatusEventArgs>(x => {
                ListViewItem item = outputsListView.CheckedItems.Cast<ListViewItem>().Single(o => o.Tag == x.Result);

                if (x.Status == GenerationStatus.Complete)
                    progressBar.Value++;

                UpdateListViewItemStatus(item, x.Status, x.Error);
            }), e);
        }
コード例 #4
0
        private void Generator_GenerationStatus(Generator generator, GenerationStatusEventArgs e) {
            this.Invoke(new GenericDelegate<GenerationStatusEventArgs>(x => {
                if (x.Status == GenerationStatus.Generating)
                    return;

                if (x.Status == GenerationStatus.Error) {
                    Logger.Error(x.Error);
                    MessageBox.Show(x.Error.Message, "Generation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                this.Generator.GenerationStatus -= new Generator.GenerationStatusEventHandler(Generator_GenerationStatus);
                this.Generator.TemplateGenerationStatus -= new Generator.TemplateGenerationStatusEventHandler(Generator_TemplateGenerationStatus);
                this.Generator.ItemGenerationStatus -= new Generator.ItemGenerationStatusEventHandler(Generator_ItemGenerationStatus);
                this.Generator = null;

                if (x.Status == GenerationStatus.Complete) {
                    bool hasErrors = outputsListView.Items.Cast<ListViewItem>().Any(o => GenerationStatus.Error.ToString().Equals(o.SubItems[statusColumn.Index].Text));

                    ToggleUI(true);
                    progressBar.Visible = false;

                    if (!hasErrors && autoCloseCheckBox.Checked) {
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    else if (hasErrors)
                        MessageBox.Show("One or more errors occurred during the generation process. Double click each error message above for more information.", "Errors Occurred", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }), e);
        }