/// <summary> /// Construct the repository using specific properties /// </summary> /// <param name="properties">the properties to set for this repository</param> /// <remarks> /// <para> /// Initializes the repository with specified properties. /// </para> /// </remarks> protected LoggerRepositorySkeleton(PropertiesDictionary properties) { m_properties = properties; m_rendererMap = new RendererMap(); m_pluginMap = new PluginMap(this); m_levelMap = new LevelMap(); m_configurationMessages = EmptyCollection.Instance; m_configured = false; AddBuiltinLevels(); // Don't disable any levels by default. m_threshold = Level.All; }
/// <summary> /// Initializes a new instance of the <see cref="Block" /> class. /// </summary> /// <param name="blocks">The ownerCollection.</param> /// <param name="initialBlockType">Initial type of the block.</param> /// <param name="text">The text.</param> public Block( ProjectBlockCollection blocks, BlockType initialBlockType, string text = "") { BlockKey = BlockKey.GetNext(); Blocks = blocks; blockType = initialBlockType; this.text = text; Properties = new PropertiesDictionary(); TextSpans = new TextSpanCollection(); accessLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); previouslyAnalyzedPlugins = new HashSet<IBlockAnalyzerProjectPlugin>(); }
/// <summary> /// Initializes a new instance of the <see cref="Project"/> class. /// </summary> public Project( ProjectProcessingState initialProcessingState = ProjectProcessingState.Interactive) { // Set up the initial states. ProcessingState = initialProcessingState; // We need the settings set up first since it may contribute // to the loading of other components of the project. Settings = new ProjectSettings(); Properties = new PropertiesDictionary(); BlockTypes = new BlockTypeSupervisor(this); Blocks = new ProjectBlockCollection(this); Commands = new BlockCommandSupervisor(this); Plugins = new PluginSupervisor(this); Macros = new ProjectMacros(); }
/* Example log4j schema event * * <log4j:event logger="first logger" level="ERROR" thread="Thread-3" timestamp="1051494121460"> * <log4j:message><![CDATA[errormsg 3]]></log4j:message> * <log4j:NDC><![CDATA[third]]></log4j:NDC> * <log4j:MDC> * <log4j:data name="some string" value="some valuethird"/> * </log4j:MDC> * <log4j:throwable><![CDATA[java.lang.Exception: someexception-third * at org.apache.log4j.chainsaw.Generator.run(Generator.java:94) * ]]></log4j:throwable> * <log4j:locationInfo class="org.apache.log4j.chainsaw.Generator" * method="run" file="Generator.java" line="94"/> * <log4j:properties> * <log4j:data name="log4jmachinename" value="windows"/> * <log4j:data name="log4japp" value="udp-generator"/> * </log4j:properties> * </log4j:event> * */ /* Since log4j 1.3 the log4j:MDC has been combined into the log4j:properties element */ /// <summary> /// Actually do the writing of the xml /// </summary> /// <param name="writer">the writer to use</param> /// <param name="loggingEvent">the event to write</param> /// <remarks> /// <para> /// Generate XML that is compatible with the log4j schema. /// </para> /// </remarks> override protected void FormatXml(XmlWriter writer, LoggingEvent loggingEvent) { // Translate logging events for log4j // Translate hostname property if (loggingEvent.LookupProperty(LoggingEvent.HostNameProperty) != null && loggingEvent.LookupProperty("log4jmachinename") == null) { loggingEvent.GetProperties()["log4jmachinename"] = loggingEvent.LookupProperty(LoggingEvent.HostNameProperty); } // translate appdomain name if (loggingEvent.LookupProperty("log4japp") == null && loggingEvent.Domain != null && loggingEvent.Domain.Length > 0) { loggingEvent.GetProperties()["log4japp"] = loggingEvent.Domain; } // translate identity name if (loggingEvent.Identity != null && loggingEvent.Identity.Length > 0 && loggingEvent.LookupProperty(LoggingEvent.IdentityProperty) == null) { loggingEvent.GetProperties()[LoggingEvent.IdentityProperty] = loggingEvent.Identity; } // translate user name if (loggingEvent.UserName != null && loggingEvent.UserName.Length > 0 && loggingEvent.LookupProperty(LoggingEvent.UserNameProperty) == null) { loggingEvent.GetProperties()[LoggingEvent.UserNameProperty] = loggingEvent.UserName; } // Write the start element writer.WriteStartElement("log4j:event"); writer.WriteAttributeString("logger", loggingEvent.LoggerName); // Calculate the timestamp as the number of milliseconds since january 1970 // // We must convert the TimeStamp to UTC before performing any mathematical // operations. This allows use to take into account discontinuities // caused by daylight savings time transitions. TimeSpan timeSince1970 = loggingEvent.TimeStamp.ToUniversalTime() - s_date1970; writer.WriteAttributeString("timestamp", XmlConvert.ToString((long)timeSince1970.TotalMilliseconds)); writer.WriteAttributeString("level", loggingEvent.Level.DisplayName); writer.WriteAttributeString("thread", loggingEvent.ThreadName); // Append the message text writer.WriteStartElement("log4j:message"); Transform.WriteEscapedXmlString(writer, loggingEvent.RenderedMessage, this.InvalidCharReplacement); writer.WriteEndElement(); object ndcObj = loggingEvent.LookupProperty("NDC"); if (ndcObj != null) { string valueStr = loggingEvent.Repository.RendererMap.FindAndRender(ndcObj); if (valueStr != null && valueStr.Length > 0) { // Append the NDC text writer.WriteStartElement("log4j:NDC"); Transform.WriteEscapedXmlString(writer, valueStr, this.InvalidCharReplacement); writer.WriteEndElement(); } } // Append the properties text PropertiesDictionary properties = loggingEvent.GetProperties(); if (properties.Count > 0) { writer.WriteStartElement("log4j:properties"); foreach (System.Collections.DictionaryEntry entry in properties) { writer.WriteStartElement("log4j:data"); writer.WriteAttributeString("name", (string)entry.Key); // Use an ObjectRenderer to convert the object to a string string valueStr = loggingEvent.Repository.RendererMap.FindAndRender(entry.Value); writer.WriteAttributeString("value", valueStr); writer.WriteEndElement(); } writer.WriteEndElement(); } string exceptionStr = loggingEvent.GetExceptionString(); if (exceptionStr != null && exceptionStr.Length > 0) { // Append the stack trace line writer.WriteStartElement("log4j:throwable"); Transform.WriteEscapedXmlString(writer, exceptionStr, this.InvalidCharReplacement); writer.WriteEndElement(); } if (LocationInfo) { LocationInfo locationInfo = loggingEvent.LocationInformation; writer.WriteStartElement("log4j:locationInfo"); writer.WriteAttributeString("class", locationInfo.ClassName); writer.WriteAttributeString("method", locationInfo.MethodName); writer.WriteAttributeString("file", locationInfo.FileName); writer.WriteAttributeString("line", locationInfo.LineNumber); writer.WriteEndElement(); } writer.WriteEndElement(); }
/// <summary> /// Flatten this composite collection into a single properties dictionary /// </summary> /// <returns>the flattened dictionary</returns> /// <remarks> /// <para> /// Reduces the collection of ordered dictionaries to a single dictionary /// containing the resultant values for the keys. /// </para> /// </remarks> public PropertiesDictionary Flatten() { if (m_flattened == null) { m_flattened = new PropertiesDictionary(); for(int i=m_nestedProperties.Count; --i>=0; ) { ReadOnlyPropertiesDictionary cur = (ReadOnlyPropertiesDictionary)m_nestedProperties[i]; foreach(DictionaryEntry entry in cur) { m_flattened[(string)entry.Key] = entry.Value; } } } return m_flattened; }
public void CanLogWellKnownProperties() { // Arrange CreateMessage message = null; _messagesMock .Setup(x => x.CreateAndNotify(It.IsAny <Guid>(), It.IsAny <CreateMessage>())) .Callback <Guid, CreateMessage>((logId, msg) => { message = msg; }); var now = DateTime.UtcNow; var hostname = Guid.NewGuid().ToString(); var type = Guid.NewGuid().ToString(); var application = Guid.NewGuid().ToString(); var user = Guid.NewGuid().ToString(); var source = Guid.NewGuid().ToString(); var method = Guid.NewGuid().ToString(); var version = Guid.NewGuid().ToString(); var url = Guid.NewGuid().ToString(); var statuscode = 404; var properties = new PropertiesDictionary(); properties["hostname"] = hostname; properties["type"] = type; properties["application"] = application; properties["user"] = user; properties["source"] = source; properties["method"] = method; properties["version"] = version; properties["url"] = url; properties["statuscode"] = statuscode; properties["servervariables"] = new Dictionary <string, string> { { "serverVariableKey", "serverVariableValue" } }; properties["cookies"] = new Dictionary <string, string> { { "cookiesKey", "cookiesValue" } }; properties["form"] = new Dictionary <string, string> { { "formKey", "formValue" } }; properties["querystring"] = new Dictionary <string, string> { { "queryStringKey", "queryStringValue" } }; var data = LoggingEventData(now, properties); // Act _sut.DoAppend(new LoggingEvent(data)); // Assert Assert.That(message, Is.Not.Null); Assert.That(message.Hostname, Is.EqualTo(hostname)); Assert.That(message.Type, Is.EqualTo(type)); Assert.That(message.Application, Is.EqualTo(application)); Assert.That(message.User, Is.EqualTo(user)); Assert.That(message.Source, Is.EqualTo(source)); Assert.That(message.Method, Is.EqualTo(method)); Assert.That(message.Version, Is.EqualTo(version)); Assert.That(message.Url, Is.EqualTo(url)); Assert.That(message.StatusCode, Is.EqualTo(statuscode)); Assert.That(message.ServerVariables.Any(sv => sv.Key == "serverVariableKey" && sv.Value == "serverVariableValue")); Assert.That(message.Cookies.Any(sv => sv.Key == "cookiesKey" && sv.Value == "cookiesValue")); Assert.That(message.Form.Any(sv => sv.Key == "formKey" && sv.Value == "formValue")); Assert.That(message.QueryString.Any(sv => sv.Key == "queryStringKey" && sv.Value == "queryStringValue")); }
/// <summary> /// Get the <c>PropertiesDictionary</c> for this thread. /// </summary> /// <param name="create">create the dictionary if it does not exist, otherwise return null if does not exist</param> /// <returns>the properties for this thread</returns> /// <remarks> /// <para> /// The collection returned is only to be used on the calling thread. If the /// caller needs to share the collection between different threads then the /// caller must clone the collection before doing so. /// </para> /// </remarks> internal PropertiesDictionary GetProperties(bool create) { #if NETCF PropertiesDictionary _dictionary = (PropertiesDictionary)System.Threading.Thread.GetData(s_threadLocalSlot); #endif if (_dictionary == null && create) { _dictionary = new PropertiesDictionary(); #if NETCF System.Threading.Thread.SetData(s_threadLocalSlot, _dictionary); #endif } return _dictionary; }
/// <summary> /// Construct with properties and a logger factory /// </summary> /// <param name="properties">The properties to pass to this repository.</param> /// <param name="loggerFactory">The factory to use to create new logger instances.</param> /// <remarks> /// <para> /// Initializes a new instance of the <see cref="Hierarchy" /> class with /// the specified <see cref="ILoggerFactory" />. /// </para> /// </remarks> public Hierarchy(PropertiesDictionary properties, ILoggerFactory loggerFactory) : base(properties) { if (loggerFactory == null) { throw new ArgumentNullException("loggerFactory"); } m_defaultFactory = loggerFactory; m_ht = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable()); }
public DictionaryCollectionEnumerator(PropertiesDictionary dictionary, bool keyCollection) : base(dictionary) { _keyCollection = keyCollection; }
private static bool HasEventProperties(PropertiesDictionary propertiesDictionary) { return(propertiesDictionary._eventProperties != null && propertiesDictionary._eventProperties.Count > 0); }
private static void SetCallContextData(PropertiesDictionary properties) { CallContext.SetData(c_SlotName, properties); }
/// <summary> /// Get the PropertiesDictionary stored in the LocalDataStoreSlot for this thread. /// </summary> /// <param name="create">create the dictionary if it does not exist, otherwise return null if is does not exist</param> /// <returns>the properties for this thread</returns> /// <remarks> /// <para> /// The collection returned is only to be used on the calling thread. If the /// caller needs to share the collection between different threads then the /// caller must clone the collection before doings so. /// </para> /// </remarks> internal PropertiesDictionary GetProperties(bool create) { if (!m_disabled) { try { PropertiesDictionary properties = GetCallContextData(); if (properties == null && create) { properties = new PropertiesDictionary(); SetCallContextData(properties); } return properties; } catch (SecurityException secEx) { m_disabled = true; // Thrown if we don't have permission to read or write the CallContext LogLog.Warn(declaringType, "SecurityException while accessing CallContext. Disabling LogicalThreadContextProperties", secEx); } } // Only get here is we are disabled because of a security exception if (create) { return new PropertiesDictionary(); } return null; }
public static void LoadPropertiesFromXmlStream(this IDictionary propertyBag, XmlReader reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (propertyBag == null) { throw new ArgumentNullException(nameof(propertyBag)); } while (reader.IsStartElement(PROPERTIES_ID) || reader.IsStartElement(PROPERTY_ID)) { string key = null; string value = null; bool isEmpty; if (reader.IsStartElement(PROPERTIES_ID)) { key = reader.GetAttribute(KEY_ID); string typeName = reader.GetAttribute(TYPE_ID); IDictionary nestedPropertyBag; if (String.IsNullOrEmpty(typeName)) { nestedPropertyBag = new PropertiesDictionary(); } else { Type type = GetPropertiesDictionaryType(typeName); nestedPropertyBag = (IDictionary)Activator.CreateInstance(type); } propertyBag[key] = nestedPropertyBag; isEmpty = reader.IsEmptyElement; reader.ReadStartElement(PROPERTIES_ID); LoadPropertiesFromXmlStream(nestedPropertyBag, reader); if (!isEmpty) { reader.ReadEndElement(); } } else { key = reader.GetAttribute(KEY_ID); value = reader.GetAttribute(VALUE_ID); string typeName = reader.GetAttribute(TYPE_ID); isEmpty = reader.IsEmptyElement; if (typeName == STRING_SET_ID) { StringSetCollection set = new StringSetCollection(); propertyBag[key] = set; LoadStringSet(set, reader); if (!isEmpty) { reader.ReadEndElement(); } continue; } reader.ReadStartElement(PROPERTY_ID); Type propertyType = GetPropertiesDictionaryType(typeName); if (typeName == "System.Version") { Version version; bool succeeded = Version.TryParse(value, out version); Debug.Assert(succeeded); propertyBag[key] = version; continue; } TypeConverter tc = TypeDescriptor.GetConverter(propertyType); Debug.Assert(tc.CanConvertFrom(typeof(string))); object propertyValue = tc.ConvertFromString(value); propertyBag[key] = propertyValue; Debug.Assert(isEmpty); } } }
/// <summary> /// Get the <c>PropertiesDictionary</c> for this thread. /// </summary> /// <param name="create">create the dictionary if it does not exist, otherwise return null if is does not exist</param> /// <returns>the properties for this thread</returns> /// <remarks> /// <para> /// The collection returned is only to be used on the calling thread. If the /// caller needs to share the collection between different threads then the /// caller must clone the collection before doing so. /// </para> /// </remarks> internal PropertiesDictionary GetProperties(bool create) { PropertiesDictionary properties = (PropertiesDictionary)System.Threading.Thread.GetData(s_threadLocalSlot); if (properties == null && create) { properties = new PropertiesDictionary(); System.Threading.Thread.SetData(s_threadLocalSlot, properties); } return properties; }
private static PropertiesDictionary BuildDefaultVulnerableDependenciesMap() { var result = new PropertiesDictionary(); var vulnerabilityDescriptor = new VulnerableDependencyDescriptor(); vulnerabilityDescriptor.Id = "AtlVulnerability"; vulnerabilityDescriptor.Name = "the Active Template Library (ATL)"; vulnerabilityDescriptor.VulnerabilityDescription = "contains known remote execution bugs (see https://technet.microsoft.com/en-us/library/security/ms09-035.aspx)."; vulnerabilityDescriptor.Resolution = "compile your binary using an up-to-date copy of ATL."; vulnerabilityDescriptor.FileHashes.Add("atlbase.h#FC-A7-3E-99-8B-D3-CC-E6-D6-28-75-F6-B4-27-DF-6E"); vulnerabilityDescriptor.FileHashes.Add("atlimpl.cpp#7C-4C-5D-BE-B6-EF-CB-DF-AF-8E-54-E5-0E-C0-2A-FB"); vulnerabilityDescriptor.FileHashes.Add("atlbase.h#31-F6-53-39-6A-51-B4-57-1E-F0-DD-C0-B3-54-8A-60"); vulnerabilityDescriptor.FileHashes.Add("atlcom.h#95-EB-90-BE-CF-F8-DF-1B-3E-EC-79-0A-64-B4-96-54"); vulnerabilityDescriptor.FileHashes.Add("atlcomcli.h#AC-EB-62-06-96-F2-ED-92-F8-F9-14-A0-50-48-80-25"); vulnerabilityDescriptor.FileHashes.Add("atlcom.h#AE-5D-A4-A5-23-42-EA-F8-46-74-93-91-1C-4F-3B-93"); vulnerabilityDescriptor.FileHashes.Add("atlcomcli.h#7B-C6-E4-10-50-D7-89-24-37-71-7F-1E-9D-97-84-B6"); vulnerabilityDescriptor.FileHashes.Add("atlcom.h#0B-C1-32-3B-3B-19-84-64-07-F5-3A-7A-48-36-43-B0"); vulnerabilityDescriptor.FileHashes.Add("atlcomcli.h#56-42-D5-31-BE-31-25-9B-E9-69-9F-2F-1F-68-CD-C2"); vulnerabilityDescriptor.FileHashes.Add("atlcom.h#97-D2-E6-9A-A3-D5-F2-F1-BA-2A-51-A2-B6-C8-9A-4B"); vulnerabilityDescriptor.FileHashes.Add("atlcomcli.h#A5-17-80-59-4D-4D-94-0C-68-0A-00-59-ED-6B-B3-1D"); vulnerabilityDescriptor.FileHashes.Add("atlcom.h#97-D2-E6-9A-A3-D5-F2-F1-BA-2A-51-A2-B6-C8-9A-4B"); vulnerabilityDescriptor.FileHashes.Add("atlcomcli.h#76-FB-17-FE-79-86-B9-7D-0E-09-97-85-9A-20-E9-4C"); result[vulnerabilityDescriptor.Id] = vulnerabilityDescriptor; return result; }
/// <summary> /// Sobreescritura del metodo para aplicar el Fix del location. /// </summary> /// <param name="writer"></param> /// <param name="loggingEvent"></param> protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent) { if (loggingEvent?.LocationInformation != null) { writer.WriteStartElement(this.m_elmEvent); writer.WriteAttributeString(ATTR_LOGGER, loggingEvent.LoggerName); #if NET_2_0 || NETCF_2_0 || MONO_2_0 writer.WriteAttributeString(ATTR_TIMESTAMP, XmlConvert.ToString(loggingEvent.TimeStamp, XmlDateTimeSerializationMode.Local)); #else #pragma warning disable CS0618 // Type or member is obsolete writer.WriteAttributeString(ATTR_TIMESTAMP, XmlConvert.ToString(loggingEvent.TimeStamp)); #pragma warning restore CS0618 // Type or member is obsolete #endif writer.WriteAttributeString(ATTR_LEVEL, loggingEvent.Level.DisplayName); writer.WriteAttributeString(ATTR_THREAD, loggingEvent.ThreadName); if (!string.IsNullOrEmpty(loggingEvent.Domain)) { writer.WriteAttributeString(ATTR_DOMAIN, loggingEvent.Domain); } if (!string.IsNullOrEmpty(loggingEvent.Identity)) { writer.WriteAttributeString(ATTR_IDENTITY, loggingEvent.Identity); } if (!string.IsNullOrEmpty(loggingEvent.UserName)) { writer.WriteAttributeString(ATTR_USERNAME, loggingEvent.UserName); } // Append the message text writer.WriteStartElement(this.m_elmMessage); if (!this.Base64EncodeMessage) { Transform.WriteEscapedXmlString(writer, loggingEvent.RenderedMessage, this.InvalidCharReplacement); } else { byte[] messageBytes = Encoding.UTF8.GetBytes(loggingEvent.RenderedMessage); string base64Message = Convert.ToBase64String(messageBytes, 0, messageBytes.Length); Transform.WriteEscapedXmlString(writer, base64Message, this.InvalidCharReplacement); } writer.WriteEndElement(); PropertiesDictionary properties = loggingEvent.GetProperties(); // Append the properties text if (properties.Count > 0) { writer.WriteStartElement(this.m_elmProperties); RendererMap rendererMap = loggingEvent.Repository.RendererMap; foreach (DictionaryEntry entry in properties) { writer.WriteStartElement(this.m_elmData); writer.WriteAttributeString(ATTR_NAME, Transform.MaskXmlInvalidCharacters((string)entry.Key, this.InvalidCharReplacement)); // Use an ObjectRenderer to convert the object to a string string valueStr; string render = rendererMap.FindAndRender(entry.Value); if (!this.Base64EncodeProperties) { valueStr = Transform.MaskXmlInvalidCharacters(render, this.InvalidCharReplacement); } else { byte[] propertyValueBytes = Encoding.UTF8.GetBytes(render); valueStr = Convert.ToBase64String(propertyValueBytes, 0, propertyValueBytes.Length); } writer.WriteAttributeString(ATTR_VALUE, valueStr); writer.WriteEndElement(); } writer.WriteEndElement(); } string exceptionStr = loggingEvent.GetExceptionString(); if (!string.IsNullOrEmpty(exceptionStr)) { // Append the stack trace line writer.WriteStartElement(this.m_elmException); Transform.WriteEscapedXmlString(writer, exceptionStr, this.InvalidCharReplacement); writer.WriteEndElement(); } if (this.LocationInfo) { LocationInfo locationInfo = loggingEvent.LocationInformation; string className = locationInfo.ClassName; string fileName = locationInfo.FileName; //string fullInfo = loggingEvent.LocationInformation.FullInfo; string lineNumber = locationInfo.LineNumber; string methodName = locationInfo.MethodName; writer.WriteStartElement(this.m_elmLocation); //writer.WriteAttributeString(ATTR_CLASS, locationInfo.ClassName); //writer.WriteAttributeString(ATTR_METHOD, locationInfo.MethodName); //writer.WriteAttributeString(ATTR_FILE, locationInfo.FileName); //writer.WriteAttributeString(ATTR_LINE, locationInfo.LineNumber); writer.WriteAttributeString(ATTR_CLASS, className); writer.WriteAttributeString(ATTR_METHOD, methodName); writer.WriteAttributeString(ATTR_FILE, fileName); writer.WriteAttributeString(ATTR_LINE, lineNumber); writer.WriteEndElement(); } writer.WriteEndElement(); } else { base.FormatXml(writer, loggingEvent); } }
private BinaryAnalyzerContext CreateContext(TestMessageLogger logger, PropertiesDictionary policy, string target) { var context = new BinaryAnalyzerContext(); context.Logger = logger; context.Policy = policy; if (target != null) { context.TargetUri = new Uri(target); } return context; }
protected DictionaryEnumeratorBase(PropertiesDictionary dictionary) { _dictionary = dictionary; }
private void Verify( IBinarySkimmer skimmer, IEnumerable<string> additionalTestFiles, bool useDefaultPolicy, bool expectToPass) { var targets = new List<string>(); string ruleName = skimmer.GetType().Name; string testFilesDirectory = ruleName; testFilesDirectory = Path.Combine(Environment.CurrentDirectory, "FunctionalTestsData", testFilesDirectory); testFilesDirectory = Path.Combine(testFilesDirectory, expectToPass ? "Pass" : "Fail"); Assert.True(Directory.Exists(testFilesDirectory)); foreach (string target in Directory.GetFiles(testFilesDirectory, "*", SearchOption.AllDirectories)) { if (AnalyzeCommand.ValidAnalysisFileExtensions.Contains(Path.GetExtension(target))) { targets.Add(target); } } if (additionalTestFiles != null) { foreach (string additionalTestFile in additionalTestFiles) { targets.Add(additionalTestFile); } } var context = new BinaryAnalyzerContext(); var logger = new TestMessageLogger(); context.Logger = logger; PropertiesDictionary policy = null; if (useDefaultPolicy) { policy = new PropertiesDictionary(); } context.Policy = policy; skimmer.Initialize(context); foreach (string target in targets) { PE pe = new PE(target); if (!pe.IsPEFile) { continue; } context = CreateContext(logger, policy, target); context.Rule = skimmer; string reasonForNotAnalyzing; if (skimmer.CanAnalyze(context, out reasonForNotAnalyzing) != AnalysisApplicability.ApplicableToSpecifiedTarget) { continue; } skimmer.Analyze(context); } HashSet<string> expected = expectToPass ? logger.PassTargets : logger.FailTargets; HashSet<string> other = expectToPass ? logger.FailTargets : logger.PassTargets; HashSet<string> configErrors = logger.ConfigurationErrorTargets; string expectedText = expectToPass ? "success" : "failure"; string actualText = expectToPass ? "failed" : "succeeded"; var sb = new StringBuilder(); foreach (string target in targets) { if (expected.Contains(target)) { expected.Remove(target); continue; } bool missingEntirely = !other.Contains(target); if (missingEntirely && !expectToPass && target.Contains("Pdb") && configErrors.Contains(target)) { missingEntirely = false; configErrors.Remove(target); continue; } if (missingEntirely) { sb.AppendLine("Expected '" + ruleName + "' " + expectedText + " but saw no result at all for file: " + Path.GetFileName(target)); } else { other.Remove(target); sb.AppendLine("Expected '" + ruleName + "' " + expectedText + " but check " + actualText + " for: " + Path.GetFileName(target)); } } if (sb.Length > 0) { _testOutputHelper.WriteLine(sb.ToString()); } Assert.Equal(0, sb.Length); Assert.Equal(0, expected.Count); Assert.Equal(0, other.Count); }
public DictionaryEnumerator(PropertiesDictionary dictionary) : base(dictionary) { }
internal static Dictionary <MachineFamily, CompilerVersionToMitigation[]> LoadCompilerDataFromConfig(PropertiesDictionary policy) { if (_compilerData == null) { _compilerData = new Dictionary <MachineFamily, CompilerVersionToMitigation[]>(); PropertiesDictionary configData = policy.GetProperty(MitigatedCompilers); foreach (var key in configData.Keys) { MachineFamily machine = (MachineFamily)Enum.Parse(typeof(MachineFamily), key); // Neaten this up. _compilerData.Add(machine, CreateSortedVersionDictionary((PropertiesDictionary)configData[key])); } } return(_compilerData); }
protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent) { if ((loggingEvent.LookupProperty("log4net:HostName") != null) && (loggingEvent.LookupProperty("log4jmachinename") == null)) { loggingEvent.GetProperties()["log4jmachinename"] = loggingEvent.LookupProperty("log4net:HostName"); } if ((loggingEvent.LookupProperty("log4japp") == null) && ((loggingEvent.Domain != null) && (loggingEvent.Domain.Length > 0))) { loggingEvent.GetProperties()["log4japp"] = loggingEvent.Domain; } if ((loggingEvent.Identity != null) && ((loggingEvent.Identity.Length > 0) && (loggingEvent.LookupProperty("log4net:Identity") == null))) { loggingEvent.GetProperties()["log4net:Identity"] = loggingEvent.Identity; } if ((loggingEvent.UserName != null) && ((loggingEvent.UserName.Length > 0) && (loggingEvent.LookupProperty("log4net:UserName") == null))) { loggingEvent.GetProperties()["log4net:UserName"] = loggingEvent.UserName; } writer.WriteStartElement("log4j:event"); writer.WriteAttributeString("logger", loggingEvent.LoggerName); TimeSpan span = loggingEvent.TimeStamp.ToUniversalTime() - s_date1970; writer.WriteAttributeString("timestamp", XmlConvert.ToString((long)span.TotalMilliseconds)); writer.WriteAttributeString("level", loggingEvent.Level.DisplayName); writer.WriteAttributeString("thread", loggingEvent.ThreadName); writer.WriteStartElement("log4j:message"); Transform.WriteEscapedXmlString(writer, loggingEvent.RenderedMessage, base.InvalidCharReplacement); writer.WriteEndElement(); object property = loggingEvent.LookupProperty("NDC"); if (property != null) { string textData = loggingEvent.Repository.RendererMap.FindAndRender(property); if ((textData != null) && (textData.Length > 0)) { writer.WriteStartElement("log4j:NDC"); Transform.WriteEscapedXmlString(writer, textData, base.InvalidCharReplacement); writer.WriteEndElement(); } } PropertiesDictionary properties = loggingEvent.GetProperties(); if (properties.Count > 0) { writer.WriteStartElement("log4j:properties"); IEnumerator enumerator = ((IEnumerable)properties).GetEnumerator(); try { while (enumerator.MoveNext()) { DictionaryEntry current = (DictionaryEntry)enumerator.Current; writer.WriteStartElement("log4j:data"); writer.WriteAttributeString("name", (string)current.Key); string str2 = loggingEvent.Repository.RendererMap.FindAndRender(current.Value); writer.WriteAttributeString("value", str2); writer.WriteEndElement(); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } writer.WriteEndElement(); } string exceptionString = loggingEvent.GetExceptionString(); if ((exceptionString != null) && (exceptionString.Length > 0)) { writer.WriteStartElement("log4j:throwable"); Transform.WriteEscapedXmlString(writer, exceptionString, base.InvalidCharReplacement); writer.WriteEndElement(); } if (base.LocationInfo) { LocationInfo locationInformation = loggingEvent.LocationInformation; writer.WriteStartElement("log4j:locationInfo"); writer.WriteAttributeString("class", locationInformation.ClassName); writer.WriteAttributeString("method", locationInformation.MethodName); writer.WriteAttributeString("file", locationInformation.FileName); writer.WriteAttributeString("line", locationInformation.LineNumber); writer.WriteEndElement(); } writer.WriteEndElement(); }
public static BsonDocument BuildBsonDocument(LoggingEvent loggingEvent) { if (loggingEvent == null) { return(null); } var appid = ConfigurationManager.AppSettings["appid"]; if (appid == null) { appid = string.Empty; } var ip = GetIP(); var toReturn = new BsonDocument { { "timestamp", loggingEvent.TimeStamp }, { "level", loggingEvent.Level.ToString() }, { "thread", loggingEvent.ThreadName }, { "userName", loggingEvent.UserName }, { "message", GetUtf8String(loggingEvent.RenderedMessage) }, { "loggerName", loggingEvent.LoggerName }, { "domain", loggingEvent.Domain }, { "ip", ip }, { "appid", appid }, { "machineName", Environment.MachineName } }; // location information, if available if (loggingEvent.LocationInformation != null) { toReturn.Add("fileName", loggingEvent.LocationInformation.FileName); toReturn.Add("method", loggingEvent.LocationInformation.MethodName); toReturn.Add("lineNumber", loggingEvent.LocationInformation.LineNumber); toReturn.Add("className", loggingEvent.LocationInformation.ClassName); } var tcTraceID = ThreadContext.Properties["TraceId"]; if (tcTraceID != null) { var len = tcTraceID.ToString().Length; string traceID = string.Empty; if (len >= 100) { traceID = tcTraceID.ToString().Substring(0, 100); } else { traceID = tcTraceID.ToString(); } toReturn.Add("traceId", traceID); } // exception information if (loggingEvent.ExceptionObject != null) { toReturn.Add("exception", BuildExceptionBsonDocument(loggingEvent.ExceptionObject)); } // properties PropertiesDictionary compositeProperties = loggingEvent.GetProperties(); if (compositeProperties != null && compositeProperties.Count > 0) { var properties = new BsonDocument(); foreach (DictionaryEntry entry in compositeProperties) { properties.Add(entry.Key.ToString(), entry.Value.ToString()); } toReturn.Add("properties", properties); } return(toReturn); }
private static PropertiesDictionary BuildMitigatedCompilersData() { // As per https://blogs.msdn.microsoft.com/vcblog/2018/01/15/spectre-mitigations-in-msvc/ /* * In current versions of the MSVC compiler, the /Qspectre switch only works on optimized code. * You should make sure to compile your code with any of the optimization switches (e.g., /O2 or /O1 but NOT /Od) to have the mitigation applied. * Similarly, inspect any code that uses #pragma optimize([stg], off). Work is ongoing now to make the /Qspectre mitigation work on unoptimized code. * * AND * * What versions of MSVC support the /Qspectre switch? * All versions of Visual Studio 2017 version 15.5 and all Previews of Visual Studio version 15.6 already include an undocumented switch, /d2guardspecload, that is currently equivalent to /Qspectre. * You can use /d2guardspecload to apply the same mitigations to your code. * Please update to using /Qspectre as soon as you get a compiler that supports the switch as the /Qspectre switch will be maintained with new mitigations going forward. * * The /Qspectre switch will be available in MSVC toolsets included in all future releases of Visual Studio (including Previews). * We will also release updates to some existing versions of Visual Studio to include support for /Qspectre. * Releases of Visual Studio and Previews are announced on the Visual Studio Blog; update notifications are included in the Notification Hub. * Visual Studio updates that include support for /Qspectre will be announced on the Visual C++ Team Blog and the @visualc Twitter feed. * * We initially plan to include support for /Qspectre in the following: * Visual Studio 2017 version 15.6 Preview 4 * An upcoming servicing update to Visual Studio 2017 version 15.5 * A servicing update to Visual Studio 2017 “RTW” * A servicing update to Visual Studio 2015 Update 3 * * If you’re using an older version of MSVC we strongly encourage you to upgrade to a more recent compiler for this and other security improvements that have been developed in the last few years. * Additionally, you’ll benefit from increased conformance, code quality, and faster compile times as well as many productivity improvements in Visual Studio. * */ // UPDATED version and support information: https://blogs.msdn.microsoft.com/vcblog/2018/04/09/spectre-mitigation-changes-in-visual-studio-2017-version-15-7-preview-3/ /* * * With Visual Studio 2017 version 15.7 Preview 3 we have two new features to announce with regards to our Spectre mitigations. * First, the /Qspectre switch is now supported regardless of the selected optimization level. * Second, we have provided Spectre-mitigated implementations of the Microsoft Visual C++ libraries. * */ var compilersData = new PropertiesDictionary(); // Mitigations for x86 family of processors var x86Data = new PropertiesDictionary(); var armData = new PropertiesDictionary(); // Format of this data and the ranges: // ThrowIfMitigationDataIsInvalid requires a range here from the start of this support // to a version less than the compiler that implements the next level of mitigation support. // X86\X64 support // VS2015 15.0 Update 3 Versions // D2GuardSpecLoad version will not be back-ported // This terminates at 19.0 due to gaps in support in the 19.10 and 19.11 compilers x86Data.Add("19.00.24232.0 - 19.0.*.*", (CompilerMitigations.QSpectreAvailable).ToString()); // VS2017 RTM // This terminates at 19.10.25099 due to gaps in support in unreleased compilers x86Data.Add("19.10.25024.0 - 19.10.25099.*", (CompilerMitigations.D2GuardSpecLoadAvailable | CompilerMitigations.QSpectreAvailable).ToString()); // VS2017 - 15.5.x x86Data.Add("19.12.25830.2 - 19.12.25834.*", (CompilerMitigations.D2GuardSpecLoadAvailable).ToString()); // This terminates at 19.12.*.* due to a gap in support for 15.6 early previews x86Data.Add("19.12.25835.0 - 19.12.*.*", (CompilerMitigations.D2GuardSpecLoadAvailable | CompilerMitigations.QSpectreAvailable).ToString()); // VS2017 - 15.6 Preview 3 x86Data.Add("19.13.26029.0 - 19.13.26117.*", (CompilerMitigations.D2GuardSpecLoadAvailable).ToString()); // Version flows into 15.7 as there is no gap in support for these switches moving forwards x86Data.Add("19.13.26118.0 - 19.14.26328.*", (CompilerMitigations.D2GuardSpecLoadAvailable | CompilerMitigations.QSpectreAvailable).ToString()); // VS2017 15.7 Preview 3 // Add first support for mitigation under /Od as per https://blogs.msdn.microsoft.com/vcblog/2018/04/09/spectre-mitigation-changes-in-visual-studio-2017-version-15-7-preview-3/ // This assumes that future versions of Visual Studio (post 15.6) will always have these mitigations available. x86Data.Add("19.14.26329.0 - *.*.*.*", (CompilerMitigations.D2GuardSpecLoadAvailable | CompilerMitigations.QSpectreAvailable | CompilerMitigations.NonoptimizedCodeMitigated).ToString()); // ARM\ARM64 support // VS2017 - 15.6 Preview 4 armData.Add("19.13.26214.0 - 19.14.26328.*", (CompilerMitigations.D2GuardSpecLoadAvailable | CompilerMitigations.QSpectreAvailable).ToString()); // VS2017 15.7 Preview 3 armData.Add("19.14.26329.0 - *.*.*.*", (CompilerMitigations.D2GuardSpecLoadAvailable | CompilerMitigations.QSpectreAvailable | CompilerMitigations.NonoptimizedCodeMitigated).ToString()); compilersData.Add(MachineFamily.X86.ToString(), x86Data); compilersData.Add(MachineFamily.Arm.ToString(), armData); return(compilersData); }
private static void SetCallContextData(PropertiesDictionary properties) { #if !NETCF CallContext.LogicalSetData(c_SlotName, properties); #else CallContext.SetData(c_SlotName, properties); #endif }
public BsonDocument LoggingEventToBSON(LoggingEvent loggingEvent) { if (loggingEvent == null) { return(null); } var toReturn = new BsonDocument(); toReturn[FieldNames.Timestamp] = loggingEvent.TimeStamp; toReturn[FieldNames.Level] = loggingEvent.Level.ToString(); toReturn[FieldNames.Thread] = loggingEvent.ThreadName ?? String.Empty; if (!LooseFix) { toReturn[FieldNames.Username] = loggingEvent.UserName ?? String.Empty; } toReturn[FieldNames.Message] = loggingEvent.RenderedMessage; toReturn[FieldNames.Loggername] = loggingEvent.LoggerName ?? String.Empty; toReturn[FieldNames.Domain] = loggingEvent.Domain ?? String.Empty; toReturn[FieldNames.Machinename] = MachineName ?? String.Empty; toReturn[FieldNames.ProgramName] = ProgramName ?? String.Empty; // location information, if available if (!LooseFix && loggingEvent.LocationInformation != null) { toReturn[FieldNames.Filename] = loggingEvent.LocationInformation.FileName ?? String.Empty; toReturn[FieldNames.Method] = loggingEvent.LocationInformation.MethodName ?? String.Empty; toReturn[FieldNames.Linenumber] = loggingEvent.LocationInformation.LineNumber ?? String.Empty; toReturn[FieldNames.Classname] = loggingEvent.LocationInformation.ClassName ?? String.Empty; } // exception information if (loggingEvent.ExceptionObject != null) { toReturn[FieldNames.Exception] = ExceptionToBSON(loggingEvent.ExceptionObject); if (loggingEvent.ExceptionObject.InnerException != null) { //Serialize all inner exception in a bson array var innerExceptionList = new BsonArray(); var actualEx = loggingEvent.ExceptionObject.InnerException; while (actualEx != null) { var ex = ExceptionToBSON(actualEx); innerExceptionList.Add(ex); if (actualEx.InnerException == null) { //this is the first exception toReturn[FieldNames.FirstException] = ExceptionToBSON(actualEx); } actualEx = actualEx.InnerException; } toReturn[FieldNames.Innerexception] = innerExceptionList; } } // properties PropertiesDictionary compositeProperties = loggingEvent.GetProperties(); if (compositeProperties != null && compositeProperties.Count > 0) { var properties = new BsonDocument(); foreach (DictionaryEntry entry in compositeProperties) { if (entry.Value == null) { continue; } //remember that no property can have a point in it because it cannot be saved. String key = entry.Key.ToString().Replace(".", "|"); BsonValue value; if (!BsonTypeMapper.TryMapToBsonValue(entry.Value, out value)) { properties[key] = entry.Value.ToBsonDocument(); } else { properties[key] = value; } } toReturn[FieldNames.Customproperties] = properties; } return(toReturn); }
private void CacheProperties() { if (m_data.Properties == null && this.m_cacheUpdatable) { if (m_compositeProperties == null) { CreateCompositeProperties(); } PropertiesDictionary flattenedProperties = m_compositeProperties.Flatten(); PropertiesDictionary fixedProperties = new PropertiesDictionary(); // Validate properties foreach (DictionaryEntry entry in flattenedProperties) { string key = entry.Key as string; if (key != null) { object val = entry.Value; // Fix any IFixingRequired objects IFixingRequired fixingRequired = val as IFixingRequired; if (fixingRequired != null) { val = fixingRequired.GetFixedObject(); } // Strip keys with null values if (val != null) { fixedProperties[key] = val; } } } m_data.Properties = fixedProperties; } }
private void Log(Level level, string methodInfo, object message, Exception exception = null, PropertiesDictionary properties = null) { var eventData = new LoggingEventData() { LocationInfo = new LocationInfo(_typeName, methodInfo, "", ""), Level = level, Message = GetRenderedFormat(message), TimeStamp = DateTime.Now, LoggerName = _logger.Name, ThreadName = Thread.CurrentThread.Name, Domain = SystemInfo.ApplicationFriendlyName, ExceptionString = GetRenderedFormat(exception), Properties = properties ?? new PropertiesDictionary() }; _logger.Log(new LoggingEvent(eventData)); }
/// <summary> /// Actually do the writing of the xml /// </summary> /// <param name="writer">the writer to use</param> /// <param name="loggingEvent">the event to write</param> /// <remarks> /// <para> /// Generate XML that is compatible with the log4j schema. /// </para> /// </remarks> protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent) { if (loggingEvent.LookupProperty("log4net:HostName") != null && loggingEvent.LookupProperty("log4jmachinename") == null) { loggingEvent.GetProperties()["log4jmachinename"] = loggingEvent.LookupProperty("log4net:HostName"); } if (loggingEvent.LookupProperty("log4japp") == null && loggingEvent.Domain != null && loggingEvent.Domain.Length > 0) { loggingEvent.GetProperties()["log4japp"] = loggingEvent.Domain; } if (loggingEvent.Identity != null && loggingEvent.Identity.Length > 0 && loggingEvent.LookupProperty("log4net:Identity") == null) { loggingEvent.GetProperties()["log4net:Identity"] = loggingEvent.Identity; } if (loggingEvent.UserName != null && loggingEvent.UserName.Length > 0 && loggingEvent.LookupProperty("log4net:UserName") == null) { loggingEvent.GetProperties()["log4net:UserName"] = loggingEvent.UserName; } writer.WriteStartElement("log4j:event"); writer.WriteAttributeString("logger", loggingEvent.LoggerName); writer.WriteAttributeString("timestamp", XmlConvert.ToString((long)(loggingEvent.TimeStampUtc - s_date1970).TotalMilliseconds)); writer.WriteAttributeString("level", loggingEvent.Level.DisplayName); writer.WriteAttributeString("thread", loggingEvent.ThreadName); writer.WriteStartElement("log4j:message"); Transform.WriteEscapedXmlString(writer, loggingEvent.RenderedMessage, base.InvalidCharReplacement); writer.WriteEndElement(); object obj = loggingEvent.LookupProperty("NDC"); if (obj != null) { string text = loggingEvent.Repository.RendererMap.FindAndRender(obj); if (text != null && text.Length > 0) { writer.WriteStartElement("log4j:NDC"); Transform.WriteEscapedXmlString(writer, text, base.InvalidCharReplacement); writer.WriteEndElement(); } } PropertiesDictionary properties = loggingEvent.GetProperties(); if (properties.Count > 0) { writer.WriteStartElement("log4j:properties"); foreach (DictionaryEntry item in (IEnumerable)properties) { writer.WriteStartElement("log4j:data"); writer.WriteAttributeString("name", (string)item.Key); string value = loggingEvent.Repository.RendererMap.FindAndRender(item.Value); writer.WriteAttributeString("value", value); writer.WriteEndElement(); } writer.WriteEndElement(); } string exceptionString = loggingEvent.GetExceptionString(); if (exceptionString != null && exceptionString.Length > 0) { writer.WriteStartElement("log4j:throwable"); Transform.WriteEscapedXmlString(writer, exceptionString, base.InvalidCharReplacement); writer.WriteEndElement(); } if (base.LocationInfo) { LocationInfo locationInformation = loggingEvent.LocationInformation; writer.WriteStartElement("log4j:locationInfo"); writer.WriteAttributeString("class", locationInformation.ClassName); writer.WriteAttributeString("method", locationInformation.MethodName); writer.WriteAttributeString("file", locationInformation.FileName); writer.WriteAttributeString("line", locationInformation.LineNumber); writer.WriteEndElement(); } writer.WriteEndElement(); }
/// <summary> /// Add a Properties Dictionary to this composite collection /// </summary> /// <param name="properties">the properties to add</param> /// <remarks> /// <para> /// Properties dictionaries added first take precedence over dictionaries added /// later. /// </para> /// </remarks> public void Add(ReadOnlyPropertiesDictionary properties) { m_flattened = null; m_nestedProperties.Add(properties); }
public override AnalysisApplicability CanAnalyzePE(PEBinary target, PropertiesDictionary policy, out string reasonForNotAnalyzing) { reasonForNotAnalyzing = null; return(AnalysisApplicability.ApplicableToSpecifiedTarget); }
/// <summary> /// Add a Properties Dictionary to this composite collection /// </summary> /// <param name="properties">the properties to add</param> /// <remarks> /// <para> /// Properties dictionaries added first take precedence over dictionaries added /// later. /// </para> /// </remarks> public void Add(ReadOnlyPropertiesDictionary properties) { m_flattened = null; m_nestedProperties.Add(properties); }
public static BsonDocument BuildBsonDocument(LoggingEvent loggingEvent) { if (loggingEvent == null) { return(null); } var toReturn = new BsonDocument { { "timestamp", loggingEvent.TimeStamp }, { "level", loggingEvent.Level.ToString() }, { "thread", loggingEvent.ThreadName }, { "userName", loggingEvent.UserName }, { "message", loggingEvent.RenderedMessage }, { "loggerName", loggingEvent.LoggerName }, { "domain", loggingEvent.Domain }, { "machineName", Environment.MachineName } }; // location information, if available if (loggingEvent.LocationInformation != null) { if (!string.IsNullOrWhiteSpace(loggingEvent.LocationInformation.FileName)) { toReturn.Add("fileName", loggingEvent.LocationInformation.FileName); } if (!string.IsNullOrWhiteSpace(loggingEvent.LocationInformation.MethodName)) { toReturn.Add("method", loggingEvent.LocationInformation.MethodName); } if (!string.IsNullOrWhiteSpace(loggingEvent.LocationInformation.LineNumber)) { toReturn.Add("lineNumber", loggingEvent.LocationInformation.LineNumber); } if (!string.IsNullOrWhiteSpace(loggingEvent.LocationInformation.ClassName)) { toReturn.Add("className", loggingEvent.LocationInformation.ClassName); } } // exception information if (loggingEvent.ExceptionObject != null) { toReturn.Add("exception", BuildExceptionBsonDocument(loggingEvent.ExceptionObject)); } // properties PropertiesDictionary compositeProperties = loggingEvent.GetProperties(); if (compositeProperties != null && compositeProperties.Count > 0) { var properties = new BsonDocument(); foreach (DictionaryEntry entry in compositeProperties) { if (entry.Value != null) { properties.Add(entry.Key.ToString(), entry.Value.ToString()); } } toReturn.Add("properties", properties); } return(toReturn); }
private void Verify( IBinarySkimmer skimmer, IEnumerable <string> additionalTestFiles, bool useDefaultPolicy, bool expectToPass) { var targets = new List <string>(); string ruleName = skimmer.GetType().Name; string testFilesDirectory = ruleName; testFilesDirectory = Path.Combine(Environment.CurrentDirectory, "FunctionalTestsData", testFilesDirectory); testFilesDirectory = Path.Combine(testFilesDirectory, expectToPass ? "Pass" : "Fail"); Assert.True(Directory.Exists(testFilesDirectory)); foreach (string target in Directory.GetFiles(testFilesDirectory, "*", SearchOption.AllDirectories)) { if (AnalyzeCommand.ValidAnalysisFileExtensions.Contains(Path.GetExtension(target))) { targets.Add(target); } } if (additionalTestFiles != null) { foreach (string additionalTestFile in additionalTestFiles) { targets.Add(additionalTestFile); } } var context = new BinaryAnalyzerContext(); var logger = new TestMessageLogger(); context.Logger = logger; PropertiesDictionary policy = null; if (useDefaultPolicy) { policy = new PropertiesDictionary(); } context.Policy = policy; skimmer.Initialize(context); foreach (string target in targets) { PE pe = new PE(target); if (!pe.IsPEFile) { continue; } context = CreateContext(logger, policy, target); context.Rule = skimmer; string reasonForNotAnalyzing; if (skimmer.CanAnalyze(context, out reasonForNotAnalyzing) != AnalysisApplicability.ApplicableToSpecifiedTarget) { continue; } skimmer.Analyze(context); } HashSet <string> expected = expectToPass ? logger.PassTargets : logger.FailTargets; HashSet <string> other = expectToPass ? logger.FailTargets : logger.PassTargets; HashSet <string> configErrors = logger.ConfigurationErrorTargets; string expectedText = expectToPass ? "success" : "failure"; string actualText = expectToPass ? "failed" : "succeeded"; var sb = new StringBuilder(); foreach (string target in targets) { if (expected.Contains(target)) { expected.Remove(target); continue; } bool missingEntirely = !other.Contains(target); if (missingEntirely && !expectToPass && target.Contains("Pdb") && configErrors.Contains(target)) { missingEntirely = false; configErrors.Remove(target); continue; } if (missingEntirely) { sb.AppendLine("Expected '" + ruleName + "' " + expectedText + " but saw no result at all for file: " + Path.GetFileName(target)); } else { other.Remove(target); sb.AppendLine("Expected '" + ruleName + "' " + expectedText + " but check " + actualText + " for: " + Path.GetFileName(target)); } } if (sb.Length > 0) { _testOutputHelper.WriteLine(sb.ToString()); } Assert.Equal(0, sb.Length); Assert.Equal(0, expected.Count); Assert.Equal(0, other.Count); }
/// <summary> /// Does the actual writing of the XML. /// </summary> /// <param name="writer">The writer to use to output the event to.</param> /// <param name="loggingEvent">The event to write.</param> /// <remarks> /// <para> /// Override the base class <see cref="M:log4net.Layout.XmlLayoutBase.FormatXml(System.Xml.XmlWriter,log4net.Core.LoggingEvent)" /> method /// to write the <see cref="T:log4net.Core.LoggingEvent" /> to the <see cref="T:System.Xml.XmlWriter" />. /// </para> /// </remarks> protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent) { writer.WriteStartElement(m_elmEvent); writer.WriteAttributeString("logger", loggingEvent.LoggerName); writer.WriteAttributeString("timestamp", XmlConvert.ToString(loggingEvent.TimeStamp, XmlDateTimeSerializationMode.Local)); writer.WriteAttributeString("level", loggingEvent.Level.DisplayName); writer.WriteAttributeString("thread", loggingEvent.ThreadName); if (loggingEvent.Domain != null && loggingEvent.Domain.Length > 0) { writer.WriteAttributeString("domain", loggingEvent.Domain); } if (loggingEvent.Identity != null && loggingEvent.Identity.Length > 0) { writer.WriteAttributeString("identity", loggingEvent.Identity); } if (loggingEvent.UserName != null && loggingEvent.UserName.Length > 0) { writer.WriteAttributeString("username", loggingEvent.UserName); } writer.WriteStartElement(m_elmMessage); if (!Base64EncodeMessage) { Transform.WriteEscapedXmlString(writer, loggingEvent.RenderedMessage, base.InvalidCharReplacement); } else { byte[] bytes = Encoding.UTF8.GetBytes(loggingEvent.RenderedMessage); string textData = Convert.ToBase64String(bytes, 0, bytes.Length); Transform.WriteEscapedXmlString(writer, textData, base.InvalidCharReplacement); } writer.WriteEndElement(); PropertiesDictionary properties = loggingEvent.GetProperties(); if (properties.Count > 0) { writer.WriteStartElement(m_elmProperties); foreach (DictionaryEntry item in (IEnumerable)properties) { writer.WriteStartElement(m_elmData); writer.WriteAttributeString("name", Transform.MaskXmlInvalidCharacters((string)item.Key, base.InvalidCharReplacement)); string text = null; if (!Base64EncodeProperties) { text = Transform.MaskXmlInvalidCharacters(loggingEvent.Repository.RendererMap.FindAndRender(item.Value), base.InvalidCharReplacement); } else { byte[] bytes2 = Encoding.UTF8.GetBytes(loggingEvent.Repository.RendererMap.FindAndRender(item.Value)); text = Convert.ToBase64String(bytes2, 0, bytes2.Length); } writer.WriteAttributeString("value", text); writer.WriteEndElement(); } writer.WriteEndElement(); } string exceptionString = loggingEvent.GetExceptionString(); if (exceptionString != null && exceptionString.Length > 0) { writer.WriteStartElement(m_elmException); Transform.WriteEscapedXmlString(writer, exceptionString, base.InvalidCharReplacement); writer.WriteEndElement(); } if (base.LocationInfo) { LocationInfo locationInformation = loggingEvent.LocationInformation; writer.WriteStartElement(m_elmLocation); writer.WriteAttributeString("class", locationInformation.ClassName); writer.WriteAttributeString("method", locationInformation.MethodName); writer.WriteAttributeString("file", locationInformation.FileName); writer.WriteAttributeString("line", locationInformation.LineNumber); writer.WriteEndElement(); } writer.WriteEndElement(); }
public Hierarchy(PropertiesDictionary properties) : this(properties, new DefaultLoggerFactory()) { }
public String GetText(MemberVisualizationTypes type) { String res = String.Empty; String key0 = String.Empty; if (type == MemberVisualizationTypes.Key || type == MemberVisualizationTypes.KeyAndCaption) { if (PropertiesDictionary.ContainsKey(KEY0_PROPERTY)) { if (PropertiesDictionary[KEY0_PROPERTY] != null) { key0 = PropertiesDictionary[KEY0_PROPERTY].ToString(); } else { // в режиме отображения кодов вместо null нужно светить Caption, а то получается когда в таблице несколько вычисляемых элементов у всех их светится null (ПФ) // key0 = "null"; } } } // Определяем что именно нужно светить в контроле switch (type) { case MemberVisualizationTypes.Caption: res = Caption; // debug // Caption += " " + Sorted_MemberIndexInAxis.ToString(); break; case MemberVisualizationTypes.Key: // Для элементов уровня ALL вместо ключа 0 (который никак нельзя поменять) отображаем Caption if (LevelDepth == 0 && !String.IsNullOrEmpty(LevelName) && LevelName.ToLower().Contains(".[(all)]")) { res = Caption; } else { //Если ключ в запросе не получался, то выводим просто Caption if (!String.IsNullOrEmpty(key0)) { res = key0; } else { res = Caption; } } break; case MemberVisualizationTypes.KeyAndCaption: // Для элементов уровня ALL вместо ключа 0 (который никак нельзя поменять) отображаем Caption if (LevelDepth == 0 && !String.IsNullOrEmpty(LevelName) && LevelName.ToLower().Contains(".[(all)]")) { res = Caption; } else { //Если ключ в запросе не получался, то выводим просто Caption if (!String.IsNullOrEmpty(key0)) { res = key0 + " " + Caption; } else { res = Caption; } } break; case MemberVisualizationTypes.UniqueName: res = UniqueName; break; default: res = Caption; break; } return(res); }
private static bool HasMessageProperties(PropertiesDictionary propertiesDictionary) { return(propertiesDictionary._messageProperties != null && propertiesDictionary._messageProperties.Count > 0); }
public async Task DatabricksTestEndToEndGeneration() { var flowName = "dbconfiggentest"; var testingConfig = await File.ReadAllTextAsync(@"Resource\databricksFlowSaved.json"); await DesignTimeStorage.SaveByName(flowName, testingConfig, FlowDataManager.DataCollectionName); await CommonData.Add("defaultJobTemplate", @"Resource\sparkJobTemplate.json"); await CommonData.Add(ConfigFlattenerManager.DefaultConfigName, @"Resource\flattenerConfig.json"); await CommonData.Add(FlowDataManager.CommonDataName_DefaultFlowConfig, @"Resource\flowDefault.json"); var result = await this.RuntimeConfigGeneration.GenerateRuntimeConfigs(flowName); var runtimeConfigFolder = result.Properties?.GetValueOrDefault(PrepareJobConfigVariables.ResultPropertyName_RuntimeConfigFolder, null); Assert.IsTrue(result.IsSuccess); Assert.AreEqual(expected: 4, actual: RuntimeStorage.Cache.Count); // verify output schema file is expected var expectedSchema = JsonConfig.From(await File.ReadAllTextAsync(@"Resource\schema.json")); var actualSchema = JsonConfig.From(RuntimeStorage.Cache[ResourcePathUtil.Combine(runtimeConfigFolder.ToString(), "inputschema.json")]); foreach (var match in JsonConfig.Match(expectedSchema, actualSchema)) { Assert.AreEqual(expected: match.Item2, actual: match.Item3, message: $"path:{match.Item1}"); } // verify output projection file is expected var expectedProjection = await File.ReadAllTextAsync(@"Resource\projection.txt"); var actualProjection = RuntimeStorage.Cache[ResourcePathUtil.Combine(runtimeConfigFolder.ToString(), "projection.txt")]; Assert.AreEqual(expected: expectedProjection, actual: actualProjection); // verify transform file is exepcted var expectedTransform = await File.ReadAllTextAsync(@"Resource\configgentest-combined.txt"); var actualTransform = RuntimeStorage.Cache[ResourcePathUtil.Combine(runtimeConfigFolder.ToString(), "dbconfiggentest-combined.txt")]; Assert.AreEqual(expected: expectedTransform, actual: actualTransform); // Verify output configuration is expected var actualConf = PropertiesDictionary.From(this.RuntimeStorage.Cache[ResourcePathUtil.Combine(runtimeConfigFolder.ToString(), $"{flowName}.conf")]); var expectedConf = PropertiesDictionary.From(await File.ReadAllTextAsync(@"Resource\databricksJobConfig.conf")); var matches = PropertiesDictionary.Match(expectedConf, actualConf).ToList(); foreach (var match in matches) { Console.WriteLine($"prop:{match.Item1 ?? "null"}, expected:<{match.Item2 ?? "null"}>, actual:<{match.Item3 ?? "null"}>"); } foreach (var match in matches) { Assert.AreEqual(expected: match.Item2, actual: match.Item3, message: $"property:{match.Item1}"); } // Verify metrics var expectedConfig = JsonConfig.From(await File.ReadAllTextAsync(@"Resource\databricksFlowStarted.json")); var actualConfig = JsonConfig.From(await this.DesignTimeStorage.GetByName(flowName, FlowDataManager.DataCollectionName)); foreach (var match in JsonConfig.Match(expectedConfig, actualConfig)) { Assert.AreEqual(expected: match.Item2, actual: match.Item3, message: $"path:{match.Item1}"); } Cleanup(); }
public ParameterEnumerator(PropertiesDictionary dictionary) : base(dictionary) { }
public string Flatten(JsonConfig config) { var dict = PropertiesDictionary.From(_flattenConfig?.FlattenJsonConfig(config)); return(dict?.ToString()); }
public DictionaryCollection(PropertiesDictionary dictionary, bool keyCollection) { _dictionary = dictionary; _keyCollection = keyCollection; }
private static void SetCallContextData(PropertiesDictionary properties) { CallContext.SetData(c_SlotName, properties); }
public override int Run(ExportConfigurationOptions exportOptions) { int result = FAILURE; try { PropertiesDictionary allOptions = new PropertiesDictionary(); // The export command could be updated in the future to accept an arbitrary set // of analyzers for which to build an options XML file suitable for configuring them. ImmutableArray <IOptionsProvider> providers = DriverUtilities.GetExports <IOptionsProvider>(DefaultPlugInAssemblies); foreach (IOptionsProvider provider in providers) { IOption sampleOption = null; // Every analysis options provider has access to the following default configuration knobs foreach (IOption option in provider.GetOptions()) { sampleOption = sampleOption ?? option; allOptions.SetProperty(option, option.DefaultValue, cacheDescription: true); } } IEnumerable <IRule> rules; rules = DriverUtilities.GetExports <IRule>(DefaultPlugInAssemblies); // This code injects properties that are provided for every rule instance. foreach (IRule rule in rules) { object objectResult; PropertiesDictionary properties; string ruleOptionsKey = rule.Id + "." + rule.Name + ".Options"; if (!allOptions.TryGetValue(ruleOptionsKey, out objectResult)) { objectResult = allOptions[ruleOptionsKey] = new PropertiesDictionary(); } properties = (PropertiesDictionary)objectResult; foreach (IOption option in DefaultDriverOptions.Instance.GetOptions()) { properties.SetProperty(option, option.DefaultValue, cacheDescription: true, persistToSettingsContainer: false); } } string extension = Path.GetExtension(exportOptions.OutputFilePath); if (extension.Equals(".xml", StringComparison.OrdinalIgnoreCase)) { allOptions.SaveToXml(exportOptions.OutputFilePath); } else if (extension.Equals(".json", StringComparison.OrdinalIgnoreCase)) { allOptions.SaveToJson(exportOptions.OutputFilePath); } else if (exportOptions.FileFormat == FileFormat.Xml) { allOptions.SaveToXml(exportOptions.OutputFilePath); } else { allOptions.SaveToJson(exportOptions.OutputFilePath); } Console.WriteLine("Configuration file saved to: " + Path.GetFullPath(exportOptions.OutputFilePath)); result = SUCCESS; } catch (Exception ex) { Console.Error.WriteLine(ex.ToString()); } return(result); }
private void btnFillTree_Click(object sender, EventArgs e) { nodes.Add(new TreeNode("ALL")); lst.Enqueue("ALL"); int n = lst.Count; int index = 0; for (int i = 0; i < n; i++) { string str = lst.Dequeue(); n--; Concept c = onto[str]; PropertiesDictionary pd = c.FullProperties; foreach (Property de in pd.Properties) { OntologyLibrary.OntoSem.FillerList OF = de.Fillers; foreach (Filler Ofiller in OF) { if (de.Name == "IS-A" && Ofiller.ConceptFiller != null) { TreeNode tn = new TreeNode(Ofiller.ConceptFiller.Name); int k = 0; foreach (TreeNode _n in nodes) { if (_n.Text == tn.Text) { index = k;//nodes.IndexOf(tn); goto l; } k++; } //if (nodes.Contains(tn.Text)) //{ //} } l: if (de.Name == "SUBCLASSES" && Ofiller.ConceptFiller != null) { //all.Nodes.Add(Ofiller.ConceptFiller.Name); nodes.Add(new TreeNode(Ofiller.ConceptFiller.Name)); nodes[index].Nodes.Add(new TreeNode(Ofiller.ConceptFiller.Name)); lst.Enqueue(Ofiller.ConceptFiller.Name); n++; //treeView1.Nodes.Add(nodes[nodes.Count - 1]); //richTextBox1.Text += de.Name + " = " + Ofiller.ConceptFiller.Name + "\n"; //treeView1.Nodes.Add(new TreeNode( } } } } //lb1: treeView1.Nodes.Add(nodes[0]); #region //foreach (Concept c in onto) //{ // PropertiesDictionary pd=c.FullProperties; //foreach (Property de in pd.Properties) //{ // OntologyLibrary.OntoSem.FillerList OF = de.Fillers; // foreach (Filler Ofiller in OF) // { // if (de.Name == "SUBCLASSES" && Ofiller.ConceptFiller!=null) // { // //all.Nodes.Add(Ofiller.ConceptFiller.Name); // nodes.Add(new TreeNode(Ofiller.ConceptFiller.Name)); // //richTextBox1.Text += de.Name + " = " + Ofiller.ConceptFiller.Name + "\n"; // //treeView1.Nodes.Add(new TreeNode( // } // } //} //foreach (Property de in pd.Properties) //{ // OntologyLibrary.OntoSem.FillerList OF = de.Fillers; // foreach (Filler Ofiller in OF) // { // if (de.Name == "IS-A" && Ofiller.ConceptFiller!=null) // { // TreeNode tn=new TreeNode(Ofiller.ConceptFiller.Name); // if(nodes.Contains(tn)) // { // int index = nodes.IndexOf(tn); // nodes[index].Nodes.Add(c.Name); // } // } // } //} //foreach (TreeNode node in nodes) //{ // if(!treeView1.Nodes.Contains(node)) // treeView1.Nodes.Add(node); //} //} #endregion }
/// <summary> /// Does the actual writing of the XML. /// </summary> /// <param name="writer">The writer to use to output the event to.</param> /// <param name="loggingEvent">The event to write.</param> /// <remarks> /// <para> /// Override the base class <see cref="XmlLayoutBase.FormatXml"/> method /// to write the <see cref="LoggingEvent"/> to the <see cref="XmlWriter"/>. /// </para> /// </remarks> override protected void FormatXml(XmlWriter writer, LoggingEvent loggingEvent) { writer.WriteStartElement(m_elmEvent); writer.WriteAttributeString(ATTR_LOGGER, loggingEvent.LoggerName); #if NET_2_0 || NETCF_2_0 || MONO_2_0 || NETSTANDARD2_0 writer.WriteAttributeString(ATTR_TIMESTAMP, XmlConvert.ToString(loggingEvent.TimeStamp, XmlDateTimeSerializationMode.Local)); #else writer.WriteAttributeString(ATTR_TIMESTAMP, XmlConvert.ToString(loggingEvent.TimeStamp)); #endif writer.WriteAttributeString(ATTR_LEVEL, loggingEvent.Level.DisplayName); writer.WriteAttributeString(ATTR_THREAD, loggingEvent.ThreadName); if (loggingEvent.Domain != null && loggingEvent.Domain.Length > 0) { writer.WriteAttributeString(ATTR_DOMAIN, loggingEvent.Domain); } if (loggingEvent.Identity != null && loggingEvent.Identity.Length > 0) { writer.WriteAttributeString(ATTR_IDENTITY, loggingEvent.Identity); } if (loggingEvent.UserName != null && loggingEvent.UserName.Length > 0) { writer.WriteAttributeString(ATTR_USERNAME, loggingEvent.UserName); } // Append the message text writer.WriteStartElement(m_elmMessage); if (!this.Base64EncodeMessage) { Transform.WriteEscapedXmlString(writer, loggingEvent.RenderedMessage, this.InvalidCharReplacement); } else { byte[] messageBytes = Encoding.UTF8.GetBytes(loggingEvent.RenderedMessage); string base64Message = Convert.ToBase64String(messageBytes, 0, messageBytes.Length); Transform.WriteEscapedXmlString(writer, base64Message, this.InvalidCharReplacement); } writer.WriteEndElement(); PropertiesDictionary properties = loggingEvent.GetProperties(); // Append the properties text if (properties.Count > 0) { writer.WriteStartElement(m_elmProperties); foreach (System.Collections.DictionaryEntry entry in properties) { writer.WriteStartElement(m_elmData); writer.WriteAttributeString(ATTR_NAME, Transform.MaskXmlInvalidCharacters((string)entry.Key, this.InvalidCharReplacement)); // Use an ObjectRenderer to convert the object to a string string valueStr = null; if (!this.Base64EncodeProperties) { valueStr = Transform.MaskXmlInvalidCharacters(loggingEvent.Repository.RendererMap.FindAndRender(entry.Value), this.InvalidCharReplacement); } else { byte[] propertyValueBytes = Encoding.UTF8.GetBytes(loggingEvent.Repository.RendererMap.FindAndRender(entry.Value)); valueStr = Convert.ToBase64String(propertyValueBytes, 0, propertyValueBytes.Length); } writer.WriteAttributeString(ATTR_VALUE, valueStr); writer.WriteEndElement(); } writer.WriteEndElement(); } string exceptionStr = loggingEvent.GetExceptionString(); if (exceptionStr != null && exceptionStr.Length > 0) { // Append the stack trace line writer.WriteStartElement(m_elmException); Transform.WriteEscapedXmlString(writer, exceptionStr, this.InvalidCharReplacement); writer.WriteEndElement(); } if (LocationInfo) { LocationInfo locationInfo = loggingEvent.LocationInformation; writer.WriteStartElement(m_elmLocation); writer.WriteAttributeString(ATTR_CLASS, locationInfo.ClassName); writer.WriteAttributeString(ATTR_METHOD, locationInfo.MethodName); writer.WriteAttributeString(ATTR_FILE, locationInfo.FileName); writer.WriteAttributeString(ATTR_LINE, locationInfo.LineNumber); writer.WriteEndElement(); } writer.WriteEndElement(); }
/// <summary> /// Construct with properties /// </summary> /// <param name="properties">The properties to pass to this repository.</param> /// <remarks> /// <para> /// Initializes a new instance of the <see cref="Hierarchy" /> class. /// </para> /// </remarks> public Hierarchy(PropertiesDictionary properties) : this(properties, new DefaultLoggerFactory()) { }