public void vGetServerName(string sPath) { using (StreamReader sr = new StreamReader((string.IsNullOrEmpty(sPath) ? @"\\joi\eu\Collaboration\EEPT\SQL Server Information.txt" : sPath), true)) { string sServerInformation = sr.ReadToEnd(); string[] sa; char[] delimiterChars = { '\r', '\n' }; sa = sServerInformation.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < sa.Length; i++) { if (sa[i].Contains("Server Name")) { SqlServerName = sa[i].Replace("\r", "").Replace("\n", "").Replace("Server Name = ", "").Trim(); if (!string.IsNullOrEmpty(SqlServerName)) { EEPTConnectionString = EEPTConnectionString.Replace("<SQLSERVERNAME>", SqlServerName); HOPEConnectionString = HOPEConnectionString.Replace("<SQLSERVERNAME>", SqlServerName); HB_ECO_ConnectionString = HB_ECO_ConnectionString.Replace("<SQLSERVERNAME>", SqlServerName); HummingBirdConnectionString = HummingBirdConnectionString.Replace("<SQLSERVERNAME>", SqlServerName); ProductTestConnectionString = ProductTestConnectionString.Replace("<SQLSERVERNAME>", SqlServerName); PurchasingConnectionString = PurchasingConnectionString.Replace("<SQLSERVERNAME>", SqlServerName); TrainingConnectionString = TrainingConnectionString.Replace("<SQLSERVERNAME>", SqlServerName); YesDBConnectionString = YesDBConnectionString.Replace("<SQLSERVERNAME>", SqlServerName); RepairConnectionString = RepairConnectionString.Replace("<SQLSERVERNAME>", SqlServerName); TestConnectionString = TestConnectionString.Replace("<SQLSERVERNAME>", SqlServerName); VisitorPortalConnectionString = VisitorPortalConnectionString.Replace("<SQLSERVERNAME>", SqlServerName); SQLServerConnectionString = SQLServerConnectionString.Replace("<SQLSERVERNAME>", SqlServerName); } } } } }
public static string GetConnectionString( DBMSSetting dbmsSetting, ConnectionString connectionString, SQLServerConnectionString sqlServerConnectionString, PostgreSQLConnectionString postgreSQLConnectionString) { if (dbmsSetting.UseMSSQL) { return(sqlServerConnectionString.UsersConnectionString); } else if (dbmsSetting.UsePostgreSQL) { return(postgreSQLConnectionString.UsersConnectionString); } else { return(connectionString.DefaultConnectionString); } }
/// <summary> /// Compila un esquema de base de datos /// </summary> private Schema LoadSchema(Models.SqlServerConnectionModel objConnection) { SQLServerConnectionString objConnectionString = new SQLServerConnectionString(objConnection.Server, objConnection.User, objConnection.Password, objConnection.DataBase); Schema objSchema; // Asigna el resto de las propiedades if (objConnection.DataBaseFileName.IsEmpty()) { objConnectionString.Type = SQLServerConnectionString.ConnectionType.Normal; } else { objConnectionString.DataBaseFile = objConnection.DataBaseFileName; objConnectionString.Type = SQLServerConnectionString.ConnectionType.File; } objConnectionString.UseIntegratedSecurity = objConnection.UseWindowsAuthentification; // Carga el esquema y le asigna los datos objSchema = new SchemaSqlServerProvider().LoadSchema(objConnectionString); objSchema.Server = objConnection.Server; objSchema.DataBase = objConnection.DataBase; // Devuelve el esquema return(objSchema); }
// ConfigureServices is where you register dependencies. // This method gets called by the runtime. // Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { // Add services to the collection. services .AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddXmlDataContractSerializerFormatters() .AddMvcOptions(options => { options.FormatterMappings.SetMediaTypeMappingForFormat( Format.XmlFormat.Xml, new MediaTypeHeaderValue(Format.XmlFormat.ApplicationXml)); }); services.AddMemoryCache(); _jwtSetting = Configuration.GetSection(nameof(JwtSetting)) .Get <JwtSetting>(); _dbmsSetting = Configuration.GetSection(nameof(DBMSSetting)) .Get <DBMSSetting>(); _connectionString = Configuration.GetSection(nameof(ConnectionString)) .Get <ConnectionString>(); _sqlServerConnectionString = Configuration.GetSection(nameof(SQLServerConnectionString)) .Get <SQLServerConnectionString>(); _postgreSQLConnectionString = Configuration.GetSection(nameof(PostgreSQLConnectionString)) .Get <PostgreSQLConnectionString>(); _cacheSetting = Configuration.GetSection(nameof(CacheSetting)) .Get <CacheSetting>(); _appSetting = Configuration.GetSection(nameof(AppSetting)) .Get <AppSetting>(); services .Configure <JwtSetting>( Configuration.GetSection(nameof(JwtSetting))) .Configure <DBMSSetting>( Configuration.GetSection(nameof(DBMSSetting))) .Configure <ConnectionString>( Configuration.GetSection(nameof(ConnectionString))) .Configure <SQLServerConnectionString>( Configuration.GetSection(nameof(SQLServerConnectionString))) .Configure <PostgreSQLConnectionString>( Configuration.GetSection(nameof(PostgreSQLConnectionString))) .Configure <CacheSetting>( Configuration.GetSection(nameof(CacheSetting))) .Configure <AppSetting>( Configuration.GetSection(nameof(AppSetting))); // Set authentication scheme for JWT and set JWT provider configuration. services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = false, ValidateIssuerSigningKey = true, ValidateAudience = false, ValidateLifetime = true, IssuerSigningKey = new SymmetricSecurityKey( Encoding.ASCII.GetBytes(_jwtSetting.Key)) }; }); // Register the Swagger generator, defining 1 or more Swagger documents. services.AddSwaggerGen(swagger => { swagger.SwaggerDoc("v1", new Info { Title = Parameters.Authorization, Version = "v1" }); swagger.AddSecurityDefinition(Parameters.Bearer, new ApiKeyScheme { In = Parameters.Header.FirstCharToLower(), Description = Resource.SwaggerSecurityDefinition, Name = Parameters.Authorization, Type = Parameters.ApiKey.FirstCharToLower() }); swagger.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > { { Parameters.Bearer, new string[] { } } }); }); // Create the IServiceProvider based on the container. return(AutofacConfigurator.GetAutofacServiceProvider( services, ApplicationContainer, DBMSSetting.GetDBMS(_dbmsSetting), DBMSSetting.GetConnectionString( _dbmsSetting, _connectionString, _sqlServerConnectionString, _postgreSQLConnectionString) )); }