public CLogEncodingCLogTypeSearch FindTypeAndAdvance(string encoded, CLogLineMatch traceLineMatch, ref int index) { int tempIndex = index; CLogEncodingCLogTypeSearch ret = null; if (null != (ret = TypeEncoders.FindTypeAndAdvance(encoded, traceLineMatch, ref tempIndex))) { InUseTypeEncoders.AddType(ret); index = tempIndex; return(ret); } foreach (var config in ChainedConfigurations) { tempIndex = index; if (null != (ret = config.TypeEncoders.FindTypeAndAdvance(encoded, traceLineMatch, ref tempIndex))) { InUseTypeEncoders.AddType(ret); index = tempIndex; return(ret); } } throw new CLogTypeNotFoundException("InvalidType:" + encoded, encoded, traceLineMatch); }
private uint FindUnusedEventId(Guid providerId, CLogLineMatch sourceLine) { ManifestInformation manifest = FindProviderCache(providerId); List <uint> usedEvents = new List <uint>(); foreach (var e in manifest.events.ChildNodes) { if (!(e is XmlElement)) { continue; } XmlElement ee = (XmlElement)e; if (!ee.HasAttribute("value")) { continue; } uint value = Convert.ToUInt32(ee.GetAttribute("value")); usedEvents.Add(value); } for (uint i = 1; i < 16 * 1024 - 1; ++i) { if (!usedEvents.Contains(i)) { return(i); } } throw new CLogEnterReadOnlyModeException("OutOfUniqueIds", CLogHandledException.ExceptionType.ETWOutOfUniqueIDs, sourceLine); }
private void Save(CLogLineMatch match) { if (!_dirty) { return; } if (_readOnlyMode) { throw new CLogEnterReadOnlyModeException("WontWriteWhileInReadonlyMode:ETWManifest", CLogHandledException.ExceptionType.WontWriteInReadOnlyMode, match); } // // Devs prefer XML that is readable in their editor - make an attempt to format their XML in a way that diffs okay // StringBuilder stringBuilder = new StringBuilder(); System.Xml.Linq.XElement element = System.Xml.Linq.XElement.Parse(doc.InnerXml); XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; settings.Indent = true; settings.NewLineOnAttributes = true; using (var xmlWriter = XmlWriter.Create(stringBuilder, settings)) { element.Save(xmlWriter); } File.WriteAllText(xmlFileName, stringBuilder.ToString()); _dirty = false; }
public bool Decode(CLogEncodingCLogTypeSearch type, IClogEventArg value, CLogLineMatch traceLine, out string decodedValue) { // // Compiling also caches the assembly // PrepareAssemblyCompileIfNecessary(); object[] args = new object[1]; switch (type.EncodingType) { case CLogEncodingType.UInt32: args[0] = value.AsUInt32; break; case CLogEncodingType.Int32: args[0] = value.AsInt32; break; case CLogEncodingType.ByteArray: args[0] = value.AsBinary; break; case CLogEncodingType.Pointer: args[0] = value.AsPointer; break; default: throw new NotImplementedException("UndefinedType:" + type); } string customDecoder = type.CustomDecoder; string[] bits = customDecoder.Split('.'); string member = bits[bits.Length - 1]; customDecoder = customDecoder.Substring(0, customDecoder.Length - member.Length - 1); var newType = _codeAssembly.GetType(customDecoder); var instance = _typesInterface = _codeAssembly.CreateInstance(customDecoder); decodedValue = "ERROR:" + type.CustomDecoder; if (!_compiledConverterFunctions.ContainsKey(type.CustomDecoder)) { if (null == newType) { return(true); } var meth = newType.GetMember(member).FirstOrDefault() as MethodInfo; _compiledConverterFunctions[type.CustomDecoder] = meth; } MethodInfo method = _compiledConverterFunctions[type.CustomDecoder]; decodedValue = (string)method.Invoke(_typesInterface, args); return(false); }
public static void PrintMatchDiagnostic(CLogLineMatch traceLineMatch) { if (null == traceLineMatch) { return; } CLogConsoleTrace.TraceLine(CLogConsoleTrace.TraceType.Err, $"Failing Line : {traceLineMatch.MatchedRegExX.Value}"); }
public void DecodeUniqueId(CLogLineMatch m, string arg, out string id, out int idHash) { id = null; switch (UniqueIdEncoder) { case CLogUniqueIDEncoder.Basic: idHash = Math.Abs(arg.GetHashCode()); id = arg; break; case CLogUniqueIDEncoder.StringAndNumerical: { int lastIdx = arg.LastIndexOf('_'); if (-1 == lastIdx) { throw new CLogEnterReadOnlyModeException( "Unique ID is not in the correct format, please follow the 'StringAndNumerical' format", CLogHandledException.ExceptionType.IncorrectStringAndNumericalEncoding, m); } id = arg.Substring(0, lastIdx); if (string.IsNullOrEmpty(id)) { throw new CLogEnterReadOnlyModeException( "Unique ID is not in the correct format, please follow the 'StringAndNumerical' format", CLogHandledException.ExceptionType.IncorrectStringAndNumericalEncoding, m); } try { idHash = Convert.ToInt32(arg.Substring(lastIdx + 1)); } catch (FormatException) { throw new CLogEnterReadOnlyModeException( "Unique ID was located but is not in the correct format, please follow the 'StringAndNumerical' format", CLogHandledException.ExceptionType.IncorrectStringAndNumericalEncoding, m); } } break; default: throw new CLogEnterReadOnlyModeException("Invalid ID Encoder", CLogHandledException.ExceptionType.IncorrectStringAndNumericalEncoding, m); } }
private void Save(CLogLineMatch match) { if (!_dirty) { return; } if (_readOnlyMode) { throw new CLogEnterReadOnlyModeException("WontWriteWhileInReadonlyMode:ETWManifest", CLogHandledException.ExceptionType.WontWriteInReadOnlyMode, match); } doc.Save(xmlFileName); _dirty = false; }
public CLogEncodingCLogTypeSearch FindTypeAndAdvance(string encoded, CLogLineMatch traceLineMatch, ref int index) { int tempIndex = index; CLogEncodingCLogTypeSearch ret = null; // // First scan the type encoders in our main config file // if (null != (ret = TypeEncoders.FindTypeAndAdvance(encoded, traceLineMatch, ref tempIndex))) { InUseTypeEncoders.AddType(ret); index = tempIndex; return(ret); } // // If we're unable to locate the type, iterate across each of our chained configs - note this is // recursive; such allowing for heirarchies // foreach (var config in ChainedConfigurations) { tempIndex = index; if (null != (ret = config.FindTypeAndAdvance(encoded, traceLineMatch, ref tempIndex))) { InUseTypeEncoders.AddType(ret); index = tempIndex; return(ret); } } // // Attempt to get something for the user about the actual arg; note this may be error prone as we are now confused // by their inputs // string surroundingArray = encoded.Substring(index, 15); int end = surroundingArray.IndexOf("}"); if (-1 != end) { surroundingArray = surroundingArray.Substring(0, end); } throw new CLogTypeNotFoundException(encoded, "InvalidType:" + surroundingArray, traceLineMatch); }
public CLogEncodingCLogTypeSearch FindTypeAndAdvance(string encoded, CLogLineMatch traceLineMatch, ref int index) { CLogTypeSearchNode start = _parent; string type = ""; CLogTypeSearchNode prev = null; int?prevIdx = null; for (; ;) { type += encoded[index]; if (!start.Nodes.TryGetValue(encoded[index], out start)) { if (null != prev && null != prev.UserNode) { if (null != traceLineMatch) { prev.UserNode.UsedBySourceFile.Add(traceLineMatch.SourceFile); } index = prevIdx.Value; return(prev.UserNode); } return(null); } if (index == encoded.Length - 1) { if (null != traceLineMatch) { start.UserNode.UsedBySourceFile.Add(traceLineMatch.SourceFile); } return(start.UserNode); } prev = start; prevIdx = index; ++index; } }
public bool DecodeUsingCustomDecoder(CLogEncodingCLogTypeSearch node, IClogEventArg value, CLogLineMatch traceLine, out string decodedValue) { return(_traceEmittorX.Decode(node, value, traceLine, out decodedValue)); }
public bool DecodeUsingCustomDecoder(CLogEncodingCLogTypeSearch node, IClogEventArg value, CLogLineMatch traceLine, out string decodedValue) { if (!TypeEncoders.DecodeUsingCustomDecoder(node, value, traceLine, out decodedValue)) { return(false); } foreach (var config in ChainedConfigurations) { if (!config.DecodeUsingCustomDecoder(node, value, traceLine, out decodedValue)) { return(false); } } decodedValue = "ERROR:CustomDecoderNotFound:" + node.CustomDecoder + ":" + node.DefinationEncoding; return(false); }
public CLogEncodingCLogTypeSearch FindType(CLogFileProcessor.CLogVariableBundle bundle, CLogLineMatch traceLineMatch) { int idx = 0; return(FindTypeAndAdvance(bundle.DefinationEncoding, traceLineMatch, ref idx)); }