public void CreateCode(CreationType creationType)
        {
            EnableForm(false);

            HydrateSettingsFromUI();
            if (new Version(Settings.Version) < new Version(Settings.SettingsVersion))
            {
                if (MessageBox.Show($@"This version of the Early Bound Generator ({Settings.Version}) is older than the previous ran version from the settings ({Settings.SettingsVersion}).  You should probably update the plugin before running.  Are you sure you want to continue?", @"Older Version detected", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) != DialogResult.Yes)
                {
                    EnableForm(true);
                    return;
                }
            }
            if (!SkipSaveSettings)
            {
                SaveSettings();
            }

            LogConfigSettings(creationType);
            WorkAsync(new WorkAsyncInfo("Shelling out to Command Line...",
                                        (w, e) => // Work To Do Asynchronously
            {
                var settings = (EarlyBoundGeneratorConfig)e.Argument;

                var generator = new Logic(settings);
                Logger.WireUpToReportProgress(w);
                try
                {
                    switch (creationType)
                    {
                    case CreationType.Actions:
                        w.ReportProgress(0, "Executing for Actions");
                        generator.CreateActions();
                        break;

                    case CreationType.All:
                        w.ReportProgress(0, "Executing for All");
                        generator.ExecuteAll();
                        break;

                    case CreationType.Entities:
                        w.ReportProgress(0, "Executing for Entities");
                        generator.CreateEntities();
                        break;

                    case CreationType.OptionSets:
                        w.ReportProgress(0, "Executing for OptionSets");
                        generator.CreateOptionSets();
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(creationType));
                    }
                    w.ReportProgress(99, "Creation Complete!");
                }
                catch (InvalidOperationException ex)
                {
                    w.ReportProgress(int.MinValue, ex.Message);
                }
                catch (Exception ex)
                {
                    w.ReportProgress(int.MinValue, ex.ToString());
                }
                finally
                {
                    Logger.UnwireFromReportProgress(w);
                }
            })
            {
                AsyncArgument    = Settings,
                PostWorkCallBack = e => // Creation has finished.  Cleanup
                {
                    Logger.DisplayLog(e, TxtOutput);
                    EnableForm(true);
                },
                ProgressChanged = e => // Logic wants to display an update
                {
                    Logger.DisplayLog(e, SetWorkingMessage, TxtOutput);
                }
            });
        }
        public void CreateCode(CreationType creationType)
        {
            EnableForm(false);

            WorkAsync("Shelling out to Command Line...",
                (w, e) => // Work To Do Asynchronously
                {
                    HydrateSettingsFromUI();

                    //SetGenerateEnumSettings(Settings);

                    var generator = new Logic(Settings);
                    Logic.LogHandler onLog = m => w.ReportProgress(0, m);
                    generator.OnLog += onLog;
                    try
                    {
                        switch (creationType)
                        {
                            case CreationType.Actions:
                                w.ReportProgress(0, "Executing for Actions");
                                generator.CreateActions();
                                break;
                            case CreationType.All:
                                w.ReportProgress(0, "Executing for All");
                                generator.ExecuteAll();
                                break;
                            case CreationType.Entities:
                                w.ReportProgress(0, "Executing for Entities");
                                generator.CreateEntities();
                                break;
                            case CreationType.OptionSets:
                                w.ReportProgress(0, "Executing for OptionSets");
                                generator.CreateOptionSets();
                                break;
                            default:
                                throw new ArgumentOutOfRangeException(nameof(creationType));
                        }
                        w.ReportProgress(99, "Creation Complete!");
                    }
                    catch (InvalidOperationException ex)
                    {
                        w.ReportProgress(int.MinValue, ex.Message);
                    }
                    catch (Exception ex)
                    {
                        w.ReportProgress(int.MinValue, ex.ToString());
                    }
                    finally
                    {
                        generator.OnLog -= onLog;
                    }
                },
                e => // Creation has finished.  Cleanup
                {
                    var result = e.Result as Logic.LogMessageInfo;
                    if (result != null)
                    {
                        TxtOutput.AppendText(result.Detail + Environment.NewLine);
                    }
                    EnableForm(true);
                    Settings.Save();
                },
                e => // Logic wants to display an update
                {
                    string summary;
                    var result = e.UserState as Logic.LogMessageInfo;
                    if (result == null)
                    {
                        summary = e.UserState.ToString();
                    }
                    else
                    {
                        TxtOutput.AppendText(result.Detail + Environment.NewLine);
                        summary = result.Summary;
                    }
                    // Status Update
                    if (e.ProgressPercentage == int.MinValue)
                    {
                        TxtOutput.AppendText(e.UserState + Environment.NewLine);
                    }
                    else
                    {
                        SetWorkingMessage(summary);
                    }
                });
        }
