private string GetConfigArguments(EarlyBoundGeneratorConfig earlyBoundGeneratorConfig, CreationType type) { var sb = new StringBuilder(); if (!earlyBoundGeneratorConfig.UseConnectionString) { sb.AppendFormat("/url:\"{0}\" ", earlyBoundGeneratorConfig.Url); } foreach (var argument in earlyBoundGeneratorConfig.CommandLineArguments.Where(a => a.SettingType == CreationType.All || a.SettingType == type)) { var value = argument.Value; if (argument.Name == "out") { value = GetOutputFilePath(earlyBoundGeneratorConfig, type); } if (argument.Value == null) { sb.AppendFormat("/{0} ", argument.Name); } else { sb.AppendFormat("/{0}:\"{1}\" ", argument.Name, value); } } if (!string.IsNullOrWhiteSpace(earlyBoundGeneratorConfig.ConnectionString)) { // If a connection string was specified ignore all other connection settings sb.AppendFormat("/connectionstring:\"{0}\" ", earlyBoundGeneratorConfig.ConnectionString.Replace("\"", "\"\"")); } else if (!string.IsNullOrWhiteSpace(earlyBoundGeneratorConfig.Password)) { if (earlyBoundGeneratorConfig.UseConnectionString) { // Fix for https://github.com/daryllabar/DLaB.Xrm.XrmToolBoxTools/issues/14 - Problem with CRM 2016 on premises with ADFS // CrmSvcUtil.exe /out:entities.cs / connectionstring:"Url=https://serverName.domain.com:444/orgName;Domain=myDomain;UserName=username;Password=*****" // And this command doesn't work : // CrmSvcUtil.exe /out:entitie.cs /url:"https://serverName.domain.com:444/orgName" / domain:"myDomain" / username:"******" / password:"******" var domain = string.Empty; if (!string.IsNullOrWhiteSpace(earlyBoundGeneratorConfig.Domain)) { domain = "Domain=" + earlyBoundGeneratorConfig.Domain + ";"; } //var password = earlyBoundGeneratorConfig.Password.Replace("^", "^^").Replace("\"", "^\"").Replace("&", "^&"); // Handle Double Quotes and &s??? //To handle special characters, enclose in single quotes. If password contains single quotes, they must be doubled. //https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx var password = $"'{earlyBoundGeneratorConfig.Password.Replace("'", "''")}'"; var builder = new System.Data.Common.DbConnectionStringBuilder { { "A", $"Url={earlyBoundGeneratorConfig.Url};{domain}UserName={earlyBoundGeneratorConfig.UserName};Password={password}" } }; sb.AppendFormat("/connectionstring:{0} ", builder.ConnectionString.Substring(2)); // Replace "A=" with "/connectionstring:" } else { sb.AppendFormat("/username:\"{0}\" ", earlyBoundGeneratorConfig.UserName); sb.AppendFormat("/password:\"{0}\" ", earlyBoundGeneratorConfig.Password); // Add Login Info if (!earlyBoundGeneratorConfig.UseCrmOnline && !string.IsNullOrWhiteSpace(earlyBoundGeneratorConfig.Domain)) { sb.AppendFormat("/domain:\"{0}\" ", earlyBoundGeneratorConfig.Domain); } } } if (_useInteractiveMode) { sb.Append("/interactivelogin:true "); } return(sb.ToString()); }
public Logic(EarlyBoundGeneratorConfig earlyBoundGeneratorConfig) { EarlyBoundGeneratorConfig = earlyBoundGeneratorConfig; }
private string GetConfigArguments(EarlyBoundGeneratorConfig earlyBoundGeneratorConfig, CreationType type) { var sb = new StringBuilder(); if (!earlyBoundGeneratorConfig.UseConnectionString) { sb.AppendFormat("/url:\"{0}\" ", earlyBoundGeneratorConfig.Url); } foreach (var argument in earlyBoundGeneratorConfig.CommandLineArguments.Where(a => a.SettingType == CreationType.All || a.SettingType == type)) { var value = argument.Value; if (argument.Name == "out") { value = GetOutputFilePath(earlyBoundGeneratorConfig, type); } if (argument.Value == null) { sb.AppendFormat("/{0} ", argument.Name); } else { sb.AppendFormat("/{0}:\"{1}\" ", argument.Name, value); } } if (!string.IsNullOrWhiteSpace(earlyBoundGeneratorConfig.Password)) { if (EarlyBoundGeneratorConfig.UseConnectionString) { // Fix for https://github.com/daryllabar/DLaB.Xrm.XrmToolBoxTools/issues/14 - Problem with CRM 2016 on premises with ADFS // CrmSvcUtil.exe /out:entitie.cs / connectionstring:"Url=https://serverName.domain.com:444/orgName;Domain=myDomain;UserName=username;Password=*****" // And this command doesn't work : // CrmSvcUtil.exe /out:entitie.cs /url:"https://serverName.domain.com:444/orgName" / domain:"myDomain" / username:"******" / password:"******" var domain = string.Empty; if (!string.IsNullOrWhiteSpace(earlyBoundGeneratorConfig.Domain)) { domain = "Domain=" + earlyBoundGeneratorConfig.Domain + ";"; } var password = earlyBoundGeneratorConfig.Password.Replace("\"", "^\"").Replace("&", "^&"); // Handle Double Quotes and &s??? var builder = new System.Data.Common.DbConnectionStringBuilder { { "A", $"Url={earlyBoundGeneratorConfig.Url};{domain}UserName={earlyBoundGeneratorConfig.UserName};Password={password}" } }; sb.AppendFormat("/connectionstring:{0} ", builder.ConnectionString.Substring(2)); // Replace "A=" with "/connectionstring:" } else { sb.AppendFormat("/username:\"{0}\" ", earlyBoundGeneratorConfig.UserName); sb.AppendFormat("/password:\"{0}\" ", earlyBoundGeneratorConfig.Password); // Add Login Info if (!earlyBoundGeneratorConfig.UseCrmOnline && !string.IsNullOrWhiteSpace(earlyBoundGeneratorConfig.Domain)) { sb.AppendFormat("/domain:\"{0}\" ", earlyBoundGeneratorConfig.Domain); } } } return(sb.ToString()); }
private void UpdateCrmSvcUtilConfig(EarlyBoundGeneratorConfig earlyBoundGeneratorConfig) { lock (_updateAppConfigToken) { if (_configUpdated) { return; } //load custom config file Configuration file; string filePath = Path.GetFullPath(earlyBoundGeneratorConfig.CrmSvcUtilPath) + ".config"; var map = new ExeConfigurationFileMap { ExeConfigFilename = filePath }; try { file = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); } catch (ConfigurationErrorsException ex) { if (ex.BareMessage == "Root element is missing.") { File.Delete(filePath); UpdateCrmSvcUtilConfig(earlyBoundGeneratorConfig); return; } throw; } var extensions = earlyBoundGeneratorConfig.ExtensionConfig; if (UpdateConfigAppSetting(file, "ActionCommandLineText", extensions.ActionCommandLineText, true) | UpdateConfigAppSetting(file, "ActionPrefixesWhitelist", extensions.ActionPrefixesWhitelist) | UpdateConfigAppSetting(file, "ActionPrefixesToSkip", extensions.ActionPrefixesToSkip) | UpdateConfigAppSetting(file, "ActionsWhitelist", extensions.ActionsWhitelist) | UpdateConfigAppSetting(file, "ActionsToSkip", extensions.ActionsToSkip?.Replace("-", "")) | UpdateConfigAppSetting(file, "AddDebuggerNonUserCode", extensions.AddDebuggerNonUserCode.ToString()) | UpdateConfigAppSetting(file, "AddNewFilesToProject", extensions.AddNewFilesToProject.ToString()) | UpdateConfigAppSetting(file, "CreateOneFilePerAction", extensions.CreateOneFilePerAction.ToString()) | UpdateConfigAppSetting(file, "CreateOneFilePerEntity", extensions.CreateOneFilePerEntity.ToString()) | UpdateConfigAppSetting(file, "CreateOneFilePerOptionSet", extensions.CreateOneFilePerOptionSet.ToString()) | UpdateConfigAppSetting(file, "EntityAttributeSpecifiedNames", extensions.EntityAttributeSpecifiedNames) | UpdateConfigAppSetting(file, "EntityCommandLineText", extensions.EntityCommandLineText, true) | UpdateConfigAppSetting(file, "EntitiesToSkip", extensions.EntitiesToSkip) | UpdateConfigAppSetting(file, "EntitiesWhitelist", extensions.EntitiesWhitelist) | UpdateConfigAppSetting(file, "EntityPrefixesToSkip", extensions.EntityPrefixesToSkip) | UpdateConfigAppSetting(file, "EntityPrefixesWhitelist", extensions.EntityPrefixesWhitelist) | UpdateConfigAppSetting(file, "GenerateActionAttributeNameConsts", extensions.GenerateActionAttributeNameConsts.ToString()) | UpdateConfigAppSetting(file, "GenerateAttributeNameConsts", extensions.GenerateAttributeNameConsts.ToString()) | UpdateConfigAppSetting(file, "GenerateAnonymousTypeConstructor", extensions.GenerateAnonymousTypeConstructor.ToString()) | UpdateConfigAppSetting(file, "GenerateEntityRelationships", extensions.GenerateEntityRelationships.ToString()) | UpdateConfigAppSetting(file, "GenerateEnumProperties", extensions.GenerateEnumProperties.ToString()) | UpdateConfigAppSetting(file, "GenerateOnlyReferencedOptionSets", extensions.GenerateOnlyReferencedOptionSets.ToString()) | UpdateConfigAppSetting(file, "InvalidCSharpNamePrefix", extensions.InvalidCSharpNamePrefix) | UpdateConfigAppSetting(file, "MakeAllFieldsEditable", extensions.MakeAllFieldsEditable.ToString()) | UpdateConfigAppSetting(file, "MakeReadonlyFieldsEditable", extensions.MakeReadonlyFieldsEditable.ToString()) | UpdateConfigAppSetting(file, "MakeResponseActionsEditable", extensions.MakeResponseActionsEditable.ToString()) | UpdateConfigAppSetting(file, "LocalOptionSetFormat", extensions.LocalOptionSetFormat) | UpdateConfigAppSetting(file, "OptionSetPrefixesToSkip", extensions.OptionSetPrefixesToSkip) | UpdateConfigAppSetting(file, "OptionSetsToSkip", extensions.OptionSetsToSkip) | UpdateConfigAppSetting(file, "OptionSetCommandLineText", extensions.OptionSetCommandLineText, true) | UpdateConfigAppSetting(file, "OptionSetLanguageCodeOverride", extensions.OptionSetLanguageCodeOverride?.ToString()) | UpdateConfigAppSetting(file, "ProjectNameForEarlyBoundFiles", extensions.ProjectNameForEarlyBoundFiles ?? string.Empty) | UpdateConfigAppSetting(file, "PropertyEnumMappings", extensions.PropertyEnumMappings) | UpdateConfigAppSetting(file, "RemoveRuntimeVersionComment", extensions.RemoveRuntimeVersionComment.ToString()) | UpdateConfigAppSetting(file, "UseDeprecatedOptionSetNaming", extensions.UseDeprecatedOptionSetNaming.ToString()) | UpdateConfigAppSetting(file, "UnmappedProperties", extensions.UnmappedProperties) | UpdateConfigAppSetting(file, "UseTfsToCheckoutFiles", extensions.UseTfsToCheckoutFiles.ToString()) | UpdateConfigAppSetting(file, "UseXrmClient", extensions.UseXrmClient.ToString())) { file.Save(ConfigurationSaveMode.Minimal); } _configUpdated = true; } }
// 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 = 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 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; }