コード例 #1
0
    public override bool Execute()
    {
        bool isSuccess = false;

        try
        {
            _ps = PowerShell.Create();

            _ps
            .AddCommand("Set-ExecutionPolicy")
            .AddArgument("Unrestricted")
            .AddParameter("Scope", "CurrentUser");

            _ps
            .AddStatement()
            .AddCommand(EntryPs1)
            .AddParameter("srcDirectory", TrimEndingDirectorySeparator(SolutionRoot))
            .AddParameter("sdkPath", TrimEndingDirectorySeparator(SdkInstallPath))
            .AddParameter("gamePath", TrimEndingDirectorySeparator(GameInstallPath));

            foreach (ITaskItem Arg in AdditionalArgs)
            {
                string Val = Arg.GetMetadata("Value");
                if (string.IsNullOrEmpty(Val))
                {
                    _ps.AddParameter(Arg.ItemSpec);
                }
                else
                {
                    _ps.AddParameter(Arg.ItemSpec, Val);
                }
            }

            BindStreamEntryCallback(_ps.Streams.Debug, record => LogOutput(record.ToString()));
            BindStreamEntryCallback(_ps.Streams.Information, record => LogOutput(record.ToString()));
            BindStreamEntryCallback(_ps.Streams.Verbose, record => LogOutput(record.ToString()));
            BindStreamEntryCallback(_ps.Streams.Warning, record => LogOutput(record.ToString())); // TODO: More flashy output?

            BindStreamEntryCallback(_ps.Streams.Error, record =>
            {
                // TODO: Less info than when from console
                // TODO: More flashy output?
                LogOutput(record.ToString());
                Log.LogError(record.ToString());
                isSuccess = false;
            });

            _ps.InvocationStateChanged += (sender, args) =>
            {
                if (args.InvocationStateInfo.State == PSInvocationState.Running)
                {
                    _startingMre.Set();
                }
            };

            isSuccess = true;
            _ps.Invoke();
        }
        catch (System.Exception e)
        {
            Log.LogError(e.Message);
            isSuccess = false;
        }

        return(isSuccess);
    }