public static createResponseType CreateCreateResponse(createType create) { createResponseType createResponse = new createResponseType(); createResponse.creates = new createType[] { create }; return(createResponse); }
public CreateForm(createType createType, object objToEdit) { InitializeComponent(); this.newCreation = objToEdit; this.userDefinedCreate = createType; loadPropGrid(objToEdit); }
public static createResponseType CreateCreateResponse(createType create) { var createResponse = new createResponseType { creates = new[] { create } }; return(createResponse); }
//Not well defined public void createTransformer(Transform newObject, Quaternion newRotation, int cost, Transform button) { creating = true; currentType = createType.transformer; newTransform = newObject; rotation = newRotation; this.cost = cost; }
//Not well defined public void createPump(Transform newObject, Quaternion newRotation, float pumpTimeBetween, int cost, Transform button) { creating = true; currentType = createType.pump; newTransform = newObject; rotation = newRotation; this.pumpTimeBetween = pumpTimeBetween; this.cost = cost; }
public void createTurbine(Transform newObject, Quaternion newRotation, int maxOutput, int directionIndex, int cost, Transform button, float time, Color turbineColor) { currentButton = button; currentButton.GetComponent<WindTurbineBtnInfo> ().creating = true; WindTurbineBtnInfo.anyButtonCreate = true; creating = true; currentType = createType.turbine; newTransform = newObject; rotation = newRotation; this.maxOutput = maxOutput; this.directionIndex = directionIndex; this.cost = cost; this.timeForWork = time; this.turbineColor = turbineColor; }
public static createType CreateCreate(HttpStatusCode statusCode, string id, string advisoryId = null, errorType error = null) { createType create = new createType(); create.statusCode = ((int)statusCode).ToString(); create.id = id; if (StringUtils.NotEmpty(advisoryId)) { create.advisoryId = advisoryId; } if (error != null) { create.error = error; } return(create); }
public void createTurbine(Transform newObject, Quaternion newRotation, int maxOutput, int directionIndex, int cost, Transform button, float time, Color turbineColor) { currentButton = button; currentButton.GetComponent <WindTurbineBtnInfo> ().creating = true; WindTurbineBtnInfo.anyButtonCreate = true; creating = true; currentType = createType.turbine; newTransform = newObject; rotation = newRotation; this.maxOutput = maxOutput; this.directionIndex = directionIndex; this.cost = cost; this.timeForWork = time; this.turbineColor = turbineColor; }
/// <summary> /// <see cref="Provider{TSingle, TMultiple}.Post(TMultiple, string[], string[])">Post</see> /// </summary> public override IHttpActionResult Post( List <T> objs, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) { if (!AuthenticationService.VerifyAuthenticationHeader(Request.Headers, out string sessionToken)) { return(Unauthorized()); } // Check ACLs and return StatusCode(HttpStatusCode.Forbidden) if appropriate. if (!AuthorisationService.IsAuthorised(Request.Headers, sessionToken, $"{TypeName}s", RightType.CREATE)) { return(StatusCode(HttpStatusCode.Forbidden)); } if ((zoneId != null && zoneId.Length != 1) || (contextId != null && contextId.Length != 1)) { return(BadRequest($"Request failed for object {TypeName} as Zone and/or Context are invalid.")); } ICollection <createType> createStatuses = new List <createType>(); try { bool?mustUseAdvisory = HttpUtils.GetMustUseAdvisory(Request.Headers); foreach (T obj in objs) { bool hasAdvisoryId = !string.IsNullOrWhiteSpace(obj.RefId); var status = new createType { advisoryId = (hasAdvisoryId ? obj.RefId : null) }; try { if (mustUseAdvisory.HasValue) { if (mustUseAdvisory.Value && !hasAdvisoryId) { status.error = ProviderUtils.CreateError( HttpStatusCode.BadRequest, TypeName, "Create request failed as object ID is not provided, but mustUseAdvisory is true."); status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } else { status.id = Service.Create(obj, mustUseAdvisory, zoneId?[0], contextId?[0]).RefId; status.statusCode = ((int)HttpStatusCode.Created).ToString(); } } else { status.id = Service.Create(obj, null, zoneId?[0], contextId?[0]).RefId; status.statusCode = ((int)HttpStatusCode.Created).ToString(); } } catch (AlreadyExistsException e) { status.error = ProviderUtils.CreateError( HttpStatusCode.Conflict, TypeName, $"Object {TypeName} with ID of {obj.RefId} already exists.\n{e.Message}"); status.statusCode = ((int)HttpStatusCode.Conflict).ToString(); } catch (ArgumentException e) { status.error = ProviderUtils.CreateError( HttpStatusCode.BadRequest, TypeName, $"Object to create of type {TypeName}" + (hasAdvisoryId ? $" with ID of {obj.RefId}" : "") + $" is invalid.\n {e.Message}"); status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } catch (CreateException e) { status.error = ProviderUtils.CreateError( HttpStatusCode.BadRequest, TypeName, $"Request failed for object {TypeName}" + (hasAdvisoryId ? $" with ID of {obj.RefId}" : "") + $".\n{e.Message}"); status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } catch (RejectedException e) { status.error = ProviderUtils.CreateError( HttpStatusCode.NotFound, TypeName, $"Create request rejected for object {TypeName} with ID of {obj.RefId}.\n{e.Message}"); status.statusCode = ((int)HttpStatusCode.Conflict).ToString(); } catch (Exception e) { status.error = ProviderUtils.CreateError( HttpStatusCode.InternalServerError, TypeName, $"Request failed for object {TypeName}" + (hasAdvisoryId ? $" with ID of {obj.RefId}" : "") + $".\n{e.Message}"); status.statusCode = ((int)HttpStatusCode.InternalServerError).ToString(); } createStatuses.Add(status); } } catch (Exception) { // Need to ignore exceptions otherwise it would not be possible to return status records of processed objects. } var createResponse = new createResponseType { creates = createStatuses.ToArray() }; return(Ok(createResponse)); }
public void ExplicitResponseMapperTest() { // Error. ResponseError srcError = new ResponseError { Code = 123, Description = "Err desc", Id = "42", Message = "Error occurred", Scope = "request" }; errorType destError = MapperFactory.CreateInstance <ResponseError, errorType>(srcError); // Create. CreateStatus srcCreateStatus = new CreateStatus { AdvisoryId = "src456", Error = srcError, Id = "cr8", StatusCode = "200" }; createType destCreateStatus = MapperFactory.CreateInstance <CreateStatus, createType>(srcCreateStatus); MultipleCreateResponse srcCreateResponse = new MultipleCreateResponse { StatusRecords = new List <CreateStatus> { srcCreateStatus } }; createResponseType destCreateResponse = MapperFactory.CreateInstance <MultipleCreateResponse, createResponseType>(srcCreateResponse); int index = 0; // Assert that the mapping was successful. foreach (CreateStatus record in srcCreateResponse.StatusRecords) { Assert.AreEqual(record.AdvisoryId, destCreateResponse.creates[index].advisoryId); Assert.AreEqual(record.Error.Code, destCreateResponse.creates[index].error.code); Assert.AreEqual(record.Error.Description, destCreateResponse.creates[index].error.description); Assert.AreEqual(record.Error.Id, destCreateResponse.creates[index].error.id); Assert.AreEqual(record.Error.Message, destCreateResponse.creates[index].error.message); Assert.AreEqual(record.Error.Scope, destCreateResponse.creates[index].error.scope); Assert.AreEqual(record.Id, destCreateResponse.creates[index].id); Assert.AreEqual(record.StatusCode, destCreateResponse.creates[index].statusCode); index++; } // Delete. DeleteStatus srcDeleteStatus = new DeleteStatus { Error = srcError, Id = "del8", StatusCode = "300" }; deleteStatus destDeleteStatus = MapperFactory.CreateInstance <DeleteStatus, deleteStatus>(srcDeleteStatus); MultipleDeleteResponse srcDeleteResponse = new MultipleDeleteResponse { StatusRecords = new List <DeleteStatus> { srcDeleteStatus } }; deleteResponseType destDeleteResponse = MapperFactory.CreateInstance <MultipleDeleteResponse, deleteResponseType>(srcDeleteResponse); index = 0; // Assert that the mapping was successful. foreach (DeleteStatus record in srcDeleteResponse.StatusRecords) { Assert.AreEqual(record.Error.Code, destDeleteResponse.deletes[index].error.code); Assert.AreEqual(record.Error.Description, destDeleteResponse.deletes[index].error.description); Assert.AreEqual(record.Error.Id, destDeleteResponse.deletes[index].error.id); Assert.AreEqual(record.Error.Message, destDeleteResponse.deletes[index].error.message); Assert.AreEqual(record.Error.Scope, destDeleteResponse.deletes[index].error.scope); Assert.AreEqual(record.Id, destDeleteResponse.deletes[index].id); Assert.AreEqual(record.StatusCode, destDeleteResponse.deletes[index].statusCode); index++; } // Update. UpdateStatus srcUpdateStatus = new UpdateStatus { Error = srcError, Id = "up8", StatusCode = "400" }; updateType destUpdateStatus = MapperFactory.CreateInstance <UpdateStatus, updateType>(srcUpdateStatus); MultipleUpdateResponse srcUpdateResponse = new MultipleUpdateResponse { StatusRecords = new List <UpdateStatus> { srcUpdateStatus } }; updateResponseType destUpdateResponse = MapperFactory.CreateInstance <MultipleUpdateResponse, updateResponseType>(srcUpdateResponse); index = 0; // Assert that the mapping was successful. foreach (UpdateStatus record in srcUpdateResponse.StatusRecords) { Assert.AreEqual(record.Error.Code, destUpdateResponse.updates[index].error.code); Assert.AreEqual(record.Error.Description, destUpdateResponse.updates[index].error.description); Assert.AreEqual(record.Error.Id, destUpdateResponse.updates[index].error.id); Assert.AreEqual(record.Error.Message, destUpdateResponse.updates[index].error.message); Assert.AreEqual(record.Error.Scope, destUpdateResponse.updates[index].error.scope); Assert.AreEqual(record.Id, destUpdateResponse.updates[index].id); Assert.AreEqual(record.StatusCode, destUpdateResponse.updates[index].statusCode); index++; } }
public CreateForm(createType createType) { InitializeComponent(); this.userDefinedCreate = createType; loadPropGrid(); }
public override IHttpActionResult Post(List <StudentPersonal> objs, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) { foreach (KeyValuePair <string, IEnumerable <string> > nameValues in Request.Headers) { if (log.IsDebugEnabled) { log.Debug($"*** Header field is [{nameValues.Key}:{string.Join(",", nameValues.Value)}]"); } } //return base.Post(objs, zoneId, contextId); string sessionToken; if (!authenticationService.VerifyAuthenticationHeader(Request.Headers, out sessionToken)) { return(Unauthorized()); } if ((zoneId != null && zoneId.Length != 1) || (contextId != null && contextId.Length != 1)) { return(BadRequest("Request failed for object " + typeof(StudentPersonal).Name + " as Zone and/or Context are invalid.")); } IHttpActionResult result; ICollection <createType> createStatuses = new List <createType>(); try { bool?mustUseAdvisory = HttpUtils.GetMustUseAdvisory(Request.Headers); foreach (StudentPersonal obj in objs) { bool hasAdvisoryId = !string.IsNullOrWhiteSpace(obj.RefId); createType status = new createType(); status.advisoryId = (hasAdvisoryId ? obj.RefId : null); try { if (mustUseAdvisory.HasValue && mustUseAdvisory.Value == true) { if (hasAdvisoryId) { status.id = service.Create(obj, mustUseAdvisory, zoneId: (zoneId == null ? null : zoneId[0]), contextId: (contextId == null ? null : contextId[0])).RefId; status.statusCode = ((int)HttpStatusCode.Created).ToString(); } else { status.error = ProviderUtils.CreateError(HttpStatusCode.BadRequest, typeof(StudentPersonal).Name, "Create request failed as object ID is not provided, but mustUseAdvisory is true."); status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } } else { status.id = service.Create(obj, zoneId: (zoneId == null ? null : zoneId[0]), contextId: (contextId == null ? null : contextId[0])).RefId; status.statusCode = ((int)HttpStatusCode.Created).ToString(); } } catch (AlreadyExistsException e) { status.error = ProviderUtils.CreateError(HttpStatusCode.Conflict, typeof(StudentPersonal).Name, "Object " + typeof(StudentPersonal).Name + " with ID of " + obj.RefId + " already exists.\n" + e.Message); status.statusCode = ((int)HttpStatusCode.Conflict).ToString(); } catch (ArgumentException e) { status.error = ProviderUtils.CreateError(HttpStatusCode.BadRequest, typeof(StudentPersonal).Name, "Object to create of type " + typeof(StudentPersonal).Name + (hasAdvisoryId ? " with ID of " + obj.RefId : "") + " is invalid.\n " + e.Message); status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } catch (CreateException e) { status.error = ProviderUtils.CreateError(HttpStatusCode.BadRequest, typeof(StudentPersonal).Name, "Request failed for object " + typeof(StudentPersonal).Name + (hasAdvisoryId ? " with ID of " + obj.RefId : "") + ".\n " + e.Message); status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } catch (RejectedException e) { status.error = ProviderUtils.CreateError(HttpStatusCode.NotFound, typeof(StudentPersonal).Name, "Create request rejected for object " + typeof(StudentPersonal).Name + " with ID of " + obj.RefId + ".\n" + e.Message); status.statusCode = ((int)HttpStatusCode.Conflict).ToString(); } catch (Exception e) { status.error = ProviderUtils.CreateError(HttpStatusCode.InternalServerError, typeof(StudentPersonal).Name, "Request failed for object " + typeof(StudentPersonal).Name + (hasAdvisoryId ? " with ID of " + obj.RefId : "") + ".\n " + e.Message); status.statusCode = ((int)HttpStatusCode.InternalServerError).ToString(); } createStatuses.Add(status); } } catch (Exception) { // Need to ignore exceptions otherwise it would not be possible to return status records of processed objects. } createResponseType createResponse = new createResponseType { creates = createStatuses.ToArray() }; result = Ok(createResponse); return(result); }
/// <summary> /// <see cref="Provider{TSingle, TMultiple}.Post(TMultiple, string[], string[])">Post</see> /// </summary> public override IHttpActionResult Post(List <T> objs, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) { if (!authService.VerifyAuthenticationHeader(Request.Headers)) { return(Unauthorized()); } // Check ACLs and return StatusCode(HttpStatusCode.Forbidden) if appropriate. if ((zoneId != null && zoneId.Length != 1) || (contextId != null && contextId.Length != 1)) { return(BadRequest("Request failed for object " + typeof(T).Name + " as Zone and/or Context are invalid.")); } IHttpActionResult result; ICollection <createType> createStatuses = new List <createType>(); try { foreach (T obj in objs) { bool hasAdvisoryId = !string.IsNullOrWhiteSpace(obj.RefId); createType status = new createType(); status.advisoryId = (hasAdvisoryId ? obj.RefId : null); try { bool?mustUseAdvisory = HttpUtils.GetMustUseAdvisory(Request.Headers); if (hasAdvisoryId) { if (mustUseAdvisory.HasValue && mustUseAdvisory.Value == true) { status.id = service.Create(obj, mustUseAdvisory, zoneId: (zoneId == null ? null : zoneId[0]), contextId: (contextId == null ? null : contextId[0])).RefId; status.statusCode = ((int)HttpStatusCode.Created).ToString(); } else { status.error = ProviderUtils.CreateError(HttpStatusCode.BadRequest, typeof(T).Name, "Create request failed as object ID provided (" + obj.RefId + "), but mustUseAdvisory is not specified or is false."); status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } } else { if (mustUseAdvisory.HasValue && mustUseAdvisory.Value == true) { status.error = ProviderUtils.CreateError(HttpStatusCode.BadRequest, typeof(T).Name, "Create request failed as object ID is not provided, but mustUseAdvisory is true."); status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } else { status.id = service.Create(obj, zoneId: (zoneId == null ? null : zoneId[0]), contextId: (contextId == null ? null : contextId[0])).RefId; status.statusCode = ((int)HttpStatusCode.Created).ToString(); } } } catch (AlreadyExistsException e) { status.error = ProviderUtils.CreateError(HttpStatusCode.Conflict, typeof(T).Name, "Object " + typeof(T).Name + " with ID of " + obj.RefId + " already exists.\n" + e.Message); status.statusCode = ((int)HttpStatusCode.Conflict).ToString(); } catch (ArgumentException e) { status.error = ProviderUtils.CreateError(HttpStatusCode.BadRequest, typeof(T).Name, "Object to create of type " + typeof(T).Name + (hasAdvisoryId ? " with ID of " + obj.RefId : "") + " is invalid.\n " + e.Message); status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } catch (CreateException e) { status.error = ProviderUtils.CreateError(HttpStatusCode.BadRequest, typeof(T).Name, "Request failed for object " + typeof(T).Name + (hasAdvisoryId ? " with ID of " + obj.RefId : "") + ".\n " + e.Message); status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } catch (RejectedException e) { status.error = ProviderUtils.CreateError(HttpStatusCode.NotFound, typeof(T).Name, "Create request rejected for object " + typeof(T).Name + " with ID of " + obj.RefId + ".\n" + e.Message); status.statusCode = ((int)HttpStatusCode.Conflict).ToString(); } catch (Exception e) { status.error = ProviderUtils.CreateError(HttpStatusCode.InternalServerError, typeof(T).Name, "Request failed for object " + typeof(T).Name + (hasAdvisoryId ? " with ID of " + obj.RefId : "") + ".\n " + e.Message); status.statusCode = ((int)HttpStatusCode.InternalServerError).ToString(); } createStatuses.Add(status); } } catch (Exception) { // Need to ignore exceptions otherwise it would not be possible to return status records of processed objects. } createResponseType createResponse = new createResponseType { creates = createStatuses.ToArray() }; result = Ok(createResponse); return(result); }