Пример #1
0
        public static EditServiceJson CreateFrom(PrimetonDescriptorViewModel model, JsonTemplateNames partName)
        {
            var serviceJson = new EditServiceJson
            {
                ServiceDescriptor = JsonConvert.SerializeObject(model),
                CurrentPath       = "",
                CurrentName       = partName
            };

            switch (partName)
            {
            case JsonTemplateNames.PrimetonParameter:
                serviceJson.CurrentJson = JsonConvert.SerializeObject(model.InputBody);
                break;

            case JsonTemplateNames.PrimetonReturn:
                serviceJson.CurrentJson = JsonConvert.SerializeObject(model.ReturnBody);
                break;

            default:
                throw new Exception("传入了非普元系统Web服务类型的部位参数" + partName.ToString());
            }

            return(serviceJson);
        }
Пример #2
0
        IActionResult DeleteJsonAction(JsonTemplateNames partName, IServiceDescriptorViewModel viewModel, string serviceJson)
        {
            IServiceDescriptorViewModel originalViewModel = RestoreAndUpdateService(viewModel, serviceJson);
            string serviceViewName;

            if (originalViewModel.ServiceType == ServiceType.NCWebService)
            {
                serviceViewName = nameof(EditNCWebService);
            }
            else if (originalViewModel.ServiceType == ServiceType.SimpleRESTful)
            {
                serviceViewName = nameof(EditSimpleRestfulService);
            }
            else if (originalViewModel.ServiceType == ServiceType.PrimetonService)
            {
                serviceViewName = nameof(EditPrimetonService);
            }
            else
            {
                throw new Exception("not implemented");
            }
            if (partName == JsonTemplateNames.NCParameter)
            {
                ((NCDescriptorViewModel)originalViewModel).ParameterBody = null;
            }
            else if (partName == JsonTemplateNames.NCReturn)
            {
                ((NCDescriptorViewModel)originalViewModel).ReturnBody = null;
            }
            else if (partName == JsonTemplateNames.PrimetonParameter)
            {
                ((PrimetonDescriptorViewModel)originalViewModel).InputBody = null;
            }
            else if (partName == JsonTemplateNames.PrimetonReturn)
            {
                ((PrimetonDescriptorViewModel)originalViewModel).ReturnBody = null;
            }
            else if (partName == JsonTemplateNames.RESTParameter)
            {
                ((SimpleRestfulDescriptorViewModel)originalViewModel).JsonBodyTemplate = null;
                ((SimpleRestfulDescriptorViewModel)originalViewModel).SelectedTab      = "nav-json";
            }
            else if (partName == JsonTemplateNames.RESTReturnValue)
            {
                ((SimpleRestfulDescriptorViewModel)originalViewModel).ReturnJsonTemplate = null;
            }
            TempData.Put(EDIT_SERVICE_CROSS_ACTION_DATA_KEY, originalViewModel);
            return(RedirectToAction(serviceViewName));
        }
Пример #3
0
 public static EditServiceJson CreateFrom(EsbService service, JsonTemplateNames partName)
 {
     if (service.Type == ServiceType.SimpleRESTful)
     {
         return(EditServiceJson.CreateFrom(SimpleRestfulDescriptorViewModel.CreateFrom(service), partName));
     }
     else if (service.Type == ServiceType.NCWebService)
     {
         return(EditServiceJson.CreateFrom(NCDescriptorViewModel.CreateFrom(service), partName));
     }
     else if (service.Type == ServiceType.PrimetonService)
     {
         return(EditServiceJson.CreateFrom(PrimetonDescriptorViewModel.CreateFrom(service), partName));
     }
     else
     {
         throw new Exception("not impleted service type");
     }
 }
Пример #4
0
        ServiceType GetServiceType(JsonTemplateNames partName)
        {
            switch (partName)
            {
            case JsonTemplateNames.RESTParameter:
            case JsonTemplateNames.RESTReturnValue:
                return(ServiceType.SimpleRESTful);

            case JsonTemplateNames.NCParameter:
            case JsonTemplateNames.NCReturn:
                return(ServiceType.NCWebService);

            case JsonTemplateNames.PrimetonParameter:
            case JsonTemplateNames.PrimetonReturn:
                return(ServiceType.PrimetonService);

            default:
                throw new Exception("not impleted json part.");
            }
        }
Пример #5
0
        public static EditServiceJson CreateFrom(SimpleRestfulDescriptorViewModel model, JsonTemplateNames partName)
        {
            var serviceJson = new EditServiceJson
            {
                ServiceDescriptor = JsonConvert.SerializeObject(model),
                CurrentPath       = "",
                CurrentName       = partName
            };

            switch (partName)
            {
            case JsonTemplateNames.RESTParameter:
                serviceJson.CurrentJson = JsonConvert.SerializeObject(model.JsonBodyTemplate);
                break;

            case JsonTemplateNames.RESTReturnValue:
                serviceJson.CurrentJson = JsonConvert.SerializeObject(model.ReturnJsonTemplate);
                break;

            default:
                throw new Exception("传入了非RESTful服务类型的部位参数" + partName.ToString());
            }

            return(serviceJson);
        }
