public static LogDisplay ParseFile(string logKey, string settingsXMLfilePath) { LogDisplay parserContent = new LogDisplay(); Dictionary <string, string> logFiles = new Dictionary <string, string>(); Dictionary <string, string> logFilesPatterns = new Dictionary <string, string>(); Dictionary <string, char> logFilesSeparators = new Dictionary <string, char>(); XmlReaderSettings xmlReaderSettings = new XmlReaderSettings(); xmlReaderSettings.IgnoreComments = true; xmlReaderSettings.IgnoreProcessingInstructions = true; xmlReaderSettings.IgnoreWhitespace = true; using (XmlReader xmlReader = XmlReader.Create(System.IO.File.OpenRead(settingsXMLfilePath), xmlReaderSettings)) { string key; while (false == xmlReader.EOF) { xmlReader.Read(); if (xmlReader.Name == "LogURL" && xmlReader.NodeType != XmlNodeType.EndElement) { key = xmlReader["logKey"]; logFilesPatterns.Add(key, xmlReader["logPattern"]); logFilesSeparators.Add(key, char.Parse(xmlReader["separator"])); xmlReader.Read(); logFiles.Add(key, xmlReader.Value); } } } string fileSelected = string.Empty; string filePattern = string.Empty; char fileSeparator = '|'; //Default separator if (logFiles.ContainsKey(logKey)) { fileSelected = logFiles[logKey]; filePattern = logFilesPatterns[logKey]; fileSeparator = logFilesSeparators[logKey]; parserContent.Parsing10MBLogFile(null, fileSelected, filePattern, fileSeparator); } else { parserContent.Parsing10MBLogFile(null, null, null, null); } return(parserContent); }
public static string GetLogId(string logPath, string settingsXMLfilePath) { LogDisplay parserContent = new LogDisplay(); string id; Dictionary <string, string> logFiles = new Dictionary <string, string>(); Dictionary <string, string> logFilesPatterns = new Dictionary <string, string>(); Dictionary <string, char> logFilesSeparators = new Dictionary <string, char>(); XmlReaderSettings xmlReaderSettings = new XmlReaderSettings(); xmlReaderSettings.IgnoreComments = true; xmlReaderSettings.IgnoreProcessingInstructions = true; xmlReaderSettings.IgnoreWhitespace = true; using (XmlReader xmlReader = XmlReader.Create(System.IO.File.OpenRead(settingsXMLfilePath), xmlReaderSettings)) { string key; while (false == xmlReader.EOF) { xmlReader.Read(); if (xmlReader.Name == "LogURL" && xmlReader.NodeType != XmlNodeType.EndElement) { key = xmlReader["logKey"]; logFilesPatterns.Add(key, xmlReader["logPattern"]); logFilesSeparators.Add(key, char.Parse(xmlReader["separator"])); xmlReader.Read(); logFiles.Add(key, xmlReader.Value); } } } int count = 0; int keyIndex = 0; foreach (string path in logFiles.Values) { if (path == logPath) { keyIndex = count; } count++; } id = logFiles.ElementAt(keyIndex).Key; return(id); }
public static LogDisplay Filter(LogDisplay logObject, int?startIndex, int?endIndex, string searchType, string searchContent) { bool deleteFlag = true; List <int> indexToDelete = new List <int>(); if (!string.IsNullOrEmpty(searchContent)) { for (int i = 0; i < logObject.LineParse.ElementsLog.Count; i++) { if (i < startIndex && i > endIndex) { indexToDelete.Add(i); } if (searchType != "MatchWholeWord") { if (logObject.LineParse.ElementsPattern.Contains("Ndc")) { string stringTemp = (string)((NdcElement)logObject.LineParse.ElementsLog[i].Elements[logObject.LineParse.ElementsPattern.IndexOf("Ndc")]).Element; if (stringTemp.Contains(searchContent)) { deleteFlag = false; } } if (logObject.LineParse.ElementsPattern.Contains("Message")) { string stringTemp = (string)((NdcElement)logObject.LineParse.ElementsLog[i].Elements[logObject.LineParse.ElementsPattern.IndexOf("Message")]).Element; if (stringTemp.Contains(searchContent)) { deleteFlag = false; } } } if (searchType == "MatchWholeWord") { if (logObject.LineParse.ElementsPattern.Contains("Ndc")) { string[] elementsTemp = ((string)((NdcElement)logObject.LineParse.ElementsLog[i].Elements[logObject.LineParse.ElementsPattern.IndexOf("Ndc")]).Element).Split(' '); foreach (string element in elementsTemp) { if (element.ToLower() == searchContent.ToLower()) { deleteFlag = false; } } } if (logObject.LineParse.ElementsPattern.Contains("Message")) { string[] elementsTemp = ((string)((NdcElement)logObject.LineParse.ElementsLog[i].Elements[logObject.LineParse.ElementsPattern.IndexOf("Message")]).Element).Split(' '); foreach (string element in elementsTemp) { if (element.ToLower() == searchContent.ToLower()) { deleteFlag = false; } } } } if (deleteFlag == true) { indexToDelete.Add(i); } deleteFlag = true; } for (int i = indexToDelete.Count - 1; i >= 0; i--) { logObject.LineParse.ElementsLog.RemoveAt(indexToDelete[i]); } } return(logObject); }