/// <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(); } }
/// <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> /// Download project information from Stanford University (psummaryC.html) /// </summary> /// <param name="State">Null in this implementation</param> public void DownloadFromStanford(Object State /* null */) { DateTime Start = Debug.ExecStart; lock (this) { Preferences.PreferenceSet Prefs = Preferences.PreferenceSet.Instance; WebRequest wrq = (WebRequest)WebRequest.Create("http://vspx27.stanford.edu/psummaryC.html"); wrq.Method = WebRequestMethods.Http.Get; WebResponse wrs; StreamReader sr1; if (Prefs.UseProxy) { wrq.Proxy = new WebProxy(Prefs.ProxyServer, Prefs.ProxyPort); if (Prefs.UseProxyAuth) { wrq.Proxy.Credentials = new NetworkCredential(Prefs.ProxyUser, Prefs.ProxyPass); } } else { wrq.Proxy = null; } // TODO: Handle timeouts and errors try { wrs = (WebResponse)wrq.GetResponse(); sr1 = new StreamReader(wrs.GetResponseStream(), Encoding.ASCII); if ((wrs == null) || (sr1 == null)) { throw new IOException("The web response or stream was null"); } } catch (WebException ExWeb) { ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw WebException {1}.", Debug.FunctionName, ExWeb.Message), null); ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), ""); return; } catch (IOException ExIO) { ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw IOException {1}.", Debug.FunctionName, ExIO.Message), null); ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), ""); return; } catch (Exception Ex) { ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw WebException {1}.", Debug.FunctionName, Ex.Message), null); ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), ""); return; } HTMLparser pSummary = new HTMLparser(); String sSummaryPage = sr1.ReadToEnd(); pSummary.Init(sSummaryPage); // Locate the table HTMLchunk oChunk = null; // Parse until returned oChunk is null indicating we reached end of parsing while ((oChunk = pSummary.ParseNext()) != null) { if (oChunk.sTag.ToLower() == "tr") { Protein p = new Protein(); while (((oChunk = pSummary.ParseNext()) != null) && (oChunk.sTag.ToLower() != "td")) { ; // Do nothing! } // Skip the empty attributes oChunk = pSummary.ParseNext(); try { #region Parse Code for HTML Table // Suck out the project number p.ProjectNumber = Int32.Parse(oChunk.oHTML.ToString()); // Skip the closing tag, opening tags and attributes oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); p.ServerIP = oChunk.oHTML.ToString().Trim(); // Skip the closing tag, opening tags and attributes oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); p.WorkUnitName = oChunk.oHTML.ToString().Trim(); // Skip the closing tag, opening tags and attributes oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); p.NumAtoms = Int32.Parse(oChunk.oHTML.ToString()); // Skip the closing tag, opening tags and attributes oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); p.PreferredDays = Int32.Parse(oChunk.oHTML.ToString().Substring(0, oChunk.oHTML.IndexOf('.')).Trim()); // Skip the closing tag, opening tags and attributes oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); try { p.MaxDays = Int32.Parse(oChunk.oHTML.ToString().Substring(0, oChunk.oHTML.IndexOf('.')).Trim()); } catch { p.MaxDays = 0; } oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); p.Credit = Int32.Parse(oChunk.oHTML.ToString().Substring(0, oChunk.oHTML.IndexOf('.')).Trim()); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); p.Frames = Int32.Parse(oChunk.oHTML.ToString().Trim()); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); p.Core = oChunk.oHTML.ToString(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); p.Description = oChunk.oParams["href"].ToString(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); oChunk = pSummary.ParseNext(); p.Contact = oChunk.oHTML.ToString(); #endregion if (this.ContainsKey(p.ProjectNumber)) { this[p.ProjectNumber] = p; } else { this.Add(p.ProjectNumber, p); } } catch (Exception Ex) { // Ignore this row of the table - unparseable ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw exception while parsing HTML: {1}", Debug.FunctionName, Ex.Message), null); } } } if (this.Count > 0) { OnNFOUpdated(new NFOUpdatedEventArgs()); } } SaveToCSV(_LocalNFOFile); ClassLogger.Log(LogLevel.Trace, String.Format("{0} loaded {1} proteins from Stanford", Debug.FunctionName, ProteinCollection.Instance.Count), ""); ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), ""); return; }