private void FindBoundariesEnd(Loan loan, string field)
        {
            ISet <string> fieldIds = new HashSet <string>();

            fieldIds.Add(field);
            IDictionary <string, object> results = new Dictionary <string, object>();

            LoanDataUtils.ExtractEndIndexFields(loan, fieldIds, results);
            ISet <string> uniques = new HashSet <string>();

            foreach (string key in results.Keys)
            {
                uniques.Add((string)results[key]);
            }
            Console.WriteLine(field + " == [values = " + results.Count + " ][uniques = " + uniques.Count + "]");
        }
        private void GenerateUnknownMultiIndexDetails(Session session, string guid)
        {
            GuaranteedRate.Sextant.EncompassUtils.FieldUtils.session = session;
            FieldUtils.AddFieldCollection(FieldUtils.session.Loans.FieldDescriptors.CustomFields);
            FieldUtils.AddFieldCollection(FieldUtils.session.Loans.FieldDescriptors.StandardFields);
            FieldUtils.AddFieldCollection(FieldUtils.session.Loans.FieldDescriptors.VirtualFields);

            Loan loan = SessionUtils.OpenLoan(session, guid);


            ISet <string> unknownMiddle = FieldUtils.MiddleIndexMulti();
            ISet <string> unknownEnd    = FieldUtils.EndIndexMulti();

            //Write all the known index values....
            IDictionary <string, int> indexKeySizes = LoanDataUtils.IndexKeySizes(loan);

            foreach (string key in indexKeySizes.Keys)
            {
                Console.WriteLine(key + " == " + indexKeySizes[key]);
            }

            //Things that maybe are index values

            /*
             * Console.WriteLine("Disclosures2015 == " + loan.Log.Disclosures2015.Count);
             * Console.WriteLine("DocumentOrders == " + loan.Log.DocumentOrders.Count);
             * Console.WriteLine("EDMTransactions == " + loan.Log.EDMTransactions.Count);
             * Console.WriteLine("HtmlEmailMessages == " + loan.Log.HtmlEmailMessages.Count);
             * Console.WriteLine("InvestorRegistrations == " + loan.Log.InvestorRegistrations.Count);
             * Console.WriteLine("LockCancellationRequests == " + loan.Log.LockCancellationRequests.Count);
             * Console.WriteLine("LockCancellations == " + loan.Log.LockCancellations.Count);
             * Console.WriteLine("LockConfirmations == " + loan.Log.LockConfirmations.Count);
             * Console.WriteLine("LockDenials == " + loan.Log.LockDenials.Count);
             * Console.WriteLine("LockRequests == " + loan.Log.LockRequests.Count);
             * Console.WriteLine("MilestoneEvents == " + loan.Log.MilestoneEvents.Count);
             * Console.WriteLine("MilestoneTasks == " + loan.Log.MilestoneTasks.Count);
             * Console.WriteLine("PostClosingConditions == " + loan.Log.PostClosingConditions.Count);
             * Console.WriteLine("PreliminaryConditions == " + loan.Log.PreliminaryConditions.Count);
             * Console.WriteLine("PrintEvents == " + loan.Log.PrintEvents.Count);
             * Console.WriteLine("ReceivedDownloads == " + loan.Log.ReceivedDownloads.Count);
             * Console.WriteLine("StatusOnlineUpdates == " + loan.Log.StatusOnlineUpdates.Count);
             * Console.WriteLine("TrackedDocuments == " + loan.Log.TrackedDocuments.Count);
             * Console.WriteLine("UnderwritingConditions == " + loan.Log.UnderwritingConditions.Count);
             *
             * Console.WriteLine("Servicing.IsStarted() == " + loan.Servicing.IsStarted());
             * PaymentSchedule schedule = loan.Servicing.GetPaymentSchedule();
             *
             * foreach (ScheduledPayment payment in schedule.Payments)
             *  Console.WriteLine(payment.DueDate + ": P = " + payment.Principal + ", I = " + payment.Interest);
             */


            //Console.WriteLine("Transactions.GetEnumerator().Current == " + loan.Servicing.Transactions.GetEnumerator().Current);
            //Console.WriteLine("Servicing.IsStarted() == " + loan.Servicing.GetPaymentSchedule().Payments[0].);

            //For each element, itterate and print their values...

            /*
             * foreach (string field in unknownMiddle.OrderBy(x => x.ToString()))
             * {
             *  FindBoundariesMiddle(loan, field);
             * }
             */

            foreach (string field in unknownEnd.OrderBy(x => x.ToString()))
            {
                FindBoundariesEnd(loan, field);
            }

            if (loan != null)
            {
                loan.Close();
            }
        }
        static void Main(string[] args)
        {
            var config = new JsonEncompassConfig();

            config.Init(System.IO.File.ReadAllText("../../ConsoleTester.json"));
            var server      = config.GetValue <string>("encompass-url", String.Empty);
            var userid      = config.GetValue <string>("encompass-userid", String.Empty);
            var password    = config.GetValue <string>("encompass-password", String.Empty);
            var loanNumbers = config.GetValue <List <string> >("test-loans", new List <string>());

            if (server == String.Empty)
            {
                Console.Write("Please enter the url of your Encompass instance and press enter.");
                server = Console.ReadLine();
            }

            if (userid == String.Empty)
            {
                Console.Write("Please enter your Encompass userid and press enter.");
                userid = Console.ReadLine();
            }

            if (password == String.Empty)
            {
                Console.Write("Please enter your Encompass password and press enter.");
                while (true)
                {
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Enter)
                    {
                        break;
                    }
                    password += key.KeyChar;
                }
            }

            Console.WriteLine();
            Console.WriteLine("Logging into Encompass");
            using (var sess = SessionUtils.GetEncompassSession(server, userid, password))
            {
                if (!loanNumbers.Any())
                {
                    Console.WriteLine("Please enter a loan number to test and press enter.");
                    loanNumbers.Add(Console.ReadLine());
                }

                var sw = new Stopwatch();
                foreach (var ln in loanNumbers)
                {
                    Console.WriteLine($"opening loan {ln}");
                    var loan = SessionUtils.OpenLoanFromLoanNumber(sess, ln);
                    Console.WriteLine("Extracting");
                    FieldUtils.session = sess;
                    sw.Start();
                    var serialized = JsonConvert.SerializeObject(LoanDataUtils.ExtractEverything(loan));
                    var path       = String.Format(@"c:\junk\{0}.json", ln);
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                    System.IO.File.WriteAllText(path, serialized);
                    sw.Stop();
                    Console.WriteLine($"Extracted loan {ln} in {sw.ElapsedMilliseconds / 1000} seconds.");
                    sw.Reset();
                    loan.Close();
                }
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
        }