예제 #1
0
        private DiscoveredServer GetServer(IDataAccessPoint dataAccessPoint, DataAccessContext context, bool setInitialDatabase)
        {
            IDataAccessCredentials credentials = dataAccessPoint.GetCredentialsIfExists(context);

            if (string.IsNullOrWhiteSpace(dataAccessPoint.Server))
            {
                throw new NullReferenceException("Could not get connection string because Server was null on dataAccessPoint '" + dataAccessPoint + "'");
            }

            string dbName = null;

            if (setInitialDatabase)
            {
                if (!string.IsNullOrWhiteSpace(dataAccessPoint.Database))
                {
                    dbName = dataAccessPoint.GetQuerySyntaxHelper().GetRuntimeName(dataAccessPoint.Database);
                }
                else
                {
                    throw new Exception("Could not get server with setInitialDatabase=true because no Database was set on IDataAccessPoint " + dataAccessPoint);
                }
            }

            var server = new DiscoveredServer(dataAccessPoint.Server, dbName, dataAccessPoint.DatabaseType, credentials?.Username, credentials?.GetDecryptedPassword());

            return(server);
        }
예제 #2
0
        public DataTableViewerUI(IDataAccessPoint source, string sql, string caption)
        {
            InitializeComponent();

            try
            {
                using (DbConnection con = DataAccessPortal.GetInstance().ExpectServer(source, DataAccessContext.DataExport).GetConnection())
                {
                    con.Open();

                    using (var cmd = DatabaseCommandHelper.GetCommand(sql, con))
                        using (var da = DatabaseCommandHelper.GetDataAdapter(cmd))
                        {
                            DataTable dt = new DataTable();
                            da.Fill(dt);
                            dataGridView1.DataSource = dt;
                        }
                }
            }
            catch (Exception e)
            {
                ExceptionViewer.Show("Failed to connect to source " + source + " and execute SQL: " + Environment.NewLine + sql, e);
            }

            this.Text = caption;
        }
예제 #3
0
 public CohortIdentificationTaskExecution(IDataAccessPoint cacheServerIfAny, string countSQL, string cumulativeSQL, CancellationTokenSource cancellationTokenSource, int subQueries, int subqueriesCached, bool isResultsForRootContainer)
 {
     _cacheServerIfAny         = cacheServerIfAny;
     SubQueries                = subQueries;
     SubqueriesCached          = subqueriesCached;
     CountSQL                  = countSQL;
     CumulativeSQL             = cumulativeSQL;
     _cancellationTokenSource  = cancellationTokenSource;
     IsResultsForRootContainer = isResultsForRootContainer;
 }
예제 #4
0
 public LogManager(IDataAccessPoint loggingServer) : this(DataAccessPortal.GetInstance().ExpectServer(loggingServer, DataAccessContext.Logging))
 {
     DataAccessPointIfAny = loggingServer;
 }
 private DbConnection GetConnectionToOtherTable(IDataAccessPoint tableInfo)
 {
     return(DataAccessPortal.GetInstance()
            .ExpectServer(tableInfo, DataAccessContext.InternalDataProcessing)
            .GetConnection());
 }
예제 #6
0
        /// <inheritdoc/>
        public DiscoveredServer GetDistinctLiveDatabaseServer(DataAccessContext context, bool setInitialDatabase, out IDataAccessPoint distinctAccessPoint)
        {
            var tables = GetTableInfosIdeallyJustFromMainTables();

            distinctAccessPoint = tables.FirstOrDefault();

            return(DataAccessPortal.GetInstance().ExpectDistinctServer(tables, context, setInitialDatabase));
        }
예제 #7
0
 /// <summary>
 /// Attempts to add <paramref name="point"/> to the collection returning true if it was successfully added.  Returns false
 /// if not added (e.g. if <see cref="SingleServer"/> is true and <paramref name="point"/> is to a different server/type).
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public bool TryAdd(IDataAccessPoint point)
 {
     return(TryAddRange(new [] { point }));
 }
예제 #8
0
 /// <summary>
 /// Adds the given <paramref name="point"/> to the collection. Throws InvalidOperationException if <see cref="SingleServer"/>
 /// is set and the new <paramref name="point"/> is on a different server or <see cref="DatabaseType"/>
 /// </summary>
 /// <param name="point"></param>
 public void Add(IDataAccessPoint point)
 {
     AddRange(new[] { point });
 }
