Exemplo n.º 1
0
        public DataSource GetSingleById(long dataSourceId, bool loadTables, bool loadColumns)
        {
            try
            {
                var db      = SqlDatabaseFactory.Create(Constants.ConnectionStrings.Core);
                var command = db.GetStoredProcCommand("[dbo].[pr_GetDataSourceById]");

                db.AddInParameter(command, "@data_source_id", SqlDbType.BigInt, dataSourceId);

                using (var result = db.ExecuteDataSet(command))
                {
                    if (result.Tables[0].Rows.Count == 0)
                    {
                        throw new Exception("The data source could not be found. It might've been deleted by another user.");
                    }

                    var dataSourceRow     = result.Tables[0].Rows[0];
                    var connectionInfoRow = result.Tables[1].Rows[0];

                    DataSource source = convertDataRowToDataSource(dataSourceRow);
                    source.DataConnectionInfo = convertDataRowToDataConnectionInfo(connectionInfoRow);

                    if (loadTables)
                    {
                        source.Tables.AddRange(GetTableInfosByDataSourceId(dataSourceId, loadColumns));
                    }

                    return(source);
                }
            }
            catch (Exception ex)
            {
                throw new BasicDataException(string.Format("An unexpected error occurred while getting connections. ERROR: {0}", ex.Message), ex);
            }
        }
Exemplo n.º 2
0
        public List <DataSource> GetAllByProjectId(int projectId, bool loadTables, bool loadColumns)
        {
            try
            {
                List <DataSource> resultSet;

                var db      = SqlDatabaseFactory.Create(Constants.ConnectionStrings.Core);
                var command = db.GetStoredProcCommand("[dbo].[pr_GetDataSourcesByProjectId]");

                db.AddInParameter(command, "@project_id", SqlDbType.Int, projectId);

                using (var result = db.ExecuteDataSet(command))
                {
                    var defaultTable = result.Tables[0];
                    resultSet = new List <DataSource>(defaultTable.Rows.Count);
                    resultSet.AddRange(from DataRow row in defaultTable.Rows
                                       select convertDataRowToDataSource(row));
                }

                return(resultSet);
            }
            catch (Exception ex)
            {
                throw new BasicDataException(string.Format("An unexpected error occurred while getting connections. ERROR: {0}", ex.Message), ex);
            }
        }
Exemplo n.º 3
0
        public List <ColumnInfo> GetColumnInfosByTableInfoId(long tableInfoId)
        {
            try
            {
                List <ColumnInfo> resultSet;

                var db      = SqlDatabaseFactory.Create(Constants.ConnectionStrings.Core);
                var command = db.GetStoredProcCommand("[dbo].[pr_GetColumnsInfosByTableInfoId]");

                db.AddInParameter(command, "@table_info_id", DbType.Int64, tableInfoId);

                using (var result = db.ExecuteDataSet(command))
                {
                    var defaultTable = result.Tables[0];
                    resultSet = new List <ColumnInfo>(defaultTable.Rows.Count);
                    resultSet.AddRange(from DataRow row in defaultTable.Rows
                                       select convertDataRowToColumnInfo(row));
                }

                return(resultSet);
            }
            catch (Exception ex)
            {
                throw new BasicDataException(string.Format("An unexpected error occurred while loading columns by table id. ERROR: {0}", ex.Message), ex);
            }
        }
Exemplo n.º 4
0
        public void UpdateTableInfoMappings(long dataSourceId, List <TableInfo> tableInfos)
        {
            var datasource = GetSingleById(dataSourceId, false, false);

            try
            {
                var db = SqlDatabaseFactory.Create(Constants.ConnectionStrings.Core);

                // Delete existing
                deleteAllTableInfosAndColumnInfos(db, dataSourceId);

                // Connect to the database in the connection info
                var databaseConn = DatabaseFacadeFactory.Create(datasource.DataConnectionInfo);

                // Add schema
                foreach (TableInfo tableInfo in tableInfos)
                {
                    // add table
                    long tableId = createTableInfo(db, dataSourceId, tableInfo);
                    // add columns
                    bulkInsertColumnInfos(db, tableId, databaseConn.GetColumns(tableInfo.ObjectId));
                }
            }
            catch (Exception ex)
            {
                throw new BasicDataException(string.Format("An unexpected error occurred while updating tables mappings. ERROR: {0}", ex.Message), ex);
            }
        }
Exemplo n.º 5
0
        public DataConnectionInfo CreateConnection(string serverName, string databaseName, string username, string password, DataConnectionType type)
        {
            try
            {
                var db = SqlDatabaseFactory.Create(Constants.ConnectionStrings.Core);

                var command = db.GetStoredProcCommand("[dbo].[pr_CreateDataConnectionInfo]");
                db.AddInParameter(command, "@server_name", SqlDbType.NVarChar, serverName);
                db.AddInParameter(command, "@database_name", SqlDbType.NVarChar, databaseName);
                db.AddInParameter(command, "@username", SqlDbType.NVarChar, username);
                db.AddInParameter(command, "@password", SqlDbType.NVarChar, password);
                db.AddInParameter(command, "@type", SqlDbType.SmallInt, type);

                using (DataSet dataSet = db.ExecuteDataSet(command))
                {
                    var connectionInfo = new DataConnectionInfo();

                    connectionInfo.DatabaseName         = databaseName;
                    connectionInfo.ServerName           = serverName;
                    connectionInfo.Username             = username;
                    connectionInfo.Password             = password;
                    connectionInfo.ConnectionType       = type;
                    connectionInfo.DataConnectionInfoId = dataSet.Tables[0].Rows[0].Field <long>(0);
                    connectionInfo.ModifiedOn           = DateTime.Now;
                    connectionInfo.CreatedOn            = DateTime.Now;

                    return(connectionInfo);
                }
            }
            catch (Exception ex)
            {
                throw new BasicDataException(string.Format("An unexpected error occurred while creating a connection. ERROR: {0}", ex.Message), ex);
            }
        }
