#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
}
}
|