Example #1
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);
        }
Example #2
0
        /// <summary>
        /// 假定uiViewModel参数是来自用户视图的数据已绑定模型,
        /// 而当前实例是一个从数据库或视图中恢复出来的老模型,
        /// 那么,应当运行本方法完成用户可能发生的输入更改。
        /// 注意:本方法仅更新那些绑定到了视图上的form control的值。
        /// </summary>
        /// <param name="uiViewModel"></param>
        public void UpdateFromUI(IServiceDescriptorViewModel uiViewModel)
        {
            SimpleRestfulDescriptorViewModel viewModel = (SimpleRestfulDescriptorViewModel)uiViewModel;

            this.BaseApiUrl          = viewModel.BaseApiUrl;
            this.FormBodyTemplate    = viewModel.FormBodyTemplate;
            this.Method              = viewModel.Method;
            this.QueryStringTemplate = viewModel.QueryStringTemplate;
            this.RouteDataTemplate   = viewModel.RouteDataTemplate;
            this.SelectedTab         = viewModel.SelectedTab;
            this.ReturnType          = viewModel.ReturnType;
            this.SuccessRule         = viewModel.SuccessRule;
            this.SuccessPath         = viewModel.SuccessPath;
            this.SuccessRegx         = viewModel.SuccessRegx;
            this.IgnoreCase          = viewModel.IgnoreCase;
        }
Example #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");
     }
 }
Example #4
0
        /// <summary>
        /// 从一个EsbService定义中创建一个视图模型并返回。
        /// </summary>
        /// <param name="service"></param>
        /// <returns></returns>
        public static SimpleRestfulDescriptorViewModel CreateFrom(EsbService service)
        {
            if (service.Type != ServiceType.SimpleRESTful)
            {
                throw new Exception("服务不是Simple RESTful类型的。");
            }

            var model = JsonConvert.DeserializeObject <SimpleRestfulDescriptorViewModel>(service.ServiceDescriptor);

            if (model == null)
            {
                model = new SimpleRestfulDescriptorViewModel();
            }
            model.ServiceID    = service.ID;
            model.ServiceName  = service.Name;
            model.ActiveStatus = service.ActiveStatus == 1;
            if (model.Headers == null)
            {
                model.Headers = new Dictionary <string, string>();
            }

            return(model);
        }