Ejemplo n.º 1
0
        /// <summary>
        /// Updates "console" with a message in a specific color
        /// </summary>
        /// <param name="updateMsg">Message to output to "console"</param>
        /// <param name="color">Color from list of: yel, grn, blu, red</param>
        private void UpdateConsole(string updateMsg, string color)
        {
            // Check color input against list of used colors
            Color textColor = new Color();

            switch (color)
            {
            case "yel":     // Minor errors or important notices
                textColor = Color.Yellow;
                break;

            case "grn":     // Completed steps/tasks
                textColor = Color.Lime;
                break;

            case "blu":     // Started steps/tasks
                textColor = Color.Aqua;
                break;

            case "red":     // Errors
                textColor = Color.Red;
                break;

            default:
                textColor = Color.White;
                break;
            }

            // Output message with color
            TxtOutput.AppendText(Environment.NewLine + DateTime.Now.ToString("HH:mm:ss") + " >> " + updateMsg, textColor);
            TxtOutput.SelectionStart = TxtOutput.Text.Length;
            TxtOutput.ScrollToCaret();
        }
Ejemplo n.º 2
0
 private void HydrateUiFromSettings(string settingsPath)
 {
     try
     {
         Settings = EarlyBoundGeneratorConfig.Load(settingsPath);
         Settings.CrmSvcUtilRealtiveRootPath = Paths.PluginsPath;
         SettingsMap = new SettingsMap(this, Settings)
         {
             SettingsPath = settingsPath
         };
         PropertiesGrid.SelectedObject = SettingsMap;
         SkipSaveSettings = false;
     }
     catch (Exception ex)
     {
         TxtOutput.AppendText($"Unable to Load Settings from Config file: {settingsPath}.  {ex}");
         var result = MessageBox.Show(@"The Settings File is either empty or malformed.  Would you like to reset the file to the default settings?", @"Unable to Load Settings!", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
         if (result == DialogResult.Yes)
         {
             Settings = EarlyBoundGeneratorConfig.GetDefault();
             Settings.CrmSvcUtilRealtiveRootPath = Paths.PluginsPath;
         }
         else
         {
             SkipSaveSettings = true;
         }
     }
 }
Ejemplo n.º 3
0
        private void LogConfigSettings(CreationType creationType)
        {
            var properties = Settings.ExtensionConfig.GetType().GetProperties().ToDictionary(
                k => k.Name,
                v => v.GetValue(Settings.ExtensionConfig)?.ToString() ?? string.Empty);

            foreach (var kvp in properties.ToList())
            {
                if (kvp.Key.ToLower().EndsWith("list"))
                {
                    properties.Add(kvp.Key + "Count", string.IsNullOrWhiteSpace(kvp.Value)
                        ? "0"
                        : kvp.Value.Split('|').Length.ToString());
                }
            }

            properties["AudibleCompletionNotification"] = Settings.AudibleCompletionNotification.ToString();
            properties["CrmSvcUtilRelativePath"]        = Settings.CrmSvcUtilRelativePath;
            properties["IncludeCommandLine"]            = Settings.IncludeCommandLine.ToString();
            properties["MaskPassword"]    = Settings.MaskPassword.ToString();
            properties["SupportsActions"] = Settings.SupportsActions.ToString();
            properties["UseCrmOnline"]    = Settings.UseCrmOnline.ToString();
            properties["Version"]         = Settings.Version;
            properties["CreationType"]    = creationType.ToString();

            if (Telemetry.Enabled)
            {
                TxtOutput.AppendText($"Tracking {creationType} Generation Event." + Environment.NewLine);
                Telemetry.TrackEvent("ConfigSettings", properties);
            }
            else
            {
                TxtOutput.AppendText("Tracking not enabled!  Please consider allowing the Xrm Tool Box to send anonymous statistics via the Configuration --> Settings -- Data Collect.  This allows reporting for which features are used and what features can be deprecated." + Environment.NewLine);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

        // This event handler deals with the results of the background operation
        private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            TxtOutput.AppendText("\n");

            if (e.Cancelled)
            {
                TxtOutput.AppendText("Process Cancelled 🚫");
                BtnCancel.Content   = "Cancel";
                BtnCancel.IsEnabled = true;
            }
            else if (e.Error != null)
            {
                TxtOutput.AppendText(
                    "ERROR!\nThe following error occured during the conversion:\n\n" + e.Error.Message
                    );
            }
            else
            {
                TxtOutput.AppendText("Finished");
            }

            BtnOpenFile.Visibility  = Visibility.Visible;
            BtnCancel.Visibility    = Visibility.Collapsed;
            WpOffsetInput.IsEnabled = true;
        }
Ejemplo n.º 5
0
        private void HydrateUiFromSettings(string settingsPath)
        {
            try
            {
                Settings = EarlyBoundGeneratorConfig.Load(settingsPath);
                Settings.CrmSvcUtilRealtiveRootPath = Paths.PluginsPath;
                SkipSaveSettings = false;
            }
            catch (Exception ex)
            {
                TxtOutput.AppendText($"Unable to Load Settings from Config file: {settingsPath}.  {ex}");
                var result = MessageBox.Show(@"The Settings File is either empty or malformed.  Would you like to reset the file to the default settings?", @"Unable to Load Settings!", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    Settings = EarlyBoundGeneratorConfig.GetDefault();
                    Settings.CrmSvcUtilRealtiveRootPath = Paths.PluginsPath;
                }
                else
                {
                    SkipSaveSettings = true;
                }
            }

            ChkAddDebuggerNonUserCode.Checked     = Settings.ExtensionConfig.AddDebuggerNonUserCode;
            ChkAddFilesToProject.Checked          = Settings.ExtensionConfig.AddNewFilesToProject;
            ChkAudibleCompletion.Checked          = Settings.AudibleCompletionNotification;
            ChkCreateOneActionFile.Checked        = Settings.ExtensionConfig.CreateOneFilePerAction;
            ChkCreateOneEntityFile.Checked        = Settings.ExtensionConfig.CreateOneFilePerEntity;
            ChkCreateOneOptionSetFile.Checked     = Settings.ExtensionConfig.CreateOneFilePerOptionSet;
            ChkEditableResponseActions.Checked    = Settings.ExtensionConfig.MakeResponseActionsEditable;
            ChkIncludeCommandLine.Checked         = Settings.IncludeCommandLine;
            ChkMakeReadonlyFieldsEditable.Checked = Settings.ExtensionConfig.MakeReadonlyFieldsEditable;
            ChkMaskPassword.Checked = Settings.MaskPassword;
            ChkGenerateActionAttributeNameConsts.Checked = Settings.ExtensionConfig.GenerateActionAttributeNameConsts;
            ChkGenerateAttributeNameConsts.Checked       = Settings.ExtensionConfig.GenerateAttributeNameConsts;
            ChkGenerateAnonymousTypeConstructor.Checked  = Settings.ExtensionConfig.GenerateAnonymousTypeConstructor;
            ChkGenerateEntityRelationships.Checked       = Settings.ExtensionConfig.GenerateEntityRelationships;
            ChkGenerateOptionSetEnums.Checked            = Settings.ExtensionConfig.GenerateEnumProperties;
            ChkRemoveRuntimeComment.Checked         = Settings.ExtensionConfig.RemoveRuntimeVersionComment;
            ChkUseDeprecatedOptionSetNaming.Checked = Settings.ExtensionConfig.UseDeprecatedOptionSetNaming;
            ChkUseTFS.Checked               = Settings.ExtensionConfig.UseTfsToCheckoutFiles;
            ChkUseXrmClient.Checked         = Settings.ExtensionConfig.UseXrmClient;
            TxtActionPath.Text              = Settings.ActionOutPath;
            TxtEntityPath.Text              = Settings.EntityOutPath;
            TxtInvalidCSharpNamePrefix.Text = Settings.ExtensionConfig.InvalidCSharpNamePrefix;
            TxtOptionSetFormat.Text         = Settings.ExtensionConfig.LocalOptionSetFormat;
            TxtLanguageCodeOverride.Text    = Settings.ExtensionConfig.OptionSetLanguageCodeOverride + "";
            TxtNamespace.Text               = Settings.Namespace;
            TxtOptionSetPath.Text           = Settings.OptionSetOutPath;
            TxtServiceContextName.Text      = Settings.ServiceContextName;

            // Hide or show labels based on checked preferences
            LblActionsDirectory.Visible    = ChkCreateOneActionFile.Checked;
            LblActionPath.Visible          = !LblActionsDirectory.Visible;
            LblEntitiesDirectory.Visible   = ChkCreateOneEntityFile.Checked;
            LblEntityPath.Visible          = !LblEntitiesDirectory.Visible;
            LblOptionSetsDirectory.Visible = ChkCreateOneOptionSetFile.Checked;
            LblOptionSetPath.Visible       = !LblOptionSetsDirectory.Visible;
            SetAddFilesToProjectVisibility();
        }
Ejemplo n.º 6
0
        private void GenerateWithDefaultSettings()
        {
            var results = new object[]
            {
                new List <string> {
                    "Y", "C:\\Temp\\AdvXTB\\Abc.Xrm\\Abc.Xrm.sln"
                },
                "Abc.Xrm",
                new NuGetPackage
                {
                    Id               = "Microsoft.CrmSdk.CoreAssemblies",
                    LicenseUrl       = "http://download.microsoft.com/download/E/1/8/E18C0FAD-FEC8-44CD-9A16-98EDC4DAC7A2/LicenseTerms.docx",
                    Name             = "Microsoft Dynamics 365 SDK core assemblies",
                    Version          = new Version("9.0.2.5"),
                    VersionText      = "9.0.2.5",
                    XrmToolingClient = false
                },
                "Y",
                "Abc.Xrm",
                "Abc.Xrm.WorkflowCore",
                new List <string> {
                    "Y", "Abc.Xrm.Test", "Abc.Xrm.TestCore"
                },
                new List <string> {
                    "Y", "Abc.Xrm.Plugin", "0"
                },
                "Abc.Xrm.Plugin.Tests",
                new List <string> {
                    "Y", "Abc.Xrm.Workflow", "1"
                },
                "Abc.Xrm.Workflow.Tests",
                new List <string> {
                    "0", "0"
                },
            };

            var info        = InitializeSolutionInfo.InitializeSolution(results);
            var solutionDir = Path.GetDirectoryName(info.SolutionPath) ?? Guid.NewGuid().ToString();

            if (Directory.Exists(solutionDir))
            {
                foreach (var file in Directory.EnumerateFiles(solutionDir, "*", SearchOption.AllDirectories))
                {
                    File.Delete(file);
                }

                Directory.Delete(solutionDir, true);
            }

            do
            {
                TxtOutput.AppendText("Creating Directory." + Environment.NewLine);
                Directory.CreateDirectory(solutionDir);
            } while (!Directory.Exists(solutionDir));

            File.Copy("C:\\Temp\\AdvXTB\\Abc.Xrm.sln", info.SolutionPath);
            Execute(info);
        }
Ejemplo n.º 7
0
 private void BtnTryAll_Click(object sender, EventArgs e)
 {
     TxtOutput.Clear();
     for (int a = 0; a < 26; a++)
     {
         TxtOutput.AppendText(a.ToString() + " " + Decipher(TxtInput.Text, a) + System.Environment.NewLine);
     }
     TxtOutput.ScrollToCaret();
 }
Ejemplo n.º 8
0
 public void AddOutput(string txt)
 {
     TxtOutput.BeginInvoke((Action) delegate()
     {
         TxtOutput.AppendText(txt);
         //TxtOutput.SelectionStart = TxtOutput.Text.Length;
         //TxtOutput.ScrollToCaret();
     });
 }
Ejemplo n.º 9
0
        // ReSharper disable once InconsistentNaming
        private void HydrateSettingsFromUI()
        {
            if (ConnectionDetail != null)
            {
                TxtOutput.AppendText("CRM Authentication Type Detected: " + ConnectionDetail.AuthType + Environment.NewLine);
                Settings.AuthType            = ConnectionDetail.AuthType;
                Settings.Domain              = ConnectionDetail.UserDomain;
                Settings.Password            = ConnectionDetail.GetUserPassword();
                Settings.SupportsActions     = ConnectionDetail.OrganizationMajorVersion >= Crm2013;
                Settings.UseConnectionString = Settings.UseConnectionString || Settings.AuthType == AuthenticationProviderType.ActiveDirectory;
                Settings.UseCrmOnline        = ConnectionDetail.UseOnline;
                Settings.UserName            = ConnectionDetail.UserName;
                Settings.Url = Settings.UseConnectionString ?
                               ConnectionDetail.OrganizationServiceUrl.Replace(@"/XRMServices/2011/Organization.svc", string.Empty) :
                               ConnectionDetail.OrganizationServiceUrl;
            }

            Settings.ActionOutPath = TxtActionPath.Text;
            Settings.EntityOutPath = TxtEntityPath.Text;
            if (ChkUseDeprecatedOptionSetNaming.Checked)
            {
                Settings.SetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.CodeWriterFilter, @"DLaB.CrmSvcUtilExtensions.OptionSet.CodeWriterFilterService,DLaB.CrmSvcUtilExtensions");
                Settings.SetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.NamingService, string.Empty);
            }
            else
            {
                var defaultConfig = Config.GetDefault();
                Settings.SetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.CodeWriterFilter, defaultConfig.GetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.CodeWriterFilter).Value);
                Settings.SetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.NamingService, defaultConfig.GetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.NamingService).Value);
            }

            var extensions = Settings.ExtensionConfig;

            extensions.AddDebuggerNonUserCode           = ChkAddDebuggerNonUserCode.Checked;
            extensions.AddNewFilesToProject             = ChkAddFilesToProject.Checked;
            extensions.CreateOneFilePerAction           = ChkCreateOneActionFile.Checked;
            extensions.CreateOneFilePerEntity           = ChkCreateOneEntityFile.Checked;
            extensions.CreateOneFilePerOptionSet        = ChkCreateOneOptionSetFile.Checked;
            extensions.GenerateAttributeNameConsts      = ChkGenerateAttributeNameConsts.Checked;
            extensions.GenerateAnonymousTypeConstructor = ChkGenerateAnonymousTypeConstructor.Checked;
            extensions.GenerateEntityRelationships      = ChkGenerateEntityRelationships.Checked;
            extensions.GenerateEnumProperties           = ChkGenerateOptionSetEnums.Checked;
            extensions.InvalidCSharpNamePrefix          = TxtInvalidCSharpNamePrefix.Text;
            extensions.MakeReadonlyFieldsEditable       = ChkMakeReadonlyFieldsEditable.Checked;
            extensions.LocalOptionSetFormat             = TxtOptionSetFormat.Text;
            extensions.RemoveRuntimeVersionComment      = ChkRemoveRuntimeComment.Checked;
            extensions.UseXrmClient = ChkUseXrmClient.Checked;
            extensions.UseDeprecatedOptionSetNaming = ChkUseDeprecatedOptionSetNaming.Checked;
            extensions.UseTfsToCheckoutFiles        = ChkUseTFS.Checked;
            Settings.AudibleCompletionNotification  = ChkAudibleCompletion.Checked;
            Settings.IncludeCommandLine             = ChkIncludeCommandLine.Checked;
            Settings.MaskPassword       = ChkMaskPassword.Checked;
            Settings.Namespace          = TxtNamespace.Text;
            Settings.OptionSetOutPath   = TxtOptionSetPath.Text;
            Settings.ServiceContextName = string.IsNullOrWhiteSpace(TxtServiceContextName.Text) ? null : TxtServiceContextName.Text;
        }
        // ReSharper disable once InconsistentNaming
        private void HydrateSettingsFromUI()
        {
            if (ConnectionDetail != null)
            {
                TxtOutput.AppendText("CRM Authentication Type Detected: " + ConnectionDetail.AuthType + Environment.NewLine);
                Settings.Domain          = GetUserDomain();
                Settings.Password        = ConnectionDetail.GetUserPassword();
                Settings.SupportsActions = ConnectionDetail.OrganizationMajorVersion >= Crm2013;
                Settings.UseCrmOnline    = ConnectionDetail.UseOnline;
                Settings.UserName        = ConnectionDetail.UserName;
                Settings.Url             = ConnectionDetail.GetUrlString();

                if (Settings.UseConnectionString &&
                    string.IsNullOrWhiteSpace(Settings.Password) &&
                    ConnectionDetail.NewAuthType != AuthenticationType.Certificate &&
                    ConnectionDetail.NewAuthType != AuthenticationType.ClientSecret &&
                    ConnectionDetail.NewAuthType != AuthenticationType.OAuth)
                {
                    // Fix for https://github.com/daryllabar/DLaB.Xrm.XrmToolBoxTools/issues/43
                    // Difficulties with Early Bound Generator #43

                    var askForPassword = new PasswordDialog(this);
                    Settings.Password = askForPassword.ShowDialog(this) == DialogResult.OK ? askForPassword.Password : "******";
                }
                if (ConnectionDetail.AuthType == AuthenticationProviderType.ActiveDirectory && string.IsNullOrWhiteSpace(Settings.UserName))
                {
                    Settings.UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                }
                if (string.IsNullOrWhiteSpace(Settings.ConnectionString))
                {
                    // Load any non-username/password situations via connection string #268
                    Settings.ConnectionString = ConnectionDetail.GetNonUserConnectionString();
                    if (!string.IsNullOrWhiteSpace(Settings.ConnectionString))
                    {
                        Settings.UseConnectionString = true;
                    }
                }
            }

            SettingsMap.PushChanges();
            Settings.RootPath = Path.GetDirectoryName(Path.GetFullPath(TxtSettingsPath.Text));
            if (SettingsMap.UseDeprecatedOptionSetNaming)
            {
                Settings.SetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.CodeWriterFilter, @"DLaB.CrmSvcUtilExtensions.OptionSet.CodeWriterFilterService,DLaB.CrmSvcUtilExtensions");
                Settings.SetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.NamingService, string.Empty);
            }
            else
            {
                var defaultConfig = EarlyBoundGeneratorConfig.GetDefault();
                defaultConfig.CrmSvcUtilRelativeRootPath = Paths.PluginsPath;
                Settings.SetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.CodeWriterFilter, defaultConfig.GetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.CodeWriterFilter).Value);
                Settings.SetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.NamingService, defaultConfig.GetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.NamingService).Value);
            }
        }
