Beispiel #1
0
        public static string GetFileLine(CLogLineMatch TraceLine)
        {
            if (null != TraceLine && null != TraceLine.SourceFile)
            {
                int    line     = 1;
                int    lastLine = 1;
                string file     = System.IO.File.ReadAllText(TraceLine.SourceFile).Substring(0, TraceLine.MatchedRegEx.Index);
                for (int i = 0; i < file.Length; ++i)
                {
                    if (file[i] == '\n')
                    {
                        string prev = file.Substring(lastLine, i - 1 - lastLine);
                        //Console.WriteLine("Line: " + line + " " + prev);
                        lastLine = i + 1;
                        ++line;
                    }
                }

                string fullPath = System.IO.Path.GetFullPath(TraceLine.SourceFile);
                return($"{fullPath}({line},1)");
            }
            else
            {
                return("");
            }
        }
Beispiel #2
0
 public CLogTypeNotFoundException(string msg, string partialType, CLogLineMatch traceLine,
                                  Exception e = null) : base(msg, ExceptionType.UndefinedType, traceLine, e)
 {
     AreReadOnly = true;
     Exception   = e;
     PartialType = partialType;
     InfoString  = "Missing Type : " + partialType;
 }
Beispiel #3
0
 public CLogDecodedTraceLine(string uniqueId, string sourceFile, string userString, string userStringNoPrefix, CLogLineMatch m, CLogConfigurationFile c,
                             string mac, CLogFileProcessor.CLogVariableBundle[] args)
 {
     SourceFile          = sourceFile;
     macroName           = mac;
     UniqueId            = uniqueId;
     match               = m;
     configFile          = c;
     TraceString         = userString;
     splitArgs           = args;
     TraceStringNoPrefix = userStringNoPrefix;
 }
Beispiel #4
0
        public CLogDecodedTraceLine(string uniqueId, string sourceFile, string userString, string userStringNoPrefix, CLogLineMatch m, CLogConfigurationFile c,
                                    CLogTraceMacroDefination mac, CLogFileProcessor.CLogVariableBundle[] args, CLogFileProcessor.DecomposedString decompString)
        {
            SourceFile          = sourceFile;
            macro               = mac;
            UniqueId            = uniqueId;
            match               = m;
            configFile          = c;
            TraceString         = userString;
            splitArgs           = args;
            TraceStringNoPrefix = userStringNoPrefix;

            DecomposedString = decompString;
        }
Beispiel #5
0
        private static SortedList <int, CLogLineMatch> UpdateMatches(string data, string sourceFileName, CLogTraceMacroDefination inspect)
        {
            string inspectToken = inspect.MacroName + "\\s*" + @"\((?<args>.*?)\);";
            Regex  r            = new Regex(inspectToken, RegexOptions.Singleline);
            SortedList <int, CLogLineMatch> matches = new SortedList <int, CLogLineMatch>();

            foreach (Match m in r.Matches(data))
            {
                CLogLineMatch lineMatch = new CLogLineMatch(sourceFileName, m);
                matches.Add(m.Groups["0"].Index, lineMatch);
            }

            return(matches);
        }
Beispiel #6
0
        public CLogEncodingCLogTypeSearch FindTypeX(CLogFileProcessor.CLogVariableBundle bundle, CLogLineMatch traceLineMatch)
        {
            int idx = 0;

            return(_sideCarFile.ConfigFile.FindTypeAndAdvance(bundle.DefinationEncoding, traceLineMatch, ref idx));
        }
Beispiel #7
0
 public CLogHandledException(string msg, ExceptionType type, CLogLineMatch traceLine, Exception e = null) : base(msg)
 {
     Exception = e;
     TraceLine = traceLine;
     Type      = type;
 }
Beispiel #8
0
 public CLogEnterReadOnlyModeException(string msg, CLogHandledException.ExceptionType type, CLogLineMatch traceLine, Exception e = null) :
     base(msg, type, traceLine, e)
 {
     AreReadOnly = true;
     Exception   = e;
     InfoString  = msg;
 }
