Example #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);
        }
Example #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);
        }
Example #3
0
        public override CommandResult Do(IExecutionContext context)
        {
            string      absolutePackageFilePath = context.GetStringFrom(PackageFilePath);
            string      logFilePath             = Path.Combine(context.ExecutedPackage.PackagePath, Guid.NewGuid().ToString("N") + ".log");
            DTSExecutor executor = new DTSExecutor(absolutePackageFilePath, logFilePath, false);

            executor.OnLogger   += new LoggerEvent(context.Log.AddLogEvent);
            executor.OnProgress += new ProgressEvent(
                (percent) =>
            {
                context.Log.SendProgress(new ExecutionProgressInfo()
                {
                    Message      = "Выполнение DTS-пакета",
                    ModuleName   = "CMExecuteDTS",
                    ProgressCost = 0
                });
                //CheckForPendingCancel(context);
            });
            foreach (DTSGlobalVariable param in Parameters)
            {
                object absoluteVariableValue = context.GetResult(param.VariableValue);
                executor.SaveParameter(param.VariableName, absoluteVariableValue);
            }

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

            cnclexecutor.Execute(() =>
            {
                executor.Execute();
            });


            return(CommandResult.Next);
        }