コード例 #1
0
ファイル: Topic.cs プロジェクト: netcorepal/aliyun.mns
 /// <inheritdoc/>
 public SetTopicAttributesResponse SetAttributes(SetTopicAttributesRequest request)
 {
     return(AggregateExceptionExtract.Extract(() =>
     {
         return SetAttributesAsync(request).Result;
     }));
 }
コード例 #2
0
        internal SetTopicAttributesResponse SetTopicAttributes(SetTopicAttributesRequest request)
        {
            var marshaller   = new SetTopicAttributesRequestMarshaller();
            var unmarshaller = SetTopicAttributesResponseUnmarshaller.Instance;

            return(Invoke <SetTopicAttributesRequest, SetTopicAttributesResponse>(request, marshaller, unmarshaller));
        }
コード例 #3
0
        /// <summary>
        /// Initiates the asynchronous execution of the SetTopicAttributes operation.
        /// <seealso cref="Amazon.SimpleNotificationService.IAmazonSimpleNotificationService"/>
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the SetTopicAttributes 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 <SetTopicAttributesResponse> SetTopicAttributesAsync(SetTopicAttributesRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new SetTopicAttributesRequestMarshaller();
            var unmarshaller = SetTopicAttributesResponseUnmarshaller.Instance;

            return(Invoke <IRequest, SetTopicAttributesRequest, SetTopicAttributesResponse>(request, marshaller, unmarshaller, signer, cancellationToken));
        }
        private async Task EnsureServerSideEncryptionIsUpdatedAsync(ServerSideEncryption config)
        {
            if (ServerSideEncryptionNeedsUpdating(config))
            {
                var request = new SetTopicAttributesRequest
                {
                    TopicArn       = Arn,
                    AttributeName  = JustSayingConstants.AttributeEncryptionKeyId,
                    AttributeValue = config?.KmsMasterKeyId ?? string.Empty
                };

                var response = await Client.SetTopicAttributesAsync(request).ConfigureAwait(false);

                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    ServerSideEncryption = string.IsNullOrEmpty(config?.KmsMasterKeyId)
                        ? null
                        : config;
                }
                else
                {
                    _log.LogWarning(
                        "Request to set topic attribute '{TopicAttributeName}' to '{TopicAttributeValue}' failed with status code '{HttpStatusCode}'.",
                        request.AttributeName,
                        request.AttributeValue,
                        response.HttpStatusCode);
                }
            }
        }
コード例 #5
0
ファイル: Topic.cs プロジェクト: netcorepal/aliyun.mns
        public async Task <SetTopicAttributesResponse> SetAttributesAsync(TopicAttributes attributes)
        {
            var request = new SetTopicAttributesRequest {
                Attributes = attributes
            };

            return(await SetAttributesAsync(request).ConfigureAwait(false));
        }
コード例 #6
0
ファイル: Topic.cs プロジェクト: EsonXie/Aliyun.MNS.Standrad
        /// <inheritdoc/>
        public SetTopicAttributesResponse SetAttributes(TopicAttributes attributes)
        {
            var request = new SetTopicAttributesRequest {
                Attributes = attributes
            };

            return(SetAttributes(request));
        }
コード例 #7
0
ファイル: Topic.cs プロジェクト: netcorepal/aliyun.mns
        public async Task <SetTopicAttributesResponse> SetAttributesAsync(SetTopicAttributesRequest request)
        {
            request.TopicName = this.TopicName;

            var marshaller   = new SetTopicAttributesRequestMarshaller();
            var unmarshaller = SetTopicAttributesResponseUnmarshaller.Instance;

            return(await _serviceClient.InvokeAsync <SetTopicAttributesRequest, SetTopicAttributesResponse>(request, marshaller, unmarshaller).ConfigureAwait(false));
        }
コード例 #8
0
ファイル: Topic.cs プロジェクト: EsonXie/Aliyun.MNS.Standrad
        /// <inheritdoc/>
        public SetTopicAttributesResponse SetAttributes(SetTopicAttributesRequest request)
        {
            request.TopicName = this.TopicName;

            var marshaller   = new SetTopicAttributesRequestMarshaller();
            var unmarshaller = SetTopicAttributesResponseUnmarshaller.Instance;

            return(_serviceClient.Invoke <SetTopicAttributesRequest, SetTopicAttributesResponse>(request, marshaller, unmarshaller));
        }
コード例 #9
0
ファイル: Topic.cs プロジェクト: EsonXie/Aliyun.MNS.Standrad
        /// <inheritdoc/>
        public IAsyncResult BeginSetAttributes(SetTopicAttributesRequest request, AsyncCallback callback, object state)
        {
            request.TopicName = this.TopicName;

            var marshaller   = new SetTopicAttributesRequestMarshaller();
            var unmarshaller = SetTopicAttributesResponseUnmarshaller.Instance;

            return(_serviceClient.BeginInvoke <SetTopicAttributesRequest>(request, marshaller, unmarshaller,
                                                                          callback, state));
        }
