Esempio n. 1
0
        private CMExecuteSQLNonQuery CreateMainCommand(IExecutionContext context, string commandGuid)
        {
            List <SqlParameterClass> parameters = InitFilelistParameters(context);

            context.Log.AddLogInformation("Параметры SQL-команды RESTORE_FILELIST инициализированы");
            string            resultSetCtxName         = Guid.NewGuid().ToString("N");
            string            absoluteConnectionString = context.GetStringFrom(ConnectionString);
            CMExecuteSQLQuery query = new CMExecuteSQLQuery()
            {
                CommandType      = CommandType.Text,
                CommandText      = RESTORE_FILELIST_TEMPLATE.Replace("{command_guid}", commandGuid),
                CommandTimeout   = CommandTimeout,
                ConnectionString = absoluteConnectionString,
                Parameters       = parameters,
                ResultName       = resultSetCtxName
            };

            query.Do(context);
            context.Log.AddLogInformation("SQL-команда RESTORE_FILELIST выполнена");

            parameters = InitRestoreParameters(context, resultSetCtxName);
            context.Log.AddLogInformation("Параметры SQL-команды RESTORE_DATABASE инициализированы");
            CMExecuteSQLNonQuery cmd = new CMExecuteSQLNonQuery()
            {
                CommandType      = CommandType.Text,
                CommandText      = QUERY_RESTORE_BACKUP_TEMPLATE,
                CommandTimeout   = CommandTimeout,
                ConnectionString = absoluteConnectionString,
                Parameters       = parameters
            };

            return(cmd);
        }
Esempio n. 2
0
        public override CommandResult Do(IExecutionContext context)
        {
            context.Log.AddLogInformation("Вход в SQLCreateBackup.Do(ExecutionContext)");
            try
            {
                string absoluteConnectionString = context.GetStringFrom(ConnectionString);
                context.Log.AddLogInformation("ConnectionString ='" + absoluteConnectionString + "'");
                string commandGuid = Guid.NewGuid().ToString("N");
                List <SqlParameterClass> parameters = InitParameters(context);
                context.Log.AddLogInformation("Параметры SQL-команды инициализированы");
                int startProgress = context.Log.CurrentProgress;
                progress             = new SqlCommandProgress(commandGuid, absoluteConnectionString, POLLING_PERIOD);
                progress.OnProgress += new ProgressEvent((percent) =>
                {
                    IncProgress(context, percent, startProgress);
                });
                context.Log.AddLogInformation("Экземпляр SqlCommandProgress создан и запущен");

                CMExecuteSQLNonQuery query = new CMExecuteSQLNonQuery()
                {
                    CommandType      = CommandType.Text,
                    CommandText      = QUERY_CREATE_BACKUP_TEMPLATE.Replace("{command_guid}", commandGuid),
                    CommandTimeout   = CommandTimeout,
                    ConnectionString = absoluteConnectionString,
                    Parameters       = parameters
                };
                //query.Do(context);

                CancellingExecutor executor = new CancellingExecutor(() =>
                {
                    QueryCancelEventArgs args = new QueryCancelEventArgs();
                    context.Log.GetPendingCancel(args);
                    return(args.Cancel);
                });

                executor.Execute(() =>
                {
                    query.Do(context);
                });



                context.Log.AddLogInformation("Экземпляр SQL-команды выполняющей бэкап БД выполнен");
                IncProgress(context, 100, startProgress);
            }
            finally
            {
                if (progress != null)
                {
                    progress.StopPolling();
                    context.Log.AddLogInformation("Экземпляр SqlCommandProgress остановлен");
                }
                context.Log.AddLogInformation("Выход из SQLCreateBackup.Do(ExecutionContext)");
            }

            return(CommandResult.Next);
        }
Esempio n. 3
0
        public override CommandResult Do(IExecutionContext context)
        {
            context.Log.AddLogInformation("Вход в SQLRestoreBackup.Do(ExecutionContext)");
            SqlCommandProgress progress = null;

            try
            {
                string absoluteConnectionString = context.GetStringFrom(ConnectionString);

                if (_cmd == null)
                {
                    _commandGuid = Guid.NewGuid().ToString("N");
                    _cmd         = CreateMainCommand(context, _commandGuid);
                }

                int startProgress = context.Log.CurrentProgress;
                progress             = new SqlCommandProgress(_commandGuid, absoluteConnectionString, POLLING_PERIOD);
                progress.OnProgress += new ProgressEvent((percent) =>
                {
                    IncProgress(context, percent, startProgress);
                });
                context.Log.AddLogInformation("Объект Progress запущен");


                CancellingExecutor executor = new CancellingExecutor(() =>
                {
                    QueryCancelEventArgs args = new QueryCancelEventArgs();
                    context.Log.GetPendingCancel(args);
                    return(args.Cancel);
                });

                executor.Execute(() =>
                {
                    _cmd.Do(context);
                });

                context.Log.AddLogInformation("SQL-команда RESTORE_DATABASE выполнена");
            }
            finally
            {
                if (progress != null)
                {
                    progress.StopPolling();
                    context.Log.AddLogInformation("Объект Progress остановлен");
                }
            }
            context.Log.AddLogInformation("Выход из SQLRestoreBackup.Do(ExecutionContext)");
            return(CommandResult.Next);
        }
