private static void UnmarshallResult(XmlUnmarshallerContext context, CreateApplicationResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("Application", targetDepth)) { var unmarshaller = ApplicationDescriptionUnmarshaller.Instance; response.Application = unmarshaller.Unmarshall(context); continue; } } } return; }
private static void ParseValidationError(CreateApplicationResponse response, out string message, out string errorCode) { var map = new Dictionary <string, string> { { ValidationErrorCodes.InvalidCandidateState, CandidateErrorCodes.CandidateStateError }, { ValidationErrorCodes.CandidateNotFound, CandidateErrorCodes.CandidateNotFoundError }, { ValidationErrorCodes.UnknownCandidate, CandidateErrorCodes.CandidateNotFoundError }, { ValidationErrorCodes.InvalidVacancyState, VacancyErrorCodes.LegacyVacancyStateError } }; foreach (var pair in map) { var validationError = response.ValidationErrors.FirstOrDefault(each => each.ErrorCode == pair.Key); if (validationError != null) { message = string.Format("{0} (ErrorCode='{1}')", validationError.Message, pair.Key); errorCode = pair.Value; return; } } // Failed to parse expected validation error. message = string.Format("{0} unexpected validation error(s): {1}", response.ValidationErrors.Count(), JsonConvert.SerializeObject(response, Formatting.None)); errorCode = ApplicationErrorCodes.ApplicationCreationFailed; }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreateApplicationResponse response = new CreateApplicationResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("applicationArn", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ApplicationArn = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("applicationId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ApplicationId = unmarshaller.Unmarshall(context); continue; } } return(response); }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { CreateApplicationResponse response = new CreateApplicationResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.IsStartElement) { if (context.TestExpression("CreateApplicationResult", 2)) { UnmarshallResult(context, response); continue; } if (context.TestExpression("ResponseMetadata", 2)) { response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context); } } } return(response); }
/// <summary> /// <para> Creates an application that has one configuration template named <c>default</c> and no application versions. </para> /// <para><b>NOTE:</b> The default configuration template is for a 32-bit version of the Amazon Linux operating system running the Tomcat 6 /// application container. </para> /// </summary> /// /// <param name="createApplicationRequest">Container for the necessary parameters to execute the CreateApplication service method on /// AmazonElasticBeanstalk.</param> /// /// <returns>The response from the CreateApplication service method, as returned by AmazonElasticBeanstalk.</returns> /// /// <exception cref="TooManyApplicationsException"/> public CreateApplicationResponse CreateApplication(CreateApplicationRequest createApplicationRequest) { IRequest <CreateApplicationRequest> request = new CreateApplicationRequestMarshaller().Marshall(createApplicationRequest); CreateApplicationResponse response = Invoke <CreateApplicationRequest, CreateApplicationResponse> (request, this.signer, CreateApplicationResponseUnmarshaller.GetInstance()); return(response); }
private int SendRequest(Guid candidateId, CreateApplicationRequest request) { CreateApplicationResponse response = null; _service.Use("SecureService", client => response = client.CreateApplication(request)); if (response == null || (response.ValidationErrors != null && response.ValidationErrors.Any())) { string message; string errorCode; if (response == null) { message = "No response"; errorCode = ApplicationErrorCodes.ApplicationCreationFailed; } else if (IsDuplicateError(response)) { message = "Duplicate application"; errorCode = ApplicationErrorCodes.ApplicationDuplicatedError; } else { ParseValidationError(response, out message, out errorCode); } throw new DomainException(errorCode, new { message, candidateId, vacancyId = request.Application.VacancyId }); } return(response.ApplicationId); }
public void SetUp() { _getAccountResponse = _fixture.Create <GetAccountResponse>(); _command = _fixture.Create <CreateApplicationCommand>(); _response = _fixture.Create <CreateApplicationResponse>(); _getStandardResponse = _fixture.Create <GetStandardsListItem>(); _account = _fixture.Create <Account>(); _accountsService = new Mock <IAccountsService>(); _accountsService.Setup(x => x.GetAccount(_command.EncodedAccountId)).ReturnsAsync(_account); _coursesApiClient = new Mock <ICoursesApiClient <CoursesApiConfiguration> >(); _coursesApiClient.Setup(x => x.Get <GetStandardsListItem>(It.Is <GetStandardDetailsByIdRequest>(r => r.Id == _command.StandardId))) .ReturnsAsync(_getStandardResponse); _levyTransferMatchingService = new Mock <ILevyTransferMatchingService>(); _levyTransferMatchingService.Setup(x => x.GetAccount(It.Is <GetAccountRequest>(r => r.AccountId == _command.EmployerAccountId))) .ReturnsAsync(_getAccountResponse); _levyTransferMatchingService.Setup(x => x.CreateApplication(It.IsAny <CreateApplicationRequest>())) .Callback <CreateApplicationRequest>(r => _createApplicationRequest = r) .ReturnsAsync(_response); _handler = new CreateApplicationCommandHandler(_levyTransferMatchingService.Object, _accountsService.Object, Mock.Of <ILogger <CreateApplicationCommandHandler> >(), _coursesApiClient.Object); }
public async Task <CreateApplicationResponse> CreateApplicationsAsync(string name, string description) { using (var request = new HttpRequestMessage(HttpMethod.Post, path)) { CreateApplication createApplication = new CreateApplication(); createApplication.description = description; createApplication.name = name; var str = JsonConvert.SerializeObject(createApplication); request.Content = new StringContent(str, Encoding.UTF8, "application/json"); var httpclient = services.GetService <IHttpClientFactory>(); var client = httpclient.CreateClient("AdminAuth"); using (HttpResponseMessage result = await client.SendAsync(request)) { if (result.IsSuccessStatusCode) { var parsedJson = JsonConvert.DeserializeObject <Models.ApplicationModel>(await result.Content.ReadAsStringAsync()); CreateApplicationResponse applicationModel = new CreateApplicationResponse(true, parsedJson); return(applicationModel); } else { var parsedJson = JsonConvert.DeserializeObject <RequestError>(await result.Content.ReadAsStringAsync()); CreateApplicationResponse applicationModel = new CreateApplicationResponse(false, parsedJson); return(applicationModel); } } } }
public async Task <CreateApplicationResponse> Register(RegisterApplicationRequest o) { var result = new CreateApplicationResponse(o.RequestId); result.Id = await Server.Register(o.Name, o.Description); return(result); }
public async Task <CreateApplicationResponse> CreateApplication(CreateApplicationModel userData, CancellationToken cancellationToken) { CreateApplicationResponse responseModel = new CreateApplicationResponse(); try { var httpRequestMessage = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri("YourServerUri"), Content = new StringContent(JsonConvert.SerializeObject(userData), Encoding.UTF8, "application/json") }; HttpClient client = new HttpClient(); HttpResponseMessage response = await client.SendAsync(httpRequestMessage); if (cancellationToken.IsCancellationRequested) { cancellationToken.ThrowIfCancellationRequested(); } if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError) { throw new ApplicationException($"inner exception : {await response.Content.ReadAsStringAsync()}"); } if (response.StatusCode == System.Net.HttpStatusCode.OK) { try { responseModel = JsonConvert.DeserializeObject <CreateApplicationResponse>(await response.Content.ReadAsStringAsync()); } catch (Exception e) { throw new ApplicationException("Failed while deserializing the object of a not successful response", e); } } else { throw new ApplicationException($" Wrong response with status {response.StatusCode} , {await response.Content.ReadAsStringAsync()}"); } } catch (Exception) { throw; } return(responseModel); }
public void CRUDApplication() { string applicationName = "dotnet-integ-app" + DateTime.Now.Ticks; CreateApplicationRequest createRequest = new CreateApplicationRequest() { ApplicationName = applicationName, Description = "Test Application" }; CreateApplicationResponse createResponse = Client.CreateApplication(createRequest); Assert.IsNotNull(createResponse.ResponseMetadata.RequestId); try { DescribeApplicationsResponse describeResponse = Client.DescribeApplications(new DescribeApplicationsRequest() { ApplicationNames = new List <string>() { applicationName } }); Assert.AreEqual(1, describeResponse.Applications.Count); ApplicationDescription app = describeResponse.Applications[0]; Assert.AreEqual(applicationName, app.ApplicationName); Assert.AreEqual("Test Application", app.Description); Assert.AreNotEqual(DateTime.MinValue, app.DateCreated); Assert.AreNotEqual(DateTime.MinValue, app.DateUpdated); UpdateApplicationRequest updateRequest = new UpdateApplicationRequest() { ApplicationName = applicationName, Description = "updated description" }; UpdateApplicationResponse updateResponse = Client.UpdateApplication(updateRequest); Assert.AreEqual(applicationName, updateResponse.Application.ApplicationName); Assert.AreEqual("updated description", updateResponse.Application.Description); } finally { Client.DeleteApplication(new DeleteApplicationRequest() { ApplicationName = applicationName }); } }
public static CreateApplicationResponse Unmarshall(UnmarshallerContext _ctx) { CreateApplicationResponse createApplicationResponse = new CreateApplicationResponse(); createApplicationResponse.HttpResponse = _ctx.HttpResponse; createApplicationResponse.Message = _ctx.StringValue("CreateApplication.Message"); createApplicationResponse.RequestId = _ctx.StringValue("CreateApplication.RequestId"); createApplicationResponse.TraceId = _ctx.StringValue("CreateApplication.TraceId"); createApplicationResponse.ErrorCode = _ctx.StringValue("CreateApplication.ErrorCode"); createApplicationResponse.Code = _ctx.StringValue("CreateApplication.Code"); createApplicationResponse.Success = _ctx.BooleanValue("CreateApplication.Success"); CreateApplicationResponse.CreateApplication_Data data = new CreateApplicationResponse.CreateApplication_Data(); data.AppId = _ctx.StringValue("CreateApplication.Data.AppId"); data.ChangeOrderId = _ctx.StringValue("CreateApplication.Data.ChangeOrderId"); createApplicationResponse.Data = data; return(createApplicationResponse); }
public CreateApplicationResponse Post(CreateApplicationRequest request) { CreateApplicationResponse resp; using (var con = TenantDbFactory.DataDB.GetNewConnection()) { if (!string.IsNullOrEmpty(request.Colvalues["applicationname"].ToString())) { string sql = ""; if (request.Id > 0) { sql = "UPDATE eb_applications SET applicationname = @applicationname, description= @description WHERE id = @id RETURNING id"; } else { sql = "INSERT INTO eb_applications (applicationname, description) VALUES (@applicationname, @description) RETURNING id"; } DbParameter[] parameters = { this.TenantDbFactory.ObjectsDB.GetNewParameter("applicationname", System.Data.DbType.String, request.Colvalues["applicationname"]), this.TenantDbFactory.ObjectsDB.GetNewParameter("description", System.Data.DbType.String, request.Colvalues["description"]), this.TenantDbFactory.ObjectsDB.GetNewParameter("id", System.Data.DbType.Int32, request.Id) }; var dt = this.TenantDbFactory.ObjectsDB.DoQuery(sql, parameters); resp = new CreateApplicationResponse() { id = Convert.ToInt32(dt.Rows[0][0]) }; } else { resp = new CreateApplicationResponse() { id = 0 }; } } return(resp); }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { CreateApplicationResponse response = new CreateApplicationResponse(); while (context.Read()) { if (context.IsStartElement) { if (context.TestExpression("CreateApplicationResult", 2)) { response.CreateApplicationResult = CreateApplicationResultUnmarshaller.GetInstance().Unmarshall(context); continue; } if (context.TestExpression("ResponseMetadata", 2)) { response.ResponseMetadata = ResponseMetadataUnmarshaller.GetInstance().Unmarshall(context); } } } 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) { CreateApplicationResponse response = new CreateApplicationResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("applicationId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ApplicationId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("author", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Author = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("creationTime", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.CreationTime = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("description", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Description = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("homePageUrl", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.HomePageUrl = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("isVerifiedAuthor", targetDepth)) { var unmarshaller = BoolUnmarshaller.Instance; response.IsVerifiedAuthor = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("labels", targetDepth)) { var unmarshaller = new ListUnmarshaller <string, StringUnmarshaller>(StringUnmarshaller.Instance); response.Labels = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("licenseUrl", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.LicenseUrl = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("name", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Name = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("readmeUrl", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ReadmeUrl = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("spdxLicenseId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.SpdxLicenseId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("verifiedAuthorUrl", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.VerifiedAuthorUrl = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("version", targetDepth)) { var unmarshaller = VersionUnmarshaller.Instance; response.Version = unmarshaller.Unmarshall(context); continue; } } 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) { CreateApplicationResponse response = new CreateApplicationResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("ApiGatewayProxy", targetDepth)) { var unmarshaller = ApiGatewayProxyInputUnmarshaller.Instance; response.ApiGatewayProxy = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("ApplicationId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ApplicationId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Arn", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Arn = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("CreatedByAccountId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.CreatedByAccountId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("CreatedTime", targetDepth)) { var unmarshaller = DateTimeUnmarshaller.Instance; response.CreatedTime = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("EnvironmentId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.EnvironmentId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("LastUpdatedTime", targetDepth)) { var unmarshaller = DateTimeUnmarshaller.Instance; response.LastUpdatedTime = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Name", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Name = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("OwnerAccountId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.OwnerAccountId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("ProxyType", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ProxyType = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("State", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.State = 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("VpcId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.VpcId = unmarshaller.Unmarshall(context); continue; } } return(response); }
private static bool IsDuplicateError(CreateApplicationResponse response) { return(response.ValidationErrors.Any(e => e.ErrorCode == ValidationErrorCodes.DuplicateApplication)); }