/// <summary> /// Deserialize the instance from XML /// </summary> /// <param name="xmlData"></param> public override void FromXml(XmlNode xmlData) { DateTime Start = Debug.ExecStart; try { base.FromXml(xmlData); } catch { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, "Cannot load base instance data."), null); } try { this._Server = xmlData.SelectSingleNode(XmlPropServ).InnerText; } catch { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, "Cannot load FTP server."), null); } try { this._Path = xmlData.SelectSingleNode(XmlPropPath).InnerText; } catch { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, "Cannot load FTP path."), null); } try { this._Username = xmlData.SelectSingleNode(XmlPropUser).InnerText; } catch { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, "Cannot load FTP username."), null); } try { this._Password = xmlData.SelectSingleNode(XmlPropPass).InnerText; } catch { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, "Cannot load FTP password."), null); } ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), ""); }
/// <summary> /// Seralize the instance to XML /// </summary> /// <returns></returns> public override System.Xml.XmlDocument ToXml() { DateTime Start = Debug.ExecStart; try { XmlDocument xmlDoc = base.ToXml(); xmlDoc.ChildNodes[0].AppendChild(XMLOps.createXmlNode(xmlDoc, XmlPropType, this.GetType().ToString())); xmlDoc.ChildNodes[0].AppendChild(XMLOps.createXmlNode(xmlDoc, XmlPropServ, Server)); xmlDoc.ChildNodes[0].AppendChild(XMLOps.createXmlNode(xmlDoc, XmlPropPath, Path)); xmlDoc.ChildNodes[0].AppendChild(XMLOps.createXmlNode(xmlDoc, XmlPropUser, Username)); xmlDoc.ChildNodes[0].AppendChild(XMLOps.createXmlNode(xmlDoc, XmlPropPass, Password)); ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), ""); return(xmlDoc); } catch (Exception Ex) { ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null); return(null); } }
/// <summary> /// Retrieve the instance's log files /// </summary> public override void Retrieve() { DateTime Start = Debug.ExecStart; // Don't retrieve data if we only retrieved successfully less than a minute ago if ((LastRetrievalTime + new TimeSpan(0, 1, 0)) > DateTime.Now) { return; } if (MakeInstanceDir()) { // Retrieve FAHLog.txt (or equivalent) System.IO.FileInfo fiLog = new System.IO.FileInfo(_Path + "\\" + RemoteFAHLogFilename); String FAHLog_txt = base.BaseDirectory + LocalFAHLog; try { fiLog.CopyTo(FAHLog_txt, true); } catch (Exception Ex) { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null); return; } // Retrieve UnitInfo.txt (or equivalent) System.IO.FileInfo fiUI = new System.IO.FileInfo(_Path + "\\" + RemoteUnitInfoFilename); String UnitInfo_txt = base.BaseDirectory + LocalUnitInfo; try { fiUI.CopyTo(UnitInfo_txt, true); } catch (Exception Ex) { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null); return; } base.Retrieve(); } ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), ""); }
/// <summary> /// Retrieve the log and unit info files from the configured FTP location /// </summary> public override void Retrieve() { DateTime Start = Debug.ExecStart; // If last retrieval was less than a minute ago, don't do it again if ((LastRetrievalTime + new TimeSpan(0, 1, 0)) > DateTime.Now) { return; } if (MakeInstanceDir()) { Preferences.PreferenceSet Prefs = Preferences.PreferenceSet.Instance; // Download FAHlog.txt FtpWebRequest ftpc1 = (FtpWebRequest)FtpWebRequest.Create("ftp://" + this._Server + this._Path + this.RemoteFAHLogFilename); ftpc1.Method = WebRequestMethods.Ftp.DownloadFile; if ((_Username != "") && (_Username != null)) { if (_Username.Contains("\\")) { String[] UserParts = _Username.Split('\\'); ftpc1.Credentials = new NetworkCredential(UserParts[1], _Password, UserParts[0]); } else { ftpc1.Credentials = new NetworkCredential(_Username, _Password); } } ftpc1.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); if (Prefs.UseProxy) { ftpc1.Proxy = new WebProxy(Prefs.ProxyServer, Prefs.ProxyPort); if (Prefs.UseProxyAuth) { ftpc1.Proxy.Credentials = new NetworkCredential(Prefs.ProxyUser, Prefs.ProxyPass); } } else { ftpc1.Proxy = null; } FtpWebResponse ftpr1; try { ftpr1 = (FtpWebResponse)ftpc1.GetResponse(); } catch (Exception Ex) { ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null); return; } String FAHLog_txt = base.BaseDirectory + LocalFAHLog; StreamWriter sw1 = new StreamWriter(FAHLog_txt, false); StreamReader sr1 = new StreamReader(ftpr1.GetResponseStream(), Encoding.ASCII); sw1.Write(sr1.ReadToEnd()); sw1.Flush(); sw1.Close(); sr1.Close(); // Download unitinfo.txt FtpWebRequest ftpc2 = (FtpWebRequest)FtpWebRequest.Create("ftp://" + this._Server + this._Path + this.RemoteUnitInfoFilename); if ((_Username != "") && (_Username != null)) { if (_Username.Contains("\\")) { String[] UserParts = _Username.Split('\\'); ftpc2.Credentials = new NetworkCredential(UserParts[1], _Password, UserParts[0]); } else { ftpc2.Credentials = new NetworkCredential(_Username, _Password); } } ftpc2.Method = System.Net.WebRequestMethods.Ftp.DownloadFile; ftpc2.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); if (Prefs.UseProxy) { ftpc2.Proxy = new WebProxy(Prefs.ProxyServer, Prefs.ProxyPort); if (Prefs.UseProxyAuth) { ftpc2.Proxy.Credentials = new NetworkCredential(Prefs.ProxyUser, Prefs.ProxyPass); } } else { ftpc2.Proxy = null; } System.Net.FtpWebResponse ftpr2; try { ftpr2 = (System.Net.FtpWebResponse)ftpc2.GetResponse(); } catch (Exception Ex) { ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null); return; } String UnitInfo_txt = base.BaseDirectory + LocalUnitInfo; StreamWriter sw2 = new StreamWriter(UnitInfo_txt, false); StreamReader sr2 = new StreamReader(ftpr2.GetResponseStream(), Encoding.ASCII); sw2.Write(sr2.ReadToEnd()); sw2.Flush(); sw2.Close(); sr2.Close(); base.Retrieve(); } ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), ""); }
/// <summary> /// /// </summary> public override void Retrieve() { // If we last retrieved data less than a minute ago, don't do it again if ((LastRetrievalTime + new TimeSpan(0, 1, 0)) > DateTime.Now) { return; } if (MakeInstanceDir()) { Preferences.PreferenceSet Prefs = Preferences.PreferenceSet.Instance; // Download FAHlog.txt WebRequest httpc1 = (WebRequest)WebRequest.Create(this._URL + "/" + this.RemoteFAHLogFilename); httpc1.Credentials = new NetworkCredential(_Username, _Password); httpc1.Method = WebRequestMethods.Http.Get; httpc1.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); if (Prefs.UseProxy) { httpc1.Proxy = new WebProxy(Prefs.ProxyServer, Prefs.ProxyPort); if (Prefs.UseProxyAuth) { httpc1.Proxy.Credentials = new NetworkCredential(Prefs.ProxyUser, Prefs.ProxyPass); } } else { httpc1.Proxy = null; } try { WebResponse r1 = (WebResponse)httpc1.GetResponse(); String FAHLog_txt = base.BaseDirectory + LocalFAHLog; StreamWriter sw1 = new StreamWriter(FAHLog_txt, false); StreamReader sr1 = new StreamReader(r1.GetResponseStream(), Encoding.ASCII); sw1.Write(sr1.ReadToEnd()); sw1.Flush(); sw1.Close(); sr1.Close(); } catch (Exception Ex) { ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null); } // Download unitinfo.txt WebRequest httpc2 = (WebRequest)WebRequest.Create(this._URL + "/" + this.RemoteUnitInfoFilename); httpc2.Credentials = new NetworkCredential(_Username, _Password); httpc2.Method = WebRequestMethods.Http.Get; httpc2.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); if (Prefs.UseProxy) { httpc2.Proxy = new WebProxy(Prefs.ProxyServer, Prefs.ProxyPort); if (Prefs.UseProxyAuth) { httpc2.Proxy.Credentials = new NetworkCredential(Prefs.ProxyUser, Prefs.ProxyPass); } } else { httpc2.Proxy = null; } try { WebResponse r2 = (WebResponse)httpc2.GetResponse(); String UnitInfo_txt = base.BaseDirectory + LocalUnitInfo; StreamWriter sw2 = new StreamWriter(UnitInfo_txt, false); StreamReader sr2 = new StreamReader(r2.GetResponseStream(), Encoding.ASCII); sw2.Write(sr2.ReadToEnd()); sw2.Flush(); sw2.Close(); sr2.Close(); } catch (Exception Ex) { ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null); } base.Retrieve(); } }