コード例 #1
0
        public async Task RunAsync()
        {
            // Validate script file.
            if (!File.Exists(ScriptPath))
            {
                throw new FileNotFoundException(StringUtil.Loc("FileNotFound", ScriptPath));
            }

            // Create the handler data.
            var scriptDirectory = Path.GetDirectoryName(ScriptPath);
            var handlerData     = new PowerShellExeHandlerData()
            {
                Target              = ScriptPath,
                WorkingDirectory    = scriptDirectory,
                FailOnStandardError = "false"
            };

            // Create the handler.
            var handlerFactory = HostContext.GetService <IHandlerFactory>();
            var handler        = (PowerShellExeHandler)handlerFactory.Create(
                ExecutionContext,
                ExecutionContext.Endpoints,
                handlerData,
                new Dictionary <string, string>(),
                taskDirectory: scriptDirectory,
                filePathInputRootDirectory: string.Empty);

            // Add the access token to the handler.
            handler.AccessToken = AccessToken;

            // Run the task.
            await handler.RunAsync();
        }
コード例 #2
0
        public async Task RunAsync()
        {
            // Validate script file.
            if (!File.Exists(ScriptPath))
            {
                throw new FileNotFoundException(StringUtil.Loc("FileNotFound", ScriptPath));
            }

            // Create the handler data.
            var scriptDirectory = Path.GetDirectoryName(ScriptPath);
            var handlerData     = new PowerShellExeHandlerData()
            {
                Target              = ScriptPath,
                WorkingDirectory    = scriptDirectory,
                FailOnStandardError = "false"
            };

            // Create the handler invoker
            var stepHost = HostContext.CreateService <IDefaultStepHost>();

            // Create the handler.
            var handlerFactory = HostContext.GetService <IHandlerFactory>();
            var handler        = (PowerShellExeHandler)handlerFactory.Create(
                executionContext: ExecutionContext,
                task: null,
                stepHost: stepHost,
                endpoints: ExecutionContext.Endpoints,
                secureFiles: new List <SecureFile>(0),
                data: handlerData,
                inputs: new Dictionary <string, string>(),
                environment: new Dictionary <string, string>(VarUtil.EnvironmentVariableKeyComparer),
                runtimeVariables: ExecutionContext.Variables,
                taskDirectory: scriptDirectory);

            // Add the access token to the handler.
            handler.AccessToken = AccessToken;

            // Run the task.
            await handler.RunAsync();
        }