Пример #1
0
        internal static void Main(string[] args)
        {
            // Create a new isolated COBOL runtime
            using (var runUnit = new RunUnit())
            {
                // Instantiate the COBOL class to use in the runtime
                var logger = new CobolLogger
                {
                    UserId = "testuser"
                };

                // Add it to the runtime
                runUnit.Add(logger);

                // All calls to methods in the COBOL class now executes in this runtime
                logger.Warning("Warning from .NET");
                logger.Error(string.Format("Test error {0}", logger.GetGuid()));

                logger.UserId = "anotheruser";

                logger.Warning("Another warning");
                logger.Error("And another error");

                Console.ReadKey();

                // Clean up runtime resources
                runUnit.StopRun();
            }
        }
        private static LoanData CallLoanAmort(LoanParameters parameters, TraceWriter log)
        {
            // Map the parameters to the SmartLinkage input
            var loanInfo = new Loaninfo()
            {
                Loanterm  = parameters.T,
                Principal = parameters.P,
                Rate      = parameters.R
            };

            var outData = new Outdata();

            try
            {
                using (var runUnit = new RunUnit <LOANAMORT>())
                {
                    runUnit.Call(nameof(LOANAMORT), loanInfo.Reference, outData.Reference);
                }
            }
            catch (Exception ex)
            {
                log.Error("LOANAMORT run unit call failed", ex);
                return(null);
            }

            var date = DateTime.Now;

            if (date.Day > 28)
            {
                var daysToAdjust = (date.Day - 28) * -1;
                date = date.AddDays(daysToAdjust);
            }

            var loanData = new LoanData();

            loanData.TotalInterest = outData.Outtotintpaid;

            for (int i = 0; i < loanInfo.Loanterm; i++)
            {
                var loanPayment = new AmortData()
                {
                    PayDateNo     = string.Format("#{0} {1}", i, date.AddMonths(i + 1).ToShortDateString()),
                    Payment       = outData.get_Outpayment(i),
                    InterestPaid  = outData.get_Outintpaid(i),
                    PrincipalPaid = outData.get_Outprincpaid(i),
                    Balance       = outData.get_Outbalance(i)
                };
                loanData.AmortList.Add(loanPayment);
            }

            return(loanData);
        }