Ejemplo n.º 11
0
        private void BtnShowResults_Click(object sender, EventArgs e)
        {
            TxtOutput.Text = String.Format("{0,-12}{1,14}\n", "Rating", "Frequency", TxtOutput.Text);
            TxtOutput.AppendText(Environment.NewLine);

            for (int i = 0; i < output.Length / 2; i++)
            {
                TxtOutput.Text += String.Format("{0, -12}{1, 14}", output[i, 0], output[i, 1]);
                TxtOutput.AppendText(Environment.NewLine);
            }
        }
        private void EarlyBoundGenerator_Load(object sender, EventArgs e)
        {
            if (ConnectionDetail != null)
            {
                DisplayActionsIfSupported(false);
            }
            try
            {
                Settings = EarlyBoundGeneratorConfig.Load(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
            }
            catch (Exception ex)
            {
                TxtOutput.AppendText("Unable to Load Settings form Config: " + ex);
                SkipSaveSettings = true;
                Settings         = EarlyBoundGeneratorConfig.GetDefault();
            }
            ChkAddDebuggerNonUserCode.Checked     = Settings.ExtensionConfig.AddDebuggerNonUserCode;
            ChkAddFilesToProject.Checked          = Settings.ExtensionConfig.AddNewFilesToProject;
            ChkAudibleCompletion.Checked          = Settings.AudibleCompletionNotification;
            ChkCreateOneActionFile.Checked        = Settings.ExtensionConfig.CreateOneFilePerAction;
            ChkCreateOneEntityFile.Checked        = Settings.ExtensionConfig.CreateOneFilePerEntity;
            ChkCreateOneOptionSetFile.Checked     = Settings.ExtensionConfig.CreateOneFilePerOptionSet;
            ChkIncludeCommandLine.Checked         = Settings.IncludeCommandLine;
            ChkMakeReadonlyFieldsEditable.Checked = Settings.ExtensionConfig.MakeReadonlyFieldsEditable;
            ChkMaskPassword.Checked = Settings.MaskPassword;
            ChkGenerateAttributeNameConsts.Checked      = Settings.ExtensionConfig.GenerateAttributeNameConsts;
            ChkGenerateAnonymousTypeConstructor.Checked = Settings.ExtensionConfig.GenerateAnonymousTypeConstructor;
            ChkGenerateEntityRelationships.Checked      = Settings.ExtensionConfig.GenerateEntityRelationships;
            ChkGenerateOptionSetEnums.Checked           = Settings.ExtensionConfig.GenerateEnumProperties;
            ChkRemoveRuntimeComment.Checked             = Settings.ExtensionConfig.RemoveRuntimeVersionComment;
            ChkUseDeprecatedOptionSetNaming.Checked     = Settings.ExtensionConfig.UseDeprecatedOptionSetNaming;
            ChkUseTFS.Checked               = Settings.ExtensionConfig.UseTfsToCheckoutFiles;
            ChkUseXrmClient.Checked         = Settings.ExtensionConfig.UseXrmClient;
            TxtActionPath.Text              = Settings.ActionOutPath;
            TxtEntityPath.Text              = Settings.EntityOutPath;
            TxtInvalidCSharpNamePrefix.Text = Settings.ExtensionConfig.InvalidCSharpNamePrefix;
            TxtOptionSetFormat.Text         = Settings.ExtensionConfig.LocalOptionSetFormat;
            TxtNamespace.Text               = Settings.Namespace;
            TxtOptionSetPath.Text           = Settings.OptionSetOutPath;
            TxtServiceContextName.Text      = Settings.ServiceContextName;

            // Hide or show labels based on checked preferences
            LblActionsDirectory.Visible    = ChkCreateOneActionFile.Checked;
            LblActionPath.Visible          = !LblActionsDirectory.Visible;
            LblEntitiesDirectory.Visible   = ChkCreateOneEntityFile.Checked;
            LblEntityPath.Visible          = !LblEntitiesDirectory.Visible;
            LblOptionSetsDirectory.Visible = ChkCreateOneOptionSetFile.Checked;
            LblOptionSetPath.Visible       = !LblOptionSetsDirectory.Visible;
            SetAddFilesToProjectVisibility();
        }
Ejemplo n.º 13
0
        private void ExecuteBttn_Click(object sender, EventArgs e)
        {
            try
            {
                switch (ActionCmb.SelectedIndex)
                {
                case 0:
                    ShowAddAcceleratorsWizard();
                    break;

                case 1:
                    ShowAddAssemblyWizard();
                    break;

                case 2:
                    ExecuteInstallCodeSnippets();
                    break;

                case 3:
                    GenerateWithDefaultSettings();
                    break;

                case 4:
                    GenerateAddAssemblyWithDefaultSettings();
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtOutput.AppendText(Environment.NewLine + ex);
            }
        }
Ejemplo n.º 14
0
 private void Write(object data)
 {
     TxtOutput.AppendText("" + data);
 }
Ejemplo n.º 15
0
 // Procédure pour dire en vocal ce qu'on veut
 public void say(String h)
 {
     s.Speak(h);
     TxtOutput.AppendText(h + "\n");
 }
        public void CreateCode(CreationType creationType)
        {
            EnableForm(false);

            HydrateSettingsFromUI();
            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);
                        }
                    }
                }
            });
        }
