public void FormatsWithNoTokens()
        {
            TextFormatter formatter = new TextFormatter("no tokens");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("no tokens", actual);
        }
		public string[] Format(string markup)
		{
			var formatter = new TextFormatter();

			var output = formatter.Format(markup);
			var result = string.Format("<html>\r\n\t<body>\r\n{0}\r\n\t</body>\r\n</html>", output);

			return result.Split(new[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);
		}
		public static void TestFormat(string srcPath, string goldPath)
		{
			var formatter = new TextFormatter();
			string result;
			using (var reader = new StreamReader(srcPath))
				result = string.Format("<html>\r\n\t<body>\r\n{0}\r\n\t</body>\r\n</html>", formatter.Format(reader.ReadToEnd()));

			CompareSamples(goldPath, result);
		}
        public void FormatsMixedTextAndTokens()
        {
            TextFormatter formatter = new TextFormatter("some {newline} mixed{tab}text");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("some " + Environment.NewLine + " mixed\ttext", actual);
        }
        public void FormatsWithTwoConstants()
        {
            TextFormatter formatter = new TextFormatter("{newline}{tab}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual(Environment.NewLine + "\t", actual);
        }
Beispiel #6
0
        public void TextFormatterHandlesCategoriesForManyTwoCategoriesBug1816()
        {
            ILogFormatter formatter = new TextFormatter("{category}");

            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            entry.Categories = new string[] { "category1", "category2", "category3", "category4" };

            Assert.AreEqual("category1, category2, category3, category4", formatter.Format(entry));
        }
Beispiel #7
0
        private string FormatEntry(string template, LogEntry entry)
        {
            TextFormatterData data = new TextFormatterData();

            data.Template.Value = template;

            TextFormatter formatter = new TextFormatter(data);

            return(formatter.Format(entry));
        }
Beispiel #8
0
        public void FormatsLocalProcessNameToken()
        {
            var formatter = new TextFormatter("Process name: {localProcessName}");
            var entry     = CommonUtil.GetDefaultLogEntry();

            entry.ProcessName = "__some process__";

            var actual = formatter.Format(entry);

            Assert.AreEqual("Process name: " + LogEntry.GetProcessName(), actual);
        }
Beispiel #9
0
        public void FormatReflectedPropertyTokenFunctionPropertyFoundAndNullValue()
        {
            CustomLogEntry entry = new CustomLogEntry();

            ILogFormatter formatter = new TextFormatter("Reflected Property Value: {property(MyPropertyThatReturnsNull)}");
            string        actual    = formatter.Format(entry);

            string expected = "Reflected Property Value: ";

            Assert.AreEqual(expected, actual);
        }
Beispiel #10
0
        public void LogSendingMessageException(Exception ex, string sink, LogEntry logEntry)
        {
            logger.AddMessage(Header, SR.InvalidSink(sink));

            TextFormatter formatter        = new TextFormatter(new TextFormatterData());
            string        formattedMessage = formatter.Format(logEntry);

            logger.AddMessage(logEntry.Category, SR.InvalidSinkMessage(formattedMessage));

            logger.WriteToLog(ex, Severity.Warning);
        }
Beispiel #11
0
        public async Task WriteAsync(IEnumerable <LogEvent> events)
        {
            foreach (LogEvent e in events)
            {
                CheckRolling(e.EventTime);

                await _writer.WriteLineAsync(TextFormatter.Format(e, null, true));
            }

            _writer.Flush();
        }
Beispiel #12
0
        public void Write(IEnumerable <LogEvent> events)
        {
            foreach (LogEvent e in events)
            {
                CheckRolling(e.EventTime);

                _writer.WriteLine(TextFormatter.Format(e, null, true));
            }

            _writer.Flush();
        }
Beispiel #13
0
        public void FormatsErrorMessagesToken()
        {
            TextFormatter formatter = new TextFormatter("Errors: {errorMessages}");
            LogEntry      entry     = CommonUtil.GetDefaultLogEntry();

            entry.AddErrorMessage("an error message");

            string actual = formatter.Format(entry);

            Assert.AreEqual("Errors: " + entry.ErrorMessages, actual);
        }
Beispiel #14
0
        public void FormatReflectedPropertyTokenFunctionPropertyNotFound()
        {
            CustomLogEntry entry = new CustomLogEntry();

            ILogFormatter formatter = new TextFormatter("Reflected Property Value: {property(PropertyNotFound)}");
            string        actual    = formatter.Format(entry);

            string expected = string.Concat("Reflected Property Value: ", string.Format(Resources.ReflectedPropertyTokenNotFound, "PropertyNotFound"));

            Assert.AreEqual(expected, actual);
        }
Beispiel #15
0
        public void TimeStampTokenLocalTimeWithFormat()
        {
            CustomLogEntry entry = new CustomLogEntry();

            entry.TimeStamp = DateTime.MaxValue;
            ILogFormatter formatter = new TextFormatter("TimeStamp: {timestamp(local:F)}");
            string        actual    = formatter.Format(entry);

            string expected = string.Concat("TimeStamp: " + DateTime.MaxValue.ToLocalTime().ToString("F", CultureInfo.CurrentCulture));

            Assert.AreEqual(expected, actual);
        }
Beispiel #16
0
        public void LogProcessLogException(LogEntry logEntry, Exception ex)
        {
            // distribution failed so write the event to the event log as a backup
            logger.AddMessage(Header, SR.ProcessMessageFailed);

            TextFormatter formatter        = new TextFormatter(new TextFormatterData());
            string        formattedMessage = formatter.Format(logEntry);

            logger.AddMessage(SR.ProcessMessageFailed2, SR.ProcessMessageFailed3(formattedMessage));

            logger.WriteToLog(ex, Severity.Error);
        }
Beispiel #17
0
 public override void Emit(LogEvent logEvent)
 {
     using (var renderSpace = new StringWriter())
     {
         TextFormatter.Format(logEvent, renderSpace);
         DiagnosticsService.WriteTrace(
             (uint)logEvent.Level,
             Category,
             GetTraceSeverityByLogEventLevel(logEvent.Level),
             renderSpace.ToString());
     }
 }
Beispiel #18
0
        public void TimeStampTokenUtcTime()
        {
            CustomLogEntry entry = new CustomLogEntry();

            entry.TimeStamp = DateTime.MaxValue;

            ILogFormatter formatter = new TextFormatter("TimeStamp: {timestamp}");
            string        actual    = formatter.Format(entry);

            string expected = string.Concat("TimeStamp: " + DateTime.MaxValue.ToString());

            Assert.AreEqual(expected, actual);
        }
Beispiel #19
0
        public void DictionaryTokenCanHandleInternalParenthesisAsLongAsTheyAreNotFollowedByACurlyBracket()
        {
            TextFormatter  formatter         = new TextFormatter("{dictionary(({key})-{value} - )}");
            CustomLogEntry entry             = new CustomLogEntry();
            Dictionary <string, object> hash = new Dictionary <string, object>();

            hash["key1"]             = "value1";
            hash["key2"]             = "value2";
            entry.ExtendedProperties = hash;

            string actual = formatter.Format(entry);

            Assert.AreEqual("(key1)-value1 - (key2)-value2 - ", actual);
        }
Beispiel #20
0
    private void OnInfoButtonClick()
    {
        var agentData = GameController.Instance.ActiveAgent.AgentData;
        var helpText  = agentData.HelpText;

        helpText = TextFormatter.Format(helpText);

        Time.timeScale       = 0f;
        _infoPopupText.text  = helpText;
        _previewImage.sprite = agentData.PreviewSprite;

        _infoPopupCanvasGroup.DOFade(1f, 0.5f);
        _infoPopupCanvasGroup.blocksRaycasts = true;
    }
        public async Task SendEmailAsync(string templateName, string email, object viewData)
        {
            IDictionary <string, object> dict = viewData as Dictionary <string, object>;

            if (dict == null)
            {
                dict = viewData.ToDictionary();
            }

            var emailMessage = new EmailMessage();

            emailMessage.EmailTo = email;

            emailMessage.Subject = _textFormatter.Format(
                Path.Combine(_options.TemplateDirectoryPath, $"{templateName}_Subject.txt"),
                dict);

            emailMessage.Text = _textFormatter.Format(
                Path.Combine(_options.TemplateDirectoryPath, $"{templateName}_Body.txt"),
                dict);

            await _emailSender.SendEmailAsync(emailMessage);
        }
Beispiel #22
0
        public async Task SendSmsAsync(string templateName, string number, object viewData)
        {
            IDictionary <string, object> dict = viewData as Dictionary <string, object>;

            if (dict == null)
            {
                dict = viewData.ToDictionary();
            }

            var message = _textFormatter.Format(
                Path.Combine(_options.TemplateDirectoryPath, $"{templateName}.txt"),
                dict);

            await _smsSender.SendSmsAsync(number, message);
        }
Beispiel #23
0
        public void Write(IEnumerable <LogEvent> events)
        {
            foreach (LogEvent e in events)
            {
                string line = TextFormatter.Format(e, _format);

                if (e.ErrorException != null)
                {
                    Trace.TraceError(line);
                }
                else
                {
                    Trace.TraceInformation(line);
                }
            }
        }
        public void Justified()
        {
            var text     = "Lorem ipsum dolor sit amet, consecteturoriumuselratietoneritumusaden adipiscing elit. Aenean nec convallis magna, in pretium tellus.\n\nPellentesque mattis arcu sed neque pretium tincidunt. Nam magna neque, convallis quis dapibus sit amet, pulvinar sit amet arcu.";
            var actual   = TextFormatter.Format(input: text, lineWidth: 40, leftMargin: 2, firstLineLeftMargin: 4, justify: true);
            var expected = @"    Lorem    ipsum    dolor   sit  amet,
  consecteturoriumuselratietoneritumusad
  en    adipiscing    elit.  Aenean  nec
  convallis magna, in pretium tellus.
  
  Pellentesque  mattis  arcu  sed  neque
  pretium  tincidunt.  Nam  magna neque,
  convallis    quis  dapibus  sit  amet,
  pulvinar sit amet arcu.".Replace("\r\n", "\n");

            Assert.AreEqual(expected, actual.result);
        }
Beispiel #25
0
        public override void Test_ITalker_SetText_GetText()
        {
            var talker     = this.GetTalker();
            var orgSetting = talker.IsTextSeparatingByLineBreaks;

            try
            {
                var text = "テキスト設定テストです。\nテスト\tテスト\tテスト。";

                // 改行削除設定
                talker.IsTextSeparatingByLineBreaks = false;

                // テキスト設定
                {
                    var r = talker.SetText(text);
                    Assert.IsTrue(r.Value, r.Message);
                }

                // テキスト取得
                {
                    var r = talker.GetText();
                    Assert.IsNotNull(r.Value, r.Message);
                    Assert.AreEqual(r.Value, TextFormatter.Format(text, false));
                }

                // 改行⇒半角スペース置換設定
                talker.IsTextSeparatingByLineBreaks = true;

                // テキスト設定
                {
                    var r = talker.SetText(text);
                    Assert.IsTrue(r.Value, r.Message);
                }

                // テキスト取得
                {
                    var r = talker.GetText();
                    Assert.IsNotNull(r.Value, r.Message);
                    Assert.AreEqual(r.Value, TextFormatter.Format(text, true));
                }
            }
            finally
            {
                // 設定を元に戻しておく
                talker.IsTextSeparatingByLineBreaks = orgSetting;
            }
        }
Beispiel #26
0
        public void Family_Should_Be_Formatted_To_One_Line(string labelValue)
        {
            using (var ms = new MemoryStream())
            {
                var metricFamily = new CMetricFamily
                {
                    Name = "family1",
                    Help = "help",
                    Type = CMetricType.Counter
                };

                var metricCounter = new CCounter {
                    Value = 100
                };
                metricFamily.Metrics = new[]
                {
                    new CMetric
                    {
                        CCounter = metricCounter,
                        Labels   = new[]
                        {
                            new CLabelPair {
                                Name = "label1", Value = labelValue
                            }
                        }
                    }
                };

                TextFormatter.Format(ms, new[]
                {
                    metricFamily
                });

                using (var sr = new StringReader(Encoding.UTF8.GetString(ms.ToArray())))
                {
                    var linesCount = 0;
                    var line       = "";
                    while ((line = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                        linesCount += 1;
                    }

                    Assert.Equal(3, linesCount);
                }
            }
        }
Beispiel #27
0
        public void Emit(LogEvent logEvent)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException(nameof(logEvent));
            }

            StringWriter strWriter = new StringWriter();

            TextFormatter.Format(logEvent, strWriter);
            string renderedMessage = strWriter.ToString();

            lock (_syncRoot)
            {
                Callback(logEvent, renderedMessage);
            }
        }
Beispiel #28
0
        IEnumerable <TextBlock> BuildHoverText(SystemTextId id, Func <ICharacterSheet, int> getValue, Func <ICharacterSheet, int> getMax)
        {
            var assets    = Resolve <IAssetManager>();
            var party     = Resolve <IParty>();
            var settings  = Resolve <ISettings>();
            var formatter = new TextFormatter(assets, settings.Gameplay.Language);
            var member    = party[_activeCharacter]?.Apparent;

            if (member == null)
            {
                yield break;
            }

            var block = formatter.Format(assets.LoadString(id, settings.Gameplay.Language)).Item1.First();

            block.Text += $" {getValue(member)} / {getMax(member)}";
            yield return(block);
        }
Beispiel #29
0
        public async Task WriteAsync(IEnumerable <LogEvent> events)
        {
            if (events == null)
            {
                return;
            }

            var sb = new StringBuilder();

            foreach (LogEvent e in events)
            {
                sb.AppendLine(TextFormatter.Format(e, _format));
            }

            using (MemoryStream ms = sb.ToString().ToMemoryStream())
            {
                await _blobStorage.AppendFromStreamAsync(_documentId, ms);
            }
        }
        public void TestFormat()
        {
            ILogFormatter formatter = new TextFormatter();
            LogEntry      entry     = new CustomLogEntry();

            string message = formatter.Format(entry);

            Assert.AreNotEqual(message, string.Empty, "Empty log");

            Assert.AreNotEqual(message.IndexOf("Message: Foo"), 0, "Message not present");
            Assert.AreNotEqual(message.IndexOf("EventId: 1"), 0, "EventId not present");
            Assert.AreNotEqual(message.IndexOf("Severity: Error"), 0, "Severity not present");
            Assert.AreNotEqual(message.IndexOf("Title:FooTitle"), 0, "Title not present");

            Assert.AreNotEqual(message.IndexOf(string.Format("Timestamp: {0}", entry.TimestampString)), -1, "Timestamp not present");
            Assert.AreNotEqual(message.IndexOf(string.Format("Message: {0}", entry.Message)), 0, "Message not present");
            Assert.AreNotEqual(message.IndexOf(string.Format("EventId: {0}", entry.EventId)), 0, "EventId not present");
            Assert.AreNotEqual(message.IndexOf(string.Format("Severity: {0}", entry.Severity)), 0, "Severity not present");
            Assert.AreNotEqual(message.IndexOf(string.Format("Title: {0}", entry.Title)), 0, "Title not present");
        }
Beispiel #31
0
        protected override void OnBeforeQueryStatus(object sender, EventArgs e)
        {
            base.OnBeforeQueryStatus(sender, e);
            if (!Command.Visible)
            {
                return;
            }
            var xml    = Repository.GetSelected();
            var writer = WriterProvider();

            Output          = writer.Write(xml);
            Command.Visible = !string.IsNullOrEmpty(Output);
            if (string.IsNullOrEmpty(Output))
            {
                return;
            }
            var elementCount = Repository.GetNodeCount(xml, Output);

            Command.Text = TextFormatter.Format(Output, elementCount);
        }
        public void Write(IEnumerable <LogEvent> events)
        {
            if (events == null)
            {
                return;
            }

            var sb = new StringBuilder();

            foreach (LogEvent e in events)
            {
                sb.AppendLine(TextFormatter.Format(e, _format, true));
            }

            Task.Run(() =>
            {
                using (MemoryStream ms = sb.ToString().ToMemoryStream())
                {
                    _blobStorage.WriteAsync(_documentId, ms, true);
                }
            });
        }
Beispiel #33
0
        public async Task WriteAsync(IEnumerable <LogEvent> events)
        {
            CloudAppendBlob blob = null;
            var             sb   = new StringBuilder();

            foreach (LogEvent e in events)
            {
                if (blob == null)
                {
                    blob = await GetBlobAsync(e.EventTime);
                }

                string line = TextFormatter.Format(e);
                sb.AppendLine(line);
            }

            if (blob != null)
            {
                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())))
                {
                    await blob.AppendBlockAsync(ms);
                }
            }
        }
        public void FormatsProcessNameToken()
        {
            TextFormatter formatter = new TextFormatter("Process name: {processName}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Process name: " + entry.ProcessName, actual);
        }
        public void FormatsLocalProcessIdToken()
        {
            TextFormatter formatter = new TextFormatter("Process id: {localProcessId}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Process id: " + entry.ProcessId, actual);
        }
        public void FormatsActivityIdToken()
        {
            TextFormatter formatter = new TextFormatter("Activity id: {activity}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Activity id: " + entry.ActivityId.ToString("D", CultureInfo.CurrentCulture), actual);
        }
        public void FormatsLocalProcessNameToken()
        {
            var formatter = new TextFormatter("Process name: {localProcessName}");
            var entry = CommonUtil.GetDefaultLogEntry();
            entry.ProcessName = "__some process__";

            var actual = formatter.Format(entry);

            Assert.AreEqual("Process name: " + LogEntry.GetProcessName(), actual);
        }
        public void FormatsTitleToken()
        {
            TextFormatter formatter = new TextFormatter("Title: {title}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Title: " + entry.Title, actual);
        }
        public void FormatsLocalTimestampWithCustomFormat()
        {
            TextFormatter formatter = new TextFormatter("Timestamp: {timestamp(local:dd-MM-yyyy hh:mm)}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Timestamp: " + entry.TimeStamp.ToLocalTime().ToString("dd-MM-yyyy hh:mm", CultureInfo.CurrentCulture), actual);
        }
        public void TimeStampTokenLocalTimeWithFormat()
        {
            CustomLogEntry entry = new CustomLogEntry();
            entry.TimeStamp = DateTime.MaxValue;
            ILogFormatter formatter = new TextFormatter("TimeStamp: {timestamp(local:F)}");
            string actual = formatter.Format(entry);

            string expected = string.Concat("TimeStamp: " + DateTime.MaxValue.ToLocalTime().ToString("F", CultureInfo.CurrentCulture));
            Assert.AreEqual(expected, actual);
        }
        public void FormatsAppDomainToken()
        {
            TextFormatter formatter = new TextFormatter("App domain: {appDomain}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("App domain: " + entry.AppDomainName, actual);
        }
        public void FormatReflectedPropertyTokenFunctionPropertyFoundAndNullValue()
        {
            CustomLogEntry entry = new CustomLogEntry();

            ILogFormatter formatter = new TextFormatter("Reflected Property Value: {property(MyPropertyThatReturnsNull)}");
            string actual = formatter.Format(entry);

            string expected = "Reflected Property Value: ";
            Assert.AreEqual(expected, actual);
        }
        public void TimeStampTokenUtcTime()
        {
            CustomLogEntry entry = new CustomLogEntry();
            entry.TimeStamp = DateTime.MaxValue;

            ILogFormatter formatter = new TextFormatter("TimeStamp: {timestamp}");
            string actual = formatter.Format(entry);

            string expected = string.Concat("TimeStamp: " + DateTime.MaxValue.ToString());
            Assert.AreEqual(expected, actual);
        }
 string FormatEntry(string template,
                    LogEntry entry)
 {
     TextFormatter formatter = new TextFormatter(template);
     return formatter.Format(entry);
 }
        public void TextFromatterWithEmptyTemplateUsesDefaultTemplate()
        {
            TextFormatter formatter = new TextFormatter("");

            LogEntry entry = CommonUtil.GetDefaultLogEntry();
            entry.Title = Guid.NewGuid().ToString();
            entry.AppDomainName = Guid.NewGuid().ToString();
            entry.MachineName = Guid.NewGuid().ToString();
            entry.ManagedThreadName = Guid.NewGuid().ToString();
            entry.Message = Guid.NewGuid().ToString();
            string category = Guid.NewGuid().ToString();
            entry.Categories = new string[] { category };
            entry.ProcessName = Guid.NewGuid().ToString();

            string formattedMessage = formatter.Format(entry);

            Assert.IsTrue(formattedMessage.IndexOf(AppDomain.CurrentDomain.FriendlyName) != -1);
            Assert.IsTrue(formattedMessage.IndexOf(entry.Title) != -1);
            Assert.IsTrue(formattedMessage.IndexOf(Environment.MachineName) != -1);
            Assert.IsTrue(formattedMessage.IndexOf(entry.ManagedThreadName) != -1);
            Assert.IsTrue(formattedMessage.IndexOf(entry.Message) != -1);
            Assert.IsTrue(formattedMessage.IndexOf(entry.Title) != -1);
            Assert.IsTrue(formattedMessage.IndexOf(category) != -1);
            Assert.IsTrue(formattedMessage.IndexOf(LogEntry.GetProcessName()) != -1);
        }
        public void FormatsMessageToken()
        {
            TextFormatter formatter = new TextFormatter("Message: {message}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Message: " + entry.Message, actual);
        }
        public void FormatsLocalAppDomainToken()
        {
            TextFormatter formatter = new TextFormatter("App domain: {localAppDomain}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("App domain: " + AppDomain.CurrentDomain.FriendlyName, actual);
        }
        private string FormatEntry(string template, LogEntry entry)
        {
            TextFormatter formatter = new TextFormatter(template);

            return(formatter.Format(entry));
        }
        public void DictionaryTokenCanHandleInternalParenthesisAsLongAsTheyAreNotFollowedByACurlyBracket()
        {
            TextFormatter formatter = new TextFormatter("{dictionary(({key})-{value} - )}");
            CustomLogEntry entry = new CustomLogEntry();
            Dictionary<string, object> hash = new Dictionary<string, object>();
            hash["key1"] = "value1";
            hash["key2"] = "value2";
            entry.ExtendedProperties = hash;

            string actual = formatter.Format(entry);

            Assert.AreEqual("(key1)-value1 - (key2)-value2 - ", actual);
        }
        public void FormatsTimestampWithNoFormat()
        {
            TextFormatter formatter = new TextFormatter("Timestamp: {timestamp}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Timestamp: " + entry.TimeStamp.ToString(CultureInfo.CurrentCulture), actual);
        }
        public void FormatsLocalMachineToken()
        {
            TextFormatter formatter = new TextFormatter("Machine name: {localMachine}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Machine name: " + Environment.MachineName, actual);
        }
        public void FormatsThreadIdToken()
        {
            TextFormatter formatter = new TextFormatter("Thread id: {win32ThreadId}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Thread id: " + entry.Win32ThreadId, actual);
        }
Beispiel #53
0
        private string FormatEntry(string template, LogEntry entry)
        {
            TextFormatterData data = new TextFormatterData();
            data.Template.Value = template;

            TextFormatter formatter = new TextFormatter(data);
            return formatter.Format(entry);
        }
        public void FormatsThreadNameToken()
        {
            TextFormatter formatter = new TextFormatter("Thread name: {threadName}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Thread name: " + entry.ManagedThreadName, actual);
        }
        public void FormatsPriorityToken()
        {
            TextFormatter formatter = new TextFormatter("Priority: {priority}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Priority: " + entry.Priority.ToString(CultureInfo.CurrentCulture), actual);
        }
        public void FormatsErrorMessagesToken()
        {
            TextFormatter formatter = new TextFormatter("Errors: {errorMessages}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();
            entry.AddErrorMessage("an error message");

            string actual = formatter.Format(entry);

            Assert.AreEqual("Errors: " + entry.ErrorMessages, actual);
        }
        public void FormatterIsReusableBug1769()
        {
            ILogFormatter formatter = new TextFormatter("{message}");

            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            entry.Message = "message1";
            Assert.AreEqual(entry.Message, formatter.Format(entry));

            entry.Message = "message2";
            Assert.AreEqual(entry.Message, formatter.Format(entry));

            entry.Message = "message3";
            Assert.AreEqual(entry.Message, formatter.Format(entry));
        }
        public void FormatsCategoryToken()
        {
            TextFormatter formatter = new TextFormatter("Categories: {category}");
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Categories: " + TextFormatter.FormatCategoriesCollection(entry.Categories), actual);
        }
Beispiel #59
0
        public bool Run(
            string projectAssembly,
            string sourceDirectory,
            IList <string> sourceFiles,
            IList <string> generationList,
            IWriter writer,
            TextFormatter textFormatter,
            IDictionary <string, string> typeOverrideMap
            )
        {
            var overallStopwatch = Stopwatch.StartNew();
            var stopwatch        = Stopwatch.StartNew();

            GlobalLogger.Info($"=== Consolidate Source Files");
            var sourceFilesAsText = GetSourceFilesAsSingleTextString(
                sourceDirectory,
                sourceFiles
                );

            GlobalLogger.Info($"=== Consolidated Source Files | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generated AST");
            var ast = new TypeScriptAST(
                sourceFilesAsText,
                "source-combined.ts"
                );

            GlobalLogger.Info($"=== Generated AST | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");
            var notGeneratedClassNames = new List <string>();

            var generatedStatements = new List <GeneratedStatement>();

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generate Cached Entity Object");
            var cachedEntityObject = GenerateCachedEntityObject.GenerateClassStatement();

            generatedStatements.Add(
                new GeneratedStatement(
                    cachedEntityObject,
                    GenerateCachedEntityObject.GenerateString()
                    )
                );
            GlobalLogger.Info($"=== Generated Cached Entity Object | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generate Class Statements");
            var generatedClassStatements = GenerateClassFromList(
                ast,
                projectAssembly,
                generationList,
                notGeneratedClassNames,
                typeOverrideMap,
                new List <ClassStatement> {
                cachedEntityObject
            }
                );

            generatedClassStatements.Remove(cachedEntityObject);
            GlobalLogger.Info($"=== Generated Class Statements | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generate Statements");
            foreach (var generatedStatement in generatedClassStatements)
            {
                generatedStatements.Add(
                    new GeneratedStatement(
                        generatedStatement,
                        GenerateClassStatementString.Generate(
                            generatedStatement,
                            textFormatter
                            )
                        )
                    );
            }
            GlobalLogger.Info($"=== Generated Statements | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            stopwatch.Restart();
            GlobalLogger.Info($"=== Generating Shimmed Classes");
            foreach (var notGeneratedInterfaceName in notGeneratedClassNames)
            {
                if (!JavaScriptProvidedApiIdentifier.Identify(notGeneratedInterfaceName, out _))
                {
                    var classShim = GenerateClassShim.GenerateClassStatement(
                        notGeneratedInterfaceName
                        );
                    generatedStatements.Add(
                        new GeneratedStatement(
                            classShim,
                            textFormatter.Format(
                                GenerateClassShim.GenerateString(
                                    classShim
                                    )
                                )
                            )
                        );
                    GlobalLogger.Info($"=== Generated Shimmed Class: {notGeneratedInterfaceName}");
                }
            }
            GlobalLogger.Info($"=== Generated Shimmed Classes | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            // Write Generated Statements to Passed in Writer
            stopwatch.Restart();
            GlobalLogger.Info($"=== Writing Generated Statements");
            writer.Write(
                generatedStatements
                );
            GlobalLogger.Info($"=== Finished Writing Generated Statements | ElapsedTime: {stopwatch.ElapsedMilliseconds}ms");

            GlobalLogger.Success($"=== Finished Run | ElapsedTime: {overallStopwatch.ElapsedMilliseconds}ms");

            return(true);
        }
        public void FormatsPropertyToken()
        {
            TextFormatter formatter = new TextFormatter("Reflected Property Value: {property(MyProperty)}");
            CustomLogEntry entry = new CustomLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Reflected Property Value: myPropertyValue", actual);
        }