protected List <string> ExtractProps(PropertiesDictionary props, string prefix) { // extract optional custom properties which have a special prefix if (props == null) { new List <string>(); } var customProps = props.GetKeys() .Where(x => x.StartsWith(prefix)) .Select(x => x.Substring(prefix.Length, x.Length - prefix.Length)) .OrderBy(x => x) .ToList(); if (customProps.Count() == 0) { new List <string>(); } var keyValues = new List <string>(); foreach (var propName in customProps) { var val = (string)props[prefix + propName]; val = val.Replace('"', ' '); // remove quotes keyValues.Add($"{propName}=\"{val}\""); } return(keyValues); }
public void TestSerialization() { PropertiesDictionary pd = new PropertiesDictionary(); for (int i = 0; i < 10; i++) { pd[i.ToString()] = i; } Assert.AreEqual(10, pd.Count, "Dictionary should have 10 items"); // Serialize the properties into a memory stream BinaryFormatter formatter = new BinaryFormatter(); MemoryStream memory = new MemoryStream(); formatter.Serialize(memory, pd); // Deserialize the stream into a new properties dictionary memory.Position = 0; PropertiesDictionary pd2 = (PropertiesDictionary)formatter.Deserialize(memory); Assert.AreEqual(10, pd2.Count, "Deserialized Dictionary should have 10 items"); foreach (string key in pd.GetKeys()) { Assert.AreEqual(pd[key], pd2[key], "Check Value Persisted for key [{0}]", key); } }
public string[] GetKeys() { if (_dictionary != null) { return(_dictionary.GetKeys()); } return(null); }
// TODO: Fix this so it doesn't break Send() private Dictionary <string, string> PropertiesToLabels(PropertiesDictionary properties) { return(properties .GetKeys() .ToDictionary( key => key, key => properties[key].ToString())); }
/// <summary> /// Get the keys stored in the properties. /// </summary> /// <para> /// Gets the keys stored in the properties. /// </para> /// <returns>a set of the defined keys</returns> public string[] GetKeys() { #if NETCF PropertiesDictionary _dictionary = GetProperties(false); #endif if (_dictionary != null) { return(_dictionary.GetKeys()); } return(null); }
static string String(PropertiesDictionary properties, string name) { if (properties == null || properties.Count == 0) { return(null); } if (!properties.GetKeys().Any(key => key.ToLower().Equals(name.ToLower()))) { return(null); } var property = properties[name.ToLower()]; return(property?.ToString()); }
private List <Item> PropertiesToData(PropertiesDictionary properties) { var items = new List <Item>(); foreach (var key in properties.GetKeys().Where(key => !knownKeys.Contains(key.ToLower()))) { var value = properties[key]; if (value != null) { items.Add(new Item(key, properties[key].ToString())); } } return(items); }
private void CompareProperties(Dictionary <string, object> expected, PropertiesDictionary actual) { // It is okay for the actual to have more, but it must have all from expected. var expectedKeys = expected.Keys; var actualKeys = actual.GetKeys(); var missingKeys = expectedKeys .Except(actualKeys) .ToList(); var nonMatchingKeys = expectedKeys .Where(key => !Equals(expected[key].ToString(), actual[key].ToString())) .ToList(); missingKeys.Count().Should().Be(0, because: "Missing properties: " + string.Join(", ", missingKeys)); nonMatchingKeys.Count().Should().Be(0, because: "Non-matching properties: " + string.Join(", ", nonMatchingKeys)); }
/// <summary> /// Creates the event. /// </summary> /// <param name="formatMessage">Function to format the message.</param> /// <param name="domain">Gets the AppDomain friendly name.</param> /// <param name="exceptionObject">Gets the exception object used to initialize this event.</param> /// <param name="identity">Gets the identity of the current thread principal.</param> /// <param name="level">Gets the log4net Level of the logging event.</param> /// <param name="loggerName">Gets the name of the logger that logged the event.</param> /// <param name="properties">Additional event specific properties.</param> /// <param name="message">Gets the message, rendered through the log4net.Repository.ILoggerRepository.RendererMap.</param> /// <param name="threadName">Gets the name of the current thread.</param> /// <param name="timestamp">Gets the time of the logging event.</param> /// <param name="userName">Gets the name of the current user.</param> public AzureLoggingEvent(Func <string> formatMessage, string domain, Exception exceptionObject, string identity, Level level, string loggerName, PropertiesDictionary properties, string message, string threadName, DateTime timestamp, string userName) { Domain = domain; ExceptionObject = exceptionObject; Identity = identity; LoggerName = loggerName; Properties = new Dictionary <string, object>(); Message = formatMessage != null?formatMessage() : message; ThreadName = threadName; Timestamp = timestamp; UserName = userName; LevelValue = level.Value; LevelName = level.Name; string[] propertyKeys = properties.GetKeys(); foreach (string propertyKey in propertyKeys) { Properties[propertyKey] = properties[propertyKey]; } }
private static void AddLog4NetProperties(PropertiesDictionary properties, IDictionary <string, string> metaData) { if (properties == null) { return; } foreach (string key in properties.GetKeys()) { if (string.IsNullOrEmpty(key) || key.StartsWith("log4net", StringComparison.OrdinalIgnoreCase) || key.StartsWith("ai.", StringComparison.OrdinalIgnoreCase)) { continue; } object value = properties[key]; if (value != null) { AddLoggingEventProperty(key, value.ToString(), metaData); } } }