Ejemplo n.º 17
0
 public void Print(string text)
 {
     TxtOutput.AppendText(text);
 }
Ejemplo n.º 18
0
        // ReSharper disable once InconsistentNaming
        private void HydrateSettingsFromUI()
        {
            if (ConnectionDetail != null)
            {
                TxtOutput.AppendText("CRM Authentication Type Detected: " + ConnectionDetail.AuthType + Environment.NewLine);
                Settings.AuthType            = ConnectionDetail.AuthType;
                Settings.Domain              = GetUserDomain();
                Settings.Password            = ConnectionDetail.GetUserPassword();
                Settings.SupportsActions     = ConnectionDetail.OrganizationMajorVersion >= Crm2013;
                Settings.UseConnectionString = Settings.UseConnectionString; // #151 || Settings.AuthType == AuthenticationProviderType.ActiveDirectory;
                Settings.UseCrmOnline        = ConnectionDetail.UseOnline;
                Settings.UserName            = ConnectionDetail.UserName;
                Settings.Url = GetUrlString();

                if (Settings.UseConnectionString && string.IsNullOrWhiteSpace(Settings.Password))
                {
                    // Fix for https://github.com/daryllabar/DLaB.Xrm.XrmToolBoxTools/issues/43
                    // Difficulties with Early Bound Generator #43

                    var askForPassowrd = new PasswordDialog(this);
                    Settings.Password = askForPassowrd.ShowDialog(this) == DialogResult.OK ? askForPassowrd.Password : "******";
                }
                if (ConnectionDetail.AuthType == AuthenticationProviderType.ActiveDirectory && string.IsNullOrWhiteSpace(Settings.UserName))
                {
                    Settings.UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                }
            }

            Settings.ActionOutPath = TxtActionPath.Text;
            Settings.EntityOutPath = TxtEntityPath.Text;
            Settings.RootPath      = Path.GetDirectoryName(Path.GetFullPath(TxtSettingsPath.Text));
            if (ChkUseDeprecatedOptionSetNaming.Checked)
            {
                Settings.SetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.CodeWriterFilter, @"DLaB.CrmSvcUtilExtensions.OptionSet.CodeWriterFilterService,DLaB.CrmSvcUtilExtensions");
                Settings.SetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.NamingService, string.Empty);
            }
            else
            {
                var defaultConfig = EarlyBoundGeneratorConfig.GetDefault();
                Settings.SetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.CodeWriterFilter, defaultConfig.GetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.CodeWriterFilter).Value);
                Settings.SetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.NamingService, defaultConfig.GetExtensionArgument(CreationType.OptionSets, CrmSrvUtilService.NamingService).Value);
            }

            var validLanguageCode = int.TryParse(TxtLanguageCodeOverride.Text, out var languageCode);

            var extensions = Settings.ExtensionConfig;

            extensions.AddDebuggerNonUserCode            = ChkAddDebuggerNonUserCode.Checked;
            extensions.AddNewFilesToProject              = ChkAddFilesToProject.Checked;
            extensions.CreateOneFilePerAction            = ChkCreateOneActionFile.Checked;
            extensions.CreateOneFilePerEntity            = ChkCreateOneEntityFile.Checked;
            extensions.CreateOneFilePerOptionSet         = ChkCreateOneOptionSetFile.Checked;
            extensions.GenerateActionAttributeNameConsts = ChkGenerateActionAttributeNameConsts.Checked;
            extensions.GenerateAttributeNameConsts       = ChkGenerateAttributeNameConsts.Checked;
            extensions.GenerateAnonymousTypeConstructor  = ChkGenerateAnonymousTypeConstructor.Checked;
            extensions.GenerateEntityRelationships       = ChkGenerateEntityRelationships.Checked;
            extensions.GenerateEnumProperties            = ChkGenerateOptionSetEnums.Checked;
            extensions.InvalidCSharpNamePrefix           = TxtInvalidCSharpNamePrefix.Text;
            extensions.MakeReadonlyFieldsEditable        = ChkMakeReadonlyFieldsEditable.Checked;
            extensions.MakeResponseActionsEditable       = ChkEditableResponseActions.Checked;
            extensions.LocalOptionSetFormat              = TxtOptionSetFormat.Text;
            extensions.OptionSetLanguageCodeOverride     = validLanguageCode ? languageCode : (int?)null;
            extensions.RemoveRuntimeVersionComment       = ChkRemoveRuntimeComment.Checked;
            extensions.UseXrmClient = ChkUseXrmClient.Checked;
            extensions.UseDeprecatedOptionSetNaming = ChkUseDeprecatedOptionSetNaming.Checked;
            extensions.UseTfsToCheckoutFiles        = ChkUseTFS.Checked;
            Settings.AudibleCompletionNotification  = ChkAudibleCompletion.Checked;
            Settings.IncludeCommandLine             = ChkIncludeCommandLine.Checked;
            Settings.MaskPassword       = ChkMaskPassword.Checked;
            Settings.Namespace          = TxtNamespace.Text;
            Settings.OptionSetOutPath   = TxtOptionSetPath.Text;
            Settings.ServiceContextName = string.IsNullOrWhiteSpace(TxtServiceContextName.Text) ? null : TxtServiceContextName.Text;
        }
