Exemplo n.º 1
0
 public AddAgency()
 {
     // Get the Classic RMS Connection String :Note this is kind of a hack and not
     // the best way to get at this information.
     // It is implemented this way to be consistent with the other connection strings.
     ClassicRmsConnectionString = ContextConnectionStringManager.Get("VSI_SYSTEM");
 }
Exemplo n.º 2
0
        /// <summary>
        /// Should return false if the command is not in a state ready to be executed.
        /// </summary>
        public override bool Ready()
        {
            if (string.IsNullOrWhiteSpace(Target))
            {
                return(false);
            }

            var conn = new SqlConnectionStringBuilder {
                DataSource = Target
            };

            if (string.IsNullOrWhiteSpace(Username))
            {
                conn.IntegratedSecurity = true;
            }
            else
            {
                conn.UserID   = Username;
                conn.Password = Password;
            }

            ConnectionString = conn.ToString();

            // Setup the Default Connection Strings
            ContextConnectionStringManager.SetupDefaultConnections(ConnectionString);

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Apply the Context Update.
        /// </summary>
        public virtual void Apply()
        {
            // Get the type information for the target migration of this Update.
            var migrationMetadata = new TMigration() as IMigrationMetadata;

            // Determine if this Update should target the "Latest" migration for the DbContext.
            // LatestMigration does not implement IMigrationMetadata.
            // All normal migrations will.
            var targetMigrationIsLatest = migrationMetadata == null;

            // Get the name of the target migration for this package or null if the target is "Latest".
            var targetMigrationName = targetMigrationIsLatest ? null: migrationMetadata.Id;

            // Create an Instance of the DbContext so we can get the connection information.
            var context = new TContext();

            // Instantiate the Configuration class
            var migrationConfiguration = new TConfiguration();

            // Specify the target Database of the Migration.  Note: We Only Support Sql Server
            migrationConfiguration.TargetDatabase =
                new DbConnectionInfo(ContextConnectionStringManager.Get(context.ContextName), "System.Data.SqlClient");

            // Create the DBMigrator
            var migrator = new DbMigrator(migrationConfiguration);

            // Migrate the database to the target migration
            migrator.Update(targetMigrationName);

            // Write only to the console to keep any observer from thinking we aren't busy.
            Console.Write(@".");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Preprocess the data and display any errors found
        /// </summary>
        private static void PreprocessData()
        {
            // Set the Context Connection Strings
            ContextConnectionStringManager.SetupDefaultConnections(Settings.Target);

            PreprocessDataEntryCommonMigrations(ContextNames.Reports);
            PreprocessDataEntryCommonMigrations(ContextNames.Summaries);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create the Unit Of Work and add it to the dictionary.
        /// </summary>
        /// <typeparam name="TUnitOfWork">The Type of Unit Of Work to add to the Dictionary</typeparam>
        /// <param name="key">Name of the Key to find the UnitOfWork in the Dictionary</param>
        private UnitOfWork AddUnitOfWork <TUnitOfWork>(string key) where TUnitOfWork : UnitOfWork, new()
        {
            var connString = string.Format(ConfigurationManager.ConnectionStrings[key].ConnectionString, _dbSource);

            ContextConnectionStringManager.SetupDefaultConnections(connString);
            var unitOfWork = new TUnitOfWork();

            _unitsOfWork.Add(key, unitOfWork);

            return(unitOfWork);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Process the incoming arguments
        /// </summary>
        private static void ProcessArguments(Dictionary <string, string> arguments)
        {
            // Load Settings
            Settings.LoadFromArguments(arguments);

            // Set the Context Connection Strings
            ContextConnectionStringManager.SetupDefaultConnections(Settings.Target);

            // Silent mode will hide the console window.
            if (Settings.Silent)
            {
                WindowsInterop.HideConsole();
                Log.Info("Running Silent");
            }

            // Make sure we have proper options to continue.
            var validTarget         = !string.IsNullOrWhiteSpace(Settings.Target);
            var validApplication    = !string.IsNullOrWhiteSpace(Settings.AppPoolIdentity);
            var validImplementation = !string.IsNullOrWhiteSpace(Settings.Implementation);

            if (!validTarget)
            {
                Exit("Invalid target.", 1);
            }
            if (!validApplication)
            {
                Exit("Application is required.", 1);
            }
            if (!validImplementation)
            {
                Exit("Implementation is required.", 1);   // Is it? (yes for the Meta)
            }
            // Log Current Settings
            Settings.LogCurrentValues();

            // If we are dropping databases ask to make sure.
            if (!Settings.Silent && Settings.Reinstall)
            {
                Log.Info("");
                Log.Info(@"Reinstalling will drop any existing databases.");

                // Console Interaction
                Console.Write(@"Are you sure you want to continue? (y/n): _");
                Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                var answer = Console.ReadLine();
                if (answer != null &&
                    !string.Equals(answer.Trim(), "y", StringComparison.InvariantCultureIgnoreCase))
                {
                    Exit("Installation was aborted!");
                }
            }
        }
 /// <summary>
 /// Uninstall the Product.
 /// </summary>
 public void Uninstall()
 {
     // A formal Uninstall isn't implemented yet, for now just remove all the databases.
     new DropCommand(ContextConnectionStringManager.Get(ContextNames.Administration), true).Execute();
     new DropCommand(ContextConnectionStringManager.Get(ContextNames.Audit), true).Execute();
     new DropCommand(ContextConnectionStringManager.Get(ContextNames.Media), true).Execute();
     new DropCommand(ContextConnectionStringManager.Get(ContextNames.Messaging), true).Execute();
     new DropCommand(ContextConnectionStringManager.Get(ContextNames.Metadata), true).Execute();
     new DropCommand(ContextConnectionStringManager.Get(ContextNames.RecentInfo), true).Execute();
     new DropCommand(ContextConnectionStringManager.Get(ContextNames.Reports), true).Execute();
     new DropCommand(ContextConnectionStringManager.Get(ContextNames.Summaries), true).Execute();
     new DropCommand(ContextConnectionStringManager.Get(ContextNames.ExternalApi), true).Execute();
 }
Exemplo n.º 8
0
        /// <summary>
        /// Preprocess the common migrations for the given context
        /// </summary>
        private static void PreprocessDataEntryCommonMigrations(string context)
        {
            Log.Info("Preprocessing {0}...", context);
            //connect to 4.7.1 sql database
            var connectionString = ContextConnectionStringManager.Get(context);

            using (var conn = new SqlConnection(connectionString))
            {
                conn.Open();
                ExecutePreprocessDataEntryMigrations(conn, context);
            }
            Log.Info(Program.LineBreak);
            Log.Info("");
        }
 private static void GrantAccess(string appPoolIdentity, string contextName)
 {
     SqlScripting.ExecuteScript(
         ContextConnectionStringManager.Get(contextName),
         SqlScripting.InjectParameters(ScriptCatalog.SetApplicationPermissions, appPoolIdentity, contextName));
 }
Exemplo n.º 10
0
        /// <summary>
        /// Enable File Streaming on the MediaDbContext
        /// </summary>
        public static void Enable( )
        {
            Log.Info("Enabling Sql File Streaming");

            // TODO: Configurable?
            const string fileGroupName = "fg";
            const string dataFileName  = "file";

            // Get the Connection String to the Media DbContext
            var mediaDbConnectionString = new SqlConnectionStringBuilder(ContextConnectionStringManager.Get(ContextNames.Media));

            // Get the server name from the connection string.
            var mediaDbDatasource = mediaDbConnectionString.DataSource;

            // Get the catalog name of the media database.
            var mediaDbDatabaseName = mediaDbConnectionString.InitialCatalog;

            // Connect with SMO.
            var server = new Microsoft.SqlServer.Management.Smo.Server(mediaDbDatasource);

            server.ConnectionContext.AutoDisconnectMode = Microsoft.SqlServer.Management.Common.AutoDisconnectMode.NoAutoDisconnect;

            // Determine the Filestream directory.
            var          serverName          = server.ComputerNamePhysicalNetBIOS;
            const string filestreamPathLocal = @"C:\TriTech\InformRMS\Data\FileStream"; // TODO: Derive from input options.
            var          isLocalDeploy       = IsHostLocal(serverName);
            var          filestreamPathUnc   = isLocalDeploy ? "" : String.Format(@"\\{0}\{1}", serverName, filestreamPathLocal.Replace(':', '$'));

            // Create the Filestream directory, if necessary.
            var filestreamDirectory = isLocalDeploy
                ? Path.GetDirectoryName(filestreamPathLocal)
                : Path.GetDirectoryName(filestreamPathUnc);

            if (!Directory.Exists(filestreamDirectory))
            {
                Directory.CreateDirectory(filestreamDirectory);
            }

            // Update the Filestream access level, if necessary. This is required before Filestream is enabled on a database.
            const int target = (int)Microsoft.SqlServer.Management.Smo.FilestreamAccessLevelType.FullAccess;

            if (server.Configuration.FilestreamAccessLevel.ConfigValue != target)
            {
                Log.Info("Changing Filestream access level to: {0}", target);
                server.Configuration.FilestreamAccessLevel.ConfigValue = target;
                server.Configuration.Alter();
            }

            // Manually create the database from the context.
            // We need to do this because Filestream has to be enabled on the database before we can create Filestream columns.
            var database = server.Databases
                           .Cast <Microsoft.SqlServer.Management.Smo.Database>()
                           .FirstOrDefault(x => x.Name.Equals(mediaDbDatabaseName, StringComparison.OrdinalIgnoreCase));

            if (database == null)
            {
                Log.Info("Creating database {0}.", mediaDbDatabaseName);
                database = new Microsoft.SqlServer.Management.Smo.Database(server, mediaDbDatabaseName);
                database.Create();
            }

            // Create a FileGroup for Filestream data, if necessary.
            if (String.IsNullOrWhiteSpace(database.FilestreamDirectoryName))
            {
                var fg = new Microsoft.SqlServer.Management.Smo.FileGroup(database, fileGroupName, true);
                fg.Create();

                var file = new Microsoft.SqlServer.Management.Smo.DataFile(fg, dataFileName, filestreamPathLocal);
                file.Create();
            }

            // Disconnect.
            server.ConnectionContext.Disconnect();

            // Attempt to determine if FileStreaming is already setup
            var result = SqlScripting.ExecuteNonQuery(mediaDbConnectionString.ToString(), @"
                SELECT OBJECT_NAME(object_id) AS TableName, name AS ColumnName
                FROM sys.columns
                WHERE is_filestream = 1 AND OBJECT_NAME(object_id) = 'MEDIASTORAGES' AND name = 'MEDIA'");

            // The Drop Column will fail if the table is already setup with File Streaming.
            // Make sure we only execute the script if the FileStream is not already setup.
            if (result < 1)
            {
                // Enable Filestream on the MediaStorages table.
                SqlScripting.ExecuteScript(mediaDbConnectionString.ToString(), @"
                -- Filestream-enabled tables must have a RowGuidCol column. This cannot be added through fluent mapping.
                alter table [dbo].[MediaStorages] drop column [MediaGuid]
                alter table [dbo].[MediaStorages] add [MediaGuid] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE DEFAULT NEWID()

                -- Manually create the filestream column. NOTE: SQL will not allow the FILESTREAM attribute to be added to an existing column, and the column must be created as part of the model (so it can be accessed via code), so drop and recreate it here.
                alter table [dbo].[MediaStorages] drop column [Media]
                alter table [dbo].[MediaStorages] add [Media] varbinary(max) FILESTREAM null");
            }
        }