Esempio n. 1
0
        /// <summary>
        /// Removes an entry from the specified logging profile.
        /// </summary>
        /// <param name="profileName">Logging profile name.</param>
        /// <param name="kind">The kind of the log entry.</param>
        /// <param name="sinkName">The name of the sink.</param>
        public void RemoveProfileEntry(string profileName, LogEntryKind kind, string sinkName)
        {
            // Verify if the name of the sink is valid.
            if (!allSinks.ContainsKey(sinkName))
            {
                throw new ArgumentException("The log sink doesn't exist.", "sinkName");
            }

            // Verify if the name of the profile exists.
            if (!profilesMap.ContainsKey(profileName))
            {
                throw new ArgumentException(String.Format("The profile \"{0}\" which you try to delete the rule from is not defined.", profileName), "profileName");
            }

            if (!profilesMap[profileName].ContainsKey(sinkName))
            {
                return;
            }

            if (!profilesMap[profileName][sinkName].Contains(kind))
            {
                return;
            }

            // Ignore the result
            profilesMap[profileName][sinkName].Remove(kind);
        }
Esempio n. 2
0
        private void Log(CheckResult checkResult, string message)
        {
            lock (checkerLock)
            {
                // Logging
                LogEntryKind kind = succeededLogKind;

                switch (checkResult)
                {
                //CheckResult.Succeeded is the default condition.

                case CheckResult.Failed:
                    kind = failedLogKind;
                    break;

                case CheckResult.Inconclusive:
                    kind = inconclusiveLogKind;
                    break;

                //Do not need default.
                default:
                    break;
                }

                testSite.Log.Add(
                    kind,
                    message);

                if (checkResult != CheckResult.Succeeded)
                {
                    LogFailingStacks();
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Adds an entry to the specified logging profile.
        /// </summary>
        /// <param name="profileName">Logging profile name.</param>
        /// <param name="kind">The kind of the log entry.</param>
        /// <param name="sinkName">The name of the sink.</param>
        public void AddProfileEntry(string profileName, LogEntryKind kind, string sinkName)
        {
            // Verify if the name of the sink is valid.
            if (!allSinks.ContainsKey(sinkName))
            {
                throw new ArgumentException("The log sink doesn't exist.", "sinkName");
            }

            if (!profilesMap.ContainsKey(profileName))
            {
                throw new ArgumentException(String.Format("The profile \"{0}\" does not exist.", profileName), "profileName");
            }

            // Gets the profile entry
            Dictionary <string, List <LogEntryKind> > entry = profilesMap[profileName];

            // Adds a kinds list if doesn't exsit.
            List <LogEntryKind> logNeededKinds;

            if (entry.ContainsKey(sinkName))
            {
                logNeededKinds = entry[sinkName];
            }
            else
            {
                logNeededKinds  = new List <LogEntryKind>();
                entry[sinkName] = logNeededKinds;
            }

            // Add a log-needed kind into the
            if (!logNeededKinds.Contains(kind))
            {
                logNeededKinds.Add(kind);
            }
        }
 /// <summary>
 /// Prepares the log information according to the log entry information. This method will be called
 /// before the log entry is added to all sinks.
 /// </summary>
 /// <param name="kind">Log information kind.</param>
 /// <param name="message">Log information string.</param>
 /// <param name="timeStamp">The timestamp when the log information is created.</param>
 /// <param name="testProperties">The current test runtime properties.</param>
 public virtual void PrepareLogInformation(
     LogEntryKind kind,
     string message,
     DateTime timeStamp,
     Dictionary<string, Object> testProperties)
 {
 }
Esempio n. 5
0
        public void WriteToChannel(string channel, LogEntryKind kind, string input)
        {
            lock (_text)
            {
                var lines = input.Split('\n');
                foreach (var temp in lines)
                {
                    int maxWidth = Console.WindowWidth - 1;

                    var msg = temp;
                    while (msg != null)
                    {
                        string str;

                        if (msg.Length <= maxWidth)
                        {
                            str = msg;
                            msg = null;
                        }
                        else
                        {
                            str = msg.Substring(0, maxWidth);
                            msg = msg.Substring(maxWidth);
                        }

                        _text.Add(new LogEntry(channel, kind, str));
                    }
                }

                redrawFlags |= RedrawFlags.Content;
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Prepares the log information according to the log entry information. This method will be called
 /// before the log entry is added to all sinks.
 /// </summary>
 /// <param name="kind">Log information kind.</param>
 /// <param name="message">Log information string.</param>
 /// <param name="timeStamp">The timestamp when the log information is created.</param>
 /// <param name="testProperties">The current test runtime properties.</param>
 public virtual void PrepareLogInformation(
     LogEntryKind kind,
     string message,
     DateTime timeStamp,
     Dictionary <string, Object> testProperties)
 {
 }
Esempio n. 7
0
        public override void Write(LogEntryKind kind, string msg)
        {
            if (AppendTimestamp)
            {
                msg = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " " + msg;
            }

            lock (_lock)
            {
                var color = Console.ForegroundColor;
                switch (kind)
                {
                case LogEntryKind.Error: Console.ForegroundColor = ConsoleColor.Red; break;

                case LogEntryKind.Warning: Console.ForegroundColor = ConsoleColor.Yellow; break;

                case LogEntryKind.Message: Console.ForegroundColor = ConsoleColor.Gray; break;

                case LogEntryKind.Success: Console.ForegroundColor = ConsoleColor.Green; break;

                case LogEntryKind.Debug: Console.ForegroundColor = ConsoleColor.Cyan; break;

                default: return;
                }
                Console.WriteLine(msg);
                Console.ForegroundColor = color;
            }
        }
        private void ParseProfiles(Collection <ProfileConfig> profilesConfig)
        {
            foreach (ProfileConfig profile in profilesConfig)
            {
                // Get current profile name.
                string name = profile.Name;

                if (name == null)
                {
                    throw new InvalidOperationException("The name attribute of profile is not found.");
                }

                // Extends the current parsing profile if needed.
                AddOriginalProfileEntriesIfExtend(name, profile.BaseProfile);

                AddProfileIfNotExist(profile.Name);

                // Parse all entries of a profile.
                foreach (ProfileRuleConfig rule in profile.Rules)
                {
                    LogEntryKind kind = ToKind(rule.Kind);
                    string       sink = rule.Sink;

                    // Add or remove a profile entry.
                    if (rule.Delete)
                    {
                        logProfile.RemoveProfileEntry(name, kind, rule.Sink);
                    }
                    else
                    {
                        logProfile.AddProfileEntry(name, kind, rule.Sink);
                    }
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Checks whether the beginning and the endding of a group logging message are matched.
        /// If they are not matched, an InvalidOperationException exception will be raised.
        /// </summary>
        /// <param name="kind">A beginning group log entry kind.</param>
        protected void EnsureLoggingGroupMatching(LogEntryKind kind)
        {
            LogMode mode = LogKindToMode(kind);

            if (mode == LogMode.BeginGroupMode)
            {
                // Push begin group kind.
                loggedBeginGroupEntries.Push(kind);
            }
            else if (mode == LogMode.EndGroupMode)
            {
                // Verifies if this is a matching group kind.
                if (loggedBeginGroupEntries.Count == 0)
                {
                    throw new InvalidOperationException(
                              "The end group kind must be present after a corresponding begin group kind.");
                }
                else if (kind != GetMatchedEndGroupKind(loggedBeginGroupEntries.Peek()))
                {
                    throw new InvalidOperationException("The end group kind is mismatched.");
                }

                // Pop the verified group kind.
                loggedBeginGroupEntries.Pop();
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Adds an entry to the specified logging profile.
        /// </summary>
        /// <param name="profileName">Logging profile name.</param>
        /// <param name="kind">The kind of the log entry.</param>
        /// <param name="sinkName">The name of the sink.</param>
        public void AddProfileEntry(string profileName, LogEntryKind kind, string sinkName)
        {
            // Verify if the name of the sink is valid.
            if (!allSinks.ContainsKey(sinkName))
            {
                throw new ArgumentException("The log sink doesn't exist.", "sinkName");
            }

            if (!profilesMap.ContainsKey(profileName))
            {
                throw new ArgumentException(String.Format("The profile \"{0}\" does not exist.", profileName), "profileName");
            }

            // Gets the profile entry
            Dictionary<string, List<LogEntryKind>> entry = profilesMap[profileName];

            // Adds a kinds list if doesn't exsit.
            List<LogEntryKind> logNeededKinds;
            if (entry.ContainsKey(sinkName))
            {
                logNeededKinds = entry[sinkName];
            }
            else
            {
                logNeededKinds = new List<LogEntryKind>();
                entry[sinkName] = logNeededKinds;
            }

            // Add a log-needed kind into the
            if (!logNeededKinds.Contains(kind))
            {
                logNeededKinds.Add(kind);
            }
        }
Esempio n. 11
0
 public override void Write(LogEntryKind kind, string msg)
 {
     lock (_lock)
     {
         sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " " + msg);
         sw.Flush();
     }
 }
Esempio n. 12
0
 public static void WriteLine(this TestContext testContext, LogEntryKind logEntryKind, string message, params object[] args)
 {
     Console.Out.WriteLine(
         "{0}-[{1}]: {2}",
         DateTime.Now.ToString("yy-MM-dd hh:mm:ss.fffffff"),
         logEntryKind.ToString(),
         message,
         args);
 }
Esempio n. 13
0
        /// <summary>
        /// Implements <see cref="ILogger.IsActive"/>
        /// </summary>
        /// <param name="kind">Log entry kind.</param>
        /// <returns>True indicates the given log kind is active; otherwise, false.</returns>
        public bool IsActive(LogEntryKind kind)
        {
            if (activeKinds == null)
            {
                return(false);
            }

            return(activeKinds.Contains(kind));
        }
Esempio n. 14
0
 private static bool IsCheckPointType(LogEntryKind kind)
 {
     return(
         kind == LogEntryKind.CheckFailed ||
         kind == LogEntryKind.CheckInconclusive ||
         kind == LogEntryKind.Checkpoint ||
         kind == LogEntryKind.CheckSucceeded ||
         kind == LogEntryKind.CheckUnverified ||
         kind == LogEntryKind.Debug
         );
 }
Esempio n. 15
0
 private void WriteEntry(LogEntryKind kind, string message, DateTime timeStamp, string testCaseName)
 {
     Writer.WriteStartElement("LogEntry");
     Writer.WriteAttributeString("kind", kind.ToString());
     Writer.WriteAttributeString("timeStamp", GetTimeStampString(timeStamp));
     if (kind == LogEntryKind.Checkpoint && !string.IsNullOrEmpty(testCaseName))
     {
         Writer.WriteAttributeString("testCase", testCaseName);
     }
     Writer.WriteElementString("Message", ReplaceInvalidChars(message));
     Writer.WriteEndElement();
 }
Esempio n. 16
0
        /// <summary>
        /// Gets the corresponding end group kind of a beginning group log kind.
        /// </summary>
        /// <param name="kind">The beginning of a group log kind.</param>
        /// <returns>The corresponding end group kind.</returns>
        private static LogEntryKind GetMatchedEndGroupKind(LogEntryKind kind)
        {
            switch (kind)
            {
            case LogEntryKind.BeginGroup:
                return(LogEntryKind.EndGroup);

            case LogEntryKind.EnterAdapter:
                return(LogEntryKind.ExitAdapter);

            case LogEntryKind.EnterMethod:
                return(LogEntryKind.ExitMethod);
            }
            throw new ArgumentException("The inputted entry kind has not an end group kind.");
        }
Esempio n. 17
0
        public void WriteToChannel(string channel, LogEntryKind kind, string input)
        {
            lock (_channels)
            {
                var lines = input.Split('\n');
                foreach (var temp in lines)
                {
                    int maxWidth = Console.WindowWidth - 1;

                    var msg = temp;
                    while (msg != null)
                    {
                        string str;

                        if (msg.Length <= maxWidth)
                        {
                            str = msg;
                            msg = null;
                        }
                        else
                        {
                            str = msg.Substring(0, maxWidth);
                            msg = msg.Substring(maxWidth);
                        }

                        List <LogEntry> list;

                        if (_channels.ContainsKey(channel))
                        {
                            list = _channels[channel];
                        }
                        else
                        {
                            list = new List <LogEntry>();
                            _channels[channel] = list;
                        }

                        list.Add(new LogEntry(kind, str));
                        if (channel == currentChannel)
                        {
                            _logIndex = list.Count - 1;
                        }
                    }
                }

                redrawFlags |= RedrawFlags.Content;
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Converts a log entry kind to the corresponding logging mode.
        /// </summary>
        /// <param name="kind">The kind of logging entry</param>
        /// <returns>The logging mode to be applied.</returns>
        protected static LogMode LogKindToMode(LogEntryKind kind)
        {
            switch (kind)
            {
            case LogEntryKind.BeginGroup:
            case LogEntryKind.EnterAdapter:
            case LogEntryKind.EnterMethod:
                return(LogMode.BeginGroupMode);

            case LogEntryKind.EndGroup:
            case LogEntryKind.ExitAdapter:
            case LogEntryKind.ExitMethod:
                return(LogMode.EndGroupMode);
            }
            // Normal log entries.
            return(LogMode.EntryMode);
        }
Esempio n. 19
0
        /// <summary>
        /// Constructs an instance of DefaultChecker.
        /// </summary>
        /// <param name="testSite">The test site to be bound.</param>
        /// <param name="checkerName">The name of the current checker (Assert, Assume or Debug).</param>
        /// <param name="failedLogKind">The log entry kind for logging a failed check.</param>
        /// <param name="succeededLogKind">The log entry kind for logging a succeeded check.</param>
        /// <param name="inconclusiveLogKind">The log entry kind for logging an inconclusive check.</param>
        /// <param name="checkerConfig">The checker confuguration to crate async error processor.</param>
        protected DefaultChecker(
            ITestSite testSite,
            string checkerName,
            LogEntryKind failedLogKind,
            LogEntryKind succeededLogKind,
            LogEntryKind inconclusiveLogKind,
            ICheckerConfig checkerConfig)
        {
            this.testSite            = testSite;
            this.checkerName         = checkerName;
            this.failedLogKind       = failedLogKind;
            this.succeededLogKind    = succeededLogKind;
            this.inconclusiveLogKind = inconclusiveLogKind;
            this.exceptionFilter     = testSite.Properties[ConfigurationPropertyName.ExceptionFilter];

            if (checkerConfig == null)
            {
                throw new ArgumentNullException("checkerConfig");
            }

            this.asyncErrorProcessor = new AsynchronousErrorProcessor(
                checkerConfig.AssertFailuresBeforeThrowException, checkerConfig.MaxFailuresToDisplayPerTestCase);

            testSite.TestStarted += new EventHandler <TestStartFinishEventArgs>(
                delegate(object sender, TestStartFinishEventArgs e)
            {
                asyncErrorProcessor.Initialize();
            }
                );

            testSite.TestFinished += new EventHandler <TestStartFinishEventArgs>(
                delegate(object sender, TestStartFinishEventArgs e)
            {
                asyncErrorProcessor.Cleanup();
            }
                );

            if (null != testSite.Properties.Get("ExceptionalRequirements"))
            {
                var reqList = testSite.Properties.Get("ExceptionalRequirements").Split(',');
                foreach (string req in reqList)
                {
                    this.exceptionalRequirements.Add(req.Trim());
                }
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Map a PtfTestOutcome value to its corresponding LogEntryKind value.
        /// </summary>
        /// <param name="unitTestOutcome">Unit test outcome</param>
        /// <returns>The log entry kind</returns>
        public static LogEntryKind PtfTestOutcomeToLogEntryKind(PtfTestOutcome unitTestOutcome)
        {
            LogEntryKind logEntryKind = LogEntryKind.TestUnknown;

            switch (unitTestOutcome)
            {
            case PtfTestOutcome.Failed:
                logEntryKind = LogEntryKind.TestFailed;
                break;

            case PtfTestOutcome.Inconclusive:
                logEntryKind = LogEntryKind.TestInconclusive;
                break;

            case PtfTestOutcome.Passed:
                logEntryKind = LogEntryKind.TestPassed;
                break;

            case PtfTestOutcome.InProgress:
                logEntryKind = LogEntryKind.TestInProgress;
                break;

            case PtfTestOutcome.Error:
                logEntryKind = LogEntryKind.TestError;
                break;

            case PtfTestOutcome.Timeout:
                logEntryKind = LogEntryKind.TestTimeout;
                break;

            case PtfTestOutcome.Aborted:
                logEntryKind = LogEntryKind.TestAborted;
                break;

            default:
                logEntryKind = LogEntryKind.TestUnknown;
                break;
            }

            return(logEntryKind);
        }
Esempio n. 21
0
        /// <summary>
        /// Implements <see cref="ILogger.Add"/>
        /// </summary>
        /// <param name="kind">The log message kind.</param>
        /// <param name="message">A composite format string.</param>
        /// <param name="parameters">An Object array containing one or more objects to format.</param>
        public void Add(LogEntryKind kind, string message, params object[] parameters)
        {
            AvoidInvalidCall();
            ProcessErrors();

            // prepare log info and sinks
            Dictionary <string, object> info = CreateLogInformationBag(kind, message, parameters);
            List <LogSink> sinks             = logProfile.GetSinksOfProfile(activeLogProfile, kind);

            // identify sinks that need to notify immediately
            List <LogSink> immediateSinks = new List <LogSink>();
            List <LogSink> ordinarySinks  = new List <LogSink>();

            foreach (LogSink sink in sinks)
            {
                if (sink.NotifyImmediately)
                {
                    immediateSinks.Add(sink);
                }
                else
                {
                    ordinarySinks.Add(sink);
                }
            }
            WriteInfoToSinks(info, immediateSinks);

            // wait until queue size drops below max
            hWrite.WaitOne();
            lock (logMessageQueue)
            {
                // write a message and inform reader that queue is able to read
                logMessageQueue.Enqueue(new AvailableLogMessage(ordinarySinks, info, false));
                hRead.Set();

                // disable writer if queue size exceeds its max capability
                if (logMessageQueue.Count >= MaxCapability)
                {
                    hWrite.Reset();
                }
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Gets all the log sink instances of a profile.
        /// </summary>
        /// <param name="profileName">The name of the profile.</param>
        /// <param name="kind">The log kind which the result sinks associated with.</param>
        /// <returns>A list which contains the log sinks.</returns>
        internal List <LogSink> GetSinksOfProfile(string profileName, LogEntryKind kind)
        {
            List <LogSink> sinks = new List <LogSink>();

            // Gets specified profile information.
            Dictionary <string, List <LogEntryKind> > profile = profilesMap[profileName];

            // Scans all sinks associated with the profile.
            foreach (string sinkName in profile.Keys)
            {
                // Retrieves the sink instance by name.
                LogSink sink = allSinks[sinkName];

                // Check if this log entry kind can be accepted by this sink.
                if (profile[sinkName].Contains(kind))
                {
                    sinks.Add(sink);
                }
            }

            return(sinks);
        }
Esempio n. 23
0
        public override void Write(LogEntryKind kind, string msg)
        {
            lock (_lock)
            {
                var color = Console.ForegroundColor;
                switch (kind)
                {
                case LogEntryKind.Error: Console.ForegroundColor = ConsoleColor.Red; break;

                case LogEntryKind.Warning: Console.ForegroundColor = ConsoleColor.Yellow; break;

                case LogEntryKind.Message: Console.ForegroundColor = ConsoleColor.Gray; break;

                case LogEntryKind.Sucess: Console.ForegroundColor = ConsoleColor.Green; break;

                case LogEntryKind.Debug: Console.ForegroundColor = ConsoleColor.Cyan; break;

                default: return;
                }
                Console.WriteLine(msg);
                Console.ForegroundColor = color;
            }
        }
Esempio n. 24
0
 private void WriteAny(LogEntryKind kind, string message, DateTime timeStamp)
 {
     if (sw == null)
     {
         return;
     }
     if (!String.IsNullOrEmpty(message))
     {
         try
         {
             sw.Write(
                 timeStampFormat,  // format sting
                 timeStamp.Year,   // paramters
                 timeStamp.Month,
                 timeStamp.Day,
                 timeStamp.Hour,
                 timeStamp.Minute,
                 timeStamp.Second,
                 timeStamp.Millisecond);
             sw.Write(String.Format(" [{0}] {1}\n", kind.ToString(), message));
         }
         catch { sw = null; }
     }
 }
Esempio n. 25
0
        public override void PrepareLogInformation(
            LogEntryKind kind,
            string message,
            DateTime timeStamp,
            Dictionary <string, Object> testProperties)
        {
            if (testProperties.ContainsKey(TestPropertyNames.CurrentTestCaseName) &&
                testProperties[TestPropertyNames.CurrentTestCaseName] != null)
            {
                testCaseName = testProperties[TestPropertyNames.CurrentTestCaseName] as string;
            }
            else
            {
                testCaseName = null;
            }

            if (testProperties.ContainsKey(TestPropertyNames.CurrentTestOutcome) &&
                testProperties[TestPropertyNames.CurrentTestOutcome] != null)
            {
                PtfTestOutcome currentTestOutcome =
                    (PtfTestOutcome)testProperties[TestPropertyNames.CurrentTestOutcome];
                UpdateStatus(currentTestOutcome);
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Implements <see cref="ILogger.Add"/>
        /// </summary>
        /// <param name="kind">The log message kind.</param>
        /// <param name="message">A composite format string.</param>
        /// <param name="parameters">An Object array containing one or more objects to format.</param>        
        public void Add(LogEntryKind kind, string message, params object[] parameters)
        {
            AvoidInvalidCall();
            ProcessErrors();

            // prepare log info and sinks
            Dictionary<string, object> info = CreateLogInformationBag(kind, message, parameters);
            List<LogSink> sinks = logProfile.GetSinksOfProfile(activeLogProfile, kind);

            // identify sinks that need to notify immediately
            List<LogSink> immediateSinks = new List<LogSink>();
            List<LogSink> ordinarySinks = new List<LogSink>();
            foreach (LogSink sink in sinks)
            {
                if (sink.NotifyImmediately)
                {
                    immediateSinks.Add(sink);
                }
                else
                {
                    ordinarySinks.Add(sink);
                }
            }
            WriteInfoToSinks(info, immediateSinks);

            // wait until queue size drops below max
            hWrite.WaitOne();
            lock (logMessageQueue)
            {
                // write a message and inform reader that queue is able to read
                logMessageQueue.Enqueue(new AvailableLogMessage(ordinarySinks, info, false));
                hRead.Set();

                // disable writer if queue size exceeds its max capability
                if (logMessageQueue.Count >= MaxCapability)
                {
                    hWrite.Reset();
                }
            }
        }
Esempio n. 27
0
        private Dictionary <string, object> CreateLogInformationBag(
            LogEntryKind kind,
            string message,
            params object[] parameters
            )
        {
            Dictionary <string, object> information   = new Dictionary <string, object>();
            Dictionary <string, bool>   allowOverride = new Dictionary <string, bool>();

            // Append PTF-reserved information: LogEntryKind
            information.Add(LogInformationName.LogEntryKind, kind);
            allowOverride.Add(LogInformationName.LogEntryKind, false);

            // Append PTF-reserved information: CurrentTestCaseName
            if (testSite.TestProperties.ContainsKey(TestPropertyNames.CurrentTestCaseName))
            {
                information.Add(TestPropertyNames.CurrentTestCaseName,
                                testSite.TestProperties[TestPropertyNames.CurrentTestCaseName]);
                allowOverride.Add(TestPropertyNames.CurrentTestCaseName, false);
            }

            // Append PTF-reserved information: Message
            string msg = parameters != null && parameters.Length > 0 ? String.Format(message, parameters) : message;

            information.Add(LogInformationName.Message, msg);
            allowOverride.Add(LogInformationName.Message, false);

            // Append PTF-reserved information: TimeStamp
            DateTime timeStamp = DateTime.Now;

            information.Add(LogInformationName.TimeStamp, timeStamp);
            allowOverride.Add(LogInformationName.TimeStamp, false);

            lock (registeredProviders)
            {
                // Append information provided by providers.
                foreach (LogProvider provider in registeredProviders)
                {
                    provider.PrepareLogInformation(kind, msg, timeStamp, Site.TestProperties);

                    Dictionary <string, object> providedInfo = provider.Information;

                    foreach (string name in providedInfo.Keys)
                    {
                        if (information.ContainsKey(name) && !allowOverride[name])
                        {
                            // The information isn't allowed to be overridden.
                            throw new InvalidOperationException(
                                      String.Format("Log information '{0}' is not allowed to be overridden.",
                                                    name));
                        }
                        else
                        {
                            // Append log information.
                            information[name]   = providedInfo[name];
                            allowOverride[name] = provider.AllowOverride;
                        }
                    }
                }
            }
            return(information);
        }
        public override void PrepareLogInformation(
            LogEntryKind kind,
            string message,
            DateTime timeStamp,
            Dictionary<string, Object> testProperties)
        {
            if (testProperties.ContainsKey(TestPropertyNames.CurrentTestCaseName)
                && testProperties[TestPropertyNames.CurrentTestCaseName] != null)
            {
                testCaseName = testProperties[TestPropertyNames.CurrentTestCaseName] as string;
            }
            else
            {
                testCaseName = null;
            }

            if (testProperties.ContainsKey(TestPropertyNames.CurrentTestOutcome)
                && testProperties[TestPropertyNames.CurrentTestOutcome] != null)
            {
                PtfTestOutcome currentTestOutcome =
                (PtfTestOutcome)testProperties[TestPropertyNames.CurrentTestOutcome];
                UpdateStatus(currentTestOutcome);
            }
        }
Esempio n. 29
0
 private void WriteEntry(LogEntryKind kind, string message, DateTime timeStamp, string testCaseName)
 {
     Writer.WriteStartElement("LogEntry");
     Writer.WriteAttributeString("kind", kind.ToString());
     Writer.WriteAttributeString("timeStamp", GetTimeStampString(timeStamp));
     if (kind == LogEntryKind.Checkpoint && !string.IsNullOrEmpty(testCaseName))
     {
         Writer.WriteAttributeString("testCase", testCaseName);
     }
     Writer.WriteElementString("Message", ReplaceInvalidChars(message));
     Writer.WriteEndElement();
 }
Esempio n. 30
0
 public override void Write(LogEntryKind kind, string msg)
 {
     WriteToChannel(DefaultChannel, kind, msg);
 }
Esempio n. 31
0
 public LogEntry(string channel, LogEntryKind kind, string text)
 {
     this.Channel = channel;
     this.Kind    = kind;
     this.Text    = text;
 }
Esempio n. 32
0
 public override void Write(LogEntryKind kind, string msg)
 {
     File.AppendAllLines(fileName, new string[] { msg });
 }
Esempio n. 33
0
        /// <summary>
        /// Removes an entry from the specified logging profile.
        /// </summary>
        /// <param name="profileName">Logging profile name.</param>
        /// <param name="kind">The kind of the log entry.</param>
        /// <param name="sinkName">The name of the sink.</param>
        public void RemoveProfileEntry(string profileName, LogEntryKind kind, string sinkName)
        {
            // Verify if the name of the sink is valid.
            if (!allSinks.ContainsKey(sinkName))
            {
                throw new ArgumentException("The log sink doesn't exist.", "sinkName");
            }

            // Verify if the name of the profile exists.
            if (!profilesMap.ContainsKey(profileName))
            {
                throw new ArgumentException(String.Format("The profile \"{0}\" which you try to delete the rule from is not defined.", profileName), "profileName");
            }

            if (!profilesMap[profileName].ContainsKey(sinkName))
            {
                return;
            }

            if (!profilesMap[profileName][sinkName].Contains(kind))
            {
                return;
            }

            // Ignore the result
            profilesMap[profileName][sinkName].Remove(kind);
        }
Esempio n. 34
0
        /// <summary>
        /// Implements <see cref="ILogger.IsActive"/>
        /// </summary>
        /// <param name="kind">Log entry kind.</param>
        /// <returns>True indicates the given log kind is active; otherwise, false.</returns>
        public bool IsActive(LogEntryKind kind)
        {
            if (activeKinds == null)
            {
                return false;
            }

            return activeKinds.Contains(kind);
        }
Esempio n. 35
0
 private void WriteEntry(LogEntryKind kind, string message, DateTime timeStamp)
 {
     WriteLineWithIndent(timeStamp, "[{0}] {1}", kind.ToString(), message);
 }
Esempio n. 36
0
        private Dictionary<string, object> CreateLogInformationBag(
            LogEntryKind kind,
            string message,
            params object[] parameters
            )
        {
            Dictionary<string, object> information = new Dictionary<string, object>();
            Dictionary<string, bool> allowOverride = new Dictionary<string, bool>();

            // Append PTF-reserved information: LogEntryKind
            information.Add(LogInformationName.LogEntryKind, kind);
            allowOverride.Add(LogInformationName.LogEntryKind, false);

            // Append PTF-reserved information: CurrentTestCaseName
            if (testSite.TestProperties.ContainsKey(TestPropertyNames.CurrentTestCaseName))
            {
                information.Add(TestPropertyNames.CurrentTestCaseName,
                    testSite.TestProperties[TestPropertyNames.CurrentTestCaseName]);
                allowOverride.Add(TestPropertyNames.CurrentTestCaseName, false);
            }

            // Append PTF-reserved information: Message
            string msg = parameters != null && parameters.Length > 0 ? String.Format(message, parameters) : message;
            information.Add(LogInformationName.Message, msg);
            allowOverride.Add(LogInformationName.Message, false);

            // Append PTF-reserved information: TimeStamp
            DateTime timeStamp = DateTime.Now;
            information.Add(LogInformationName.TimeStamp, timeStamp);
            allowOverride.Add(LogInformationName.TimeStamp, false);

            lock (registeredProviders)
            {
                // Append information provided by providers.
                foreach (LogProvider provider in registeredProviders)
                {
                    provider.PrepareLogInformation(kind, msg, timeStamp, Site.TestProperties);

                    Dictionary<string, object> providedInfo = provider.Information;

                    foreach (string name in providedInfo.Keys)
                    {
                        if (information.ContainsKey(name) && !allowOverride[name])
                        {
                            // The information isn't allowed to be overridden.
                            throw new InvalidOperationException(
                                String.Format("Log information '{0}' is not allowed to be overridden.",
                                name));
                        }
                        else
                        {
                            // Append log information.
                            information[name] = providedInfo[name];
                            allowOverride[name] = provider.AllowOverride;
                        }
                    }
                }
            }
            return information;
        }
Esempio n. 37
0
 /// <summary>
 /// Gets the corresponding end group kind of a beginning group log kind.
 /// </summary>
 /// <param name="kind">The beginning of a group log kind.</param>
 /// <returns>The corresponding end group kind.</returns>
 private static LogEntryKind GetMatchedEndGroupKind(LogEntryKind kind)
 {
     switch (kind)
     {
         case LogEntryKind.BeginGroup:
             return LogEntryKind.EndGroup;
         case LogEntryKind.EnterAdapter:
             return LogEntryKind.ExitAdapter;
         case LogEntryKind.EnterMethod:
             return LogEntryKind.ExitMethod;
     }
     throw new ArgumentException("The inputted entry kind has not an end group kind.");
 }
 private void WriteAny(LogEntryKind kind, string message, DateTime timeStamp)
 {
     if (sw == null) return;
     if (!String.IsNullOrEmpty(message))
     {
         try
         {
             sw.Write(
                 timeStampFormat,  // format sting
                 timeStamp.Year,      // paramters
                 timeStamp.Month,
                 timeStamp.Day,
                 timeStamp.Hour,
                 timeStamp.Minute,
                 timeStamp.Second,
                 timeStamp.Millisecond);
             sw.Write(String.Format(" [{0}] {1}\n", kind.ToString(), message));
         }
         catch { sw = null; }
     }
 }
Esempio n. 39
0
        /// <summary>
        /// Checks whether the beginning and the endding of a group logging message are matched.
        /// If they are not matched, an InvalidOperationException exception will be raised.
        /// </summary>
        /// <param name="kind">A beginning group log entry kind.</param>
        protected void EnsureLoggingGroupMatching(LogEntryKind kind)
        {
            LogMode mode = LogKindToMode(kind);

            if (mode == LogMode.BeginGroupMode)
            {
                // Push begin group kind.
                loggedBeginGroupEntries.Push(kind);
            }
            else if (mode == LogMode.EndGroupMode)
            {
                // Verifies if this is a matching group kind.
                if (loggedBeginGroupEntries.Count == 0)
                {
                    throw new InvalidOperationException(
                        "The end group kind must be present after a corresponding begin group kind.");
                }
                else if (kind != GetMatchedEndGroupKind(loggedBeginGroupEntries.Peek()))
                {
                    throw new InvalidOperationException("The end group kind is mismatched.");
                }

                // Pop the verified group kind.
                loggedBeginGroupEntries.Pop();
            }
        }
Esempio n. 40
0
 public abstract void Write(LogEntryKind kind, string msg);
Esempio n. 41
0
        /// <summary>
        /// Gets all the log sink instances of a profile.
        /// </summary>
        /// <param name="profileName">The name of the profile.</param>
        /// <param name="kind">The log kind which the result sinks associated with.</param>
        /// <returns>A list which contains the log sinks.</returns>
        internal List<LogSink> GetSinksOfProfile(string profileName, LogEntryKind kind)
        {
            List<LogSink> sinks = new List<LogSink>();

            // Gets specified profile information.
            Dictionary<string, List<LogEntryKind>> profile = profilesMap[profileName];

            // Scans all sinks associated with the profile.
            foreach (string sinkName in profile.Keys)
            {
                // Retrieves the sink instance by name.
                LogSink sink = allSinks[sinkName];

                // Check if this log entry kind can be accepted by this sink.
                if (profile[sinkName].Contains(kind))
                {
                    sinks.Add(sink);
                }
            }

            return sinks;
        }
Esempio n. 42
0
 private void WriteEntry(LogEntryKind kind, string message, DateTime timeStamp)
 {
     WriteLineWithIndent(timeStamp, "[{0}] {1}", kind.ToString(), message);
 }
Esempio n. 43
0
 public LogEntry(LogEntryKind kind, string text)
 {
     this.Kind = kind;
     this.Text = text;
 }
 private static bool IsCheckPointType(LogEntryKind kind)
 {
     return (
         kind == LogEntryKind.CheckFailed ||
         kind == LogEntryKind.CheckInconclusive ||
         kind == LogEntryKind.Checkpoint ||
         kind == LogEntryKind.CheckSucceeded ||
         kind == LogEntryKind.CheckUnverified ||
         kind == LogEntryKind.Debug
         );
 }
Esempio n. 45
0
 /// <summary>
 /// Converts a log entry kind to the corresponding logging mode.
 /// </summary>
 /// <param name="kind">The kind of logging entry</param>
 /// <returns>The logging mode to be applied.</returns>
 protected static LogMode LogKindToMode(LogEntryKind kind)
 {
     switch (kind)
     {
         case LogEntryKind.BeginGroup:
         case LogEntryKind.EnterAdapter:
         case LogEntryKind.EnterMethod:
             return LogMode.BeginGroupMode;
         case LogEntryKind.EndGroup:
         case LogEntryKind.ExitAdapter:
         case LogEntryKind.ExitMethod:
             return LogMode.EndGroupMode;
     }
     // Normal log entries.
     return LogMode.EntryMode;
 }