public SyslogMessage(ILocalizedTimeProvider timeProvider, Message azoMsg) { m_Severity = FromAzosLogMessageType(azoMsg.Type); m_Facility = FacilityLevel.User; m_LocalTimeStamp = timeProvider.UniversalTimeToLocalizedTime(azoMsg.UTCTimeStamp); m_Text = string.Format("{0} - {1} - {2}", azoMsg.Topic, azoMsg.From, azoMsg.Text); }
public string Run(IConfigSectionNode node, string inputValue, string macroName, IConfigSectionNode macroParams, object context = null) { if (macroName.StartsWith(AS_PREFIX, StringComparison.InvariantCultureIgnoreCase) && macroName.Length > AS_PREFIX.Length) { var type = macroName.Substring(AS_PREFIX.Length); return(GetValueAs(inputValue, type, macroParams.Navigate("$dflt|$default").Value, macroParams.Navigate("$fmt|$format").Value)); } else if (string.Equals(macroName, "now", StringComparison.InvariantCultureIgnoreCase)) { var utc = macroParams.AttrByName("utc").ValueAsBool(false); var fmt = macroParams.Navigate("$fmt|$format").ValueAsString(); var valueAttr = macroParams.AttrByName("value"); DateTime now; if (utc) { now = App.TimeSource.UTCNow; } else { ILocalizedTimeProvider timeProvider = App.Instance; if (context is ILocalizedTimeProvider) { timeProvider = (ILocalizedTimeProvider)context; } now = timeProvider.LocalizedTime; } // We inspect the "value" param that may be provided for testing purposes if (valueAttr.Exists) { now = valueAttr.Value.AsDateTimeFormat(now, fmt, utc ? DateTimeStyles.AssumeUniversal : DateTimeStyles.AssumeLocal); } return(fmt == null?now.ToString() : now.ToString(fmt)); } else if (string.Equals(macroName, "ctx-name", StringComparison.InvariantCultureIgnoreCase)) { if (context is INamed) { return(((INamed)context).Name); } } return(inputValue); }
public virtual string Run(IConfigSectionNode node, string inputValue, string macroName, IConfigSectionNode macroParams, object context = null) { if (macroName.StartsWith(AS_PREFIX, StringComparison.InvariantCultureIgnoreCase) && macroName.Length > AS_PREFIX.Length) { var type = macroName.Substring(AS_PREFIX.Length); return(GetValueAs(inputValue, type, macroParams.Navigate("$dflt|$default").Value, macroParams.Navigate("$fmt|$format").Value)); } else if (string.Equals(macroName, "now", StringComparison.InvariantCultureIgnoreCase)) { var utc = macroParams.AttrByName("utc").ValueAsBool(false); var fmt = macroParams.Navigate("$fmt|$format").ValueAsString(); var valueAttr = macroParams.AttrByName("value"); var now = Ambient.UTCNow; if (!utc) { ILocalizedTimeProvider timeProvider = context as ILocalizedTimeProvider; if (timeProvider == null && context is IApplicationComponent cmp) { timeProvider = cmp.ComponentDirector as ILocalizedTimeProvider; if (timeProvider == null) { timeProvider = cmp.App; } } now = timeProvider != null ? timeProvider.LocalizedTime : now.ToLocalTime(); } // We inspect the "value" param that may be provided for testing purposes if (valueAttr.Exists) { now = valueAttr.Value.AsDateTimeFormat(now, fmt, utc ? DateTimeStyles.AssumeUniversal : DateTimeStyles.AssumeLocal); } return(fmt == null?now.ToString() : now.ToString(fmt)); } else if (string.Equals(macroName, "ctx-name", StringComparison.InvariantCultureIgnoreCase)) { if (context is Collections.INamed) { return(((Collections.INamed)context).Name); } } return(inputValue); }