Exemplo n.º 6
0
        public Project GetSingleById(int projectId)
        {
            try
            {
                var db      = SqlDatabaseFactory.Create(Constants.ConnectionStrings.Core);
                var command = db.GetStoredProcCommand("[dbo].[pr_GetSingleProject]");
                db.AddInParameter(command, "@project_id", SqlDbType.Int, projectId);

                using (var resultDataSet = db.ExecuteDataSet(command))
                {
                    // Get Project
                    var projectInfoTable = resultDataSet.Tables[0];
                    if (projectInfoTable.Rows.Count == 0)
                    {
                        throw new Exception("Project no longer exists. It might've been deleted by another user.");
                    }

                    DataRow projectInfoRow = projectInfoTable.Rows[0];
                    Project project        = convertDataRowToProject(projectInfoRow);

                    // Get Data Sources
                    project.DataSources.AddRange(_dataSourceRepository.GetAllByProjectId(projectId, true, false));

                    return(project);
                }
            }
            catch (Exception ex)
            {
                throw new BasicDataException(
                          string.Format("An unexpected error occurred while retrieving the project. Error: {0}", ex.Message),
                          ex,
                          string.Format("Project Id: {0}", projectId));
            }
        }
Exemplo n.º 7
0
        public void CreateProject(string name, string description)
        {
            try
            {
                var db = SqlDatabaseFactory.Create(Constants.ConnectionStrings.Core);

                var command = db.GetStoredProcCommand("[dbo].[pr_CreateProject]");
                db.AddInParameter(command, "@name", SqlDbType.NVarChar, name);
                db.AddInParameter(command, "@description", SqlDbType.NVarChar, description);

                db.ExecuteNonQuery(command);
            }
            catch (Exception ex)
            {
                throw new BasicDataException(string.Format("An unexpected error occurred while creating the project. ERROR: {0}", ex.Message), ex);
            }
        }
Exemplo n.º 8
0
        public void UpdateInfo(long dataSourceId, string name, string description, int connectionInfoId)
        {
            try
            {
                var db = SqlDatabaseFactory.Create(Constants.ConnectionStrings.Core);

                var command = db.GetStoredProcCommand("[dbo].[pr_UpdateDataSourceInfo]");
                db.AddInParameter(command, "@data_source_id", SqlDbType.BigInt, dataSourceId);
                db.AddInParameter(command, "@name", SqlDbType.NVarChar, name);
                db.AddInParameter(command, "@description", SqlDbType.NVarChar, description);
                db.AddInParameter(command, "@data_connection_info_id", SqlDbType.Int, connectionInfoId);

                db.ExecuteNonQuery(command);
            }
            catch (Exception ex)
            {
                throw new BasicDataException(string.Format("An unexpected error occurred while update the data source. ERROR: {0}", ex.Message), ex);
            }
        }
        private static IObjectStoreService CreateStorageService(string storagePath, string databaseConnectionString)
        {
            IDicomMediaIdFactory      mediaIdFactory = new DicomMediaIdFactory( );
            IMediaStorageService      storageService = new FileStorageService(storagePath);
            DbSchemaProvider          schemaProvider = new StorageDbSchemaProvider( );
            IDatabaseFactory          databaseFacory = new SqlDatabaseFactory(databaseConnectionString);
            ObjectArchieveDataAdapter dataAdapter    = new ObjectArchieveDataAdapter(schemaProvider, databaseFacory);
            IObjectArchieveDataAccess dataAccess     = new ObjectArchieveDataAccess(databaseConnectionString,
                                                                                    schemaProvider,
                                                                                    dataAdapter);
            IDicomMediaWriterFactory mediaWriterFactory = new DicomMediaWriterFactory(storageService,
                                                                                      mediaIdFactory);
            IDCloudCommandFactory factory = new DCloudCommandFactory(storageService,
                                                                     dataAccess,
                                                                     mediaWriterFactory,
                                                                     mediaIdFactory);

            IObjectStoreService StoreService = new ObjectStoreService(factory);

            return(StoreService);
        }
Exemplo n.º 10
0
        public List <DataConnectionInfo> GetAllConnections()
        {
            try
            {
                List <DataConnectionInfo> resultSet;

                var db      = SqlDatabaseFactory.Create(Constants.ConnectionStrings.Core);
                var command = db.GetStoredProcCommand("[dbo].[pr_GetAllDataConnections]");

                using (var result = db.ExecuteDataSet(command))
                {
                    var defaultTable = result.Tables[0];
                    resultSet = new List <DataConnectionInfo>(defaultTable.Rows.Count);
                    resultSet.AddRange(from DataRow row in defaultTable.Rows
                                       select convertDataRowToDataConnectionInfo(row));
                }

                return(resultSet);
            }
            catch (Exception ex)
            {
                throw new BasicDataException(string.Format("An unexpected error occurred while getting connections. ERROR: {0}", ex.Message), ex);
            }
        }