예제 #1
0
        public Task <IActionResult> Get(int id)
        {
            var getRequest = new GetTopicRequest {
                Id = id
            };
            var response = Client.Get(getRequest);

            if (response.Id > 0)
            {
                return(Task.FromResult <IActionResult>(Ok(
                                                           new GetTopicResponse
                {
                    Id = response.Id,
                    Name = response.Name,
                    Description = response.Description
                }
                                                           )));
            }
            return(Task.FromResult <IActionResult>(
                       BadRequest(
                           new ErrorModel {
                Error = $"There's no topic with id {id}"
            }
                           )));
        }
        public async stt::Task GetTopicResourceNamesAsync()
        {
            moq::Mock <Publisher.PublisherClient> mockGrpcClient = new moq::Mock <Publisher.PublisherClient>(moq::MockBehavior.Strict);
            GetTopicRequest request = new GetTopicRequest
            {
                TopicAsTopicName = TopicName.FromProjectTopic("[PROJECT]", "[TOPIC]"),
            };
            Topic expectedResponse = new Topic
            {
                TopicName = TopicName.FromProjectTopic("[PROJECT]", "[TOPIC]"),
                Labels    =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                MessageStoragePolicy     = new MessageStoragePolicy(),
                KmsKeyName               = "kms_key_name06bd122b",
                SchemaSettings           = new SchemaSettings(),
                SatisfiesPzs             = false,
                MessageRetentionDuration = new wkt::Duration(),
            };

            mockGrpcClient.Setup(x => x.GetTopicAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Topic>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            PublisherServiceApiClient client = new PublisherServiceApiClientImpl(mockGrpcClient.Object, null);
            Topic responseCallSettings       = await client.GetTopicAsync(request.TopicAsTopicName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            Topic responseCancellationToken = await client.GetTopicAsync(request.TopicAsTopicName, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
예제 #3
0
        public async Task GetTopicAsync()
        {
            Mock <Publisher.PublisherClient> mockGrpcClient = new Mock <Publisher.PublisherClient>(MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateIAMPolicyClient())
            .Returns(new Mock <IAMPolicy.IAMPolicyClient>().Object);
            GetTopicRequest expectedRequest = new GetTopicRequest
            {
                TopicAsTopicName = new TopicName("[PROJECT]", "[TOPIC]"),
            };
            Topic expectedResponse = new Topic
            {
                TopicName  = new TopicName("[PROJECT]", "[TOPIC]"),
                KmsKeyName = "kmsKeyName2094986649",
            };

            mockGrpcClient.Setup(x => x.GetTopicAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Topic>(Task.FromResult(expectedResponse), null, null, null, null));
            PublisherServiceApiClient client = new PublisherServiceApiClientImpl(mockGrpcClient.Object, null);
            TopicName topic    = new TopicName("[PROJECT]", "[TOPIC]");
            Topic     response = await client.GetTopicAsync(topic);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
예제 #4
0
        public TopicDTO GetTopicDetail(string ID)
        {
            TopicDTO item = new TopicDTO();

            try
            {
                GetTopicRequest paraBody = new GetTopicRequest();
                paraBody.ID = ID;

                var     result     = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.TopicAPIGetList, null, paraBody);
                dynamic data       = result.Data;
                var     lstDataRaw = data["ListTopic"];
                var     lstObject  = JsonConvert.SerializeObject(lstDataRaw);
                item = JsonConvert.DeserializeObject <List <TopicDTO> >(lstObject)[0];

                NSLog.Logger.Info("TopicGetDetail", item);

                return(item);
            }
            catch (Exception e)
            {
                NSLog.Logger.Error("TopicGetDetail_Fail", e);
                return(item);
            }
        }
        public void GetTopic()
        {
            moq::Mock <Publisher.PublisherClient> mockGrpcClient = new moq::Mock <Publisher.PublisherClient>(moq::MockBehavior.Strict);
            GetTopicRequest request = new GetTopicRequest
            {
                TopicAsTopicName = TopicName.FromProjectTopic("[PROJECT]", "[TOPIC]"),
            };
            Topic expectedResponse = new Topic
            {
                TopicName = TopicName.FromProjectTopic("[PROJECT]", "[TOPIC]"),
                Labels    =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                MessageStoragePolicy     = new MessageStoragePolicy(),
                KmsKeyName               = "kms_key_name06bd122b",
                SchemaSettings           = new SchemaSettings(),
                SatisfiesPzs             = false,
                MessageRetentionDuration = new wkt::Duration(),
            };

            mockGrpcClient.Setup(x => x.GetTopic(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            PublisherServiceApiClient client = new PublisherServiceApiClientImpl(mockGrpcClient.Object, null);
            Topic response = client.GetTopic(request.Topic);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
예제 #6
0
        /// <summary>
        /// Gets the specified topic&#39;s configuration information.
        ///
        /// </summary>
        /// <param name="request">The request object containing the details to send. Required.</param>
        /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param>
        /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param>
        /// <returns>A response object containing details about the completed operation</returns>
        /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/ons/GetTopic.cs.html">here</a> to see an example of how to use GetTopic API.</example>
        public async Task <GetTopicResponse> GetTopic(GetTopicRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
        {
            logger.Trace("Called getTopic");
            Uri                uri            = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/topics/{topicId}".Trim('/')));
            HttpMethod         method         = new HttpMethod("GET");
            HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request);

            requestMessage.Headers.Add("Accept", "application/json");
            GenericRetrier      retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration);
            HttpResponseMessage responseMessage;

            try
            {
                if (retryingClient != null)
                {
                    responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false);
                }
                this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage);

                return(Converter.FromHttpResponseMessage <GetTopicResponse>(responseMessage));
            }
            catch (Exception e)
            {
                logger.Error($"GetTopic failed with error: {e.Message}");
                throw;
            }
        }
예제 #7
0
        public override Task <GetTopicResponse> Get(GetTopicRequest request, ServerCallContext context)
        {
            var topic    = _topicService.Get(request.Id);
            var response = new GetTopicResponse {
                Id = topic.Id, Description = topic.Description, Name = topic.Name
            };

            return(Task.FromResult(response));
        }
예제 #8
0
        /// <summary>
        /// Gets the configuration of a topic.
        /// </summary>
        /// <param name="topic">The name of the topic to get.</param>
        /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
        /// <returns>The RPC response.</returns>
        public override Topic GetTopic(
            string topic,
            CallSettings callSettings = null)
        {
            GetTopicRequest request = new GetTopicRequest
            {
                Topic = topic,
            };

            return(GrpcClient.GetTopic(
                       request,
                       _clientHelper.BuildCallOptions(null, callSettings)));
        }
 public void GetTopic_RequestObject()
 {
     // Snippet: GetTopic(GetTopicRequest,CallSettings)
     // Create client
     PublisherClient publisherClient = PublisherClient.Create();
     // Initialize request argument(s)
     GetTopicRequest request = new GetTopicRequest
     {
         TopicAsTopicName = new TopicName("[PROJECT]", "[TOPIC]"),
     };
     // Make the request
     Topic response = publisherClient.GetTopic(request);
     // End snippet
 }
예제 #10
0
        /// <summary>
        /// Gets the configuration of a topic.
        /// </summary>
        /// <param name="topic">The name of the topic to get.</param>
        /// <param name="cancellationToken">If not null, a <see cref="CancellationToken"/> to use for this RPC.</param>
        /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
        /// <returns>A Task containing the RPC response.</returns>
        public override Task <Topic> GetTopicAsync(
            string topic,
            CancellationToken?cancellationToken = null,
            CallSettings callSettings           = null)
        {
            GetTopicRequest request = new GetTopicRequest
            {
                Topic = topic,
            };

            return(GrpcClient.GetTopicAsync(
                       request,
                       _clientHelper.BuildCallOptions(cancellationToken, callSettings)
                       ).ResponseAsync);
        }
예제 #11
0
        /// <summary>
        /// 获取Topic信息
        /// </summary>
        /// <param name="req">参考<see cref="GetTopicRequest"/></param>
        /// <returns>参考<see cref="GetTopicResponse"/>实例</returns>
        public async Task <GetTopicResponse> GetTopic(GetTopicRequest req)
        {
            JsonResponseModel <GetTopicResponse> rsp = null;

            try
            {
                var strResp = await this.InternalRequest(req, "GetTopic");

                rsp = JsonConvert.DeserializeObject <JsonResponseModel <GetTopicResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
        /// <summary>Snippet for GetTopicAsync</summary>
        public async Task GetTopicAsync_RequestObject()
        {
            // Snippet: GetTopicAsync(GetTopicRequest,CallSettings)
            // Create client
            PublisherServiceApiClient publisherServiceApiClient = await PublisherServiceApiClient.CreateAsync();

            // Initialize request argument(s)
            GetTopicRequest request = new GetTopicRequest
            {
                TopicAsTopicName = new TopicName("[PROJECT]", "[TOPIC]"),
            };
            // Make the request
            Topic response = await publisherServiceApiClient.GetTopicAsync(request);

            // End snippet
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            GetTopicRequest request;

            try
            {
                request = new GetTopicRequest
                {
                    TopicId      = TopicId,
                    OpcRequestId = OpcRequestId
                };

                response = client.GetTopic(request).GetAwaiter().GetResult();
                WriteOutput(response, response.NotificationTopic);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
        /// <summary>
        /// Gets the specified topic's configuration information.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <GetTopicResponse> GetTopic(GetTopicRequest request)
        {
            var uri = new Uri($"{GetEndPoint(NotificationServices.Topics, this.Region)}/{request.TopicId}");

            var httpRequestHeaderParam = new HttpRequestHeaderParam()
            {
                OpcRequestId = request.OpcRequestId
            };
            var webResponse = await this.RestClientAsync.Get(uri, httpRequestHeaderParam);

            using (var stream = webResponse.GetResponseStream())
                using (var reader = new StreamReader(stream))
                {
                    var response = reader.ReadToEnd();

                    return(new GetTopicResponse()
                    {
                        NotificationTopic = this.JsonSerializer.Deserialize <NotificationTopicDetails>(response),
                        OpcRequestId = webResponse.Headers.Get("opc-request-id"),
                        ETag = webResponse.Headers.Get("etag")
                    });
                }
        }
예제 #15
0
        public void GetTopic2()
        {
            Mock <Publisher.PublisherClient> mockGrpcClient = new Mock <Publisher.PublisherClient>(MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateIAMPolicyClient())
            .Returns(new Mock <IAMPolicy.IAMPolicyClient>().Object);
            GetTopicRequest request = new GetTopicRequest
            {
                TopicAsTopicName = new TopicName("[PROJECT]", "[TOPIC]"),
            };
            Topic expectedResponse = new Topic
            {
                TopicName = new TopicName("[PROJECT]", "[TOPIC]"),
            };

            mockGrpcClient.Setup(x => x.GetTopic(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            PublisherServiceApiClient client = new PublisherServiceApiClientImpl(mockGrpcClient.Object, null);
            Topic response = client.GetTopic(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
예제 #16
0
        public List <TopicModel> GetListTopicData(string SearchString = null)
        {
            List <TopicModel> listData = new List <TopicModel>();

            try
            {
                GetTopicRequest paraBody = new GetTopicRequest();

                var     result     = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.TopicAPIGetList, null, paraBody);
                dynamic data       = result.Data;
                var     lstDataRaw = data["ListTopic"];
                var     lstObject  = JsonConvert.SerializeObject(lstDataRaw);
                listData = JsonConvert.DeserializeObject <List <TopicModel> >(lstObject);

                NSLog.Logger.Info("TopicGetListData", listData);

                return(listData);
            }
            catch (Exception e)
            {
                NSLog.Logger.Error("TopicGetListData_Fail", e);
                return(listData);
            }
        }