예제 #9
0
 /// <summary>
 /// Tests whether the supplied <paramref name="point"/> could be added to the current collection (without
 /// actually adding it).
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public bool AddWouldBePossible(IDataAccessPoint point)
 {
     return(Clone().TryAdd(point));
 }
예제 #10
0
        private IDataAccessPoint GetDistinct(IDataAccessPoint[] collection, DataAccessContext context, bool setInitialDatabase)
        {
            ///////////////////////Exception handling///////////////////////////////////////////////
            if (!collection.Any())
            {
                throw new Exception("No IDataAccessPoints were passed, so no connection string builder can be created");
            }

            IDataAccessPoint first = collection.First();

            //There can be only one - server
            foreach (IDataAccessPoint accessPoint in collection)
            {
                if (!first.Server.Equals(accessPoint.Server))
                {
                    throw new ExpectedIdenticalStringsException("There was a mismatch in server names for data access points " + first + " and " + accessPoint + " server names must match exactly", first.Server, accessPoint.Server);
                }

                if (first.DatabaseType != accessPoint.DatabaseType)
                {
                    throw new ExpectedIdenticalStringsException("There was a mismatch on DatabaseType for data access points " + first + " and " + accessPoint, first.DatabaseType.ToString(), accessPoint.DatabaseType.ToString());
                }

                if (setInitialDatabase)
                {
                    if (string.IsNullOrWhiteSpace(first.Database))
                    {
                        throw new Exception("DataAccessPoint '" + first + "' does not have a Database specified on it");
                    }

                    var querySyntaxHelper = accessPoint.GetQuerySyntaxHelper();

                    var firstDbName   = querySyntaxHelper.GetRuntimeName(first.Database);
                    var currentDbName = querySyntaxHelper.GetRuntimeName(accessPoint.Database);

                    if (!firstDbName.Equals(currentDbName))
                    {
                        throw new ExpectedIdenticalStringsException("All data access points must be into the same database, access points '" + first + "' and '" + accessPoint + "' are into different databases", firstDbName, currentDbName);
                    }
                }
            }

            //There can be only one - credentials (but there might not be any)
            var credentials = collection.Select(t => t.GetCredentialsIfExists(context)).ToArray();

            //if there are credentials
            if (credentials.Any(c => c != null))
            {
                if (credentials.Any(c => c == null))//all objects in collection must have a credentials if any of them do
                {
                    throw new Exception("IDataAccessPoint collection could not agree whether to use Credentials or not " + Environment.NewLine
                                        + "Objects wanting to use Credentials" + string.Join(",", collection.Where(c => c.GetCredentialsIfExists(context) != null).Select(s => s.ToString())) + Environment.NewLine
                                        + "Objects not wanting to use Credentials" + string.Join(",", collection.Where(c => c.GetCredentialsIfExists(context) == null).Select(s => s.ToString())) + Environment.NewLine
                                        );
                }
                else
                //There can be only one - Username
                if (credentials.Select(c => c.Username).Distinct().Count() != 1)
                {
                    throw new Exception("IDataAccessPoint collection could not agree on a single Username to use to access the data under context " + context + " (Servers were " + string.Join("," + Environment.NewLine, collection.Select(c => c + " = " + c.Database + " - " + c.DatabaseType)) + ")");
                }
                else
                //There can be only one - Password
                if (credentials.Select(c => c.GetDecryptedPassword()).Distinct().Count() != 1)
                {
                    throw new Exception("IDataAccessPoint collection could not agree on a single Password to use to access the data under context " + context + " (Servers were " + string.Join("," + Environment.NewLine, collection.Select(c => c + " = " + c.Database + " - " + c.DatabaseType)) + ")");
                }
            }



            ///////////////////////////////////////////////////////////////////////////////

            //the bit that actually matters:
            return(first);
        }
예제 #11
0
 public DiscoveredDatabase ExpectDatabase(IDataAccessPoint dataAccessPoint, DataAccessContext context)
 {
     return(GetServer(dataAccessPoint, context, true).GetCurrentDatabase());
 }
예제 #12
0
 public DiscoveredServer ExpectServer(IDataAccessPoint dataAccessPoint, DataAccessContext context, bool setInitialDatabase = true)
 {
     return(GetServer(dataAccessPoint, context, setInitialDatabase));
 }
예제 #13
0
 public LoggingDatabaseChecker(IDataAccessPoint target)
     : this(DataAccessPortal.GetInstance().ExpectServer(target, DataAccessContext.Logging))
 {
 }