private static RfcConfiguration ConfigureByRfcConnectionString(RfcConfiguration rfcConfiguration, string defaultAlias, string connectionString) { rfcConfiguration.DefaultServer = defaultAlias; rfcConfiguration.RfcServers ??= new List <RfcServer>(); rfcConfiguration.RfcServers.Clear(); if (string.IsNullOrWhiteSpace(defaultAlias)) { throw new RfcException("Required value is not entered in server settings: 'Alias'"); } var rfcServerConnection = new RfcServer { Alias = defaultAlias }; if (string.IsNullOrWhiteSpace(connectionString)) { throw new RfcException("'ConnectionString' is required, please check your 'ConnectionString' information and try again."); } rfcServerConnection.ConnectionOptions.Parse(connectionString); rfcConfiguration.RfcServers.Add(rfcServerConnection); if (rfcConfiguration.RfcServers.Count > 1 && !rfcConfiguration.RfcServers.Exists(s => s.Alias == rfcConfiguration.DefaultServer)) { throw new RfcException("The default server value is not included in the server definitions."); } return(rfcConfiguration); }
public RfcClient(IServiceProvider serviceProvider, IOptions <RfcConfiguration> configurationOptions) { _serviceProvider = serviceProvider; _rfcConfiguration = configurationOptions.Value; _propertyCache = _serviceProvider.GetRequiredService <IPropertyCache>(); IRfcNetWeaverLibrary rfcNetWeaverLibrary = serviceProvider.GetRequiredService <IRfcNetWeaverLibrary>(); rfcNetWeaverLibrary.EnsureLibraryPresent(); }
private static void GenerateConnectionPools(IServiceCollection services, RfcConfiguration rfcConfiguration) { foreach (RfcServer sapServerConnection in rfcConfiguration.RfcServers) { if (sapServerConnection.ConnectionPooling.Enabled) { services.AddSingleton <IRfcConnectionPool>(s => new RfcConnectionPool(s, sapServerConnection.Alias, rfcConfiguration)); } } }
public static IServiceCollection AddSapCo2(this IServiceCollection services, Action <RfcConfiguration> configurationAction) { services.AddOptions(); services.Configure(configurationAction); services.AddSapCo2Core(); services.TryAddTransient <IRfcClient, RfcClient>(); services.TryAddTransient <IRfcConnectionPoolServiceFactory, RfcConnectionPoolServiceFactory>(); services.TryAddSingleton <IPropertyCache, PropertyCache>(); RfcConfiguration sapConfiguration = services.BuildServiceProvider().GetRequiredService <IOptions <RfcConfiguration> >().Value; GenerateConnectionPools(services, sapConfiguration); return(services); }
private static RfcConfiguration ConfigureByRfcConnection(RfcConfiguration rfcConfiguration, string defaultConnectionAlias, IEnumerable <RfcServer> rfcConnections) { rfcConfiguration.DefaultServer = defaultConnectionAlias; rfcConfiguration.RfcServers ??= new List <RfcServer>(); rfcConfiguration.RfcServers.Clear(); foreach (var rfcConnection in rfcConnections) { if (rfcConfiguration.RfcServers.Any(s => s.Alias == rfcConnection.Alias)) { throw new RfcException("Multiple servers have the same 'Alias' value."); } if (string.IsNullOrWhiteSpace(rfcConnection.Alias)) { throw new RfcException("Required value is not entered in server settings: 'Alias'"); } var rfcServerConnection = new RfcServer { Alias = rfcConnection.Alias }; if (rfcConnection.ConnectionPooling != null) { rfcServerConnection.ConnectionPooling = rfcConnection.ConnectionPooling; } if (!string.IsNullOrWhiteSpace(rfcConnection.ConnectionString)) { rfcServerConnection.ConnectionOptions.Parse(rfcConnection.ConnectionString); } if (rfcConnection.ConnectionOptions != null) { rfcServerConnection.ConnectionOptions = rfcConnection.ConnectionOptions; } rfcConfiguration.RfcServers.Add(rfcServerConnection); } if (rfcConfiguration.RfcServers.Count > 1 && !rfcConfiguration.RfcServers.Exists(s => s.Alias == rfcConfiguration.DefaultServer)) { throw new RfcException("The default server value is not included in the server definitions."); } return(rfcConfiguration); }
public static void ClassInitializer(TestContext context) { RfcConfiguration = new RfcConfiguration() { DefaultServer = "TEST", RfcServers = new List <RfcServer> { new RfcServer() { Alias = "TEST", ConnectionString = "Name:TEST;AppServerHost=test.domain.com;User=username;Password=p4ssw00rd;SystemId:xxx;SystemNumber=00; Client=100; Language=TR; PoolSize=50;MaxPoolSize:100;IdleTimeout:600;Trace=0", ConnectionPooling = { Enabled = false, PoolSize = 0, IdleTimeout = TimeSpan.FromSeconds(30), IdleDetectionInterval = TimeSpan.FromSeconds(1) } }, new RfcServer() { Alias = "TEST2", ConnectionOptions = new RfcConnectionOption() { Name = "TEST2", AppServerHost = "test.domain.com", User = "******", Password = "******", SystemId = "xxx", SystemNumber = "00", Client = "100", Language = "TR", PoolSize = "50", IdleTimeout = "600", Trace = "0" }, ConnectionPooling = { Enabled = false, PoolSize = 0, IdleTimeout = TimeSpan.FromSeconds(30), IdleDetectionInterval = TimeSpan.FromSeconds(1) } } } }; RfcConfigurationOption = Options.Create(RfcConfiguration); }
private static RfcConfiguration ConfigureByConfiguration(RfcConfiguration rfcConfiguration, IConfiguration configuration, string section) { IConfigurationSection configurationSection = configuration.GetSection(section); if (configurationSection == null || !configurationSection.Exists()) { return(rfcConfiguration); } rfcConfiguration.DefaultServer = configurationSection.GetValue <string>(DEFAULT_CONNECTION_KEY); rfcConfiguration.RfcServers ??= new List <RfcServer>(); rfcConfiguration.RfcServers.Clear(); IConfigurationSection connectionsSection = configurationSection.GetSection(RFC_SERVERS_KEY); if (connectionsSection == null || !connectionsSection.Exists()) { return(rfcConfiguration); } foreach (IConfigurationSection rfcServerConnectionSection in connectionsSection.GetChildren()) { string alias = rfcServerConnectionSection.GetValue <string>(ALIAS_KEY); if (rfcConfiguration.RfcServers.Any(s => s.Alias == alias)) { throw new RfcException("Application settings are not configured correctly. Multiple servers have the same 'Alias' value."); } if (string.IsNullOrWhiteSpace(alias)) { throw new RfcException("Application settings are not configured correctly. Required value is not entered in server settings: 'Alias'"); } var rfcServerConnection = new RfcServer { Alias = alias }; IConfigurationSection poolingSection = rfcServerConnectionSection.GetSection(CONNECTION_POOLING_KEY); if (poolingSection != null && poolingSection.Exists()) { poolingSection.Bind(rfcServerConnection.ConnectionPooling); } rfcServerConnection.ConnectionString = rfcServerConnectionSection.GetValue <string>(CONNECTION_STRING_KEY); if (!string.IsNullOrWhiteSpace(rfcServerConnection.ConnectionString)) { rfcServerConnection.ConnectionOptions.Parse(rfcServerConnection.ConnectionString); } IConfigurationSection connectionOptionsSection = rfcServerConnectionSection.GetSection(CONNECTION_OPTIONS_KEY); if (connectionOptionsSection != null && connectionOptionsSection.Exists()) { connectionOptionsSection.Bind(rfcServerConnection.ConnectionOptions); } rfcConfiguration.RfcServers.Add(rfcServerConnection); } if (rfcConfiguration.RfcServers.Count > 1 && !rfcConfiguration.RfcServers.Exists(s => s.Alias == rfcConfiguration.DefaultServer)) { throw new RfcException("Application settings are not configured correctly. The default server value is not included in the server definitions."); } return(rfcConfiguration); }
public static RfcConfiguration ReadFromConfiguration(this RfcConfiguration rfcConfiguration, IConfiguration configuration, string section) { return(ConfigureByConfiguration(rfcConfiguration, configuration, section)); }
private static RfcConfiguration CreateConfiguration(this RfcConfiguration rfcConfiguration, string defaultAlias, string connectionString) { return(ConfigureByRfcConnectionString(rfcConfiguration, defaultAlias, connectionString)); }
private static RfcConfiguration CreateConfiguration(this RfcConfiguration rfcConfiguration, string defaultAlias, IEnumerable <RfcServer> rfcConnections) { return(ConfigureByRfcConnection(rfcConfiguration, defaultAlias, rfcConnections)); }
public static RfcConfiguration ReadFromConfiguration(this RfcConfiguration rfcConfiguration, IConfiguration configuration) { return(ConfigureByConfiguration(rfcConfiguration, configuration, DEFAULT_CONFIGURATION_KEY)); }
public RfcConnection(IRfcInterop interop, IOptions <RfcConfiguration> options) { _interop = interop; _rfcConfiguration = options.Value; }
public static void Cleaner() { RfcConfiguration = null; RfcConfigurationOption = null; }