예제 #1
0
        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);
        }
예제 #2
0
        public static List <ReaderRecord> ReadRecords(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)
            {
                if (handle != null)
                {
                    if (!handle(fileLine))
                    {
                        continue;
                    }
                }
                fileContents.Add(fileLine);
            }
            ftpReader.Close();
            resp.Close();

            List <ReaderRecord> records = new List <ReaderRecord>();

            foreach (string line in fileContents)
            {
                ReaderRecord rec = ReaderRecord.Parse(line);
                if (rec != null)
                {
                    records.Add(rec);
                }
            }
            return(records);
        }