Пример #6
0
        IActionResult EditJsonAction(JsonTemplateNames partName, IServiceDescriptorViewModel viewModel, string serviceJson)
        {
            IServiceDescriptorViewModel originalViewModel = RestoreAndUpdateService(viewModel, serviceJson);

            #region 为要编辑的对象设置默认值(初始化JSON模板并设置初始数据类型)
            //string errorKey = "";
            if (partName == JsonTemplateNames.NCParameter)
            {
                //errorKey = STATE_NCPARAMETER_ERROR;
                if (((NCDescriptorViewModel)originalViewModel).ParameterBody == null)
                {
                    ((NCDescriptorViewModel)originalViewModel).ParameterBody           = new JsonTemplate();
                    ((NCDescriptorViewModel)originalViewModel).ParameterBody.ValueType = Models.ValueType.Object;
                }
            }
            else if (partName == JsonTemplateNames.NCReturn)
            {
                //errorKey = STATE_NCRETURN_ERROR;
                if (((NCDescriptorViewModel)originalViewModel).ReturnBody == null)
                {
                    ((NCDescriptorViewModel)originalViewModel).ReturnBody           = new JsonTemplate();
                    ((NCDescriptorViewModel)originalViewModel).ReturnBody.ValueType = Models.ValueType.Object;
                }
            }
            else if (partName == JsonTemplateNames.PrimetonParameter)
            {
                //errorKey = STATE_PRIMETON_PARAMETER_ERROR;
                if (((PrimetonDescriptorViewModel)originalViewModel).InputBody == null)
                {
                    ((PrimetonDescriptorViewModel)originalViewModel).InputBody           = new JsonTemplate();
                    ((PrimetonDescriptorViewModel)originalViewModel).InputBody.ValueType = Models.ValueType.Object;
                }
            }
            else if (partName == JsonTemplateNames.PrimetonReturn)
            {
                //errorKey = STATE_PRIMETON_RETURN_ERROR;
                if (((PrimetonDescriptorViewModel)originalViewModel).ReturnBody == null)
                {
                    ((PrimetonDescriptorViewModel)originalViewModel).ReturnBody           = new JsonTemplate();
                    ((PrimetonDescriptorViewModel)originalViewModel).ReturnBody.ValueType = Models.ValueType.Object;
                }
            }
            else if (partName == JsonTemplateNames.RESTParameter)
            {
                //errorKey = STATE_RESTJSON_ERROR;
                if (((SimpleRestfulDescriptorViewModel)originalViewModel).JsonBodyTemplate == null)
                {
                    ((SimpleRestfulDescriptorViewModel)originalViewModel).JsonBodyTemplate           = new JsonTemplate();
                    ((SimpleRestfulDescriptorViewModel)originalViewModel).JsonBodyTemplate.ValueType = Models.ValueType.Integer;
                }
            }
            else if (partName == JsonTemplateNames.RESTReturnValue)
            {
                //errorKey = STATE_RESTRETURN_ERROR;
                if (((SimpleRestfulDescriptorViewModel)originalViewModel).ReturnJsonTemplate == null)
                {
                    ((SimpleRestfulDescriptorViewModel)originalViewModel).ReturnJsonTemplate           = new JsonTemplate();
                    ((SimpleRestfulDescriptorViewModel)originalViewModel).ReturnJsonTemplate.ValueType = Models.ValueType.Integer;
                }
            }
            #endregion

            EditServiceJson postedJson;
            if (originalViewModel.ServiceType == ServiceType.NCWebService)
            {
                postedJson = Models.EditServiceJson.CreateFrom((NCDescriptorViewModel)originalViewModel, partName);
            }
            else if (originalViewModel.ServiceType == ServiceType.SimpleRESTful)
            {
                postedJson = Models.EditServiceJson.CreateFrom((SimpleRestfulDescriptorViewModel)originalViewModel, partName);
            }
            else if (originalViewModel.ServiceType == ServiceType.PrimetonService)
            {
                postedJson = Models.EditServiceJson.CreateFrom((PrimetonDescriptorViewModel)originalViewModel, partName);
            }
            else
            {
                throw new Exception("not implemented");
            }
            TempData.Put(EDIT_JSON_CROSS_ACTION_DATA_KEY, postedJson);
            return(RedirectToAction(nameof(EditServiceJson)));

            // Exception Catch Block (old)
            // TempData[errorKey] = ex.Message;
            // TempData.Put(EDIT_SERVICE_CROSS_ACTION_DATA_KEY, originalViewModel);
            // if(partName == JsonTemplateNames.RESTParameter)
            // {
            //     ((SimpleRestfulDescriptorViewModel)originalViewModel).SelectedTab = "nav-json";
            // }
            // string serviceViewName;
            // if(originalViewModel.ServiceType == ServiceType.NCWebService)
            // {
            //     serviceViewName = nameof(EditNCWebService);
            // }
            // else if(originalViewModel.ServiceType == ServiceType.SimpleRESTful)
            // {
            //     serviceViewName = nameof(EditSimpleRestfulService);
            // }
            // else
            // {
            //     throw new Exception("not implemented");
            // }
            // return RedirectToAction(serviceViewName);
        }