Beispiel #9
0
        public static CLogTypeContainer[] BuildTypes(CLogConfigurationFile configFile, CLogLineMatch traceLineMatch, string argString,
                                                     string traceLine,
                                                     out string cleanedString)
        {
            List <CLogTypeContainer> ret = new List <CLogTypeContainer>();
            string pieces   = string.Empty;
            int    argCount = 0;

            cleanedString = string.Empty;
            string prefixString = "";

            if (string.IsNullOrEmpty(argString))
            {
                return(new CLogTypeContainer[0]);
            }

            // Make surew e start and stop with a quote - this prevents L"" (unicode) as well as other oddities that seem to be 'okay' in WPP but shoudlnt be okay
            argString = argString.Trim();

            for (int i = 0; i < argString.Length; ++i)
            {
                pieces += argString[i];

                if ('%' == argString[i])
                {
                    pieces += argCount++;
                    pieces += " ";

                    CLogTypeContainer newNode = new CLogTypeContainer();
                    newNode.LeadingString    = prefixString;
                    newNode.ArgStartingIndex = i;

                    ++i;

                    CLogEncodingCLogTypeSearch t;

                    try
                    {
                        // 'i' will point to the final character on a match (such that i+1 is the next fresh character)
                        t = configFile.FindTypeAndAdvance(argString, traceLineMatch, ref i);
                    }
                    catch (CLogTypeNotFoundException e)
                    {
                        throw e;
                    }

                    newNode.TypeNode  = t;
                    newNode.ArgLength = i - newNode.ArgStartingIndex + 1;
                    prefixString      = "";

                    ret.Add(newNode);
                }
                else
                {
                    prefixString += argString[i];
                }
            }

            cleanedString = pieces;
            return(ret.ToArray());
        }
Beispiel #10
0
        private static SortedList <int, CLogLineMatch> UpdateMatches(string data, string sourceFileName, CLogTraceMacroDefination inspect)
        {
            string inspectToken;


            if (!inspect.ClassFunctionEncoding)
            {
                inspectToken = inspect.MacroName + "\\s*" + @"\((?<args>.*?)\);";
            }
            else
            {
                inspectToken = inspect.MacroName + "\\.(?<methodname>[A-Za-z0-9_-]*)" + @"\((?<args>.*?)\);";
            }

            Regex r = new Regex(inspectToken, RegexOptions.Singleline);
            SortedList <int, CLogLineMatch> matches = new SortedList <int, CLogLineMatch>();

            foreach (Match m in r.Matches(data))
            {
                string uid           = "";
                string args          = "";
                string encodedString = "";

                List <string> splitArgs = new List <string>();
                if (inspect.NoEncodingOk)
                {
                    args = m.Groups["args"].ToString();

                    splitArgs = new List <string>(SplitWithEscapedQuotes(args, ','));

                    if (0 != args.Length && inspect.EncodedArgNumber >= splitArgs.Count)
                    {
                        throw new CLogHandledException("EncodedArgNumberTooLarge", CLogHandledException.ExceptionType.EncodedArgNumberInvalid, null);
                    }
                }
                else if (inspect.ClassFunctionEncoding)
                {
                    uid  = m.Groups["methodname"].ToString();
                    args = m.Groups["args"].ToString();

                    splitArgs = new List <string>(SplitWithEscapedQuotes(args, ','));

                    if (inspect.EncodedArgNumber >= splitArgs.Count)
                    {
                        throw new CLogHandledException("EncodedArgNumberTooLarge", CLogHandledException.ExceptionType.EncodedArgNumberInvalid, null);
                    }

                    encodedString = splitArgs[inspect.EncodedArgNumber];
                }
                else
                {
                    args = m.Groups["args"].ToString();

                    splitArgs = new List <string>(SplitWithEscapedQuotes(args, ','));
                    uid       = splitArgs[0].Trim();

                    if (inspect.EncodedArgNumber >= splitArgs.Count)
                    {
                        throw new CLogHandledException("EncodedArgNumberTooLarge", CLogHandledException.ExceptionType.EncodedArgNumberInvalid, null);
                    }

                    encodedString = splitArgs[inspect.EncodedArgNumber];
                }

                CLogLineMatch lineMatch = new CLogLineMatch(sourceFileName, m, uid, encodedString, args, splitArgs.ToArray());
                matches.Add(m.Groups["0"].Index, lineMatch);
            }

            return(matches);
        }
