public static CreateApiResponse Unmarshall(UnmarshallerContext context)
        {
            CreateApiResponse createApiResponse = new CreateApiResponse();

            createApiResponse.HttpResponse = context.HttpResponse;
            createApiResponse.RequestId = context.StringValue("CreateApi.RequestId");
            createApiResponse.ApiId = context.StringValue("CreateApi.ApiId");

            return createApiResponse;
        }
        public static CreateApiResponse Unmarshall(UnmarshallerContext context)
        {
            CreateApiResponse createApiResponse = new CreateApiResponse();

            createApiResponse.HttpResponse = context.HttpResponse;
            createApiResponse.RequestId    = context.StringValue("CreateApi.RequestId");
            createApiResponse.ApiId        = context.StringValue("CreateApi.ApiId");

            return(createApiResponse);
        }
Пример #3
0
        /**
         * Create Key from CreateApiKeyRequest
         */
        public async Task <string> CreateKey(CreateApiKeyRequest createApiKeyRequest, string ipAddress)
        {
            var createApiResponse       = new CreateApiResponse();
            var createApiFailedResponse = new CreateApiResponseFailed();

            var account = await this._accountRepository.GetAccountByLogin(createApiKeyRequest.login);

            //return failed if account is wrong
            if (account == null || account.Password != createApiKeyRequest.password)
            {
                createApiFailedResponse.Reason = Enum.GetName(typeof(CreateApiFailedEnum), CreateApiFailedEnum.FAILED);
                return(JsonConvert.SerializeObject(createApiFailedResponse));
            }

            this._accountRepository.Entities().AddOrUpdate(account.Id, account, (i, editedAccount) =>
            {
                //if expired token or empty
                if (account.ApiKeyExpirationDate == null || (DateTime)account.ApiKeyExpirationDate <= DateTime.Now)
                {
                    editedAccount.ApiKey = Guid.NewGuid().ToString();
                    editedAccount.ApiKeyExpirationDate = DateTime.Now.AddHours(50);//4
                }

                editedAccount.Ip       = ipAddress;
                editedAccount.IsEdited = true;

                return(editedAccount);
            });


            createApiResponse.AccountId = account.Id;
            createApiResponse.AddedDate = DateTimeOffset.Now;
            createApiResponse.Data      = new CreateApiResponseData()
            {
                Country  = "FR",
                Currency = "EUR"
            };
            createApiResponse.Key            = account.ApiKey;
            createApiResponse.ExpirationDate = DateTime.Now.AddHours(50);//4
            createApiResponse.RefreshToken   = "";
            createApiResponse.Ip             = account.Ip;

            return(JsonConvert.SerializeObject(createApiResponse));
        }
Пример #4
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateApiResponse response = new CreateApiResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("apiEndpoint", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ApiEndpoint = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("apiId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ApiId = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("apiKeySelectionExpression", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ApiKeySelectionExpression = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("corsConfiguration", targetDepth))
                {
                    var unmarshaller = CorsUnmarshaller.Instance;
                    response.CorsConfiguration = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("createdDate", targetDepth))
                {
                    var unmarshaller = DateTimeUnmarshaller.Instance;
                    response.CreatedDate = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("description", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Description = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("disableSchemaValidation", targetDepth))
                {
                    var unmarshaller = BoolUnmarshaller.Instance;
                    response.DisableSchemaValidation = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("importInfo", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <string, StringUnmarshaller>(StringUnmarshaller.Instance);
                    response.ImportInfo = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("name", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Name = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("protocolType", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ProtocolType = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("routeSelectionExpression", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.RouteSelectionExpression = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("tags", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance);
                    response.Tags = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("version", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Version = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("warnings", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <string, StringUnmarshaller>(StringUnmarshaller.Instance);
                    response.Warnings = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }