public static async Task <FlowExecutionStateInstruction> GetInstructionsForStep(string flowTrackingId, string stepTrackingId, bool useNamedSession = false) { Uri uri = await RestConstants.GetUriAsync(SERVICE_URL, "GetInstructionsForStep"); GetInstructionsForStepBody requestBody = new GetInstructionsForStepBody { Context = useNamedSession ? new UserContext(RestConstants.NamedSessionId) : await AuthService.Instance.GetUserContextAsync(), FlowTrackingId = flowTrackingId, StepTrackingId = stepTrackingId }; try { HttpClient httpClient = new HttpClient(); var response = await httpClient.PostAsync(uri, RestConstants.SerializeBody(requestBody)); if (response.IsSuccessStatusCode) { var responseBody = await response.Content.ReadAsStringAsync(); var resultWrapper = JsonConvert.DeserializeObject <GetInstructionsForStepWrapper>(responseBody); //var task = OfflineService.Instance.SaveDataAsync($"{uri.AbsolutePath}/{flowTrackingId}/{stepTrackingId}", resultWrapper); //var task = OfflineService.Instance.SaveInstructionAsync(resultWrapper.GetInstructionsForStepResult.FlowId, 1, resultWrapper.GetInstructionsForStepResult); return(resultWrapper.GetInstructionsForStepResult); } } catch (Exception ex) { Debug.WriteLine(@" ERROR {0}", ex.Message); } return(null); }
public static async Task <DataDescription[]> GetFlowInputsOnly(string flowId) { Uri uri = await RestConstants.GetUriAsync(SERVICE_URL, "GetFlowInputsOnly"); GetFlowInputsBody body = new GetFlowInputsBody { FlowId = flowId, Context = await AuthService.Instance.GetUserContextAsync(), }; try { HttpClient httpClient = new HttpClient(); var response = await httpClient.PostAsync(uri, RestConstants.SerializeBody(body)); if (response.IsSuccessStatusCode) { var responseBody = await response.Content.ReadAsStringAsync(); var resultWrapper = JsonConvert.DeserializeObject <GetFlowInputsOnlyWrapper>(responseBody); return(resultWrapper.GetFlowInputsOnlyResult); } } catch (Exception ex) { Debug.WriteLine(@" ERROR {0}", ex.Message); } return(new DataDescription[0]); }
public static async void FormClosed(string flowTrackingId, string stepTrackingId) { Uri uri = await RestConstants.GetUriAsync(SERVICE_URL, "FormClosed"); FormClosedBody requestBody = new FormClosedBody { UserContext = await AuthService.Instance.GetUserContextAsync(), FlowTrackingId = flowTrackingId, StepTrackingId = stepTrackingId }; try { HttpClient httpClient = new HttpClient(); var response = await httpClient.PostAsync(uri, RestConstants.SerializeBody(requestBody)); if (response.IsSuccessStatusCode) { // TODO logging Debug.WriteLine("Problem closing form on server:", response); } } catch (Exception ex) { Debug.WriteLine(@" ERROR {0}", ex.Message); } }
public static async Task <object> FormLoadComplete(string formSessionInfoId) { Uri uri = await RestConstants.GetUriAsync(SERVICE_URL, "FormLoadComplete"); FormServiceRequestBody requestBody = new FormServiceRequestBody { UserContext = await AuthService.Instance.GetUserContextAsync(), FormSessionInfoId = formSessionInfoId }; try { HttpClient httpClient = new HttpClient(); var response = await httpClient.PostAsync(uri, RestConstants.SerializeBody(requestBody)); if (response.IsSuccessStatusCode) { var responseBody = await response.Content.ReadAsStringAsync(); var resultWrapper = JsonConvert.DeserializeObject <FormLoadCompleteResponse>(responseBody); return(resultWrapper.FormLoadCompleteResult); } } catch (Exception ex) { Debug.WriteLine(@" ERROR {0}", ex.Message); } return(null); }
public static string GetWorkflowActionFlowUrl(string flowId, Session session) { // e.g. // http://localhost/decisions/Primary/H/?FlowId=ad129170-5fc1-11e9-b51f-802bf99b288c&ForceFormat=true&Location=Maximized&Chrome=Off var url = $"{session.ServerBaseUrl}{RestConstants.MOBILE_API_ROOT}/" + $"?{RestConstants.FLOW_ID}={flowId}"; url = AuthService.Instance.AppendSessionId(url); url = RestConstants.AppendEmbedFlowParams(url); return(url); }
public static async Task <FlowExecutionStateInstruction> StartFlowWithData(string flowId, DataPair[] data, bool useNamedSession = false) { if (string.IsNullOrEmpty(flowId)) { Debug.WriteLine("flowId cannot be null or empty"); return(null); } Uri uri = await RestConstants.GetUriAsync(SERVICE_URL, "StartFlowWithData"); if (!useNamedSession) { Session session = await AuthService.Instance.CheckSessionAsync(); } try { StartFlowWithDataBody requestBody = new StartFlowWithDataBody { Data = data, FlowId = flowId, Context = useNamedSession ? new UserContext(RestConstants.NamedSessionId) : await AuthService.Instance.GetUserContextAsync(), }; HttpClient httpClient = new HttpClient(); var response = await httpClient.PostAsync(uri, RestConstants.SerializeBody(requestBody)); if (response.IsSuccessStatusCode) { var responseBody = await response.Content.ReadAsStringAsync(); //Debug.Write(responseBody); var resultWrapper = JsonConvert.DeserializeObject <StartFlowWithDataWrapper>(responseBody); //var task = OfflineService.Instance.SaveDataAsync($"{uri.AbsolutePath}/{flowId}", resultWrapper); if (!string.IsNullOrEmpty(resultWrapper.StartFlowWithDataResult.ExceptionMessage)) { throw new Exception(resultWrapper.StartFlowWithDataResult.ExceptionMessage); } //var task = await OfflineService.Instance.SaveInstructionAsync(flowId, 0, resultWrapper.StartFlowWithDataResult); return(resultWrapper.StartFlowWithDataResult); } } 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); }
private static string GetImageData <T>(ComponentContainer child, StandAloneFormSessionInfo info) { string name = child.ComponentId ?? child.ComponentName; string sessionid = info.FormSessionInfoId; string gen = Array.Find(info.InitialControlsData, data => data.Name.Equals(name)).OutputValue.ToString(); var uriTask = RestConstants.GetUriAsync("FormService", "GetFileStream?"); uriTask.Wait(); string url = uriTask.Result.AbsoluteUri + $"formSessionInfoId={sessionid}&componentId={name}&fileId=silverimagefile&downloadFile=true&gen={gen}"; return(url); }
// Idealist in me wants this elsewhere, as it's not "display logic," strictly speaking. public void UpdateAssignmentUrl() { if (Connectivity.NetworkAccess != NetworkAccess.Internet) { viewModel.IsWebViewSuccess = false; } else { string url = $"{AuthService.Instance.CurrentSession.ServerBaseUrl}{RestConstants.MOBILE_API_ROOT}/" + $"?{RestConstants.ASSIGNMENT_ID}={assignment.AssignmentId}"; url = AuthService.Instance.AppendSessionId(url); url = RestConstants.AppendChromeless(url); url = RestConstants.AppendLocationCenter(url); viewModel.Url = url; } }
public async Task <List <Workflow> > GetAllOfflineCatalogItemsAsync() { var session = await AuthService.Instance.CheckSessionAsync(); if (!session.IsValid) { return(null); } using (var httpClient = new HttpClient()) { var uri = await RestConstants.GetUriAsync(RestConstants.WORKFLOW_CATALOG, "GetAllOfflineCatalogItems"); GetAllOfflineCatalogItemsRequest requestBody = new GetAllOfflineCatalogItemsRequest { UserContext = await AuthService.Instance.GetUserContextAsync() }; try { List <Workflow> workflows = new List <Workflow>(); var response = await httpClient.PostAsync(uri, RestConstants.SerializeBody(requestBody)); if (response.IsSuccessStatusCode) { var body = await response.Content.ReadAsStringAsync(); var resultWrapper = JsonConvert.DeserializeObject <GetAllOfflineCatalogItemsResultWrapper>(body, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); workflows = resultWrapper.GetAllOfflineCatalogItemsResult; } return(workflows); } catch (Exception ex) { Debug.WriteLine($"GetAllOfflineCatalogItemsAsync - {ex.Message}"); } } return(null); }
public async Task <DecisionsFormInfoEvent> SubmitOfflineForms(string categoryItemId, List <OfflineFormSubmission> formSubmissions) { var session = await AuthService.Instance.CheckSessionAsync(); if (!session.IsValid) { return(null); } using (var httpClient = new HttpClient()) { var uri = await RestConstants.GetUriAsync(RestConstants.WORKFLOW_CATALOG, "SubmitOfflineForms"); SubmitOfflineFormsRequestBody requestBody = new SubmitOfflineFormsRequestBody { UserContext = await AuthService.Instance.GetUserContextAsync(), FormSubmissions = formSubmissions.ToArray(), CatalogItemId = categoryItemId }; try { var response = await httpClient.PostAsync(uri, RestConstants.SerializeBody(requestBody)); if (response.IsSuccessStatusCode) { var responseBody = await response.Content.ReadAsStringAsync(); var submitOfflineFormsResponse = JsonConvert.DeserializeObject <SubmitOfflineFormsResponse>(responseBody); return(FormService.GetNextFormInstruction(submitOfflineFormsResponse.SubmitOfflineFormsResult)); } else { Debug.Write(response); } } catch (Exception ex) { Debug.WriteLine(@" ERROR {0}", ex.Message); } } return(null); }
public async Task <IEnumerable <Workflow> > GetAllMobileServiceCatalogItemsAsync() { IEnumerable <Workflow> workflows = new List <Workflow>(); var session = await AuthService.Instance.CheckSessionAsync(); if (!session.IsValid) { return(workflows); } using (HttpClient httpClient = new HttpClient()) { var uri = await RestConstants.GetUriAsync(RestConstants.WORKFLOW_CATALOG, "GetAllMobileServiceCatalogItems"); GetAllRequestBody requestBody = new GetAllRequestBody { UserContext = await AuthService.Instance.GetUserContextAsync(), }; var postBody = RestConstants.SerializeBody(requestBody); var response = await httpClient.PostAsync(uri, postBody); if (response.IsSuccessStatusCode) { var body = await response.Content.ReadAsStringAsync(); var converterSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; var resultWrapper = JsonConvert.DeserializeObject <GetAllWorkflowsResult>(body, converterSettings); workflows = resultWrapper.GetAllMobileServiceCatalogItemsResult; } } return(workflows); }
public static async Task <DecisionsFormInfoEvent> SelectPath(string formSessionInfoId, string outcomeName, DataPair[] controlsData, bool useNamedSession = false) { Uri uri = await RestConstants.GetUriAsync(SERVICE_URL, "SelectPath"); SelectPathRequestBody requestBody = new SelectPathRequestBody { UserContext = useNamedSession ? new UserContext(RestConstants.NamedSessionId) : await AuthService.Instance.GetUserContextAsync(), FormSessionInfoId = formSessionInfoId, OutcomeName = outcomeName, ControlsData = controlsData, RuleSessionInfos = new object[0] // TODO rules }; var postBody = RestConstants.SerializeBody(requestBody); Debug.Write(postBody); try { HttpClient httpClient = new HttpClient(); var response = await httpClient.PostAsync(uri, postBody); if (response.IsSuccessStatusCode) { var responseBody = await response.Content.ReadAsStringAsync(); var resultWrapper = JsonConvert.DeserializeObject <SelectPathResponse>(responseBody); return(GetNextFormInstruction(resultWrapper.SelectPathResult)); } else { Debug.Write(response); } } catch (Exception ex) { Debug.WriteLine(@" ERROR {0}", ex.Message); } return(null); }
// TODO dry these methods up with a good generic... public static async Task <StandAloneFormSessionInfo> GetFormSessionSurfaceJson(FlowExecutionStateInstruction instruction, bool useNamedSession = false) { Uri uri = await RestConstants.GetUriAsync(SERVICE_URL, "GetFormSessionSurfaceJson"); try { FormServiceRequestBody requestBody = new FormServiceRequestBody { UserContext = useNamedSession ? new UserContext(RestConstants.NamedSessionId) : await AuthService.Instance.GetUserContextAsync(), FormSessionInfoId = instruction.FormSessionId }; var serializedBody = RestConstants.SerializeBody(requestBody); HttpClient httpClient = new HttpClient(); var response = await httpClient.PostAsync(uri, serializedBody); if (response.IsSuccessStatusCode) { var responseBody = await response.Content.ReadAsStringAsync(); var resultWrapper = JsonConvert.DeserializeObject <GetFormSessionSurfaceJsonResponse>(responseBody); // we need $type field to specify component type in form data // NewtonJson can't deserialize field which starts with '$', so we needed to replace it to get correct deserialization. resultWrapper.GetFormSessionSurfaceJsonResult = resultWrapper.GetFormSessionSurfaceJsonResult.Replace("$type", "__type"); StandAloneFormSessionInfo info = JsonConvert.DeserializeObject <StandAloneFormSessionInfo>( resultWrapper.GetFormSessionSurfaceJsonResult); return(info); } } catch (Exception ex) { Debug.WriteLine(@" ERROR {0}", ex.Message); } return(null); }
public RestProvider([NotNull] ApplicationContext appContext, IRestClientFactory restClientFactory) : base(appContext, RestConstants.CreateProviderMetadata()) { _restClientFactory = restClientFactory; }
public static string GetImageInfoUrl(ImageInfo info, int width = 48, int height = 48) { if (info.ImageType == (long)ImageInfoType.Url) { return(info.ImageUrl); } else if (info.ImageType == (long)ImageInfoType.StoredImage) { return(Uri.EscapeUriString($"{AuthService.Instance.CurrentSession.ServerBaseUrl}/Handlers/SvgImage.ashx?svgFile={info.ImageId}&width={width}&height={height}")); } else if (info.ImageType == (long)ImageInfoType.Document) { return(Uri.EscapeUriString($"{AuthService.Instance.CurrentSession.ServerBaseUrl}/Handlers/SvgImage.ashx?documentId={info.DocumentId}&width={width}height=${height}")); } else if (info.ImageType == (long)ImageInfoType.RawData && info.ImageFileReferenceId != null) { var fileNameArr = ((string)info.ImageFileReferenceId).Split('-'); if (fileNameArr.Length >= 2) { string referenceId = (string)info.ImageFileReferenceId; referenceId = referenceId.Replace($"{fileNameArr[0]}_", ""); return(Uri.EscapeUriString($"{AuthService.Instance.CurrentSession.ServerBaseUrl}/{RestConstants.GetServiceUri("FileReferenceService", "DownloadFile")}?id={fileNameArr[0]}&filename={referenceId}")); } } return(null); }