Beispiel #1
0
        // Create -------------------------------------

        /// <summary>
        /// Creates a connector.
        /// </summary>
        /// <param name="scope">The scope to consider.</param>
        /// <param name="dataSource">The data source to consider.</param>
        /// <param name="connectorDefinitionUniqueId">The connector definition name to consider.</param>
        /// <param name="log">The log of execution to consider.</param>
        /// <returns>Returns True if the connector has been opened. False otherwise.</returns>
        public static T Open <T>(
            this IBdoScope scope,
            IDatasource dataSource,
            string connectorDefinitionUniqueId,
            IBdoLog log = null)
            where T : class, IBdoConnection
        {
            if (log == null)
            {
                log = new BdoLog();
            }

            if (dataSource == null)
            {
                log.AddError("Data source missing");
            }
            else if (!string.IsNullOrEmpty(connectorDefinitionUniqueId) && dataSource.HasConfiguration(connectorDefinitionUniqueId))
            {
                log.AddError("Connection not defined in data source", description: "No connector is defined in the specified data source.");
            }
            else if (!string.IsNullOrEmpty(connectorDefinitionUniqueId))
            {
                return(scope.Open <T>(dataSource.GetConfiguration(connectorDefinitionUniqueId), log));
            }
            else if (dataSource.Configurations.Count > 0)
            {
                return(scope.Open <T>(dataSource.Configurations[0], log));
            }

            return(default);