示例#1
0
        private static RestActionCache LoadById2(int id, RockContext rockContext)
        {
            var restActionService = new RestActionService(rockContext);
            var restActionModel   = restActionService.Get(id);

            if (restActionModel != null)
            {
                return(new RestActionCache(restActionModel));
            }

            return(null);
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack)
            {
                var service    = new RestActionService(new RockContext());
                var restAction = service.Get(PageParameter("RestActionId").AsInteger());

                if (restAction != null)
                {
                    var config            = GlobalConfiguration.Configuration;
                    var explorer          = config.Services.GetApiExplorer();
                    var controllerActions = explorer.ApiDescriptions.Where(a => (a.ActionDescriptor.ControllerDescriptor.ControllerName == restAction.Controller.Name));
                    var apiDescription    = controllerActions.FirstOrDefault(a => a.ID == restAction.ApiId);
                    if (apiDescription != null)
                    {
                        hfUrl.Value       = this.ResolveUrl("~/" + apiDescription.RelativePath);
                        lUrlPreview.Text  = apiDescription.HttpMethod.ToString().ToUpper() + " " + hfUrl.Value;
                        btnDELETE.Visible = apiDescription.HttpMethod == System.Net.Http.HttpMethod.Delete;

                        btnGET.Visible            = apiDescription.HttpMethod == System.Net.Http.HttpMethod.Get;
                        rblLoadAttributes.Visible = apiDescription.HttpMethod == System.Net.Http.HttpMethod.Get;

                        btnPUT.Visible    = apiDescription.HttpMethod == System.Net.Http.HttpMethod.Put;
                        btnPOST.Visible   = apiDescription.HttpMethod == System.Net.Http.HttpMethod.Post;
                        tbPayload.Visible = apiDescription.HttpMethod == System.Net.Http.HttpMethod.Post || apiDescription.HttpMethod == System.Net.Http.HttpMethod.Put;

                        foreach (var param in apiDescription.ParameterDescriptions)
                        {
                            if (param.Source == System.Web.Http.Description.ApiParameterSource.FromUri)
                            {
                                lstParameterValues.Value += param.Name + "|";
                            }
                        }
                    }
                    else
                    {
                        // todo warning
                    }
                }
            }
        }