public static void Main(string[] args)
        {
            try
            {
                // Build Vault Engine calculation parameters
                var componentsApi = new ComponentsApi(GetEngineApiConfiguration());

                var componentsResponse = componentsApi.GetVaultComponentsWithHttpInfo(VaultDefaultDocument);

                var vaultComponentId = componentsResponse.Data.FirstOrDefault(component =>
                                                                              (component.Value.Name == VaultComponentName &&
                                                                               component.Value.Category == VaultComponentCategory))
                                       .Key;
                Console.WriteLine($"Vault Component Id : {vaultComponentId}");

                var vaultAccount = new VaultIdentifier(VaultDefaultAccount);
                var vaultDates   = new VaultDateParameters(VaultStartDate, VaultEndDate, VaultFrequency);

                var configurationApi = new ConfigurationsApi(GetEngineApiConfiguration());

                var configurationResponse = configurationApi.GetVaultConfigurationsWithHttpInfo(vaultAccount.Id);
                var vaultConfiguration    = configurationResponse.Data.First().Key;

                var vaultCalculation = new VaultCalculationParameters(vaultComponentId, vaultAccount, vaultDates, vaultConfiguration);

                var calculationApi = new VaultCalculationsApi(GetEngineApiConfiguration());

                var runCalculationResponse = calculationApi.RunVaultCalculationWithHttpInfo(vaultCalculation);

                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.GetVaultCalculationByIdWithHttpInfo(calculationId);
                }
Ejemplo n.º 2
0
        private ApiResponse <object> RunCalculation()
        {
            var vaultComponents = _componentsApi.GetVaultComponentsWithHttpInfo(CommonParameters.VaultDefaultDocument);

            var vaultComponentId       = vaultComponents.Data.Keys.First();
            var vaultAccountIdentifier = new VaultIdentifier(CommonParameters.VaultDefaultAccount);
            var vaultDates             = new VaultDateParameters(CommonParameters.VaultStartDate, CommonParameters.VaultEndDate, CommonParameters.VaultFrequency);
            var vaultConfiguration     = _configurationsApi.GetVaultConfigurationsWithHttpInfo(CommonParameters.VaultDefaultAccount);
            var vaultConfigurationId   = vaultConfiguration.Data.Keys.First();

            var paCalculation = new VaultCalculationParameters(vaultComponentId, vaultAccountIdentifier, vaultDates, vaultConfigurationId);

            var response = _calculationsApi.RunVaultCalculationWithHttpInfo(paCalculation);

            return(response);
        }