コード例 #10
0
ファイル: SNS.cs プロジェクト: ShowOps/aws-sdk-net
        public void CRUDTopics()
        {
            // list all topics
            var allTopics         = GetAllTopics();
            var currentTopicCount = allTopics.Count;

            // create new topic
            var name = "dotnetsdk" + DateTime.Now.Ticks;
            var createTopicRequest = new CreateTopicRequest
            {
                Name = name
            };
            var createTopicResult = Client.CreateTopic(createTopicRequest);
            var topicArn          = createTopicResult.TopicArn;

            try
            {
                // verify there is a new topic
                allTopics = GetAllTopics();
                Assert.AreNotEqual(currentTopicCount, allTopics.Count);

                // set topic attribute
                var setTopicAttributesRequest = new SetTopicAttributesRequest
                {
                    TopicArn       = topicArn,
                    AttributeName  = "DisplayName",
                    AttributeValue = "Test topic"
                };
                Client.SetTopicAttributes(setTopicAttributesRequest);

                // verify topic attributes
                var getTopicAttributesRequest = new GetTopicAttributesRequest
                {
                    TopicArn = topicArn
                };
                var topicAttributes =
                    Client.GetTopicAttributes(getTopicAttributesRequest).Attributes;
                Assert.AreEqual(setTopicAttributesRequest.AttributeValue,
                                topicAttributes[setTopicAttributesRequest.AttributeName]);
            }
            finally
            {
                // delete new topic
                var deleteTopicRequest = new DeleteTopicRequest
                {
                    TopicArn = topicArn
                };
                Client.DeleteTopic(deleteTopicRequest);

                // verify the topic was deleted
                allTopics = GetAllTopics();
                Assert.AreEqual(currentTopicCount, allTopics.Count);
            }
        }
コード例 #11
0
        internal SetTopicAttributesResponse SetTopicAttributes(SetTopicAttributesRequest request)
        {
            var task = SetTopicAttributesAsync(request);

            try
            {
                return(task.Result);
            }
            catch (AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return(null);
            }
        }
コード例 #12
0
        private async Task SaveAsync(string sourceArn, IAmazonSimpleNotificationService client)
        {
            ActionIdentifier[] actions = { SNSActionIdentifiers.Subscribe };

            var snsPolicy = new Policy()
                            .WithStatements(GetDefaultStatement(sourceArn))
                            .WithStatements(new Statement(Statement.StatementEffect.Allow)
                                            .WithPrincipals(_accountIds.Select(a => new Principal(a)).ToArray())
                                            .WithResources(new Resource(sourceArn))
                                            .WithActionIdentifiers(actions));
            var attributeValue            = snsPolicy.ToJson();
            var setQueueAttributesRequest = new SetTopicAttributesRequest(sourceArn, "Policy", attributeValue);

            await client.SetTopicAttributesAsync(setQueueAttributesRequest).ConfigureAwait(false);
        }
コード例 #13
0
        internal static async Task SaveAsync(SnsPolicyDetails policyDetails, IAmazonSimpleNotificationService client)
        {
            var sourceAccountId           = ExtractSourceAccountId(policyDetails.SourceArn);
            var policyJson                = $@"{{
    ""Version"" : ""2012-10-17"",
    ""Statement"" : [
        {{
            ""Sid"" : ""{Guid.NewGuid().ToString().Replace("-", "")}"",
            ""Effect"" : ""Allow"",
            ""Principal"" : {{
                ""AWS"" : ""*""
            }},
            ""Action""    : [
                ""sns:GetTopicAttributes"",
                ""sns:SetTopicAttributes"",
                ""sns:AddPermission"",
                ""sns:RemovePermission"",
                ""sns:DeleteTopic"",
                ""sns:Subscribe"",
                ""sns:Publish""
            ],
            ""Resource""  : ""{policyDetails.SourceArn}"",
            ""Condition"" : {{
                ""StringEquals"" : {{
                    ""AWS:SourceOwner"" : ""{sourceAccountId}""
                }}
            }}
        }},
        {{
            ""Sid"" : ""{Guid.NewGuid().ToString().Replace("-", "")}"",
            ""Effect"" : ""Allow"",
            ""Principal"" : {{
                ""AWS"" : {JsonSerializer.Serialize(policyDetails.AccountIds)}
            }},
            ""Action""    : ""sns:Subscribe"",
            ""Resource""  : ""{policyDetails.SourceArn}""
        }}
    ]
}}";
            var setQueueAttributesRequest = new SetTopicAttributesRequest(policyDetails.SourceArn, "Policy", policyJson);

            await client.SetTopicAttributesAsync(setQueueAttributesRequest).ConfigureAwait(false);
        }
