public static void Main(string[] args) { try { // Build SPAR Engine calculation parameters var componentsApi = new ComponentsApi(GetEngineApiConfiguration()); var componentsResponse = componentsApi.GetSPARComponentsWithHttpInfo(SPARDefaultDocument); var sparComponentId = componentsResponse.Data.FirstOrDefault(component => (component.Value.Name == SPARComponentName && component.Value.Category == SPARComponentCategory)).Key; Console.WriteLine($"SPAR Component Id : {sparComponentId}"); var sparAccountIdentifier = new SPARIdentifier(SPARBenchmarkR1000, SPARBenchmarkRussellReturnType, SPARBenchmarkRussellPrefix); var sparAccounts = new List <SPARIdentifier> { sparAccountIdentifier }; var sparBenchmarkIdentifier = new SPARIdentifier(SPARBenchmarkRussellPr2000, SPARBenchmarkRussellReturnType, SPARBenchmarkRussellPrefix); var sparCalculation = new SPARCalculationParameters(sparComponentId, sparAccounts, sparBenchmarkIdentifier); var calculationApi = new SPARCalculationsApi(GetEngineApiConfiguration()); var runCalculationResponse = calculationApi.RunSPARCalculationWithHttpInfo(sparCalculation); var calculationId = string.Empty; while (runCalculationResponse.StatusCode == HttpStatusCode.Accepted) { if (string.IsNullOrWhiteSpace(calculationId)) { runCalculationResponse.Headers.TryGetValue("Location", out var location); calculationId = location?[0].Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last(); } if (runCalculationResponse.Headers.ContainsKey("Cache-Control") && runCalculationResponse.Headers["Cache-Control"][0] is var maxAge && !string.IsNullOrWhiteSpace(maxAge)) { var age = int.Parse(maxAge.Replace("max-age=", "")); Console.WriteLine($"Sleeping for {age} seconds"); Thread.Sleep(age * 1000); } else { Console.WriteLine("Sleeping for 2 seconds"); // Sleep for at least 2 seconds. Thread.Sleep(2000); } runCalculationResponse = calculationApi.GetSPARCalculationByIdWithHttpInfo(calculationId); }
public void Init() { sparCalculationsApi = new SPARCalculationsApi(CommonFunctions.BuildConfiguration()); componentsApi = new ComponentsApi(CommonFunctions.BuildConfiguration()); }
public void Init() { _calculationsApi = new SPARCalculationsApi(CommonFunctions.BuildConfiguration(Engine.SPAR)); _componentsApi = new ComponentsApi(CommonFunctions.BuildConfiguration(Engine.SPAR)); }
public static void Main(string[] args) { try { var calculationParameters = new SPARCalculationParametersRoot { Data = new Dictionary <string, SPARCalculationParameters> { { "1", GetSparCalculationParameters() } } }; var calculationApi = new SPARCalculationsApi(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. //var cacheControl = "max-stale=300"; //var calculationResponse = calculationApi.PostAndCalculateWithHttpInfo(null, cacheControl, calculationParameters); if (calculationResponse.StatusCode == HttpStatusCode.Created) { ObjectRoot result = (ObjectRoot)calculationResponse.Data; PrintResult(result); return; } 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 sparCalculation in status.Data.Units) { if (sparCalculation.Value.Status == CalculationUnitStatus.StatusEnum.Success) { var resultResponse = calculationApi.GetCalculationUnitResultByIdWithHttpInfo(calculationId, sparCalculation.Key); PrintResult(resultResponse.Data); } else { Console.WriteLine($"Calculation Unit Id : {sparCalculation.Key} Failed!!!"); Console.WriteLine($"Error message : {sparCalculation.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; } }