/// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>  
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateSubscriptionResponse response = new CreateSubscriptionResponse();


            return response;
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateSubscriptionResponse response = new CreateSubscriptionResponse();


            return(response);
        }
Exemplo n.º 3
0
        public void CreateSubscriptionAsyncNull()
        {
            var response = new CreateSubscriptionResponse();
            var channel  = new TestRequestChannel(response);

            channel.Invoking(c => c.CreateSubscriptionAsync(null))
            .Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 4
0
        private static async Task <CreateSubscriptionResponse> CreateProductSubscription(string productName,
                                                                                         string azureSubscriptionId,
                                                                                         string subscriptionDisplayName,
                                                                                         string subscriptionId,
                                                                                         string resourceGroupName,
                                                                                         string serviceName,
                                                                                         string token,
                                                                                         ILogger log)
        {
            // Reference: https://docs.microsoft.com/en-us/rest/api/apimanagement/2019-01-01/subscription/createorupdate

            // Format the request URI
            var createSubscriptionUri =
                $"https://management.azure.com/subscriptions/{azureSubscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/subscriptions/{subscriptionId}?api-version=2019-01-01";

            // Clear the request headers, set the content type
            // and add the bearer token.
            Client.DefaultRequestHeaders.Accept.Clear();
            Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            Client.DefaultRequestHeaders.Remove("Authorization");
            Client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);

            // Update the body of the request with the subscription information.
            // The product subscription ID is already passed into the request as
            // a parameter, the rest of the data is passed into the body.
            var requestBody = new CreateSubscriptionRequest
            {
                Properties = new Properties
                {
                    DisplayName = subscriptionDisplayName,
                    Scope       =
                        $"/subscriptions/{azureSubscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/products/{productName}"
                }
            };

            // Serialize and encode the request body
            var jsonRequest = JsonConvert.SerializeObject(requestBody);
            var content     = new StringContent(jsonRequest, Encoding.UTF8, "application/json");

            // Make the request to create the product subscription
            var response = await Client.PutAsync(createSubscriptionUri, content);

            var result = await response.Content.ReadAsStringAsync();

            // Format the response and return
            var json = JObject.Parse(result);
            var createSubscriptionResponse = new CreateSubscriptionResponse
            {
                PrimaryKey   = json["properties"]["primaryKey"].ToString(),
                SecondaryKey = json["properties"]["secondaryKey"].ToString()
            };

            return(createSubscriptionResponse);
        }
Exemplo n.º 5
0
        public async Task CreateSubscriptionAsync()
        {
            var response = new CreateSubscriptionResponse();
            var request  = new CreateSubscriptionRequest();
            var channel  = new TestRequestChannel(response);

            var ret = await channel.CreateSubscriptionAsync(request);

            ret
            .Should().BeSameAs(response);

            channel.Request
            .Should().BeSameAs(request);
        }
