Created
January 2, 2014 09:50
-
-
Save oexenhave/8217041 to your computer and use it in GitHub Desktop.
TimeLog Project API Scaffolding class
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 System; | |
using System.Configuration; | |
using System.Linq; | |
namespace APIScaffolding | |
{ | |
public class TimelogServices | |
{ | |
private TimeLogSecurityService.SecurityServiceClient _securityService; | |
public TimeLogSecurityService.SecurityServiceClient SecurityService | |
{ | |
get | |
{ | |
if (_securityService == null) | |
{ | |
_securityService = new TimeLogSecurityService.SecurityServiceClient(); | |
} | |
return _securityService; | |
} | |
} | |
private TimeLogSecurityService.SecurityToken _securityToken; | |
public TimeLogSecurityService.SecurityToken SecurityToken | |
{ | |
get | |
{ | |
if (_securityService == null) | |
{ | |
var _getTokenRaw = SecurityService.GetToken( | |
ConfigurationManager.AppSettings["ApiUser"], | |
ConfigurationManager.AppSettings["ApiPassword"] | |
); | |
if (_getTokenRaw.ResponseState == TimeLogSecurityService.ExecutionStatus.Success | |
&& _getTokenRaw.Return.Any()) | |
{ | |
_securityToken = _getTokenRaw.Return[0]; | |
} | |
} | |
return _securityToken; | |
} | |
} | |
public bool IsSecurityServiceAlive() | |
{ | |
try | |
{ | |
return SecurityService.IsAlive(); | |
} | |
catch (Exception) | |
{ | |
return false; | |
} | |
} | |
private TimeLogOrganisationService.OrganisationServiceClient _organisationService; | |
public TimeLogOrganisationService.OrganisationServiceClient OrganisationService | |
{ | |
get | |
{ | |
if (_organisationService == null) | |
{ | |
_organisationService = new TimeLogOrganisationService.OrganisationServiceClient(); | |
} | |
return _organisationService; | |
} | |
} | |
public TimeLogOrganisationService.SecurityToken OrganisationToken | |
{ | |
get | |
{ | |
if (SecurityToken != null) | |
{ | |
return new TimeLogOrganisationService.SecurityToken | |
{ | |
Expires = SecurityToken.Expires, | |
Hash = SecurityToken.Hash, | |
Initials = SecurityToken.Initials | |
}; | |
} | |
return null; | |
} | |
} | |
public bool IsOrganisationServiceAlive() | |
{ | |
try | |
{ | |
return OrganisationService.IsAlive(); | |
} | |
catch (Exception) | |
{ | |
return false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment