Beispiel #1
0
 /// <summary>
 /// Wait for package actions and log messages.
 /// </summary>
 protected void WaitAndLogPackageActions()
 {
     try
     {
         while (true)
         {
             var message = blockingCollection.Take();
             if (message is ExecutionCompleteMessage)
             {
                 break;
             }
             else if (message is ScriptMessage)
             {
                 ScriptMessage scriptMessage = message as ScriptMessage;
                 ExecutePSScriptInternal(scriptMessage.ScriptPath);
             }
             else if (message is LogMessage)
             {
                 LogMessage logMessage = message as LogMessage;
                 LogCore(logMessage.Level, logMessage.Content);
             }
         }
     }
     catch (InvalidOperationException ex)
     {
         LogCore(MessageLevel.Error, ex.Message);
     }
 }
        void ExecutePSScriptInternal(ScriptMessage message)
        {
            try {
                var request = new ScriptExecutionRequest(
                    message.ScriptPath,
                    message.InstallPath,
                    message.Identity,
                    message.Project);

                var psVariable = SessionState.PSVariable;

                // set temp variables to pass to the script
                psVariable.Set("__rootPath", request.InstallPath);
                psVariable.Set("__toolsPath", request.ToolsPath);
                psVariable.Set("__package", request.ScriptPackage);
                psVariable.Set("__project", request.Project);

                if (request.ScriptPath != null)
                {
                    string command = "& " + PathUtility.EscapePSPath(request.ScriptPath) + " $__rootPath $__toolsPath $__package $__project";
                    LogCore(MessageLevel.Info, String.Format(CultureInfo.CurrentCulture, "Executing script file '{0}'", request.ScriptPath));

                    InvokeCommand.InvokeScript(command, false, PipelineResultTypes.Error, null, null);
                }

                // clear temp variables
                SessionState.PSVariable.Remove("__rootPath");
                SessionState.PSVariable.Remove("__toolsPath");
                SessionState.PSVariable.Remove("__package");
                SessionState.PSVariable.Remove("__project");
            } catch (Exception ex) {
                message.Exception = ex;
            } finally {
                message.EndSemaphore.Release();
            }
        }