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 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); }
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); }
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); }