//Gets the input start date or WTMP time for InputFile public string getInputStartTime() { string last_line = null; foreach (var line in File.ReadLines(this.getFileName()).Reverse()) { last_line = line; break; } Match match = Regex.Match(last_line, RegularExpressions.getPattern("date")); return(match.Value); }
//parses the different Session Types public void parse(String singleSession) { switch (RegularExpressions.getRecordType(singleSession)) { case "complete": { mParser.parseXML(singleSession, RegularExpressions.getRecordType(singleSession)); break; } case "incomplete": { mParser.parseXML(singleSession, RegularExpressions.getRecordType(singleSession)); break; } case "system-crash": { mParser.parseXML(singleSession, RegularExpressions.getRecordType(singleSession)); break; } case "system-shutdown": { mParser.parseXML(singleSession, RegularExpressions.getRecordType(singleSession)); break; } case "reboot": { mParser.parseXML(singleSession, RegularExpressions.getRecordType(singleSession)); break; } case "runlevel-change": { mParser.parseXML(singleSession, RegularExpressions.getRecordType(singleSession)); break; } default: { Console.WriteLine("other"); break; } } }
//Checks Validity of Input File , If WTMP trailer is missing, reutns false public bool isValid() { string last_line = null; foreach (var line in File.ReadLines(this.getFileName()).Reverse()) { last_line = line; break; } if (RegularExpressions.getwtmpTrailerStatus(last_line)) { return(true); } return(false); }
public void readSessions() { if (!lastInputFile.isValid()) { //Write to error log and exit here error.writeError("Specified file is not valid" + Argconstants.INPUT_FILE); Console.WriteLine("Is valid"); } int counter = 0; String line; Console.WriteLine(this.lastInputFile.getInputStartTime()); Console.WriteLine(this.lastInputFile.getCreationTime()); try { StreamReader file = new StreamReader(this.lastInputFile.getFileName()); while ((line = file.ReadLine()) != null) { if (RegularExpressions.getRecordType(line).Equals("none")) { this.writeToSuspenseFile(line); continue; } this.parse(line); counter++; } file.Close(); Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e); throw; } }
public void parseXML(String line, String type) { switch (type) { case "complete": { document = XDocument.Load(Argconstants.MARKUP_FILE); document.Element("Sessions").Add(new XElement(type, new XElement(mUsername.GetType().Name, new XText(mUsername.getField(line))) , new XElement(mTerminal.GetType().Name, new XText(mTerminal.getField(line))) , new XElement(mDate.GetType().Name, new XText(mDate.getField(line))) , new XElement(mDuration.GetType().Name, new XText(mDuration.getField(line))) , new XElement(mRemoteTerminal.GetType().Name, new XText(mRemoteTerminal.getField(line))) )); document.Save(Argconstants.MARKUP_FILE); break; } case "incomplete": { document = XDocument.Load(Argconstants.MARKUP_FILE); document.Element("Sessions").Add(new XElement(type, new XElement(mUsername.GetType().Name, new XText(mUsername.getField(line))) , new XElement(mTerminal.GetType().Name, new XText(mTerminal.getField(line))) , new XElement(mDate.GetType().Name, new XText(mDate.getField(line))) , new XElement(mDuration.GetType().Name, new XText(mDuration.getField(line))) , new XElement(mRemoteTerminal.GetType().Name, new XText(mRemoteTerminal.getField(line))) )); document.Save(Argconstants.MARKUP_FILE); break; } case "system-crash": { document = XDocument.Load(Argconstants.MARKUP_FILE); document.Element("Sessions").Add(new XElement(type, new XElement(mUsername.GetType().Name, new XText(mUsername.getField(line))) , new XElement(mTerminal.GetType().Name, new XText(mTerminal.getField(line))) , new XElement(mDate.GetType().Name, new XText(mDate.getField(line))) , new XElement(mDuration.GetType().Name, new XText(mDuration.getField(line))) )); document.Save(Argconstants.MARKUP_FILE); break; } case "system-shutdown": { document = XDocument.Load(Argconstants.MARKUP_FILE); document.Element("Sessions").Add(new XElement(type, new XElement(mDate.GetType().Name, new XText(mDate.getField(line))) , new XElement(mDuration.GetType().Name, new XText(mDuration.getField(line))) , new XElement(mTerminal.GetType().Name, new XText(mTerminal.getField(line))) )); document.Save(Argconstants.MARKUP_FILE); break; } case "reboot": { document = XDocument.Load(Argconstants.MARKUP_FILE); document.Element("Sessions").Add(new XElement(type, new XElement(mDate.GetType().Name, new XText(mDate.getField(line))) , new XElement(mDuration.GetType().Name, new XText(mDuration.getField(line))) , new XElement(mTerminal.GetType().Name, new XText(mTerminal.getField(line))) )); document.Save(Argconstants.MARKUP_FILE); break; } case "runlevel-change": { document = XDocument.Load(Argconstants.MARKUP_FILE); document.Element("Sessions").Add(new XElement(type, new XElement("Description"), new XText(RegularExpressions.getRunLevel(line)) , new XElement(mDate.GetType().Name, new XText(mDate.getField(line))) , new XElement(mDuration.GetType().Name, new XText(mDuration.getField(line))) , new XElement(mTerminal.GetType().Name, new XText(mTerminal.getField(line))) )); document.Save(Argconstants.MARKUP_FILE); break; } } }
//Subclass of Field to Hold Information related to the Terminal of Sessions //Returns the Terminal from a parsed session public override string getField(string session) { Match match = Regex.Match(session, RegularExpressions.getPattern("terminal")); return(match.Value); }
//Subclass of Field to Hold Information related to the Terminal of Sessions //Returns the Terminal from a parsed session public override String getField(String session) { Match match = Regex.Match(session, RegularExpressions.getPattern("username")); return(match.Value); }