TandemFileParser.cs :  » Network-Clients » edtFTPnet » EnterpriseDT » Net » Ftp » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Network Clients » edtFTPnet 
edtFTPnet » EnterpriseDT » Net » Ftp » TandemFileParser.cs
// edtFTPnet
// 
// Copyright (C) 2008 Enterprise Distributed Technologies Ltd
// 
// www.enterprisedt.com
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Bug fixes, suggestions and comments should posted on 
// http://www.enterprisedt.com/forums/index.php
// 
// Change Log:
// 
// $Log: TandemFileParser.cs,v $
// Revision 1.1  2008-08-26 00:24:13  bruceb
// tandem parser
//
//


using System;
using System.Globalization;
using EnterpriseDT.Util;
using EnterpriseDT.Util.Debug;

namespace EnterpriseDT.Net.Ftp{    
  /// <summary>  
  /// Represents a remote Tandem file parser.
  /// </summary>
    /// <remarks>
    /// It can be explicitly set in FTPConnection by:
    /// <![CDATA[
    /// ftp.FileInfoParser.FileParser = new TandemFileParser();
    /// ]]>
    /// </remarks>
  /// <author>       Bruce Blackshaw
  /// </author>
  /// <version>      $Revision: 1.1 $
  /// </version>
  public class TandemFileParser : FTPFileParser
  {      
    /// <summary> Logging object</summary>
    private Logger log;
        
    /// <summary>Date format</summary>
    private static readonly string format1 = "d'-'MMM'-'yy HH':'mm':'ss";
    
        /// <summary>array of formats</summary> 
        private string[] formats = {format1};
               
    /// <summary> Number of expected fields</summary>
    private const int MIN_EXPECTED_FIELD_COUNT = 7;

        /// <summary>Trim array for permissions string</summary>
        private char[] trimChars = { '"' };
    
    /// <summary> Default constructor</summary>
    public TandemFileParser()
    {
            log = Logger.GetLogger("TandemFileParser");
    }

        /// <summary>
        /// Get flag indicating whether or not the most recent parse returned seconds.
        /// </summary>
        public override bool TimeIncludesSeconds
        {
            get { return true; }
        }

        public override string ToString()
        {
            return "Tandem";
        }

        /// <summary>
        /// Test for valid format for this parser
        /// </summary>
        /// <param name="listing">listing to test</param>
        /// <returns>true if valid</returns>
        public override bool IsValidFormat(string[] listing)
        {
            return IsHeader(listing[0]);
        }

        private bool IsHeader(string line)
        {
            if (line.IndexOf("Code") > 0 && line.IndexOf("EOF") > 0 &&
                line.IndexOf("RWEP") > 0)
                return true;
            return false;
        }

    /// <summary> Parse server supplied string. Should be in
    /// form 
    /// <![CDATA[
    /// File         Code             EOF  Last Modification    Owner  RWEP
        /// IARPTS        101            16354 18-Mar-08 15:09:12 244, 10 "nnnn"
        /// JENNYCB2      101            16384 10-Jul-08 11:44:56 244, 10 "nnnn"
    /// ]]>
    /// </summary>
    /// <param name="raw">  
    /// raw string to parse
    /// </param>
    public override FTPFile Parse(string raw)
    {
            if (IsHeader(raw))
                return null;

            string[] fields = StringSplitter.Split(raw);

            if (fields.Length < MIN_EXPECTED_FIELD_COUNT)
                return null;

            string name = fields[0];
      
      // first two fields are date time
            string lastModifiedStr = fields[3] + " " + fields[4];
            DateTime lastModified = DateTime.MinValue;
            try
            {
                lastModified = DateTime.ParseExact(lastModifiedStr, formats,
                                    ParsingCulture.DateTimeFormat, DateTimeStyles.None);
            }
            catch (FormatException)
            {
                log.Warn("Failed to parse date string '" + lastModifiedStr + "'");
            }

      // dir flag
      bool isDir = false;
      long size = 0L;
      try
      {
        size = Int64.Parse(fields[2]);
      }
      catch (FormatException)
      {
        log.Warn("Failed to parse size: " + fields[2]);
      }

            string owner = fields[5] + fields[6];
            string permissions = fields[7].Trim(trimChars);

            FTPFile file = new FTPFile(FTPFile.UNKNOWN, raw, name, size, isDir, ref lastModified);
            file.Owner = owner;
            file.Permissions = permissions;
            return file;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.