Exemplo n.º 6
0
        public async Task <CreateSubscriptionResponse> CreateSubscription(CreateSubscriptionRequest subscriptionRequest)
        {
            CreateSubscriptionResponse response = new CreateSubscriptionResponse();

            Subscription subscription = new Subscription();


            AddPseudoSkusToSubscription(subscriptionRequest.PseudoSkusToAdd, subscription);

            ThrowExceptionIfSubscriptionIsInvalid(subscription);

            _subscriptionRepository.Add <Subscription>(subscription);

            //When not using the EF repository use the ISubscriptionLToDRepository
            //_subscriptionRepository.Add(subscription);
            // commit using unit of work
            //_uow.Commit();

            await _subscriptionRepository.SaveAll();

            response.Subscription = _mapper.Map <SubscriptionView>(subscription);

            return(response);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Invokes the CreateSubscription service.
        /// </summary>
        public IServiceResponse CreateSubscription(IServiceRequest incoming)
        {
            CreateSubscriptionResponse response = null;

            CreateSubscriptionRequest request = (CreateSubscriptionRequest)incoming;

            uint subscriptionId = 0;
            double revisedPublishingInterval = 0;
            uint revisedLifetimeCount = 0;
            uint revisedMaxKeepAliveCount = 0;

            response = new CreateSubscriptionResponse();

            response.ResponseHeader = ServerInstance.CreateSubscription(
               request.RequestHeader,
               request.RequestedPublishingInterval,
               request.RequestedLifetimeCount,
               request.RequestedMaxKeepAliveCount,
               request.MaxNotificationsPerPublish,
               request.PublishingEnabled,
               request.Priority,
               out subscriptionId,
               out revisedPublishingInterval,
               out revisedLifetimeCount,
               out revisedMaxKeepAliveCount);

            response.SubscriptionId            = subscriptionId;
            response.RevisedPublishingInterval = revisedPublishingInterval;
            response.RevisedLifetimeCount      = revisedLifetimeCount;
            response.RevisedMaxKeepAliveCount  = revisedMaxKeepAliveCount;

            return response;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes the message with a service fault.
        /// </summary>
        public CreateSubscriptionResponseMessage(ServiceFault ServiceFault)
        {
            this.CreateSubscriptionResponse = new CreateSubscriptionResponse();

            if (ServiceFault != null)
            {
                this.CreateSubscriptionResponse.ResponseHeader = ServiceFault.ResponseHeader;
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes the message with the body.
 /// </summary>
 public CreateSubscriptionResponseMessage(CreateSubscriptionResponse CreateSubscriptionResponse)
 {
     this.CreateSubscriptionResponse = CreateSubscriptionResponse;
 }
Exemplo n.º 10
0
        /// <summary cref="IServiceMessage.CreateResponse" />
        public object CreateResponse(IServiceResponse response)
        {
            CreateSubscriptionResponse body = response as CreateSubscriptionResponse;

            if (body == null)
            {
                body = new CreateSubscriptionResponse();
                body.ResponseHeader = ((ServiceFault)response).ResponseHeader;
            }

            return new CreateSubscriptionResponseMessage(body);
        }
        public static void Main(string[] args)
        {
            var            chain = new CredentialProfileStoreChain();
            AWSCredentials awsCredentials;

            chain.TryGetAWSCredentials("DD MWS", out awsCredentials);
            var creds = awsCredentials.GetCredentials();


            // Developer AWS access key
            string accessKey = creds.AccessKey;

            // Developer AWS secret key
            string secretKey = creds.SecretKey;

            // The client application name
            string appName = "CSharpSampleCode";

            // The client application version
            string appVersion = "1.0";

            string sellerId      = "ARA1ZW7ZHL5MQ";
            string marketplaceId = "ATVPDKIKX0DER";
            // The endpoint for region service and version (see developer guide)
            // ex: https://mws.amazonservices.com
            string serviceURL = "https://mws.amazonservices.com";

            // Create a configuration object
            MWSSubscriptionsServiceConfig config = new MWSSubscriptionsServiceConfig();

            config.ServiceURL = serviceURL;
            // Set other client connection configurations here if needed
            // Create the client itself
            MWSSubscriptionsService client = new MWSSubscriptionsServiceClient(accessKey, secretKey, appName, appVersion, config);

            MWSSubscriptionsServiceSample sample = new MWSSubscriptionsServiceSample(client);

            // Uncomment the operation you'd like to test here
            // TODO: Modify the request created in the Invoke method to be valid

            try
            {
                IMWSResponse response = null;
                // response = sample.InvokeCreateSubscription();
                // response = sample.InvokeDeleteSubscription();

                // succesfully called
                //response = sample.InvokeRegisterDestination();
                //RegisterDestinationResponse registerDestinationResponse = (RegisterDestinationResponse)response;
                response = sample.InvokeCreateSubscription();
                CreateSubscriptionResponse createSubscriptionResponse = (CreateSubscriptionResponse)response;


                // response = sample.InvokeGetSubscription();
                //response = sample.InvokeListRegisteredDestinations();
                //response = sample.InvokeListSubscriptions();
                response = sample.InvokeRegisterDestination();
                //response = sample.InvokeSendTestNotificationToDestination();
                // response = sample.InvokeUpdateSubscription();
                // response = sample.InvokeGetServiceStatus();
                Console.WriteLine("Response:");
                ResponseHeaderMetadata rhmd = response.ResponseHeaderMetadata;
                // We recommend logging the request id and timestamp of every call.
                Console.WriteLine("RequestId: " + rhmd.RequestId);
                Console.WriteLine("Timestamp: " + rhmd.Timestamp);
                string responseXml = response.ToXML();
                Console.WriteLine(responseXml);
            }
            catch (MWSSubscriptionsServiceException ex)
            {
                // Exception properties are important for diagnostics.
                ResponseHeaderMetadata rhmd = ex.ResponseHeaderMetadata;
                Console.WriteLine("Service Exception:");
                if (rhmd != null)
                {
                    Console.WriteLine("RequestId: " + rhmd.RequestId);
                    Console.WriteLine("Timestamp: " + rhmd.Timestamp);
                }
                Console.WriteLine("Message: " + ex.Message);
                Console.WriteLine("StatusCode: " + ex.StatusCode);
                Console.WriteLine("ErrorCode: " + ex.ErrorCode);
                Console.WriteLine("ErrorType: " + ex.ErrorType);
                throw ex;
            }
        }