Skip to content

Instantly share code, notes, and snippets.

@oexenhave
Created January 2, 2014 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oexenhave/8217396 to your computer and use it in GitHub Desktop.
Save oexenhave/8217396 to your computer and use it in GitHub Desktop.
TimeLog Project API Scaffolding method example
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