Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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;
        }