public static void Main(string[] args) { try { var calculationParameters = new VaultCalculationParametersRoot { Data = new Dictionary <string, VaultCalculationParameters> { { "1", GetVaultCalculationParameters1() }, { "2", GetVaultCalculationParameters2() } } }; var calculationApi = new VaultCalculationsApi(GetApiConfiguration()); var calculationResponse = calculationApi.PostAndCalculateWithHttpInfo(null, null, calculationParameters); // Comment the above line and uncomment the below lines to add cache control configuration. Results are by default cached for 12 hours; Setting max-stale=300 will fetch a cached result which is at max 5 minutes older. max-stale=0 will be a fresh adhoc run and the max-stale value is in seconds. //var cacheControl = "max-stale=300"; //var calculationResponse = calculationApi.PostAndCalculateWithHttpInfo(null, cacheControl, calculationParameters); CalculationStatusRoot status = (CalculationStatusRoot)calculationResponse.Data; var calculationId = status.Data.Calculationid; Console.WriteLine("Calculation Id: " + calculationId); ApiResponse <CalculationStatusRoot> getStatusResponse = null; while (status.Data.Status == CalculationStatus.StatusEnum.Queued || status.Data.Status == CalculationStatus.StatusEnum.Executing) { if (getStatusResponse != null) { if (getStatusResponse.Headers.ContainsKey("Cache-Control")) { var maxAge = getStatusResponse.Headers["Cache-Control"][0]; if (string.IsNullOrWhiteSpace(maxAge)) { Console.WriteLine("Sleeping for 2 seconds"); // Sleep for at least 2 seconds. Thread.Sleep(2000); } else { var age = int.Parse(maxAge.Replace("max-age=", "")); Console.WriteLine($"Sleeping for {age} seconds"); Thread.Sleep(age * 1000); } } } getStatusResponse = calculationApi.GetCalculationStatusByIdWithHttpInfo(calculationId); status = getStatusResponse.Data; } Console.WriteLine("Calculation Completed"); foreach (var vaultCalculation in status.Data.Units) { if (vaultCalculation.Value.Status == CalculationUnitStatus.StatusEnum.Success) { var resultResponse = calculationApi.GetCalculationUnitResultByIdWithHttpInfo(calculationId, vaultCalculation.Key); PrintResult(resultResponse.Data); } else { Console.WriteLine($"Calculation Unit Id : {vaultCalculation.Key} Failed!!!"); Console.WriteLine($"Error message : {vaultCalculation.Value.Errors}"); } } Console.ReadKey(); } catch (ApiException e) { Console.WriteLine($"Status Code: {e.ErrorCode}"); Console.WriteLine($"Reason : {e.Message}"); Console.WriteLine(e.StackTrace); } catch (Exception e) { Console.WriteLine(e); throw; } }
public void EnginesApi_Get_Vault_Calculation_Success() { var calculationResponse = RunCalculation(); Assert.IsTrue(calculationResponse.StatusCode == HttpStatusCode.Accepted, "Create response status code should be 202 - Accepted."); CalculationStatusRoot calculationStatus = (CalculationStatusRoot)calculationResponse.Data; var calculationId = calculationStatus.Data.Calculationid; Assert.IsTrue(!string.IsNullOrWhiteSpace(calculationId), "Create response calculation id should be present."); ApiResponse <CalculationStatusRoot> getStatusResponse = null; while (calculationStatus.Data.Status == CalculationStatus.StatusEnum.Queued || calculationStatus.Data.Status == CalculationStatus.StatusEnum.Executing) { if (getStatusResponse != null) { Assert.IsTrue(getStatusResponse.Data != null, "Response Data should not be null."); Assert.IsTrue(getStatusResponse.Data.Data.Status == CalculationStatus.StatusEnum.Executing || getStatusResponse.Data.Data.Status == CalculationStatus.StatusEnum.Queued, "Response Data should have batch status as processing or queued."); if (getStatusResponse.Headers.ContainsKey("Cache-Control")) { var maxAge = getStatusResponse.Headers["Cache-Control"][0]; if (string.IsNullOrWhiteSpace(maxAge)) { Console.WriteLine("Sleeping for 2 seconds"); // Sleep for at least 2 seconds. Thread.Sleep(2000); } else { var age = int.Parse(maxAge.Replace("max-age=", "")); Console.WriteLine($"Sleeping for {age} seconds"); Thread.Sleep(age * 1000); } } } getStatusResponse = vaultCalculationsApi.GetCalculationStatusByIdWithHttpInfo(calculationId); calculationStatus = getStatusResponse.Data; } Assert.IsTrue(calculationStatus.Data.Status == CalculationStatus.StatusEnum.Completed, "Response Data should have calculation status as completed."); Assert.IsTrue(calculationStatus.Data.Units.Values.All(p => p.Status == CalculationUnitStatus.StatusEnum.Success), "Response Data should have all Vault calculations status as completed."); Assert.IsTrue(calculationStatus.Data.Units.Values.All(p => p.Result != null), "Response Data should have all Vault Calculation results."); foreach (var calculation in calculationStatus.Data.Units) { var resultResponse = vaultCalculationsApi.GetCalculationUnitResultByIdWithHttpInfo(calculationId, calculation.Key); Assert.IsTrue(resultResponse.StatusCode == HttpStatusCode.OK, "Result response status code should be 200 - OK."); Assert.IsTrue(resultResponse.Data != null, "Result response data should not be null."); var stachBuilder = StachExtensionFactory.GetRowOrganizedBuilder(); stachBuilder.SetPackage(resultResponse.Data.Data); Assert.IsInstanceOfType(stachBuilder.GetPackage(), typeof(RowOrganizedPackage), "Result response data should be of type RowOrganizedPackage."); } }