private async Task<Registration> upsertRegistrationInternal(Registration registration) { Connection conn = new Connection(Connection); String resource = Path + "/Registrations/" + registration.RegistrationId; String content = registration.ToXml(); try { String response = await conn.executeRequest(resource, content, XML_CONTENT_TYPE, HttpMethod.Put, null); Registration result = new Registration(); result.loadXml(response, Path); storeRegistrationId(result.Name, result.RegistrationId, registration.ChannelUri); return result; } catch (Exception ex) { throw ex; } }
private async Task<String> createRegistrationId() { try { Connection conn = new Connection(Connection); String resource = Path + "/registrationIDs/"; String response = await conn.executeRequest(resource, null, XML_CONTENT_TYPE, HttpMethod.Post, NEW_REGISTRATION_LOCATION_HEADER, null); Uri regIdUri = new Uri(response); String[] pathFragments = regIdUri.AbsolutePath.Split('/'); String result = pathFragments[pathFragments.Length - 1]; return result; } catch (Exception ex) { throw ex; } }
private async Task deleteRegistrationInternal(String registrationId) { Connection conn = new Connection(Connection); String resource = Path + "/Registrations/" + registrationId; Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add("If-Match", "*"); try { await conn.executeRequest(resource, null, XML_CONTENT_TYPE, HttpMethod.Delete, headers); } catch (Exception ex) { throw ex; } finally { removeRegistrationId(); } }