public static List <string> ReadTags(string host, string logname, CriteriaHandle handle = null) { List <string> fileContents = new List <string>(); FtpWebRequest rq = (FtpWebRequest)FtpWebRequest.Create("ftp://" + host + "/" + logname); rq.Method = WebRequestMethods.Ftp.DownloadFile; rq.Credentials = new NetworkCredential("anonymous", ""); Stream resp = rq.GetResponse().GetResponseStream(); //rq.GetRequestStream(); StreamReader ftpReader = new StreamReader(resp); string fileLine = null; while ((fileLine = ftpReader.ReadLine()) != null) { string tag = ReaderDecoder.ExtractTagID(fileLine); if (!fileContents.Contains(tag)) { if (handle != null) { if (!handle(fileLine)) { continue; } } fileContents.Add(tag); } } ftpReader.Close(); resp.Close(); return(fileContents); }
public static void Run2(string host) { string logname = ReaderLog.FS_LS; DateTime start_time = new DateTime(2013, 10, 29, 15, 14, 0); List <string> tags = ReaderUtil.ReadTags(host, logname, (fLine) => { DateTime?rec_time = ReaderDecoder.ExtractDateTime(fLine); if (rec_time != null) { if (rec_time.Value > start_time) { return(true); } } return(false); }); foreach (string tag in tags) { Console.WriteLine("Tag: {0}", tag); } }
public static void Run(string host) { string logname = ReaderLog.FS_LS; string logpath = Path.Combine("/tmp", logname); if (!File.Exists(logpath)) { Console.WriteLine("Start downloading {0} ...", logname); try { ReaderUtil.DownloadLog(host, logname, logpath, (ln, perc) => { Console.WriteLine("Downloading {0}: {1}%\r", logname, perc); }); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } string line = null; using (StreamReader reader = new StreamReader(logpath)) { while ((line = reader.ReadLine()) != null) { string tag = ReaderDecoder.ExtractTagID(line); DateTime?dt = ReaderDecoder.ExtractDateTime(line); if (dt.HasValue) { Console.WriteLine("{0}:{1}", tag, dt.Value); } } } }