예제 #1
0
 public static void HandleAvailableApplicationMaterialRequestTest()
 {
     var service = new ApplicationDataService()
     {
         UserId = 1024
     };
     var response = service.HandleAvailableApplicationMaterialRequest(new AvailableApplicationMaterialRequest()
     {
     });
 }
예제 #2
0
        public static void HandleRequest(HttpListenerContext context)
        {
            try
            {
                HttpListenerRequest request = context.Request;
                string postData             = new StreamReader(request.InputStream, Encoding.UTF8).ReadToEnd();
                byte[] rbytes = HexStringToByteArray(postData);
                object recv   = DeserializeObject(rbytes);
                Console.WriteLine("收到请求:" + recv);
                int id = int.Parse(request.Headers["UserId"]);
                HttpListenerResponse response = context.Response;//响应

                string resp         = "响应";
                string responseBody = objecttostring(resp);
                // UsrInfoService
                UserInfoService UserInfoService = new UserInfoService()
                {
                    UserId = id
                };
                DeliveryDataService DeliveryDataService = new DeliveryDataService()
                {
                    UserId = id
                };
                ApplicationDataService ApplicationDataService = new ApplicationDataService()
                {
                    UserId = id
                };
                DonationDataService DonationDataService = new DonationDataService()
                {
                    UserId = id
                };
                AdminDataService AdminDataService = new AdminDataService()
                {
                    UserId = id
                };
                if (recv is LoginRequest loginRequest)
                {
                    responseBody = objecttostring(UserInfoService.HandleLoginRequest(loginRequest));
                }
                else if (recv is UserInfoRequest userInfoRequest)
                {
                    responseBody = objecttostring(UserInfoService.HandleUserInfoRequest(userInfoRequest));
                }
                else if (recv is RegisterRequest registerRequest)
                {
                    responseBody = objecttostring(UserInfoService.HandleRegisterRequest(registerRequest));
                }
                else if (recv is UserInfoModifyRequest userInfoModifyRequest)
                {
                    responseBody = objecttostring(UserInfoService.HandleModifyRequest(userInfoModifyRequest));
                }
                else if (recv is GetDonationListRequest getDonationListRequest)
                {
                    responseBody = objecttostring(DonationDataService.HandleGetDonationListRequest(getDonationListRequest));
                }
                else if (recv is GetDonationDetailRequest getDonationDetailRequest)
                {
                    responseBody = objecttostring(DonationDataService.HandleGetDonationDetailRequest(getDonationDetailRequest));
                }
                else if (recv is AvailableDonationMaterialRequest availableDonationMaterialRequest)
                {
                    responseBody = objecttostring(DonationDataService.HandleAvailableDonationMaterialRequest(availableDonationMaterialRequest));
                }
                else if (recv is NewDonationRequest newDonationRequest)
                {
                    responseBody = objecttostring(DonationDataService.HandleNewDonationRequest(newDonationRequest));
                }
                else if (recv is CancelDonationRequest cancelDonationRequest)
                {
                    responseBody = objecttostring(DonationDataService.HandleCancelDonationRequest(cancelDonationRequest));
                }

                // DeliveryDataService
                else if (recv is DeliveryListNumRequest deliveryListNumRequest)
                {
                    responseBody = objecttostring(DeliveryDataService.HandleDeliveryListNumRequest(deliveryListNumRequest));
                }
                else if (recv is DeliveryListRequest deliveryListRequest)
                {
                    responseBody = objecttostring(DeliveryDataService.HandleDeliveryListRequest(deliveryListRequest));
                }
                else if (recv is DeliveryMoveRequest deliveryMoveRequest)
                {
                    responseBody = objecttostring(DeliveryDataService.HandleDeliveryMoveRequest(deliveryMoveRequest));
                }
                else if (recv is DeliveryApplyRequest deliveryApplyRequest)
                {
                    responseBody = objecttostring(DeliveryDataService.HandleDeliveryApplyRequest(deliveryApplyRequest));
                }

                else if (recv is AvailableApplicationMaterialRequest availableApplicationMaterialRequest)
                {
                    responseBody = objecttostring(ApplicationDataService.HandleAvailableApplicationMaterialRequest(availableApplicationMaterialRequest));
                }
                else if (recv is GetApplicationDetailRequest getApplicationDetailRequest)
                {
                    responseBody = objecttostring(ApplicationDataService.HandleGetApplicationDetailRequest(getApplicationDetailRequest));
                }
                else if (recv is GetApplicationListRequest getApplicationListRequest)
                {
                    responseBody = objecttostring(ApplicationDataService.HandleGetApplicationListRequest(getApplicationListRequest));
                }
                else if (recv is NewApplicationRequest newApplicationRequest)
                {
                    responseBody = objecttostring(ApplicationDataService.HandleNewApplicationRequest(newApplicationRequest));
                }
                else if (recv is CancelApplicationRequest cancelApplicationRequest)
                {
                    responseBody = objecttostring(ApplicationDataService.HandleCancelApplicationRequest(cancelApplicationRequest));
                }
                else if (recv is ConfirmApplicationDoneRequest confirmApplicationDoneRequest)
                {
                    responseBody = objecttostring(ApplicationDataService.HandleConfirmApplicationDoneRequest(confirmApplicationDoneRequest));
                }
                // AdminDataService
                else if (recv is MaterialAuditAgreeRequest materialAuditAgreeRequest)
                {
                    responseBody = objecttostring(AdminDataService.HandleMaterialAuditAgreeRequest(materialAuditAgreeRequest));
                }
                else if (recv is MaterialAuditListRequest materialAuditListRequest)
                {
                    responseBody = objecttostring(AdminDataService.HandleMaterialAuditListRequest(materialAuditListRequest));
                }
                else if (recv is MaterialAuditRefuseRequest materialAuditRefuseRequest)
                {
                    responseBody = objecttostring(AdminDataService.HandleMaterialAuditRefuseRequest(materialAuditRefuseRequest));
                }
                else if (recv is SecondaryPasswordChangeRequest secondaryPasswordChangeRequest)
                {
                    responseBody = objecttostring(AdminDataService.HandleSecondaryPasswordChangeRequest(secondaryPasswordChangeRequest));
                }
                else
                {
                    System.Diagnostics.Debug.Assert(false);
                }

                response.ContentLength64 = responseBody.Length;
                response.ContentType     = "text/html";
                //输出响应内容
                Stream output = response.OutputStream;
                using (StreamWriter sw = new StreamWriter(output))
                {
                    sw.Write(responseBody);
                    sw.Flush();
                    sw.Close();
                }
                Console.WriteLine("响应结束");
            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
            }
        }