Beispiel #11
0
        public static CLogTypeContainer[] BuildTypes(CLogConfigurationFile configFile, CLogLineMatch traceLineMatch, string argString,
                                                     string traceLine,
                                                     out DecomposedString decompString)
        {
            List <CLogTypeContainer> ret = new List <CLogTypeContainer>();
            string pieces   = string.Empty;
            int    argCount = 0;

            decompString = new DecomposedString();

            string prefixString = "";

            DecomposedString.EncodingArg currentArg = decompString.CreateNewArg();

            if (string.IsNullOrEmpty(argString))
            {
                return(new CLogTypeContainer[0]);
            }

            // Make sure we start and stop with a quote - this prevents L"" (unicode) as well as other oddities that seem to be 'okay' in WPP but shoudlnt be okay
            argString = argString.Trim();

            for (int i = 0; i < argString.Length; ++i)
            {
                pieces            += argString[i];
                currentArg.Prefix += argString[i];

                if ('%' == argString[i])
                {
                    pieces += (argCount++) + 1;;

                    CLogTypeContainer newNode = new CLogTypeContainer();
                    newNode.LeadingString    = prefixString;
                    newNode.ArgStartingIndex = i;

                    currentArg = decompString.CreateNewArg();

                    ++i;

                    // Check to see if a custom name is specified for this type
                    string preferredName = "";
                    if ('{' == argString[i])
                    {
                        // Skip the opening brace
                        i++;
                        if (i == argString.Length)
                        {
                            throw new CLogEnterReadOnlyModeException("InvalidNameFormatInTypeSpcifier", CLogHandledException.ExceptionType.TooFewArguments, traceLineMatch);
                        }

                        while (',' != argString[i])
                        {
                            // If we find a closing brace or a space before finding the comma, it's a parsing error
                            if ('}' == argString[i] || char.IsWhiteSpace(argString[i]))
                            {
                                throw new CLogEnterReadOnlyModeException("InvalidNameFormatInTypeSpcifier", CLogHandledException.ExceptionType.WhiteSpaceNotAllowed, traceLineMatch);
                            }

                            preferredName += argString[i];

                            i++;
                            if (i == argString.Length)
                            {
                                throw new CLogEnterReadOnlyModeException("InvalidNameFormatInTypeSpcifier", CLogHandledException.ExceptionType.TooFewArguments, traceLineMatch);
                            }
                        }

                        // Skip the comma
                        i++;

                        // Don't allow white spaces after comma
                        if (char.IsWhiteSpace(argString[i]))
                        {
                            throw new CLogEnterReadOnlyModeException("InvalidNameFormatInTypeSpcifier", CLogHandledException.ExceptionType.WhiteSpaceNotAllowed, traceLineMatch);
                        }

                        if (i == argString.Length)
                        {
                            throw new CLogEnterReadOnlyModeException("InvalidNameFormatInTypeSpcifier", CLogHandledException.ExceptionType.TooFewArguments, traceLineMatch);
                        }
                    }

                    CLogEncodingCLogTypeSearch t;

                    try
                    {
                        // 'i' will point to the final character on a match (such that i+1 is the next fresh character)
                        t = configFile.FindTypeAndAdvance(argString, traceLineMatch, ref i);
                    }
                    catch (CLogTypeNotFoundException)
                    {
                        throw;
                    }

                    // If we found a preferred name, the next character after the type should be a closing brace
                    if (preferredName.Length != 0)
                    {
                        i++;
                        if (i == argString.Length || '}' != argString[i])
                        {
                            throw new CLogEnterReadOnlyModeException("InvalidNameFormatInTypeSpcifier", CLogHandledException.ExceptionType.TooFewArguments, traceLineMatch);
                        }

                        newNode.PreferredName = preferredName;
                    }

                    // Compute lengths
                    newNode.TypeNode  = t;
                    newNode.ArgLength = i - newNode.ArgStartingIndex + 1;
                    currentArg.Type   = t;

                    prefixString = "";

                    ret.Add(newNode);
                }
                else
                {
                    prefixString += argString[i];
                }
            }

            if (!pieces.Equals(decompString.AsManifestedETWEncoding))
            {
                throw new Exception("ETW strings dont match");
            }

            return(ret.ToArray());
        }