Esempio n. 4
0
        public override CommandResult Do(IExecutionContext context)
        {
            context.Log.AddLogInformation("Вход в SQLCreateBackup.Do(ExecutionContext)");
            try
            {
                string absoluteConnectionString = context.GetStringFrom(ConnectionString);
                context.Log.AddLogInformation("ConnectionString ='" + absoluteConnectionString + "'");
                string commandGuid = Guid.NewGuid().ToString("N");
                List<SqlParameterClass> parameters = InitParameters(context);
                context.Log.AddLogInformation("Параметры SQL-команды инициализированы");
                int startProgress = context.Log.CurrentProgress;
                progress = new SqlCommandProgress(commandGuid, absoluteConnectionString, POLLING_PERIOD);
                progress.OnProgress += new ProgressEvent((percent) =>
                {
                    IncProgress(context, percent, startProgress);
                });
                context.Log.AddLogInformation("Экземпляр SqlCommandProgress создан и запущен");

                CMExecuteSQLNonQuery query = new CMExecuteSQLNonQuery()
                {
                    CommandType = CommandType.Text,
                    CommandText = QUERY_CREATE_BACKUP_TEMPLATE.Replace("{command_guid}", commandGuid),
                    CommandTimeout = CommandTimeout,
                    ConnectionString = absoluteConnectionString,
                    Parameters = parameters
                };
                //query.Do(context);

                CancellingExecutor executor = new CancellingExecutor(() =>
                {
                    QueryCancelEventArgs args = new QueryCancelEventArgs();
                    context.Log.GetPendingCancel(args);
                    return args.Cancel;
                });

                executor.Execute(() =>
                {
                    query.Do(context);
                });

                context.Log.AddLogInformation("Экземпляр SQL-команды выполняющей бэкап БД выполнен");
                IncProgress(context, 100, startProgress);
            }
            finally
            {
                if (progress != null)
                {
                    progress.StopPolling();
                    context.Log.AddLogInformation("Экземпляр SqlCommandProgress остановлен");
                }
                context.Log.AddLogInformation("Выход из SQLCreateBackup.Do(ExecutionContext)");
            }

            return CommandResult.Next;
        }
Esempio n. 5
0
        private CMExecuteSQLNonQuery CreateMainCommand(IExecutionContext context, string commandGuid)
        {
            List<SqlParameterClass> parameters = InitFilelistParameters(context);
            context.Log.AddLogInformation("Параметры SQL-команды RESTORE_FILELIST инициализированы");
            string resultSetCtxName = Guid.NewGuid().ToString("N");
            string absoluteConnectionString = context.GetStringFrom(ConnectionString);
            CMExecuteSQLQuery query = new CMExecuteSQLQuery()
            {
                CommandType = CommandType.Text,
                CommandText = RESTORE_FILELIST_TEMPLATE.Replace("{command_guid}", commandGuid),
                CommandTimeout = CommandTimeout,
                ConnectionString = absoluteConnectionString,
                Parameters = parameters,
                ResultName = resultSetCtxName
            };
            query.Do(context);
            context.Log.AddLogInformation("SQL-команда RESTORE_FILELIST выполнена");

            parameters = InitRestoreParameters(context, resultSetCtxName);
            context.Log.AddLogInformation("Параметры SQL-команды RESTORE_DATABASE инициализированы");
            CMExecuteSQLNonQuery cmd = new CMExecuteSQLNonQuery()
            {
                CommandType = CommandType.Text,
                CommandText = QUERY_RESTORE_BACKUP_TEMPLATE,
                CommandTimeout = CommandTimeout,
                ConnectionString = absoluteConnectionString,
                Parameters = parameters
            };
            return cmd;
        }
Esempio n. 6
0
        public override CommandResult Do(IExecutionContext context)
        {
            context.Log.AddLogInformation("Вход в SQLRestoreBackup.Do(ExecutionContext)");
            SqlCommandProgress progress = null;
            try
            {
                string absoluteConnectionString = context.GetStringFrom(ConnectionString);

                if (_cmd == null)
                {
                    _commandGuid = Guid.NewGuid().ToString("N");
                    _cmd = CreateMainCommand(context, _commandGuid);
                }

                int startProgress = context.Log.CurrentProgress;
                progress = new SqlCommandProgress(_commandGuid, absoluteConnectionString, POLLING_PERIOD);
                progress.OnProgress += new ProgressEvent((percent) =>
                {
                    IncProgress(context, percent, startProgress);
                });
                context.Log.AddLogInformation("Объект Progress запущен");

                CancellingExecutor executor = new CancellingExecutor(() =>
                {
                    QueryCancelEventArgs args = new QueryCancelEventArgs();
                    context.Log.GetPendingCancel(args);
                    return args.Cancel;
                });

                executor.Execute(() =>
                {
                    _cmd.Do(context);
                });

                context.Log.AddLogInformation("SQL-команда RESTORE_DATABASE выполнена");
            }
            finally
            {
                if (progress != null)
                {
                    progress.StopPolling();
                    context.Log.AddLogInformation("Объект Progress остановлен");
                }
            }
            context.Log.AddLogInformation("Выход из SQLRestoreBackup.Do(ExecutionContext)");
            return CommandResult.Next;
        }
Esempio n. 7
0
        public override CommandResult Do(IExecutionContext context, Transaction transaction)
        {
            context.Log.AddLogInformation("Вход в SQLRestoreBackup.Do(ExecutionContext,Transaction)");
            FileSetStep step = null;
            if (transaction != null)
            {
                step = transaction.CreateStep<FileSetStep>(this);
                context.Log.AddLogInformation("Шаг транзакции типа SingleFileStep создан");
                List<string> files = new List<string>();
                _commandGuid = Guid.NewGuid().ToString("N");
                _cmd = CreateMainCommand(context, _commandGuid);

                step.Init(context, files);
                context.Log.AddLogInformation("Шаг транзакции типа SingleFileStep настроен");
            }
            Do(context);
            context.Log.AddLogInformation("Выход из SQLRestoreBackup.Do(ExecutionContext,Transaction)");
            return CommandResult.Next;
        }