示例#1
0
        public override void Load(string packageContentDirectory, string packageResultFilePath)
        {
            PackageBodyFilePath = packageResultFilePath;
            PackageContentDirectory = packageContentDirectory;
            try
            {
                string packageDirectory = Path.GetDirectoryName(packageResultFilePath);
                string packageIncludedDirectory = Path.Combine(packageDirectory, PACKAGE_INCLUDED_FILES_DIRECTORY);

                if (Directory.Exists(packageIncludedDirectory))
                {
                    int totalFilesCount = Directory.GetFiles(packageIncludedDirectory, "*.*", SearchOption.AllDirectories).Count();
                    int currentFilesCount = 0;
                    int oldProgressValue = 0;
                    packageContentDirectory = Path.Combine(packageContentDirectory, PACKAGE_INCLUDED_FILES_DIRECTORY);
                    IOUtil.CopyDirectory(packageIncludedDirectory, packageContentDirectory, false, (fileName) =>
                    {
                        currentFilesCount++;
                        int currentProgress = (currentFilesCount * 100) / totalFilesCount;
                        int currentCost = 0;
                        if (currentProgress > oldProgressValue)
                        {
                            currentCost = currentProgress - oldProgressValue;
                        }
                        oldProgressValue = currentProgress;
                        OnProgressHandler(new ExecutionProgressInfo()
                        {
                            Message = fileName,
                            ModuleName = "Direct content",
                            ProgressCost = currentCost
                        });
                        QueryCancelEventArgs args = new QueryCancelEventArgs();
                        OnQueryCancelHandler(args);
                        if (args.Cancel)
                        {
                            throw new PackageExecutionCancelledException();
                        }
                    });
                }
                OnProgressHandler(new ExecutionProgressInfo
                {
                    Message = "Содержимое пакета загружено",
                    ProgressCost = 100,
                    ModuleName = "Direct content"
                });
            }
            catch (PackageExecutionCancelledException)
            {
                Clean();
            }
        }
示例#2
0
        public override CommandResult Do(IExecutionContext context)
        {
            AdjustReversibleUI();
            IterateCommands(command =>
            {
                QueryCancelEventArgs args = new QueryCancelEventArgs();
                context.Log.GetPendingCancel(args);
                if (args.Cancel)
                {
                    throw new PackageExecutionCancelledException();
                }
                CommandResult result = command.Execute(context);
                if (!(command is IContainerCommand))
                {
                    SetProgress(context, command, result);
                }
                return result;
            });

            return CommandResult.Next;
        }
示例#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;
        }
示例#4
0
 public void GetPendingCancel(QueryCancelEventArgs args)
 {
     args.Cancel = _pendingCancel;
 }
示例#5
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;
        }
示例#6
0
 protected void OnQueryCancelHandler(QueryCancelEventArgs cancel)
 {
     if (OnQueryCancel != null)
     {
         OnQueryCancel(cancel);
     }
 }
示例#7
0
文件: Logging.cs 项目: vgrinin/gin
 public void GetPendingCancel(QueryCancelEventArgs args)
 {
     args.Cancel = _pendingCancel;
 }
示例#8
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;
        }
示例#9
0
文件: Package.cs 项目: vgrinin/gin
 private void CheckPendingCancel()
 {
     QueryCancelEventArgs args = new QueryCancelEventArgs();
     _context.Log.GetPendingCancel(args);
     if (args.Cancel)
     {
         throw new PackageExecutionCancelledException();
     }
 }
示例#10
0
 void reader_OnProgress(ExecutionProgressInfo obj)
 {
     OnProgressHandler(obj);
     QueryCancelEventArgs args = new QueryCancelEventArgs();
     OnQueryCancelHandler(args);
     if (args.Cancel)
     {
         throw new PackageExecutionCancelledException();
     }
 }