示例#1
0
        public void WritesFormattedMessageToTextWriter(string text, object[] expectedSeverityAndMessages)
        {
            var parser = new SeverityPrefixParser();

            List <object> actualSeverityAndMessages = new List <object>();

            foreach (string line in text.Split('\n'))
            {
                LogSeverity severity;
                string      message;
                bool        hasSeverity = parser.ParseLine(line, out severity, out message);

                actualSeverityAndMessages.Add(new object[] { severity, message });
                Assert.AreEqual(line.StartsWith("["), hasSeverity, "Should indicate whether the line had its own severity indication.");
            }

            Assert.AreElementsEqual(expectedSeverityAndMessages, actualSeverityAndMessages);
        }
        public void LoggerAndParserAreSymmetrical(LogSeverity severity)
        {
            const string message = "Message";

            StringWriter writer = new StringWriter();

            writer.NewLine = "\n";
            var logger = new SeverityPrefixLogger(new TextLogger(writer));

            logger.Log(severity, message);

            var parser = new SeverityPrefixParser();

            LogSeverity parsedSeverity;
            string      parsedMessage;
            bool        hasSeverity = parser.ParseLine(writer.ToString().Trim(), out parsedSeverity, out parsedMessage);

            Assert.AreEqual(severity, parsedSeverity);
            Assert.AreEqual(message, parsedMessage);
            Assert.IsTrue(hasSeverity);
        }
示例#3
0
        private void StartProcess(string hostConnectionArguments)
        {
            bool useElevation = HostSetup.Elevated && !DotNetRuntimeSupport.IsUsingMono;

            CreateTemporaryConfigurationFile();

            StringBuilder hostArguments = new StringBuilder();

            hostArguments.Append(hostConnectionArguments);

            if (HostSetup.DebuggerSetup == null)
            {
                hostArguments.Append(@" /timeout:").Append((int)WatchdogTimeout.TotalSeconds);
            }

            hostArguments.Append(@" /owner-process:").Append(Process.GetCurrentProcess().Id);

            if (HostSetup.ApplicationBaseDirectory != null)
            {
                hostArguments.Append(@" /application-base-directory:""").Append(
                    FileUtils.StripTrailingBackslash(HostSetup.ApplicationBaseDirectory)).Append('"');
            }

            foreach (string hintDirectory in HostSetup.HintDirectories)
            {
                hostArguments.Append(@" /hint-directory:""").Append(
                    FileUtils.StripTrailingBackslash(hintDirectory)).Append('"');
            }

            hostArguments.Append(@" /configuration-file:""").Append(temporaryConfigurationFilePath).Append('"');

            if (HostSetup.ShadowCopy)
            {
                hostArguments.Append(@" /shadow-copy");
            }

            if (HostSetup.DebuggerSetup != null)
            {
                hostArguments.Append(@" /debug");
            }

            hostArguments.Append(" /severity-prefix");

            if (useElevation)
            {
                hostArguments.Append(" /quiet");
            }

            severityPrefixParser = new SeverityPrefixParser();

            processTask             = CreateProcessTask(GetInstalledHostProcessPath(), hostArguments.ToString(), HostSetup.WorkingDirectory ?? Environment.CurrentDirectory);
            processTask.Terminated += HandleProcessExit;

            if (useElevation)
            {
                if (HostSetup.RuntimeVersion != null)
                {
                    throw new HostException("The host does not support a non-default RuntimeVersion with Elevation.");
                }

                processTask.UseShellExecute            = true;
                processTask.ConfigureProcessStartInfo += (sender, e) =>
                {
                    e.ProcessStartInfo.Verb                    = "runas";
                    e.ProcessStartInfo.ErrorDialog             = true;
                    e.ProcessStartInfo.ErrorDialogParentHandle = GetOwnerWindowHandle();
                };
            }
            else
            {
                processTask.CaptureConsoleOutput       = true;
                processTask.CaptureConsoleError        = true;
                processTask.ConsoleOutputDataReceived += LogConsoleOutput;
                processTask.ConsoleErrorDataReceived  += LogConsoleError;

                // Force CLR runtime version.
                string runtimeVersion = HostSetup.RuntimeVersion;
                if (runtimeVersion == null)
                {
                    runtimeVersion = DotNetRuntimeSupport.MostRecentInstalledDotNetRuntimeVersion;
                }

                if (!runtimeVersion.StartsWith("v"))
                {
                    runtimeVersion = "v" + runtimeVersion; // just in case, this is a common user error
                }
                // http://msdn.microsoft.com/en-us/library/w4atty68.aspx
                if (runtimeVersion == "v4.0")
                {
                    runtimeVersion = "v4.0.30319";
                }

                processTask.SetEnvironmentVariable("COMPLUS_Version", runtimeVersion);
            }

            processTask.Start();
        }