public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next) { if (IsDocumentationRequest(context)) { var actionDescriptor = (ControllerActionDescriptor)context.ActionDescriptor; MethodInfo actionMethod = actionDescriptor.MethodInfo; IHeaderDictionary headers = context.HttpContext.Request.Headers; DocActionModel actionDocModel = await _docReader.GetActionDocModel(headers, actionMethod); if (actionDocModel == null) { context.Result = new StatusCodeResult(StatusCodes.Status404NotFound); } else { context.Result = new ObjectResult(actionDocModel); } } else { // Call the actual API method since not a documentation request. await next(); } }
public async Task <DocActionModel> GetActionDocModel(IHeaderDictionary headers, MethodInfo methodInfo) { if (methodInfo == null) { throw new ArgumentNullException(nameof(methodInfo), "Method information not specified."); } DocAction actionDoc = _docModule.GetActionDoc(methodInfo); if (actionDoc == null) { return(await Task.FromResult <DocActionModel>(null)); } var actionDocModel = new DocActionModel(actionDoc); await AddResourceDocs(actionDocModel, actionDoc); Type responseResourceType = ActionExtensions.GetActionResponseResourceType(methodInfo); if (responseResourceType != null) { // Based on the accept type, load the resource metadata which will contain information // about the associated link relations. Add documentation for each resource link. IResourceMeta resourceMeta = _resourceMediaModule.GetRequestedResourceMediaMeta(headers, responseResourceType); AddResourceRelationDocs(actionDocModel, actionDoc, resourceMeta); } return(actionDocModel); }
// Added by Bharat on 06 June 2017 public JsonResult GetReference(string RefQry) { Ctx ctx = Session["ctx"] as Ctx; DocActionModel model = new DocActionModel(ctx); RefQry = SecureEngineBridge.DecryptByClientKey(RefQry, ctx.GetSecureKey()); return(Json(JsonConvert.SerializeObject(model.GetReference(RefQry)), JsonRequestBehavior.AllowGet));; }
private void AddResourceRelationDocs(DocActionModel actionDocModel, DocAction actionDoc, IResourceMeta resourceMeta) { DocRelation[] relationDocs = resourceMeta.Links.Select( link => new DocRelation(link) { Description = GetRelationDescription(link, actionDoc, _docModule.GetCommonDefinitions()) }).ToArray(); actionDocModel.Relations = relationDocs; }
public JsonResult GetDocActions(int AD_Table_ID, int Record_ID, string docStatus, bool processing, string orderType, bool isSOTrx, string docAction, string tableName, string values, string names) { Ctx ctx = Session["ctx"] as Ctx; DocActionModel model = new DocActionModel(ctx); List <string> lstValues = JsonConvert.DeserializeObject <List <string> >(values); List <string> lstNames = JsonConvert.DeserializeObject <List <string> >(names); DocAtions action = model.GetActions(AD_Table_ID, Record_ID, docStatus, Util.GetValueOfBool(processing), orderType, Util.GetValueOfBool(isSOTrx), docAction, tableName, lstValues, lstNames); return(Json(JsonConvert.SerializeObject(action), JsonRequestBehavior.AllowGet));; }
public async Task AddResourceDocs(DocActionModel actionDocModel, DocAction actionDoc) { if (actionDocModel == null) { throw new ArgumentNullException(nameof(actionDocModel), "Action Document Model not specified."); } if (actionDoc == null) { throw new ArgumentNullException(nameof(actionDoc), "Action Document not specified."); } if (actionDoc.RequestResourceType != null) { actionDocModel.ReqestResource = _docModule.GetResourceDoc(actionDoc.RequestResourceType); actionDocModel.RequestTypeScript = await ReadTypeScriptDefinition(actionDoc.RequestResourceType); } if (actionDoc.ResponseResourceType != null) { actionDocModel.ResponseResource = _docModule.GetResourceDoc(actionDoc.ResponseResourceType); actionDocModel.ResponseTypeScript = await ReadTypeScriptDefinition(actionDoc.ResponseResourceType); } }