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 string AsCorrectType(CLogEncodingType type, IClogEventArg arg) { switch (type) { case CLogEncodingType.Int32: return(arg.AsInt32.ToString()); case CLogEncodingType.UInt32: return(arg.AsUInt32.ToString()); case CLogEncodingType.Int64: return(arg.AsInt64.ToString()); case CLogEncodingType.UInt64: return(arg.AsUInt64.ToString()); case CLogEncodingType.ANSI_String: return(arg.AsString.ToString()); /* case CLogEncodingType.UNICODE_String: * return arg.AsInt32.ToString();*/ case CLogEncodingType.Pointer: return(arg.AsUInt64.ToString()); /* case CLogEncodingType.GUID: * return arg.ToString();*/ case CLogEncodingType.Int16: return(arg.AsInt16.ToString()); case CLogEncodingType.UInt16: return(arg.AsUInt16.ToString()); case CLogEncodingType.Int8: return(arg.AsInt8.ToString()); case CLogEncodingType.UInt8: return(arg.AsUInt8.ToString()); case CLogEncodingType.ByteArray: return("UNSPECIFIED DECODER FOR BINARY TYPE"); /* * case CLogEncodingType.UserEncodingString: * return arg.AsInt32.ToString(); * case CLogEncodingType.UniqueAndDurableIdentifier: * return arg.AsInt32.ToString();*/ case CLogEncodingType.Unknown: case CLogEncodingType.Synthesized: case CLogEncodingType.Skip: default: throw new CLogEnterReadOnlyModeException("Invalid Type - likely a missing CLOG feature, consider using a different type or submiting a patch to CLOG", CLogHandledException.ExceptionType.EncoderIncompatibleWithType, null); } }
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 static void DecodeAndTraceToConsole(StreamWriter outputfile, CLogDecodedTraceLine bundle, string errorLine, CLogConfigurationFile config, Dictionary <string, IClogEventArg> valueBag, EventInformation eventInfo, bool showTimeStamp, bool showCPUInfo) { try { if (null == bundle) { Console.WriteLine($"Invalid TraceLine : {errorLine}"); return; } StringBuilder toPrint = new StringBuilder(); if (null != eventInfo) { if (showCPUInfo) { if (!String.IsNullOrEmpty(eventInfo.CPUId)) { toPrint.Append("[" + eventInfo.CPUId + "]"); } toPrint.Append("["); bool havePid = false; if (!String.IsNullOrEmpty(eventInfo.ProcessId)) { toPrint.Append(eventInfo.ProcessId); havePid = true; } if (!String.IsNullOrEmpty(eventInfo.ThreadId)) { if (havePid) { toPrint.Append("."); } toPrint.Append(eventInfo.ThreadId); } toPrint.Append("]"); } if (showTimeStamp) { toPrint.Append("[" + eventInfo.Timestamp.ToString("hh:mm:ss.ffffff") + "]"); } } CLogFileProcessor.DecomposedString decompString; CLogFileProcessor.CLogTypeContainer[] types = CLogFileProcessor.BuildTypes(config, null, bundle.TraceString, null, out decompString); if (0 == types.Length) { toPrint.Append(bundle.TraceString); goto toPrint; } CLogFileProcessor.CLogTypeContainer first = types[0]; if (valueBag.Count > 0) { int argIndex = 0; foreach (CLogFileProcessor.CLogTypeContainer type in types) { var arg = bundle.splitArgs[argIndex]; while (null == arg.DefinationEncoding) { ++argIndex; if (argIndex > bundle.splitArgs.Length) { throw new Exception("Unable to locate variable"); } arg = bundle.splitArgs[argIndex]; continue; } if (0 != arg.DefinationEncoding.CompareTo(type.TypeNode.DefinationEncoding)) { Console.WriteLine("Invalid Types in Traceline"); throw new Exception("InvalidType : " + arg.DefinationEncoding); } CLogEncodingCLogTypeSearch payload = type.TypeNode; IClogEventArg value = null; if (!valueBag.TryGetValue(arg.MacroVariableName, out value)) { value = null; } if (value == null && !valueBag.TryGetValue(arg.EventVariableName, out value)) { toPrint.Append($"<SKIPPED:BUG:MISSINGARG:{arg.MacroVariableName}:{payload.EncodingType}>"); } else { if (string.IsNullOrEmpty(type.TypeNode.CustomDecoder)) { string typeForPrint = clogutils.ClogEventPrinter.AsCorrectType(type.TypeNode.EncodingType, value); toPrint.Append($"{type.LeadingString}{typeForPrint}"); } else { string decodedValue; config.DecodeUsingCustomDecoder(type.TypeNode, value, bundle.match, out decodedValue); toPrint.Append($"{type.LeadingString}{decodedValue}"); } } first = type; ++argIndex; } string tail = bundle.TraceString.Substring(types[types.Length - 1].ArgStartingIndex + types[types.Length - 1].ArgLength); toPrint.Append(tail); } else { toPrint.Clear(); toPrint.Append(bundle.TraceString); } toPrint: if (null == outputfile) { Console.WriteLine(toPrint); } else { outputfile.WriteLine(toPrint); } } catch (Exception e) { Console.WriteLine($"Invalid TraceLine : {errorLine} " + e); } }
public bool DecodeUsingCustomDecoder(CLogEncodingCLogTypeSearch node, IClogEventArg value, CLogLineMatch traceLine, out string decodedValue) { return(_traceEmittorX.Decode(node, value, traceLine, out decodedValue)); }