Ejemplo n.º 19
0
 private void WriteLine(object data)
 {
     TxtOutput.AppendText(data + Environment.NewLine);
 }
Ejemplo n.º 20
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);
                        }
                    }
                }
            });
        }
Ejemplo n.º 21
0
 private void Log(string logtext)
 {
     TxtOutput.AppendText("\r\n");
     TxtOutput.AppendText(logtext);
 }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

        // This event handler executes on the main thread to update displayed progress in the GUI
        private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            LblProgress.Content = "Progress: " + e.ProgressPercentage + "%";
            TxtOutput.AppendText((string)e.UserState); // Append the message to the output textbox
            TxtOutput.ScrollToEnd();                   // Scroll to the bottom to keep the most recently converted files visible
        }
Ejemplo n.º 23
0
        private async void CmdStartDecryption_Click(object sender, EventArgs e)
        {
            if (CheckInput() == false)
            {
                return;
            }

            var ProgressPercent = new Progress <int>(Percent =>
            {
                ProgressBar1.Value = Percent;
                lblPercent.Text    = Percent + "%";
            });

            var ProgressConsole = new Progress <Msg>(msg =>
            {
                TxtOutput.SelectionStart  = TxtOutput.TextLength;
                TxtOutput.SelectionLength = 0;

                TxtOutput.SelectionColor = msg.TextColor;
                TxtOutput.AppendText(msg.Text + "\n");
                TxtOutput.SelectionColor = TxtOutput.ForeColor;
                TxtOutput.ScrollToCaret();
            });

            Utils.ProgressConsole = ProgressConsole;

            Decryptor decryptor;
            var       decryptorOptions = new DecryptorOptions()
            {
                UsageMode                  = RadioFolder.Checked ? Mode.Folder : Mode.File,
                UseOutputFolder            = ComboOutputPath.Text == "" ? false : true,
                UseDatabase                = ComboDbFile.Text == "" ? false : true,
                RemoveFilesAfterDecryption = false,

                InputPath    = ComboInputPath.Text,
                OutputPath   = ComboOutputPath.Text == "" ? Path.ChangeExtension(ComboInputPath.Text, ".mp4") : ComboOutputPath.Text,
                OutputFolder = ComboOutputPath.Text == "" ? Path.GetDirectoryName(ComboInputPath.Text) : ComboOutputPath.Text,
                DatabasePath = ComboDbFile.Text,
                SubTitle     = ChkSubtitle.Checked ? true : false
            };

            CmdStartDecryption.Text    = "Decrypting....";
            CmdStartDecryption.Enabled = false;
            CmdExit.Text = "Cancel";
            running      = true;
            cts          = new CancellationTokenSource();
            ct           = cts.Token;

            try
            {
                decryptor = new Decryptor(decryptorOptions, ProgressPercent, ct);
                decryptor.InitDecryptor(ENCRYPTION_KEY);

                if (decryptorOptions.UsageMode == Mode.Folder)
                {
                    await decryptor.DecryptAll(decryptorOptions.InputPath, decryptorOptions.OutputFolder);
                }

                else if (decryptorOptions.UsageMode == Mode.File)
                {
                    decryptor.Decrypt(decryptorOptions.InputPath, decryptorOptions.OutputPath);
                }
            }
            catch (OperationCanceledException Ex)
            {
                MessageBox.Show("[CANCEL] Operation Cancelled: " + Ex.Message);
                WriteToConsole("[CANCEL] Operation Cancelled: " + Ex.Message + Environment.NewLine, Color.Yellow);
            }
            catch (Exception Ex)
            {
                MessageBox.Show("[START] Error occured: " + Ex.Message);
                WriteToConsole("[START] Error occured: " + Ex.Message + Environment.NewLine, Color.Red);
            }
            finally
            {
                CmdStartDecryption.Text    = "Start Decryption";
                CmdStartDecryption.Enabled = true;
                CmdExit.Text = "Exit";
                running      = false;
                cts.Dispose();
            }
        }