/// <summary> /// Adds an XmlNode to the XmlDocument for the Activity Log. Gets the /// application directory from the registry and then opens or creates /// the Activity Log xml file. Appends the new entry to the XmlDocument /// An XmlException is thrown if there is a problem with loading the xml /// file. /// </summary> /// <example> /// <code> /// CCustSchedItem x = new CCustSchedItem(); /// x.Event = "Reconfigure Failed"; /// x.Data = "Custom 1"; /// x.MeterType = "SENTINEL"; /// x.UnitID = "Meter ID 1"; /// x.SerialNumber = "123-456-789"; /// /// x.AddItem(); /// </code> /// </example> /// <remarks> /// Revision History /// MM/DD/YY who Version Issue# Description /// -------- --- ------- ------ --------------------------------------- /// 07/14/05 rrr 7.13.00 N/A Creation of class /// 04/25/06 mrj 7.30.00 Updated for HH-Pro /// 01/15/07 mah 8.00.00 Changed registry access class from CE version /// </remarks> public void Add() { //Local variables XmlNode xmlnodeRoot; XmlNode xmlnodeTemp; bool blnFileCreated = false; //Get the data directory for the log and get the log file m_strDirectory = CRegistryHelper.GetDataDirectory(m_strApplication); blnFileCreated = GetLogFile(); //Create the xml document and load the xml file if need be if (!blnFileCreated) { m_xmldomLog = new System.Xml.XmlDocument(); m_xmldomLog.Load(m_strXmlFile); } //Create the xml node to be added ConstructLogItemNode(); //get the root node to add the xml node to xmlnodeRoot = m_xmldomLog.LastChild; xmlnodeTemp = xmlnodeRoot; //Append the xml node to the root node if (null != xmlnodeRoot) { xmlnodeTemp = xmlnodeRoot.AppendChild(m_xmlnodeLogItem); } //Save the xml documents and set variables to null m_xmldomLog.Save(m_strXmlFile); m_xmldomLog = null; xmlnodeTemp = null; xmlnodeRoot = null; }
/// <summary> /// This method reads all of the entries in the activity log and returns /// them as a generic list. /// </summary> /// <param name="strApplication">This string is used to identify the file to read. /// The assumption is that different applications will be able to generate activity /// logs and that each file can be looked up using the application name /// as a registry key /// </param> /// <returns>A generic list containing activity log items. A value of NULL will be returned /// if the file cannot be found. If the file does exist, but is unreadable, the returned list /// will be empty /// </returns> /// <remarks> /// Revision History /// MM/DD/YY who Version Issue# Description /// -------- --- ------- ------ --------------------------------------- /// 01/16/07 mah 8.00.00 Created /// </remarks> public static List <ActivityLogEntry> Read(String strApplication) { //Local variables XmlNodeList xmlEntryNodes; // XmlNode xmlnodeTemp; //Get the data directory for the log and get the log file String strDirectory = CRegistryHelper.GetDataDirectory(strApplication); //Create file info objects for the xml file to allow us to see if the activity log exists FileInfo objFile = new FileInfo(strDirectory + XML_FILE); //if the xml file does not exist than create it otherwise set the //member variable if (!objFile.Exists) { return(null); } else { List <ActivityLogEntry> logEventList = new List <ActivityLogEntry>(); String strXmlFile = objFile.FullName; XmlDocument xmldomLog = new System.Xml.XmlDocument(); xmldomLog.Load(strXmlFile); xmlEntryNodes = xmldomLog.GetElementsByTagName(NODE_ENTRY); foreach (XmlNode xmlLogEntry in xmlEntryNodes) { ActivityLogEntry logEntry = new ActivityLogEntry(strApplication); XmlNode xmlEventTime = xmlLogEntry.SelectSingleNode(NODE_TIME); if (null != xmlEventTime) { logEntry.EventTime = DateTime.Parse(xmlEventTime.InnerText, CultureInfo.InvariantCulture); } XmlNode xmlMeterType = xmlLogEntry.SelectSingleNode(NODE_METERTYPE); if (null != xmlMeterType) { logEntry.MeterType = xmlMeterType.InnerText; } XmlNode xmlMeterID = xmlLogEntry.SelectSingleNode(NODE_UNITID); if (null != xmlMeterID) { logEntry.UnitID = xmlMeterID.InnerText; } XmlNode xmlMeterSerialNumber = xmlLogEntry.SelectSingleNode(NODE_SERIAL); if (null != xmlMeterSerialNumber) { logEntry.SerialNumber = xmlMeterSerialNumber.InnerText; } XmlNode xmlEvent = xmlLogEntry.SelectSingleNode(NODE_EVENT); if (null != xmlEvent) { logEntry.Event = xmlEvent.InnerText; } XmlNode xmlEventData = xmlLogEntry.SelectSingleNode(NODE_DATA); if (null != xmlEventData) { logEntry.Data = xmlEventData.InnerText; } logEventList.Add(logEntry); } return(logEventList); } }