public void AddCheckpoint(RestServiceRequest <DeviceCheckpoint> request, RestServiceResponse <DeviceCheckpoint> response) { if (request.Body == null || request.Body.DeviceInfo == null || !request.Body.DeviceInfo.DeviceNumber.HasValue() || !request.Body.Description.HasValue()) { throw new RequestDataInvalidException("DeviceNumber", "Description"); } var retVal = _DeviceCheckpointRepository.AddCheckpoint(DeviceCheckpointTransfer.BuildDeviceCheckpointSource(request.Body)); if (retVal < 0) { switch (retVal) { default: throw new UndefinedException(retVal); } } response.Body = new DeviceCheckpoint() { Id = retVal }; }
public void AddPlan(RestServiceRequest <InspectionPlan> request, RestServiceResponse <InspectionPlan> response) { if (request.Body == null || request.Body.DeviceInfo == null || !request.Body.DeviceInfo.DeviceNumber.HasValue()) { throw new RestException("", "device number cannot be empty."); } var retVal = _InspectionPlanRepository.AddPlan(request.Body); if (retVal < 0) { switch (retVal) { case -1: throw new RestException("", string.Format("device number '{0}' does not exist.", request.Body.DeviceInfo.DeviceNumber)); default: throw new RestException("", "undefined error."); } } response.Body = new InspectionPlan() { Id = retVal }; }
public void AddRecord(RestServiceRequest <MaintenanceRecord> request, RestServiceResponse <MaintenanceRecord> response) { if (request.Body == null || request.Body.DeviceInfo == null || !request.Body.DeviceInfo.DeviceNumber.HasValue()) { throw new RestException("", "device number cannot be empty."); } var retVal = _MaintenanceRecordRepository.AddRecord(request.Body); if (retVal < 0) { switch (retVal) { case -1: throw new RestException("", string.Format("device number '{0}' does not exist.", request.Body.DeviceInfo.DeviceNumber)); case -2: throw new RestException("", string.Format("maintenance plan '{0}' does not exist.", request.Body.MaintenancePlan.Id)); default: throw new RestException("", "undefined error."); } } request.Body = new MaintenanceRecord() { Id = retVal }; }
public void AddDevice(RestServiceRequest <DeviceInfo> request, RestServiceResponse <DeviceInfo> response) { if (request.Body == null || !request.Body.DeviceNumber.HasValue() || !request.Body.DeviceName.HasValue()) { throw new RequestDataInvalidException("DeviceNumber", "DeviceName"); } var retVal = _DeviceInfoRepository.AddDevice(DeviceInfoTransfer.BuildDeviceInfoSource(request.Body), DeviceSparePartTransfer.BuildDeviceSparePartSources(request.Body.DeviceSpareParts), DeviceCheckpointTransfer.BuildDeviceCheckpointSources(request.Body.DeviceCheckpoints)); if (retVal < 0) { switch (retVal) { case -1: throw new DeviceAlreadyExistedException(request.Body.DeviceNumber); default: throw new UndefinedException(retVal); } } response.Body = new DeviceInfo() { DeviceNumber = request.Body.DeviceNumber }; }
public void QueryPlansByConditions(RestServiceRequest request, RestServiceResponse <MaintenancePlan[]> response) { //response.Paging = request.Paging; //response.Body = _MaintenancePlanRepository.QueryPlansByConditions(request.Paging, // request.GetValue("Id", 0), // request.GetValue("DeviceNumber")); }
public void QueryPlansByConditions(RestServiceRequest request, RestServiceResponse <InspectionPlan[]> response) { response.Paging = request.Paging; response.Body = _InspectionPlanRepository.QueryPlansByConditions(request.Paging, request.GetValue("Id", 0), request.GetValue("DeviceNumber")); }
public void QueryDeviceSpareParts(RestServiceRequest request, RestServiceResponse <DeviceSparePart[]> response) { response.Paging = request.Paging; response.Body = DeviceSparePartTransfer.BuildDeviceSpareParts(_DeviceSparePartRepository.QueryDeviceSpareParts( request.Paging, request.GetValue("SparePartNumber"), request.GetValue("DeviceNumber"))); }
public void QueryBriefDevices(RestServiceRequest request, RestServiceResponse <DeviceInfo[]> response) { response.Paging = request.Paging; response.Body = DeviceInfoTransfer.BuildDeviceInfos(_DeviceInfoRepository.QueryDeviceInfos( request.Paging, request.GetValue("DeviceNumber"), request.GetValue("DeviceName"))); }
public void QueryDeviceCheckpoints(RestServiceRequest request, RestServiceResponse <DeviceCheckpoint[]> response) { response.Paging = request.Paging; response.Body = DeviceCheckpointTransfer.BuildDeviceCheckpoints(_DeviceCheckpointRepository.QueryDeviceCheckpoints( request.Paging, request.GetValue <int>("DeviceCheckpointId", 0), request.GetValue("DeviceNumber"))); }
public static ExposerResultDto ToDto(this RestServiceResponse response) { ExposerResultDto dto = new ExposerResultDto(); dto.StatusCode = response.StatusCode; dto.Body = response.Body; dto.Headers = response.Headers.ToDto(); return(dto); }
public void QueryRecordsByConditions(RestServiceRequest request, RestServiceResponse <DeviceRepairRecord[]> response) { response.Paging = request.Paging; response.Body = _DeviceRepairRecordRepository.QueryRecordsByConditions(request.Paging, request.GetValue("Id", 0), request.GetValue <string>("DeviceNumber", null), request.GetValue <string>("Statuses", null).SplitByChar(','), request.GetValue <string>("StartTime", null), request.GetValue <string>("EndTime", null)); }
public void DeletePlan(RestServiceRequest <MaintenancePlan> request, RestServiceResponse <MaintenancePlan> response) { //var retVal = _MaintenancePlanRepository.DeletePlan(request.Body); //if (retVal < 0) //{ // switch (retVal) // { // case -1: throw new RestException("", string.Format("maintenance plan '{0}' does not exist.", request.Body.Id)); // default: throw new RestException("", "undefined error."); // } //} }
public RestServiceResponse <MaintenancePlan[]> GetMaintenancePlanList(RestServiceRequest request) { var response = new RestServiceResponse <MaintenancePlan[]>(); switch (request.ActionName) { case "ByConditions": _MaintenancePlanBusiness.QueryPlansByConditions(request, response); break; default: throw new ActionNotSupportedException(request.ActionName); } return(response); }
public RestServiceResponse <DeviceRepairRecord[]> GetMaintenanceRecordList(RestServiceRequest request) { var response = new RestServiceResponse <DeviceRepairRecord[]>(); switch (request.ActionName) { case "ByConditions": _DeviceRepairRecordBusiness.QueryRecordsByConditions(request, response); break; default: throw new RestException("", string.Format("it does not support action '{0}'.", request.ActionName)); } return(response); }
public RestServiceResponse <DeviceSparePart[]> GetDeviceSparePartList(RestServiceRequest request) { var response = new RestServiceResponse <DeviceSparePart[]>(); switch (request.ActionName) { case "Brief": _DeviceSparePartBusiness.QueryDeviceSpareParts(request, response); break; default: throw new ActionNotSupportedException(request.ActionName); } return(response); }
public RestServiceResponse <InspectionPlan[]> GetInspectionPlanList(RestServiceRequest request) { var response = new RestServiceResponse <InspectionPlan[]>(); switch (request.ActionName) { case "ByConditions": _InspectionPlanBusiness.QueryPlansByConditions(request, response); break; default: throw new RestException("", string.Format("it does not support action '{0}'.", request.ActionName)); } return(response); }
public void DeletePlan(RestServiceRequest <InspectionPlan> request, RestServiceResponse <InspectionPlan> response) { var retVal = _InspectionPlanRepository.DeletePlan(request.Body); if (retVal < 0) { switch (retVal) { case -1: throw new RestException("", string.Format("inspection plan '{0}' does not exist.", request.Body.Id)); default: throw new RestException("", "undefined error."); } } }
public void DeleteRecord(RestServiceRequest <MaintenanceRecord> request, RestServiceResponse <MaintenanceRecord> response) { var retVal = _MaintenanceRecordRepository.DeleteRecord(request.Body); if (retVal != 0) { switch (retVal) { case -1: throw new RestException("", string.Format("maintenance record '{0}' does not exist.", request.Body.Id)); default: throw new RestException("", "undefined error."); } } }
public void AddPlan(RestServiceRequest <MaintenancePlan> request, RestServiceResponse <MaintenancePlan> response) { //if (request.Body.DeviceInfo == null // || !request.Body.DeviceInfo.DeviceNumber.HasValue() // || !request.Body.PeriodFrom.IsDateTime() // || !request.Body.PeriodTo.IsDateTime()) //{ // throw new RequestDataInvalidException("DeviceNumber", "PeriodFrom", "PeriodTo"); //} //var deviceNumber = request.Body.DeviceInfo.DeviceNumber; //var periodFrom = DateTime.Parse(request.Body.PeriodFrom); //var periodTo = DateTime.Parse(request.Body.PeriodTo); //if (periodFrom > periodTo) //{ // throw new RequestDataInvalidException("PeriodFrom", "PeriodTo"); //} //var scheduleTimes = ScheduleHandler.GenerateDateTime((ScheduleType)Enum.Parse(typeof(ScheduleType), request.Body.ScheduleType.ToString()), // request.Body.ScheduleValue, periodFrom, periodTo); //if (scheduleTimes == null) //{ // throw new RequestDataInvalidException("ScheduleType", "ScheduleValue"); //} //var maintenanceRecordSources = new MaintenanceRecordSource[0]; //foreach (var scheduleTime in scheduleTimes) //{ // maintenanceRecordSources = maintenanceRecordSources.Append(new MaintenanceRecordSource() // { // Content = request.Body.Content, // DeviceInfo = new DeviceInfoSource() { DeviceNumber = request.Body.DeviceInfo.DeviceNumber }, // ScheduleTime = scheduleTime.ToString("yyyy-MM-dd HH:mm:ss"), // }); //} //var retVal = _MaintenancePlanRepository.AddPlan(MaintenancePlanTransfer.BuildMaintenancePlanSource(request.Body), maintenanceRecordSources); //if (retVal < 0) //{ // switch (retVal) // { // case -1: throw new DeviceNotFoundException(request.Body.DeviceInfo.DeviceNumber); // default: throw new UndefinedException(retVal); // } //} //response.Body = new MaintenancePlan() { Id = retVal }; }
public RestServiceResponse <DeviceInfo[]> GetDeviceInfoList(RestServiceRequest request) { var response = new RestServiceResponse <DeviceInfo[]>(); switch (request.ActionName) { case "Brief": _DeviceInfoBusiness.QueryBriefDevices(request, response); break; case "Detail": _DeviceInfoBusiness.QueryDetailDevices(request, response); break; default: throw new ActionNotSupportedException(request.ActionName); } return(response); }
static void Container(RestServiceResponse response) { if (response.HasError) { foreach (var error in response.Errors) { ConsoleBridging.WriteLine("Error: " + error.ErrorMessage); } } else { ConsoleBridging.WriteLine("done."); } ConsoleBridging.ReadAnyKey(); }
public RestServiceResponse <InspectionPlan> OperateInspectionPlan(RestServiceRequest <InspectionPlan> request) { var response = new RestServiceResponse <InspectionPlan>(); switch (request.ActionName) { case "Add": _InspectionPlanBusiness.AddPlan(request, response); break; case "Edit": _InspectionPlanBusiness.EditPlan(request, response); break; case "Delete": _InspectionPlanBusiness.DeletePlan(request, response); break; default: throw new RestException("", string.Format("it does not support action '{0}'.", request.ActionName)); } return(response); }
public RestServiceResponse <DeviceSparePart> OperateDeviceSparePart(RestServiceRequest <DeviceSparePart> request) { var response = new RestServiceResponse <DeviceSparePart>(); switch (request.ActionName) { case "Add": _DeviceSparePartBusiness.AddSparePart(request, response); break; case "Edit": _DeviceSparePartBusiness.EditSparePart(request, response); break; case "Delete": _DeviceSparePartBusiness.DeleteSparePart(request, response); break; default: throw new ActionNotSupportedException(request.ActionName); } return(response); }
public RestServiceResponse <DeviceRepairRecord> OperateRepairRecord(RestServiceRequest <DeviceRepairRecord> request) { var response = new RestServiceResponse <DeviceRepairRecord>(); switch (request.ActionName) { case "Add": _DeviceRepairRecordBusiness.AddRecord(request, response); break; case "Edit": _DeviceRepairRecordBusiness.EditRecord(request, response); break; case "Delete": _DeviceRepairRecordBusiness.DeleteRecord(request, response); break; default: throw new RestException("", string.Format("it does not support action '{0}'.", request.ActionName)); } return(response); }
public RestServiceResponse <MaintenancePlan> OperateMaintenancePlan(RestServiceRequest <MaintenancePlan> request) { var response = new RestServiceResponse <MaintenancePlan>(); switch (request.ActionName) { case "Add": _MaintenancePlanBusiness.AddPlan(request, response); break; case "Edit": _MaintenancePlanBusiness.EditPlan(request, response); break; case "Delete": _MaintenancePlanBusiness.DeletePlan(request, response); break; default: throw new ActionNotSupportedException(request.ActionName); } return(response); }
public void HttpClientRestServiceExecutor_ReturnOKResult() { //Arrange IRestServiceExecutor executor = new HttpClientRestServiceExecutor(); RestService restService = new RestService("https://reqres.in/api/users/", "GET", ""); RestServiceRequest request = new RestServiceRequest(restService, "GET", null, ""); //Act RestServiceResponse response = executor.Execute(request); //Assert Assert.IsNotNull(response); Assert.AreEqual(response.StatusCode, 200); Assert.IsTrue(!string.IsNullOrEmpty(response.Body)); }
public void DeleteSparePart(RestServiceRequest <DeviceSparePart> request, RestServiceResponse <DeviceSparePart> response) { if (request.Body == null || !request.Body.SparePartNumber.HasValue()) { throw new RequestDataInvalidException("SparePartNumber"); } var retVal = _DeviceSparePartRepository.DeleteSparePart(DeviceSparePartTransfer.BuildDeviceSparePartSource(request.Body)); if (retVal < 0) { switch (retVal) { default: throw new UndefinedException(retVal); } } }
public void DeleteCheckpoint(RestServiceRequest <DeviceCheckpoint> request, RestServiceResponse <DeviceCheckpoint> response) { if (request.Body == null || request.Body.Id <= 0) { throw new RequestDataInvalidException("DeviceNumber"); } var retVal = _DeviceCheckpointRepository.DeleteCheckpoint(DeviceCheckpointTransfer.BuildDeviceCheckpointSource(request.Body)); if (retVal < 0) { switch (retVal) { default: throw new UndefinedException(retVal); } } }
public void EditCheckpoint(RestServiceRequest <DeviceCheckpoint> request, RestServiceResponse <DeviceCheckpoint> response) { if (request.Body == null || request.Body.Id <= 0 || !request.Body.Description.HasValue()) { throw new RequestDataInvalidException("Id", "Description"); } var retVal = _DeviceCheckpointRepository.EditCheckpoint(DeviceCheckpointTransfer.BuildDeviceCheckpointSource(request.Body)); if (retVal < 0) { switch (retVal) { default: throw new UndefinedException(retVal); } } }
public void DeleteDevice(RestServiceRequest <DeviceInfo> request, RestServiceResponse <DeviceInfo> response) { if (!request.Body.DeviceNumber.HasValue()) { throw new RequestDataInvalidException("DeviceNumber"); } var retVal = _DeviceInfoRepository.DeleteDevice(DeviceInfoTransfer.BuildDeviceInfoSource(request.Body)); if (retVal < 0) { switch (retVal) { case -1: throw new DeviceNotFoundException(request.Body.DeviceNumber); default: throw new UndefinedException(retVal); } } }