private static void UnmarshallResult(XmlUnmarshallerContext context, GetEndpointAttributesResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("Attributes/entry", targetDepth)) { var unmarshaller = new KeyValueUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance); var item = unmarshaller.Unmarshall(context); response.Attributes.Add(item); continue; } } } return; }
private static void UnmarshallResult(XmlUnmarshallerContext context, GetEndpointAttributesResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.Read()) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("Attributes/entry", targetDepth)) { KeyValueUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller> unmarshaller = new KeyValueUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.GetInstance(), StringUnmarshaller.GetInstance()); KeyValuePair <string, string> kvp = unmarshaller.Unmarshall(context); response.Attributes.Add(kvp.Key, kvp.Value); continue; } } else if (context.IsEndElement && context.CurrentDepth < originalDepth) { return; } } return; }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { GetEndpointAttributesResponse response = new GetEndpointAttributesResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.IsStartElement) { if (context.TestExpression("GetEndpointAttributesResult", 2)) { UnmarshallResult(context, response); continue; } if (context.TestExpression("ResponseMetadata", 2)) { response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context); } } } return(response); }
public async Task <RegisterSuccessfulResult> RegisterSubscriberAsync(RegisterSubscriberModel model) { this.model = model; DynamoSubscriber subscriber = await subscribersTableOperator.GetSubscriberAsync(model.UserId, model.Token); // AWS SNS Mobile Push Algorithm // Check: http://docs.aws.amazon.com/sns/latest/dg/mobile-platform-endpoint.html bool updateNeeded = false; bool createNeeded = (subscriber == null); if (createNeeded) { subscriber = await CreateSubscriberAsync(null); createNeeded = false; } // Look up the endpoint and make sure the data in it is current, even if it was just created try { GetEndpointAttributesRequest geaRequest = new GetEndpointAttributesRequest(); geaRequest.EndpointArn = subscriber.EndpointARN; GetEndpointAttributesResponse geaResponse = await snsClient.GetEndpointAttributesAsync(geaRequest); updateNeeded = !geaResponse.Attributes["Token"].Equals(subscriber.NotificationToken) || !geaResponse.Attributes["Enabled"].Equals("true", StringComparison.OrdinalIgnoreCase); } catch (NotFoundException) { // We had a stored ARN, but the endpoint associated with it disappeared. Recreate it. createNeeded = true; } if (createNeeded) { subscriber = await CreateSubscriberAsync(subscriber); } if (updateNeeded) { // Endpoint is out of sync with the current data. Update the token and enable it. Dictionary <string, string> attrs = new Dictionary <string, string>(); attrs["Token"] = subscriber.NotificationToken; attrs["Enabled"] = "true"; SetEndpointAttributesRequest seaRequest = new SetEndpointAttributesRequest(); seaRequest.Attributes = attrs; seaRequest.EndpointArn = subscriber.EndpointARN; await snsClient.SetEndpointAttributesAsync(seaRequest); } if (tagOperator.IsTaggingAvailable()) { await tagOperator.SubscribeToTagsAsync(subscriber, model.Tags); } RegisterSuccessfulResult result = new RegisterSuccessfulResult(); result.EndpointArn = subscriber.EndpointARN; return(result); }
public static async Task RegisterDevice(Platform platform, string registrationId) { var arn = string.Empty; var _endpointArn = string.Empty; switch (platform) { case Platform.Android: arn = Constants.AndroidPlatformApplicationArn; break; case Platform.IOS: arn = Constants.iOSPlatformApplicationArn; break; } var response = new CreatePlatformEndpointResponse(); var userData = ""; try { if (!string.IsNullOrWhiteSpace(Settings.Uid)) { // Add Your User Data Here //userData = Settings.Uid; } if (string.IsNullOrEmpty(Settings.Arnsns)) { response = await SnsClient.CreatePlatformEndpointAsync(new CreatePlatformEndpointRequest { Token = registrationId, PlatformApplicationArn = arn, CustomUserData = userData }); Settings.Arnsns = response.EndpointArn; } } catch (Exception ex) { Debug.WriteLine("Error: " + ex); } if (!string.IsNullOrWhiteSpace(Settings.Arnsns)) { var results = new GetEndpointAttributesResponse(); try { var test = new GetEndpointAttributesRequest(); test.EndpointArn = Settings.Arnsns; results = await SnsClient.GetEndpointAttributesAsync(test); } catch (Exception ex) { Debug.WriteLine("Error" + ex); } if (results.Attributes == null || results.Attributes.Count == 0) { response = await SnsClient.CreatePlatformEndpointAsync(new CreatePlatformEndpointRequest { Token = registrationId, PlatformApplicationArn = arn, CustomUserData = userData }); Settings.Arnsns = response.EndpointArn; } else if (results.Attributes["Token"] != registrationId) { var updateToken = new SetEndpointAttributesRequest(); updateToken.Attributes.Add("Token", registrationId); updateToken.Attributes.Add("Enabled", "true"); updateToken.EndpointArn = Settings.Arnsns; var update = await SnsClient.SetEndpointAttributesAsync(updateToken); } } _endpointArn = response.EndpointArn; }