Пример #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);
Пример #2
0
        // Open -------------------------------------

        /// <summary>
        /// Creates a connector.
        /// </summary>
        /// <param name="scope">The scope to consider.</param>
        /// <param name="depot">The data source depot to consider.</param>
        /// <param name="dataSourceName">The data source name 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,
            IBdoDatasourceDepot depot,
            string dataSourceName,
            string connectorDefinitionUniqueId,
            IBdoLog log = null)
            where T : class, IBdoConnection
        {
            if (log == null)
            {
                log = new BdoLog();
            }

            if (depot == null)
            {
                depot = scope?.DataStore?.Get <IBdoDatasourceDepot>();
            }

            if (depot == null)
            {
                log.AddError("Data source depot missing");
            }
            else if (!depot.HasItem(dataSourceName))
            {
                log.AddError("Data source '" + dataSourceName + "' missing in depot");
            }
            else
            {
                return(scope.Open <T>(depot.Get(dataSourceName), connectorDefinitionUniqueId, log));
            }

            return(default);