/// <summary>
        /// Initiates the asynchronous execution of the GetEndpointAttributes operation.
        /// <seealso cref="Amazon.SimpleNotificationService.IAmazonSimpleNotificationService"/>
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the GetEndpointAttributes 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 <GetEndpointAttributesResponse> GetEndpointAttributesAsync(GetEndpointAttributesRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new GetEndpointAttributesRequestMarshaller();
            var unmarshaller = GetEndpointAttributesResponseUnmarshaller.Instance;

            return(Invoke <IRequest, GetEndpointAttributesRequest, GetEndpointAttributesResponse>(request, marshaller, unmarshaller, signer, cancellationToken));
        }
Ejemplo n.º 2
0
        internal GetEndpointAttributesResponse GetEndpointAttributes(GetEndpointAttributesRequest request)
        {
            var marshaller   = new GetEndpointAttributesRequestMarshaller();
            var unmarshaller = GetEndpointAttributesResponseUnmarshaller.Instance;

            return(Invoke <GetEndpointAttributesRequest, GetEndpointAttributesResponse>(request, marshaller, unmarshaller));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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 GetEndpointAttributesResponse GetEndpointAttributes(GetEndpointAttributesRequest request)
        {
            var task = GetEndpointAttributesAsync(request);

            try
            {
                return(task.Result);
            }
            catch (AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return(null);
            }
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
 public Task <GetEndpointAttributesResponse> GetEndpointAttributesAsync(GetEndpointAttributesRequest request, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 8
0
 public GetEndpointAttributesResponse GetEndpointAttributes(GetEndpointAttributesRequest request)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 9
0
 public void GetEndpointAttributesAsync(GetEndpointAttributesRequest request, AmazonServiceCallback <GetEndpointAttributesRequest, GetEndpointAttributesResponse> callback, AsyncOptions options = null)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 10
0
 public Task <GetEndpointAttributesResponse> GetEndpointAttributesAsync(GetEndpointAttributesRequest request, CancellationToken cancellationToken = new CancellationToken())
 {
     throw new NotImplementedException();
 }