public async Task <WorkFlowAction> GetWorkflowActionAsync(Workflow workflow) { if (workflowActions.TryGetValue(workflow.ServiceCatalogId, out WorkFlowAction action)) { Debug.WriteLine("returning cached workflow action"); return(action); } Session session = await AuthService.Instance.CheckSessionAsync(); if (!session.IsValid) { return(null); } Debug.WriteLine("fetching workflow action"); var relativePath = $"{RestConstants.REST_ROOT}/{RestConstants.GET_ACTIONS_FOR_ENTITY}"; var uri = new Uri($"{session.ServerBaseUrl}{relativePath}"); try { GetEntityActionsBody body = WorkflowUtil.GetWorkflowActionBody(workflow, session.SessionId); var json = JsonConvert.SerializeObject(body); StringContent content = new StringContent(json, Encoding.UTF8, RestConstants.JSON_HEADER); var response = await httpClient.PostAsync(uri, content); if (response.IsSuccessStatusCode) { var responseBody = await response.Content.ReadAsStringAsync(); var resultWrapper = JsonConvert.DeserializeObject <GetActionsForAnyEntityResponse>(responseBody); var actions = resultWrapper.GetActionsForAnyEntityResult; WorkFlowAction newAction = GetActionForWorkflow(actions, session); Debug.WriteLine("fetched workflow action"); Debug.Write(action); workflowActions.Add(workflow.ServiceCatalogId, newAction); return(newAction); } else { var responseBody = await response.Content.ReadAsStringAsync(); throw new Exception(responseBody); } } catch (Exception ex) { Debug.WriteLine(@" ERROR {0}", ex.Message); } return(null); }
public static GetEntityActionsBody GetWorkflowActionBody(Workflow workflow, string sessionId) { GetEntityActionsBody body = new GetEntityActionsBody(); body.actionTypes = new List <EntityActionType>(); body.actionTypes.Add(RestConstants.GetActionType()); body.sessionid = sessionId; body.entityID = workflow.ServiceCatalogId; // TODO would be better for this to be provided by dependency, not hard-coded: body.typeName = "DecisionsFramework.ServiceLayer.Services.ServiceCatalog.ServiceCatalogItem"; return(body); }