Exemplo n.º 1
0
        private IRfcConnection GetConnection()
        {
            if (string.IsNullOrWhiteSpace(_activeServer))
            {
                if (string.IsNullOrWhiteSpace(_rfcConfiguration.DefaultServer))
                {
                    if (_rfcConfiguration.RfcServers.Count == 1)
                    {
                        _activeServer = _rfcConfiguration.RfcServers.Single().Alias;
                    }
                    else
                    {
                        throw new RfcException("The default SAP server could not be detected.");
                    }
                }
                else
                {
                    if (_rfcConfiguration.RfcServers.Exists(s => s.Alias == _rfcConfiguration.DefaultServer))
                    {
                        _activeServer = _rfcConfiguration.DefaultServer;
                    }
                    else
                    {
                        throw new RfcException("Default SAP server connection settings were not found.");
                    }
                }
            }

            RfcServer server = _rfcConfiguration.RfcServers.Single(s => s.Alias == _activeServer);

            if (server.ConnectionPooling.Enabled)
            {
                IRfcConnectionPoolServiceFactory factory = _serviceProvider.GetRequiredService <IRfcConnectionPoolServiceFactory>();
                IRfcConnectionPool connectionPool        = factory.GetService(_activeServer);

                return(connectionPool.GetConnection());
            }

            IRfcConnection rfcConnection = _serviceProvider.GetRequiredService <IRfcConnection>();

            rfcConnection.Connect(_activeServer);
            return(rfcConnection);
        }
Exemplo n.º 2
0
 public void SetPool(IRfcConnectionPool sapConnectionPool)
 {
     _rfcConnectionPool = sapConnectionPool;
     IsPooled           = sapConnectionPool != null;
 }