コード例 #14
0
        /**
         * Convert SetTopicAttributesRequest to name value pairs
         */
        private static IDictionary<string, string> ConvertSetTopicAttributes(SetTopicAttributesRequest request)
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>();
            parameters["Action"] = "SetTopicAttributes";
            if (request.IsSetTopicArn())
            {
                parameters["TopicArn"] = request.TopicArn;
            }
            if (request.IsSetAttributeName())
            {
                parameters["AttributeName"] = request.AttributeName;
            }
            if (request.IsSetAttributeValue())
            {
                parameters["AttributeValue"] = request.AttributeValue;
            }

            return parameters;
        }
コード例 #15
0
        private static IDictionary <string, string> ConvertSetTopicAttributes(SetTopicAttributesRequest request)
        {
            IDictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary["Action"] = "SetTopicAttributes";
            if (request.IsSetTopicArn())
            {
                dictionary["TopicArn"] = request.TopicArn;
            }
            if (request.IsSetAttributeName())
            {
                dictionary["AttributeName"] = request.AttributeName;
            }
            if (request.IsSetAttributeValue())
            {
                dictionary["AttributeValue"] = request.AttributeValue;
            }
            return(dictionary);
        }
コード例 #16
0
ファイル: SNS.cs プロジェクト: MottoYang/aws-sdk-net
        public async Task CRUDTopics()
        {
            // list all topics
            var allTopics = await GetAllTopics();

            // create new topic
            var name = UtilityMethods.GenerateName("CrudTopics");
            var createTopicRequest = new CreateTopicRequest
            {
                Name = name
            };
            var createTopicResult = await Client.CreateTopicAsync(createTopicRequest);

            var topicArn = createTopicResult.TopicArn;

            _topicArns.Add(topicArn);

            // verify there is a new topic
            allTopics = await GetAllTopics();

            Assert.True(allTopics.Exists(t => t.TopicArn.Contains(name)));

            // set topic attribute
            var setTopicAttributesRequest = new SetTopicAttributesRequest
            {
                TopicArn       = topicArn,
                AttributeName  = "DisplayName",
                AttributeValue = "Test topic"
            };
            await Client.SetTopicAttributesAsync(setTopicAttributesRequest);

            // verify topic attributes
            var getTopicAttributesRequest = new GetTopicAttributesRequest
            {
                TopicArn = topicArn
            };
            var topicAttributes =
                (await Client.GetTopicAttributesAsync(getTopicAttributesRequest)).Attributes;

            Assert.Equal(setTopicAttributesRequest.AttributeValue,
                         topicAttributes[setTopicAttributesRequest.AttributeName]);
        }
コード例 #17
0
        public Task <string> CreateTopicAsync(string topicName, IDictionary <string, string>?attributes = null)
        {
            if (string.IsNullOrWhiteSpace(topicName))
            {
                throw new ArgumentException($"A non-null/empty '{topicName}' is required.", nameof(topicName));
            }

            return(createTopicAsync());

            async Task <string> createTopicAsync()
            {
                var response = await _sns.CreateTopicAsync(topicName);

                if (response.HttpStatusCode != HttpStatusCode.OK)
                {
                    throw new InvalidOperationException($"Topic creation failed for topic '{topicName}'.");
                }

                if (attributes != null && attributes.Any())
                {
                    foreach (var attribute in attributes)
                    {
                        var request = new SetTopicAttributesRequest
                        {
                            AttributeName  = attribute.Key,
                            AttributeValue = attribute.Value,
                            TopicArn       = response.TopicArn
                        };

                        var setTopicResponse = await _sns.SetTopicAttributesAsync(request);

                        if (setTopicResponse.HttpStatusCode != HttpStatusCode.OK)
                        {
                            throw new InvalidOperationException($"Unable to set attributes for topic '{topicName}'");
                        }
                    }
                }

                return(response.TopicArn);
            }
        }
コード例 #18
0
 public SetTopicAttributesResponse SetTopicAttributes(SetTopicAttributesRequest request)
 {
     throw new System.NotImplementedException();
 }
コード例 #19
0
 /// <summary>
 /// Set Topic Attributes
 /// </summary>
 /// <param name="request">Set Topic Attributes  request</param>
 /// <returns>Set Topic Attributes  Response from the service</returns>
 /// <remarks>
 /// The SetTopicAttributes action allows a topic owner to set an attribute of the topic to a new value.
 /// </remarks>
 public SetTopicAttributesResponse SetTopicAttributes(SetTopicAttributesRequest request)
 {
     return(Invoke <SetTopicAttributesResponse>(ConvertSetTopicAttributes(request)));
 }
