private void SetAttribute(string name, object value) { if (value == null) { return; } Type t = value.GetType(); if (t == typeof(int)) { int number; if (int.TryParse(value.ToString(), out number)) { this.xmlWriter.WriteAttributeString(name, number.ToString(CultureInfo.InvariantCulture)); } } else if (t == typeof(bool)) { this.xmlWriter.WriteAttributeString(name, value.ToString()); } else if (t == typeof(MessageImportance)) { MessageImportance importance = (MessageImportance)value; this.xmlWriter.WriteAttributeString(name, importance.ToString()); } else { string text = value.ToString(); if (!string.IsNullOrEmpty(text)) { this.xmlWriter.WriteAttributeString(name, text); } } }
public void LogMessage(MessageImportance importance, string message, params object[] messageArgs) { string msg = string.Format($"{importance.ToString()}: {message}", messageArgs); Messages.Add(msg); Console.WriteLine(msg); }
//use the Message Build Task to write something to build log private void LogMessage(string text, MessageImportance importance) { Message m = new Message(); m.Text = text; m.Importance = importance.ToString(); m.BuildEngine = this.BuildEngine; m.Execute(); }
private void SetAttribute(string name, object value) { if (value == null) { return; } string Text = string.Empty; Type t = value.GetType(); if (t == typeof(int)) { if (Int32.Parse(value.ToString()) > 0) //???? { Text = value.ToString(); } } else if (t == typeof(DateTime)) { DateTime dateTime = (DateTime)value; Text = dateTime.ToString("G", DateTimeFormatInfo.InvariantInfo); } else if (t == typeof(TimeSpan)) { // format TimeSpan to show only integral seconds double seconds = ((TimeSpan)value).TotalSeconds; TimeSpan whole = TimeSpan.FromSeconds(Math.Truncate(seconds)); Text = whole.ToString(); } else if (t == typeof(Boolean)) { Text = value.ToString().ToLower(); } else if (t == typeof(MessageImportance)) { MessageImportance importance = (MessageImportance)value; Text = importance.ToString().ToLower(); } else { if (!String.IsNullOrEmpty(value.ToString())) { Text = value.ToString(); } } try { xmlWriter.WriteAttributeString(name, Text); } catch (Exception ex) { throw new InvalidOperationException(string.Format("Encountered exception when creating attribute name '{0}' and value '{1}':{2}{3}", name, Text, Environment.NewLine, ex.Message), ex); } }
private void LogMessage(MessageImportance importance, string message, params object[] args) { try { Log.LogMessage(importance.ToString(), message, args); } catch (InvalidOperationException) { // Swallow exceptions for testing } }
public void LogMessage(MessageImportance importance, string message) { try { Log.LogMessage(importance.ToString(), message); } catch (InvalidOperationException) { // Swallow exceptions for testing } }
/// <summary> /// Adds a <Message /> task to the current target. /// </summary> /// <param name="text">The message to display.</param> /// <param name="importance">An optional <see cref="MessageImportance" /> to use.</param> /// <param name="condition">An optional condition to add to the task.</param> /// <param name="label">An optional label to add to the task.</param> /// <returns>The current <see cref="ProjectCreator" />.</returns> public ProjectCreator TaskMessage(string text, MessageImportance?importance = null, string?condition = null, string?label = null) { return(Task( "Message", condition, new Dictionary <string, string?> { { "Text", text }, { "Importance", importance?.ToString() }, }, label: label)); }
private void SetAttribute(XmlElement element, object obj, string name) { if (obj == null) { return; } Type t = obj.GetType(); if (t == typeof(int)) { element.SetAttribute(name, obj.ToString()); } else if (t == typeof(DateTime)) { DateTime dateTime = (DateTime)obj; element.SetAttribute(name, dateTime.ToString("G", DateTimeFormatInfo.InvariantInfo)); } else if (t == typeof(TimeSpan)) { // format TimeSpan to show only integral seconds double seconds = ((TimeSpan)obj).Seconds; TimeSpan whole = TimeSpan.FromSeconds(Math.Truncate(seconds)); //int rest = (int)(Math.Round(seconds - Math.Truncate(seconds), 2) * 100.0); //if (rest!=0) // element.SetAttribute(name, whole.ToString()+"."+rest.ToString(NumberFormatInfo.InvariantInfo)); //else element.SetAttribute(name, whole.ToString()); } else if (t == typeof(Boolean)) { element.SetAttribute(name, obj.ToString().ToLower()); } else if (t == typeof(MessageImportance)) { MessageImportance importance = (MessageImportance)obj; element.SetAttribute(name, importance.ToString().ToLower()); } else { if (obj.ToString().Length > 0) { element.SetAttribute(name, obj.ToString()); } } }
private void SetAttribute(string name, object value) { if (value == null) { return; } Type t = value.GetType(); if (t == typeof(int)) { if (Int32.Parse(value.ToString()) > 0) //???? { xmlWriter.WriteAttributeString(name, value.ToString()); } } else if (t == typeof(DateTime)) { DateTime dateTime = (DateTime)value; xmlWriter.WriteAttributeString(name, dateTime.ToString("G", DateTimeFormatInfo.InvariantInfo)); } else if (t == typeof(TimeSpan)) { // format TimeSpan to show only integral seconds double seconds = ((TimeSpan)value).TotalSeconds; TimeSpan whole = TimeSpan.FromSeconds(Math.Truncate(seconds)); xmlWriter.WriteAttributeString(name, whole.ToString()); } else if (t == typeof(Boolean)) { xmlWriter.WriteAttributeString(name, value.ToString().ToLower()); } else if (t == typeof(MessageImportance)) { MessageImportance importance = (MessageImportance)value; xmlWriter.WriteAttributeString(name, importance.ToString().ToLower()); } else { string text = value.ToString(); if (!String.IsNullOrEmpty(text)) { xmlWriter.WriteAttributeString(name, text); } } }
private void SetAttribute(XmlElement element, object obj, string name) { if (obj == null) { return; } Type t = obj.GetType(); if (t == typeof(int)) { element.SetAttribute(name, obj.ToString()); } else if (t == typeof(DateTime)) { DateTime dateTime = (DateTime)obj; element.SetAttribute(name, dateTime.ToString("G", DateTimeFormatInfo.InvariantInfo)); } else if (t == typeof(TimeSpan)) { double seconds = ((TimeSpan)obj).TotalSeconds; TimeSpan whole = TimeSpan.FromSeconds(Math.Truncate(seconds)); element.SetAttribute(name, whole.ToString()); } else if (t == typeof(Boolean)) { element.SetAttribute(name, obj.ToString().ToLower()); } else if (t == typeof(MessageImportance)) { MessageImportance importance = (MessageImportance)obj; element.SetAttribute(name, importance.ToString().ToLower()); } else { if (obj.ToString().Length > 0) { element.SetAttribute(name, obj.ToString()); } } }
private void LogMessage(MessageImportance importance, string message, params object[] args) { try { if (Log != null) Log.LogMessage(importance.ToString(), message, args); } catch (InvalidOperationException) { // Swallow exceptions for testing } }
public static void LogMessage(MessageImportance importance, string message, params object[] messageArgs) { Console.WriteLine($"{importance.ToString()}: {message}", messageArgs); }
private void LogMessage(string text, MessageImportance importance) { var m = new Message { Text = text, Importance = importance.ToString(), BuildEngine = BuildEngine }; m.Execute(); }