Ejemplo n.º 3
0
        public void CreateCode(CreationType creationType)
        {
            EnableForm(false);

            HydrateSettingsFromUI();
            if (new Version(Settings.Version) < new Version(Settings.SettingsVersion))
            {
                if (MessageBox.Show($@"This version of the Early Bound Generator ({Settings.Version}) is older than the previous ran version from the settings ({Settings.SettingsVersion}).  You should probably update the plugin before running.  Are you sure you want to countinue?", "Older Version detected", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) != DialogResult.Yes)
                {
                    EnableForm(true);
                    return;
                }
            }
            if (!SkipSaveSettings)
            {
                SaveSettings();
            }

            WorkAsync(new WorkAsyncInfo("Shelling out to Command Line...",
                                        (w, e) => // Work To Do Asynchronously
            {
                var settings = (EarlyBoundGeneratorConfig)e.Argument;

                var generator          = new Logic(settings);
                Logic.LogHandler onLog = m => w.ReportProgress(0, m);
                generator.OnLog       += onLog;
                try
                {
                    switch (creationType)
                    {
                    case CreationType.Actions:
                        w.ReportProgress(0, "Executing for Actions");
                        generator.CreateActions();
                        break;

                    case CreationType.All:
                        w.ReportProgress(0, "Executing for All");
                        generator.ExecuteAll();
                        break;

                    case CreationType.Entities:
                        w.ReportProgress(0, "Executing for Entities");
                        generator.CreateEntities();
                        break;

                    case CreationType.OptionSets:
                        w.ReportProgress(0, "Executing for OptionSets");
                        generator.CreateOptionSets();
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(creationType));
                    }
                    w.ReportProgress(99, "Creation Complete!");
                }
                catch (InvalidOperationException ex)
                {
                    w.ReportProgress(int.MinValue, ex.Message);
                }
                catch (Exception ex)
                {
                    w.ReportProgress(int.MinValue, ex.ToString());
                }
                finally
                {
                    generator.OnLog -= onLog;
                }
            })
            {
                AsyncArgument    = Settings,
                PostWorkCallBack = e => // Creation has finished.  Cleanup
                {
                    var result = e.Result as Logic.LogMessageInfo;
                    if (result != null)
                    {
                        TxtOutput.AppendText(result.Detail + Environment.NewLine);
                    }
                    EnableForm(true);
                },
                ProgressChanged = e => // Logic wants to display an update
                {
                    string summary;
                    var result = e.UserState as Logic.LogMessageInfo;
                    if (result == null)
                    {
                        summary = e.UserState.ToString();
                    }
                    else
                    {
                        if (result.Detail != null)
                        {
                            TxtOutput.AppendText(result.Detail + Environment.NewLine);
                        }
                        summary = result.Summary;
                    }
                    // Status Update
                    if (e.ProgressPercentage == int.MinValue)
                    {
                        TxtOutput.AppendText(e.UserState + Environment.NewLine);
                    }
                    else
                    {
                        if (summary != null)
                        {
                            SetWorkingMessage(summary);
                        }
                    }
                }
            });
        }