public IHttpActionResult GetPass(string passTypeIdentifier, string serialNumber) { ValidateAuthorization(Request.Headers.Authorization, passTypeIdentifier, serialNumber); PassProvider provider = GetProvider(passTypeIdentifier); try { IHttpActionResult result = GeneratePass(provider, serialNumber); if (result != null) { return(result); } Trace.TraceError("GetPass: No pass available for [{0}, {1}]", passTypeIdentifier, serialNumber); return(Content <Serialization.ApiResult>(HttpStatusCode.NoContent, new Serialization.ApiResult("No pass available."))); } catch (System.Data.Common.DbException ex) { // Do not expose possible sensitive database information from the PassProvider Trace.TraceError("GetPass for [{0}, {1}]: {2}", passTypeIdentifier, serialNumber, ex.Message); return(Content <Serialization.ApiResult>(HttpStatusCode.InternalServerError, new Serialization.ApiResult("Database Error"))); } catch (Exception ex) { Trace.TraceError("GetPass for [{0}, {1}]: {2}", passTypeIdentifier, serialNumber, ex.Message); return(Content <Serialization.ApiResult>(HttpStatusCode.InternalServerError, new Serialization.ApiResult(ex.Message))); } }
protected PassProvider GetProvider(String passTypeIdentifier) { PassProvider provider = mProviders.FirstOrDefault(p => p.SupportsPassType(passTypeIdentifier)); if (provider == null) { throw new Exceptions.PassProviderException(String.Format("No PassProvider available for \"{0}\".", passTypeIdentifier)); } return(provider); }
public IHttpActionResult RegisterDevicePass(string deviceLibraryIdentifier, string passTypeIdentifier, string serialNumber) { ValidateAuthorization(Request.Headers.Authorization, passTypeIdentifier, serialNumber); PassProvider provider = GetProvider(passTypeIdentifier); try { String body = Request.Content.ReadAsStringAsync().Result; if (!String.IsNullOrEmpty(body)) { JObject json = JObject.Parse(body); JToken token = json.SelectToken("pushToken"); if (token != null) { // Register device String pushToken = token.Value <String>(); provider.RegisterDevicePass(deviceLibraryIdentifier, passTypeIdentifier, serialNumber, pushToken); return(Ok <Serialization.ApiResult>(new Serialization.ApiResult("Pass registered"))); } } Trace.TraceError("RegisterDevicePass for [{0}, {1}, {2}]: Incomplete or invalid body.", deviceLibraryIdentifier, passTypeIdentifier, serialNumber); return(Content <Serialization.ApiResult>(HttpStatusCode.InternalServerError, new Serialization.ApiResult("Incomplete or invalid body"))); } catch (System.Data.Common.DbException ex) { // Do not expose possible sensitive database information from the PassProvider Trace.TraceError("RegisterDevicePass for [{0}, {1}, {2}]: {3}", deviceLibraryIdentifier, passTypeIdentifier, serialNumber, ex.Message); return(Content <Serialization.ApiResult>(HttpStatusCode.InternalServerError, new Serialization.ApiResult("Database Error"))); } catch (Exception ex) { Trace.TraceError("RegisterDevicePass for [{0}, {1}, {2}]: {3}", deviceLibraryIdentifier, passTypeIdentifier, serialNumber, ex.Message); return(Content <Serialization.ApiResult>(HttpStatusCode.InternalServerError, new Serialization.ApiResult(ex.Message))); } }
public IHttpActionResult GetDevicePasses(string deviceLibraryIdentifier, string passTypeIdentifier, string passesUpdatedSince = null) { List <String> passes = null; PassProvider provider = GetProvider(passTypeIdentifier); try { DateTime updatedSince; if (!DateTime.TryParseExact(passesUpdatedSince, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out updatedSince)) { updatedSince = DateTime.MinValue; } passes = provider.GetDevicePasses(deviceLibraryIdentifier, passTypeIdentifier, updatedSince); if (passes == null || !passes.Any()) { return(ResponseMessage(new HttpResponseMessage(HttpStatusCode.NoContent))); } return(Content <Serialization.UpdatedPasses>(HttpStatusCode.OK, new Serialization.UpdatedPasses() { lastUpdated = DateTime.UtcNow.ToString("yyyyMMdd"), serialNumbers = passes })); } catch (System.Data.Common.DbException ex) { // Do not expose possible sensitive database information from the PassProvider Trace.TraceError("GetDevicePasses for [{0}, {1}, {2}]: {3}", deviceLibraryIdentifier, passTypeIdentifier, passesUpdatedSince, ex.Message); return(Content <Serialization.ApiResult>(HttpStatusCode.InternalServerError, new Serialization.ApiResult("Database Error"))); } catch (Exception ex) { Trace.TraceError("GetDevicePasses for [{0}, {1}, {2}]: {3}", deviceLibraryIdentifier, passTypeIdentifier, passesUpdatedSince, ex.Message); return(Content <Serialization.ApiResult>(HttpStatusCode.InternalServerError, new Serialization.ApiResult(ex.Message))); } }
protected IHttpActionResult GeneratePass(PassProvider provider, string serialNumber) { PassGeneratorRequest request = provider.GetPass(serialNumber); if (request != null) { // Passbook webService is configured, enable it in the generated pass if (!string.IsNullOrEmpty(mServiceUrl)) { request.WebServiceUrl = mServiceUrl; request.AuthenticationToken = GenerateAuthorizationToken(provider.PassTypeIdentifier, request.SerialNumber); } PassGenerator passGenerator = new PassGenerator(); byte[] pass = passGenerator.Generate(request); return(new PassbookContentResult(pass)); } return(null); }
public IHttpActionResult UnregisterPass(string deviceLibraryIdentifier, string passTypeIdentifier, string serialNumber) { ValidateAuthorization(Request.Headers.Authorization, passTypeIdentifier, serialNumber); PassProvider provider = GetProvider(passTypeIdentifier); try { provider.UnregisterDevicePass(deviceLibraryIdentifier, passTypeIdentifier, serialNumber); return(Ok <Serialization.ApiResult>(new Serialization.ApiResult("Unregistered pass"))); } catch (System.Data.Common.DbException ex) { // Do not expose possible sensitive database information from the PassProvider Trace.TraceError("UnregisterPass for [{0}, {1}, {2}]: {3}", deviceLibraryIdentifier, passTypeIdentifier, serialNumber, ex.Message); return(Content <Serialization.ApiResult>(HttpStatusCode.InternalServerError, new Serialization.ApiResult("Database Error"))); } catch (Exception ex) { Trace.TraceError("UnregisterPass for [{0}, {1}, {2}]: {3}", deviceLibraryIdentifier, passTypeIdentifier, serialNumber, ex.Message); return(Content <Serialization.ApiResult>(HttpStatusCode.InternalServerError, new Serialization.ApiResult(ex.Message))); } }
protected IHttpActionResult GeneratePass(PassProvider provider, string serialNumber) { PassGeneratorRequest request = provider.GetPass(serialNumber); if (request != null) { // Passbook webService is configured, enable it in the generated pass if (!string.IsNullOrEmpty(mServiceUrl)) { request.WebServiceUrl = mServiceUrl; request.AuthenticationToken = GenerateAuthorizationToken(provider.PassTypeIdentifier, request.SerialNumber); } PassGenerator passGenerator = new PassGenerator(); byte[] pass = passGenerator.Generate(request); return new PassbookContentResult(pass); } return null; }