Ejemplo n.º 1
0
        private static async Task BorrowerPairsTest(IEncompassRestClient client, Loan loan, string loanId, ILoanApis loanApis)
        {
            try
            {
                var borrowerPairs = await loanApis.BorrowerPairs.GetBorrowerPairsAsync();

                Assert.AreEqual($@"{{""encompassId"":""{loan.EncompassId}""}}", loan.ToString(SerializationOptions.Dirty));
                Assert.AreEqual(0, loan.Applications.Count);
                var application   = new Application();
                var applicationId = await loanApis.BorrowerPairs.CreateBorrowerPairAsync(application);

                Assert.AreEqual($@"{{""encompassId"":""{loan.EncompassId}""}}", loan.ToString(SerializationOptions.Dirty));
                Assert.AreEqual(0, loan.Applications.Count);
                var newApplication = new Application {
                    Id = applicationId, ApplicationSignedDate = DateTime.Now.AddDays(2)
                };
                await loanApis.BorrowerPairs.UpdateBorrowerPairAsync(newApplication);

                Assert.AreEqual($@"{{""encompassId"":""{loan.EncompassId}""}}", loan.ToString(SerializationOptions.Dirty));
                Assert.AreEqual(0, loan.Applications.Count);
                Assert.IsTrue(await loanApis.BorrowerPairs.DeleteBorrowerPairAsync(applicationId));
                Assert.AreEqual($@"{{""encompassId"":""{loan.EncompassId}""}}", loan.ToString(SerializationOptions.Dirty));
                Assert.AreEqual(0, loan.Applications.Count);
            }
            finally
            {
                try
                {
                    await client.Loans.DeleteLoanAsync(loanId);
                }
                catch
                {
                }
            }
        }
        /// <summary>
        /// Refreshes the custom fields cache.
        /// </summary>
        /// <param name="client">The client to use to retrieve the custom fields.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns></returns>
        public async Task RefreshCustomFieldsAsync(IEncompassRestClient client, CancellationToken cancellationToken = default)
        {
            Preconditions.NotNull(client, nameof(client));

            var retrievedCustomFields = new Dictionary <string, FieldDescriptor>(StringComparer.OrdinalIgnoreCase);

            var customFieldsList = await client.Settings.Loan.CustomFields.GetCustomFieldsAsync(cancellationToken).ConfigureAwait(false);

            foreach (var customField in customFieldsList)
            {
                var modelPath = $"Loan.CustomFields[(FieldName == '{customField.Id}')].StringValue";
                retrievedCustomFields[customField.Id !] = new NonStandardFieldDescriptor(customField.Id !, LoanFieldDescriptors.CreateModelPath(modelPath) !, modelPath, customField.Description !, customField.Format, customField.Options?.Select(o => new FieldOption(o)).ToList(), false);
Ejemplo n.º 3
0
        /// <summary>
        /// Refreshes the custom fields cache.
        /// </summary>
        /// <param name="client">The client to use to retrieve the custom fields.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns></returns>
        public async Task RefreshCustomFieldsAsync(IEncompassRestClient client, CancellationToken cancellationToken = default)
        {
            Preconditions.NotNull(client, nameof(client));

            var retrievedCustomFields = new Dictionary <string, FieldDescriptor>(StringComparer.OrdinalIgnoreCase);

            var customFieldsList = await client.Settings.Loan.CustomFields.GetCustomFieldsAsync(cancellationToken).ConfigureAwait(false);

            foreach (var customField in customFieldsList)
            {
                var modelPath = $"Loan.CustomFields[(FieldName == '{customField.Id}')].StringValue";
                retrievedCustomFields[customField.Id] = new NonStandardFieldDescriptor(customField.Id, LoanFieldDescriptors.CreateModelPath(modelPath), modelPath, customField.Description, customField.Format, customField.Options?.Select(o => new FieldOption(o)).ToList(), false);
            }

            var customFields = _customFields;

            foreach (var pair in customFields)
            {
                if (retrievedCustomFields.TryGetValue(pair.Key, out var descriptor))
                {
                    customFields[pair.Key] = descriptor;
                    retrievedCustomFields.Remove(pair.Key);
                }
                else
                {
                    customFields.TryRemove(pair.Key, out _);
                }
            }

            foreach (var pair in retrievedCustomFields)
            {
                customFields[pair.Key] = pair.Value;
            }

            CustomFieldsLastRefreshedUtc = DateTime.UtcNow;
        }
        /// <summary>
        /// Refreshes the standard fields cache.
        /// </summary>
        /// <param name="client">The client to use to retrieve the standard fields.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns></returns>
        public static async Task RefreshStandardFieldsAsync(IEncompassRestClient client, CancellationToken cancellationToken = default)
        {
            Preconditions.NotNull(client, nameof(client));

            var entityTypes      = (await client.Schema.GetLoanSchemaAsync(includeFieldExtensions: true, cancellationToken).ConfigureAwait(false)).EntityTypes;
            var loanEntitySchema = entityTypes["Loan"];
            var fields           = new Dictionary <string, StandardFieldInfo>(StringComparer.OrdinalIgnoreCase);
            var fieldPatterns    = new Dictionary <string, StandardFieldInfo>(StringComparer.OrdinalIgnoreCase)
            {
                { "CX.{0}", new StandardFieldInfo("CX.{0}", "Loan.CustomFields[(FieldName == 'CX.{0}')].StringValue")
                  {
                      Format = LoanFieldFormat.STRING
                  } },
                { "CUST{0:00}FV", new StandardFieldInfo("CUST{0:00}FV", "Loan.CustomFields[(FieldName == 'CUST{0:00}FV')].StringValue")
                  {
                      Format = LoanFieldFormat.STRING
                  } }
            };

            PopulateFieldMappings("Loan", "Loan", null, loanEntitySchema, null, entityTypes, fields, fieldPatterns, extendedFieldInfo: true, null, null, null);

            foreach (var pair in FieldMappings._standardFields)
            {
                var fieldId           = pair.Key;
                var currentDescriptor = pair.Value;
                if (fields.TryGetValue(fieldId, out var fieldInfo))
                {
                    fields.Remove(fieldId);
                    if ((!string.IsNullOrEmpty(fieldInfo.Description) && currentDescriptor.Description != fieldInfo.Description) || currentDescriptor.ReadOnly != (fieldInfo.ReadOnly == true) || (!string.Equals(currentDescriptor.ModelPath, fieldInfo.ModelPath, StringComparison.OrdinalIgnoreCase) && !string.Equals(currentDescriptor.ModelPath, CreateModelPath(fieldInfo.ModelPath) !.ToString(), StringComparison.OrdinalIgnoreCase)))
                    {
                        var modelPath       = CreateModelPath(string.Equals(currentDescriptor.ModelPath, fieldInfo.ModelPath, StringComparison.OrdinalIgnoreCase) ? currentDescriptor.ModelPath : fieldInfo.ModelPath) !;
                        var modelPathString = modelPath.ToString();
                        var descriptor      = new NonStandardFieldDescriptor(fieldInfo.FieldId, modelPath, modelPathString, fieldInfo.Description, fieldInfo.Format, fieldInfo.Options, fieldInfo.ReadOnly == true);
                        FieldMappings._standardFields[fieldId] = descriptor;
                    }
                }
                else if (!currentDescriptor._userAdded)
                {
                    FieldMappings._standardFields.TryRemove(fieldId, out _);
                }
            }

            foreach (var pair in fields)
            {
                var fieldInfo       = pair.Value;
                var modelPath       = CreateModelPath(fieldInfo.ModelPath) !;
                var modelPathString = modelPath.ToString();
                var descriptor      = new NonStandardFieldDescriptor(fieldInfo.FieldId, modelPath, modelPathString, fieldInfo.Description, fieldInfo.Format, fieldInfo.Options, fieldInfo.ReadOnly == true);
                FieldMappings.AddField(descriptor);
            }

            foreach (var pair in FieldPatternMappings._standardFieldPatterns)
            {
                var fieldPattern      = pair.Key;
                var currentDescriptor = pair.Value;
                if (fieldPatterns.TryGetValue(fieldPattern, out var fieldInfo))
                {
                    fieldPatterns.Remove(fieldPattern);
                    if (!string.Equals(currentDescriptor.ModelPath, fieldInfo.ModelPath, StringComparison.OrdinalIgnoreCase) || currentDescriptor.ReadOnly != (fieldInfo.ReadOnly == true))
                    {
                        var modelPathPattern = string.Equals(currentDescriptor.ModelPath, fieldInfo.ModelPath, StringComparison.OrdinalIgnoreCase) ? currentDescriptor.ModelPath : fieldInfo.ModelPath;
                        var descriptor       = new NonStandardFieldDescriptor(fieldInfo.FieldId, CreateModelPath(string.Format(modelPathPattern, 1)) !, modelPathPattern, currentDescriptor.Description, fieldInfo.Format, fieldInfo.Options, fieldInfo.ReadOnly == true, multiInstance: true);
                        FieldPatternMappings._standardFieldPatterns[fieldPattern] = descriptor;
                    }
                }
                else if (!currentDescriptor._userAdded)
                {
                    FieldPatternMappings._standardFieldPatterns.TryRemove(fieldPattern, out _);
                }
            }

            foreach (var pair in fieldPatterns)
            {
                var fieldInfo        = pair.Value;
                var modelPathPattern = fieldInfo.ModelPath;
                var descriptor       = new NonStandardFieldDescriptor(fieldInfo.FieldId, CreateModelPath(string.Format(modelPathPattern, 1)) !, modelPathPattern, fieldInfo.Description, fieldInfo.Format, fieldInfo.Options, fieldInfo.ReadOnly == true, multiInstance: true);
                FieldPatternMappings.AddField(descriptor);
            }

            StandardFieldsLastRefreshedUtc = DateTime.UtcNow;
        }
        /// <summary>
        /// Initializes the export job object with the specified <paramref name="client"/>. This allows the use of the Refresh and Download methods.
        /// </summary>
        /// <param name="client"></param>
        public void Initialize(IEncompassRestClient client)
        {
            Preconditions.NotNull(client, nameof(client));

            Client = client;
        }