MainClass.cs :  » Network-Clients » fileSync » FileSync » SyncConsole » 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 » fileSync 
fileSync » FileSync » SyncConsole » MainClass.cs
#region Using Directives
using System;
using System.IO;
using FileSync.Core;
#endregion

namespace FileSync.SyncConsole{
  /// <summary>
  /// Main class.
  /// </summary>
  class MainClass
  {
    private static Utility util;
    private static Engine syncEngine;

    #region Main
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main (string[] args)
    {
      // initialize fields
      util = new Utility ();
      syncEngine = new Engine ();
      // print info
      Console.Write ( "\r\nFileSync - version: 1.0.1.1\r\n\r\n" );
      ParseArguments ( args );
    }
    #endregion

    #region Private Methods
    private static void ParseArguments ( string[] args)
    {
      if ( args.Length > 0 )
      {
        // fields
        string dir1 = "";
        string dir2 = "";
        string syncType = "";
        bool showStatus = false;

        foreach ( string arg in args )
        {
          // check if arg is a directory
          // if not parse argument
          if ( !Directory.Exists ( arg ) )
          {
            // read entered command and interpret
            switch ( arg )
            {
              case "-a":
                // set sync type to all
                syncType = "ALL";
                break;
              case "-p":
                // set to show status when complete
                showStatus = true;
                break;
              default:
                // unknown arg, print usage
                Console.Write ( util.PrintUsage () );
                break;
            }
          }
            // if directory, set fields
          else
          {
            if ( dir1 == "" )
            {
              dir1 = arg;
            }
            else
            {
              dir2 = arg;
            }
          }
        }

        try
        {
          if ( dir1 != "" )
          {
            // check syncType and sync
            switch ( syncType )
            {
              case "ALL":
                Console.Write ( "Synchronizing All for " + dir1 + " and " + dir2 + "\r\n" );
                syncEngine.SyncAll ( dir1, dir2 );
                if ( showStatus )
                {
                  Console.Write ( "\r\n--------------------\r\nSynchronizing Complete. - " + DateTime.Now.ToString() + "\r\n\r\nPress a key to continue." );
                  Console.Read();
                }
                else
                {
                  Console.Write ( "\r\n--------------------\r\nSynchronizing Complete. - " + DateTime.Now.ToString() + "\r\n" );
                }
                break;
              default:
                Console.Write ( "\r\nYou must enter a valid sync type. Run filesync -h for usage.\r\n" );
                break;
            }
          }
        }
        catch (Exception ex)
        {
          Console.WriteLine ( "Error during sync: \r\n\r\n" );
          Console.Write ( ex.Message );
        }
      }
        // if nothing no arguments, print usage
      else
      {
        Console.Write ( util.PrintUsage() );
      }

    }

    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.