/// <summary> /// Initiates the asynchronous execution of the SetEndpointAttributes operation. /// <seealso cref="Amazon.SimpleNotificationService.IAmazonSimpleNotificationService"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the SetEndpointAttributes operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <SetEndpointAttributesResponse> SetEndpointAttributesAsync(SetEndpointAttributesRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new SetEndpointAttributesRequestMarshaller(); var unmarshaller = SetEndpointAttributesResponseUnmarshaller.Instance; return(Invoke <IRequest, SetEndpointAttributesRequest, SetEndpointAttributesResponse>(request, marshaller, unmarshaller, signer, cancellationToken)); }
internal SetEndpointAttributesResponse SetEndpointAttributes(SetEndpointAttributesRequest request) { var marshaller = new SetEndpointAttributesRequestMarshaller(); var unmarshaller = SetEndpointAttributesResponseUnmarshaller.Instance; return(Invoke <SetEndpointAttributesRequest, SetEndpointAttributesResponse>(request, marshaller, unmarshaller)); }
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 bool AddDevice(string DeviceToken, out string DeviceARN) { DeviceARN = null; try { using (var client = CreateClient()) { var request = new CreatePlatformEndpointRequest { PlatformApplicationArn = ApplicationARN, Token = DeviceToken }; var response = client.CreatePlatformEndpoint(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { DeviceARN = response.EndpointArn; var attributeRequest = new GetEndpointAttributesRequest() { EndpointArn = DeviceARN }; var attributeResponse = client.GetEndpointAttributes(attributeRequest); if (attributeResponse.Attributes["Token"] != DeviceARN || attributeResponse.Attributes["Enabled"].ToLower() != "true") { var updateRequest = new SetEndpointAttributesRequest() { EndpointArn = DeviceARN, Attributes = new Dictionary <string, string>() { { "Token", DeviceToken }, { "Enabled", "true" } } }; var updateResponse = client.SetEndpointAttributes(updateRequest); return(updateResponse.HttpStatusCode == System.Net.HttpStatusCode.OK); } else { return(true); } } else { return(false); } } } catch (Exception ex) { Entities.Log.Error("SNS.CreateDeviceEndpoint", ex); return(false); } }
internal SetEndpointAttributesResponse SetEndpointAttributes(SetEndpointAttributesRequest request) { var task = SetEndpointAttributesAsync(request); try { return(task.Result); } catch (AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return(null); } }
public static async void UpdateUser(string Uid) { if (!string.IsNullOrWhiteSpace(Settings.Arnsns)) { var updateToken = new SetEndpointAttributesRequest(); updateToken.Attributes.Add("CustomUserData", Uid); updateToken.EndpointArn = Settings.Arnsns; try { var update = await SnsClient.SetEndpointAttributesAsync(updateToken); } catch { // Someone has deleted the ARN from the server manually, need to uninstall the app to get a new ARN, or eventually re-register the device here } } }
public static void SNSMobilePushAPIsSetEndpointAttributes() { #region SNSMobilePushAPIsSetEndpointAttributes var snsClient = new AmazonSimpleNotificationServiceClient(); var request = new SetEndpointAttributesRequest { EndpointArn = "arn:aws:sns:us-east-1:80398EXAMPLE:" + "endpoint/GCM/TimeCardProcessingApplication/" + "d84b5f0d-7136-3bbe-9b42-4e001EXAMPLE", Attributes = new Dictionary <string, string>() { { "Enabled", "true" } } }; snsClient.SetEndpointAttributes(request); #endregion }
/// <summary> /// Atualiza o registro de endpoint de notificação no SNS /// </summary> /// <param name="device"></param> /// <returns></returns> public static string UpdateNotificationEndpoint(DeviceEntity device) { SetEndpointAttributesRequest request = new SetEndpointAttributesRequest() { EndpointArn = device.BrokerEndpoint, }; Dictionary <string, string> atributes = new Dictionary <string, string>(); atributes.Add("Token", device.Endpoint); atributes.Add("Enabled", "true"); request.Attributes = atributes; var result = AWSFactory.SNSClient.SetEndpointAttributes(request); if (result.HttpStatusCode == System.Net.HttpStatusCode.OK) { return(device.BrokerEndpoint); } return(null); }
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; }
public Task <SetEndpointAttributesResponse> SetEndpointAttributesAsync(SetEndpointAttributesRequest request, CancellationToken cancellationToken = default(CancellationToken)) { throw new System.NotImplementedException(); }
public SetEndpointAttributesResponse SetEndpointAttributes(SetEndpointAttributesRequest request) { throw new System.NotImplementedException(); }
public void SetEndpointAttributesAsync(SetEndpointAttributesRequest request, AmazonServiceCallback <SetEndpointAttributesRequest, SetEndpointAttributesResponse> callback, AsyncOptions options = null) { throw new System.NotImplementedException(); }
public Task <SetEndpointAttributesResponse> SetEndpointAttributesAsync(SetEndpointAttributesRequest request, CancellationToken cancellationToken = new CancellationToken()) { throw new NotImplementedException(); }