コード例 #20
0
ファイル: SNSSamples.cs プロジェクト: philasmar/aws-sdk-net
        public static void SNSCreateSubscribePublish()
        {
            #region SNSCreateSubscribePublish
            var snsClient = new AmazonSimpleNotificationServiceClient();

            var topicRequest = new CreateTopicRequest
            {
                Name = "CodingTestResults"
            };

            var topicResponse = snsClient.CreateTopic(topicRequest);

            var topicAttrRequest = new SetTopicAttributesRequest
            {
                TopicArn       = topicResponse.TopicArn,
                AttributeName  = "DisplayName",
                AttributeValue = "Coding Test Results"
            };

            snsClient.SetTopicAttributes(topicAttrRequest);

            snsClient.Subscribe(new SubscribeRequest
            {
                Endpoint = "*****@*****.**",
                Protocol = "email",
                TopicArn = topicResponse.TopicArn
            });

            // Wait for up to 2 minutes for the user to confirm the subscription.
            DateTime latest = DateTime.Now + TimeSpan.FromMinutes(2);

            while (DateTime.Now < latest)
            {
                var subsRequest = new ListSubscriptionsByTopicRequest
                {
                    TopicArn = topicResponse.TopicArn
                };

                var subs = snsClient.ListSubscriptionsByTopic(subsRequest).Subscriptions;

                var sub = subs[0];

                if (!string.Equals(sub.SubscriptionArn,
                                   "PendingConfirmation", StringComparison.Ordinal))
                {
                    break;
                }

                // Wait 15 seconds before trying again.
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(15));
            }

            snsClient.Publish(new PublishRequest
            {
                Subject = "Coding Test Results for " +
                          DateTime.Today.ToShortDateString(),
                Message  = "All of today's coding tests passed.",
                TopicArn = topicResponse.TopicArn
            });
            #endregion
        }
コード例 #21
0
 public void SetTopicAttributesAsync(SetTopicAttributesRequest request, AmazonServiceCallback <SetTopicAttributesRequest, SetTopicAttributesResponse> callback, AsyncOptions options = null)
 {
     throw new System.NotImplementedException();
 }
コード例 #22
0
        public async Task <IActionResult> SNS()
        {
            var results = new List <string>();

            var topicRequest = new CreateTopicRequest {
                Name = "borislav-topic-1"
            };
            var topicResponse = await _snsClient.CreateTopicAsync(topicRequest);

            results.Add($"Topic '{topicRequest.Name}' created with status {topicResponse.HttpStatusCode}");

            var topicAttrRequest = new SetTopicAttributesRequest
            {
                TopicArn       = topicResponse.TopicArn,
                AttributeName  = "DisplayName",
                AttributeValue = "Coding Test Results"
            };
            await _snsClient.SetTopicAttributesAsync(topicAttrRequest);

            var subscribeRequest = new SubscribeRequest
            {
                Endpoint = "*****@*****.**",
                Protocol = "email",
                TopicArn = topicResponse.TopicArn
            };
            SubscribeResponse subscribeResponse = await _snsClient.SubscribeAsync(subscribeRequest);

            results.Add($"Invitation sent by email with status {subscribeResponse.HttpStatusCode}");
            results.Add("Wait for up to 2 min for the user to confirm the subscription");

            // Wait for up to 2 minutes for the user to confirm the subscription.
            DateTime latest = DateTime.Now + TimeSpan.FromMinutes(2);

            while (DateTime.Now < latest)
            {
                var subsRequest = new ListSubscriptionsByTopicRequest
                {
                    TopicArn = topicResponse.TopicArn
                };

                var subs = _snsClient.ListSubscriptionsByTopicAsync(subsRequest).Result.Subscriptions;

                if (!string.Equals(subs[0].SubscriptionArn, "PendingConfirmation", StringComparison.Ordinal))
                {
                    break;
                }

                // Wait 15 seconds before trying again.
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(15));
            }

            var publishRequest = new PublishRequest
            {
                Subject  = "Coding Test Results for " + DateTime.Today.ToShortDateString(),
                Message  = "All of today's coding tests passed",
                TopicArn = topicResponse.TopicArn
            };
            PublishResponse publishResponse = await _snsClient.PublishAsync(publishRequest);

            results.Add($"Message '{publishRequest.Message}' published with status {topicResponse.HttpStatusCode}");

            ViewBag.Results = new List <string>();
            ViewBag.Results.AddRange(results);

            return(View());
        }
コード例 #23
0
 public Task <SetTopicAttributesResponse> SetTopicAttributesAsync(SetTopicAttributesRequest request, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new System.NotImplementedException();
 }
コード例 #24
0
 public Task <SetTopicAttributesResponse> SetTopicAttributesAsync(SetTopicAttributesRequest request, CancellationToken cancellationToken = new CancellationToken())
 {
     throw new NotImplementedException();
 }