Automated teller machine emulation.
using System;
using System.IO;
using Impexpdata.Core;
using log4net;
namespace Impexpdata
{
class Program
{
private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static readonly DataExchangeService DataExchangeService = new DataExchangeService();
static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
if (args.Length == 0)
{
Log.Error("Application arguments not found.");
MarkMessageAsError();
Console.WriteLine("Application arguments not found.");
Console.ResetColor();
Console.WriteLine("Arguments: impexpdata -import <file name>.");
Console.WriteLine("Arguments: impexpdata -export <file name>.");
Console.WriteLine(@"<file name> can be absolute or relative. Like C:\impexpdata\export.cvs or just export.cvs.");
Console.WriteLine("Example: impexpdata -import import.csv");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
return;
}
if (args.Length < 2)
{
Log.Error("Application arguments count is invalid.");
MarkMessageAsError();
Console.WriteLine("Arguments count is invalid.");
Console.ResetColor();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
return;
}
var filePath = Path.IsPathRooted(args[1]) ? args[1] : Path.Combine(Properties.AppPath, args[1]);
if (!Path.GetExtension(filePath).EndsWith("csv"))
{
Log.Error("Application works only with CSV files.");
MarkMessageAsError();
Console.WriteLine("Application works only with CSV files.");
Console.ResetColor();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
return;
}
var itemsProcessedCount = 0;
var processResultMsg = string.Empty;
switch (args[0])
{
case "-import":
Log.Info("Start import data...");
itemsProcessedCount = ImportData(filePath);
if (itemsProcessedCount == -1)
{
processResultMsg = "Import data file not found.";
}
else
{
processResultMsg = string.Format("Import process completed. {0} item(s) was processed.", itemsProcessedCount);
Log.Info("Import process completed.");
}
break;
case "-export":
Log.Info("Start export data...");
itemsProcessedCount = ExportData(filePath);
processResultMsg = string.Format("Export process completed. {0} item(s) was processed.", itemsProcessedCount);
Log.Info("Export process completed.");
break;
default:
processResultMsg = "Wrong process type argument value.";
Log.Error(processResultMsg);
break;
}
Console.WriteLine(processResultMsg);
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
private static int ImportData(string filePath)
{
return DataExchangeService.ImportData(filePath);
}
private static int ExportData(string filePath)
{
return DataExchangeService.ExportData(filePath);
}
private static void MarkMessageAsError()
{
Console.ForegroundColor = ConsoleColor.Red;
}
}
}