Created
January 2, 2014 10:30
-
-
Save oexenhave/8217396 to your computer and use it in GitHub Desktop.
TimeLog Project API Scaffolding method example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using log4net; | |
using log4net.Config; | |
using System; | |
using System.Linq; | |
using System.Diagnostics; | |
using System.IO; | |
namespace APIScaffolding | |
{ | |
public class App | |
{ | |
private static readonly ILog Logger = LogManager.GetLogger(typeof(App)); | |
private static readonly DirectoryInfo AppPath = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).Directory; | |
public static void Main(string[] args) | |
{ | |
var _stopWatch = new Stopwatch(); | |
_stopWatch.Start(); | |
XmlConfigurator.Configure(new FileInfo(AppPath + "\\log4net.config")); | |
BasicConfigurator.Configure(); | |
try | |
{ | |
if (Logger.IsInfoEnabled) | |
{ | |
Logger.Info("Starting API test application..."); | |
} | |
TimelogServices timelog = new TimelogServices(); | |
var employeeRaw = timelog.OrganisationService.GetEmployeeHeaderByInitials("sox", timelog.OrganisationToken); | |
if (employeeRaw.ResponseState == TimeLogOrganisationService.ExecutionStatus.Success) | |
{ | |
if (!employeeRaw.Return.Any()) | |
{ | |
if (Logger.IsInfoEnabled) | |
{ | |
Logger.InfoFormat("No employees found"); | |
} | |
} | |
foreach (EmployeeHeader employee in employeeRaw.Return) | |
{ | |
if (Logger.IsInfoEnabled) | |
{ | |
Logger.InfoFormat("Employee {0} found", employee.Fullname); | |
} | |
} | |
} | |
else if (Logger.IsErrorEnabled) | |
{ | |
Logger.ErrorFormat("GetEmployeeHeaderByInitials failed with code: {0}", employeeRaw.ErrorCode); | |
foreach (APIMessage message in employeeRaw.Messages) | |
{ | |
Logger.WarnFormat("Result message: {0}", message.Message); | |
} | |
} | |
} | |
catch (Exception _ex) | |
{ | |
if (Logger.IsErrorEnabled) | |
{ | |
Logger.Error("Application failed", _ex); | |
} | |
} | |
finally | |
{ | |
_stopWatch.Stop(); | |
if (Logger.IsInfoEnabled) | |
{ | |
Logger.InfoFormat("Processing ended in {0} min", _stopWatch.Elapsed.TotalMinutes); | |
} | |
} | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment