public async Task Run([QueueTrigger("outputletter", Connection = "")] FormLetter myQueueItem,
                              [Table("letters")] IAsyncCollector <LetterEntity> letterTableCollector,
                              ILogger log)
        {
            //TODO map FormLetter message to LetterEntity type and save to table storage

            await letterTableCollector.AddAsync(new LetterEntity { });

            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
        }
Esempio n. 2
0
        public LetterEntity(FormLetter formLetter)
        {
            Body          = formLetter.Body;
            ExpectedDate  = formLetter.ExpectedDate;
            Heading       = formLetter.Heading;
            Likelihood    = formLetter.Likelihood;
            RequestedDate = formLetter.RequestedDate;

            //Required Table fields
            RowKey       = Guid.NewGuid().ToString();
            PartitionKey = $"{ExpectedDate:yyyy-MM}";
        }
        public async Task Run([QueueTrigger("messagetomom", Connection = "")] MessageToMom myQueueItem,
                              [Queue("outputletter")] IAsyncCollector <FormLetter> letterCollector,
                              ILogger log)
        {
            log.LogInformation($"{myQueueItem.Greeting} {myQueueItem.HowMuch} {myQueueItem.HowSoon}");
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");

            //TODO parse flattery list into comma separated string
            var str = String.Join(",", myQueueItem.Flattery);

            log.LogInformation($"{str}");
            //TODO populate Header with salutation comma separated string and "Mother"
            var newstr = myQueueItem.Greeting + (", \"Mother\"");
            //TODO calculate likelihood of receiving loan based on this decision tree
            // 100 percent likelihood (initial value) minus the probability expressed from the quotient of howmuch and the total maximum amount ($10000)
            FormLetter formLetter         = new FormLetter();
            var        calculateliklihood = 100 - (myQueueItem.HowMuch / 10000);

            formLetter.Likelihood = Convert.ToDouble(calculateliklihood);
            //TODO calculate approximate actual date of loan receipt based on this decision tree
            // funds will be made available 10 business days after day of submission
            // business days are weekdays, there are no holidays that are applicable
            var Calculatedate = myQueueItem.HowSoon;

            if (myQueueItem.HowSoon.Value.DayOfWeek == DayOfWeek.Sunday)
            {
                Calculatedate = myQueueItem.HowSoon.Value.AddDays(15);
            }
            else if (myQueueItem.HowSoon.Value.DayOfWeek == DayOfWeek.Saturday)
            {
                Calculatedate = myQueueItem.HowSoon.Value.AddDays(16);
            }
            else
            {
                Calculatedate = myQueueItem.HowSoon.Value.AddDays(14);
            }

            //TODO use new values to populate letter values per the following:
            //Body:"Really need help: I need $5523.23 by December 12,2020"
            //ExpectedDate = calculated date
            //RequestedDate = howsoon
            //Heading=Greeting
            //Likelihood = calculated likelihood

            await letterCollector.AddAsync(new FormLetter { Body          = "Really need help: I need $5523.23 by December 12,2020", ExpectedDate = (DateTime)Calculatedate,
                                                            RequestedDate = (DateTime)myQueueItem.HowSoon, Heading = newstr, Likelihood = formLetter.Likelihood });
        }
Esempio n. 4
0
        public async Task Run([QueueTrigger(Literals.outputletter, Connection = "")] FormLetter formLetter,
                              [Table(Literals.letters)] IAsyncCollector <LetterEntity> letterTableCollector,
                              ILogger logger)
        {
            try
            {
                logger.LogInformation($"--------------Queue trigger function processed: {formLetter.Heading}...--------------");

                //Map FormLetter message to LetterEntity type and save to table storage
                await letterTableCollector.AddAsync(new LetterEntity(formLetter));

                logger.LogInformation("--------------Letter Table updated.--------------");
            }
            catch (Exception e)
            {
                logger.LogError(e.ToString());
            }
        }
        public async Task RunTest()
        {
            //Arrange
            var messageToMom = new MessageToMom
            {
                From     = "*****@*****.**",
                HowSoon  = new DateTime(2021, 2, 1),
                Greeting = "So Good To Hear From You",
                HowMuch  = 1222.22m,
                Flattery = new List <string> {
                    "amazing", "fabulous", "profitable"
                },
                SubmittedDate = new DateTime(2021, 1, 27)
            };

            var expected = new FormLetter
            {
                Heading       = "Amazing, Fabulous, Profitable Mother, So Good To Hear From You",
                Likelihood    = 99.877778,
                ExpectedDate  = new DateTime(2021, 2, 10),
                RequestedDate = new DateTime(2021, 2, 1),
                Body          = "Really need help: I need $1,222.22 by February 01, 2021"
            };

            var collector = new CollectorMock <FormLetter>();

            //Act
            await new CalculateDatesAndAmountsFunction().Run(messageToMom, collector.Collector(), new LoggerMock().Logger());

            //Assert
            //Assert message has been added to Queue
            Assert.IsTrue(collector.Items.Count > 0);

            //Assert item added to queue is as expected
            FormLetter actual = collector.Items[0];

            Assert.AreEqual(expected.Heading, actual.Heading);
            Assert.AreEqual(expected.Likelihood, actual.Likelihood);
            Assert.AreEqual(expected.ExpectedDate, actual.ExpectedDate);
            Assert.AreEqual(expected.RequestedDate, actual.RequestedDate);
            Assert.AreEqual(expected.Body, actual.Body);
        }
Esempio n. 6
0
        public async Task Run([QueueTrigger("outputletter", Connection = "")] FormLetter myQueueItem,
                              [Table("letters")] IAsyncCollector <LetterEntity> letterTableCollector,
                              ILogger log)
        {
            //TODO map FormLetter message to LetterEntity type and save to table storage
            await letterTableCollector.AddAsync(new LetterEntity
            {
                PartitionKey  = "US",
                RowKey        = Guid.NewGuid().ToString(),
                Heading       = myQueueItem.Heading,
                Likelihood    = myQueueItem.Likelihood,
                ExpectedDate  = myQueueItem.ExpectedDate,
                RequestedDate = myQueueItem.RequestedDate,
                Body          = myQueueItem.Body
            });

            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
            //SaveToDatabase(letterTableCollector);
            log.LogInformation($"{myQueueItem.Heading}");
        }
Esempio n. 7
0
        public async Task Run([QueueTrigger("outputletter", Connection = "")] FormLetter myQueueItem,
                              [Table("letters")] IAsyncCollector <LetterEntity> letterTableCollector,
                              ILogger log)
        {
            Random       rand         = new Random();
            LetterEntity letterEntity = new LetterEntity
            {
                Heading       = myQueueItem.Heading,
                Likelihood    = myQueueItem.Likelihood,
                ExpectedDate  = myQueueItem.ExpectedDate,
                RequestedDate = myQueueItem.RequestedDate,
                Body          = myQueueItem.Body,
                PartitionKey  = myQueueItem.Heading.ToLower(),
                RowKey        = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString() +
                                rand.Next(10000, 99000).ToString() // Unix timestamp + random 5 digit integer
            };

            await letterTableCollector.AddAsync(letterEntity);

            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
        }
        public async Task Run([QueueTrigger("messagetomom", Connection = "")] MessageToMom myQueueItem,
                              [Queue("outputletter")] IAsyncCollector <FormLetter> letterCollector,
                              ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");

            decimal maximumAmount             = 10000.00M;
            int     businessDaysToProcessLoan = 10;

            FormLetter formLetter = new FormLetter
            {
                Heading       = $"{myQueueItem.Greeting} {string.Join(", ", myQueueItem.Flattery)} Mother",
                Likelihood    = calculateLoanLikelihood(maximumAmount, myQueueItem.HowMuch),
                ExpectedDate  = calculateApproximateLoanDate(DateTime.UtcNow, businessDaysToProcessLoan),
                RequestedDate = myQueueItem.HowSoon ?? calculateApproximateLoanDate(DateTime.UtcNow, businessDaysToProcessLoan),
                Body          = $"Really need help: I need ${myQueueItem.HowMuch} by " +
                                $"{myQueueItem.HowSoon ?? calculateApproximateLoanDate(DateTime.UtcNow, businessDaysToProcessLoan)}."
            };

            await letterCollector.AddAsync(formLetter);
        }
        public async Task Run([QueueTrigger("messagetomom", Connection = "AzureWebJobsStorage")] MessageToMom myQueueItem,
                              [Queue("outputletter")] IAsyncCollector <FormLetter> letterCollector,
                              ILogger log)
        {
            log.LogInformation($"{myQueueItem.Greeting} {myQueueItem.HowMuch} {myQueueItem.HowSoon}");
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
            //TODO parse flattery list into comma separated string

            //here I grabbed the information from myQueueItem and created a new string from it.
            string parsed = $"{myQueueItem.Flattery[0]}" + ", " + $"{myQueueItem.Flattery[1]}" + ", " + $"{myQueueItem.Flattery[2]}";

            log.LogInformation($"{parsed}");

            //TODO populate Header with salutation comma separated string and "Mother"

            //Not sure if the point was to use the myQueue.greeting so i did both possibilities
            string     salutations2 = $"{myQueueItem.Greeting}, Mother";
            FormLetter p            = new FormLetter();

            p.Heading = ($"salutation" + ", " + $"Mother");

            //TODO calculate likelihood of receiving loan based on this decision tree
            // 100 percent likelihood (initial value) minus the probability expressed from the quotient of howmuch and the total maximum amount ($10000)
            //Not sure if I understood the goal of this one but it was some easy math.
            //grab the variable from myQueueItem.howMuch

            var division = (10000 / myQueueItem.HowMuch);
            var percent  = (100 - division);

            log.LogInformation($"{percent}");

            //TODO calculate approximate actual date of loan receipt based on this decision tree

            // funds will be made available 10 business days after day of submission
            // business days are weekdays, there are no holidays that are applicable

            //For this I grabbed the current DateTime, found out what day of the week that was.
            //Then ran that through some if else statements to figure out when the loan would be due.
            var dt  = DateTime.Now;
            var day = dt.DayOfWeek;

            log.LogInformation($"{dt.DayOfWeek}");
            if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday || day == DayOfWeek.Friday)
            {
                var dueDay = dt.AddDays(14);
                log.LogInformation($"The actual date of loan receipt is, " + $"{dueDay}");
            }
            else if (day == DayOfWeek.Saturday)
            {
                var dueDay = dt.AddDays(13);
                log.LogInformation($"The actual date of loan receipt is, " + $"{dueDay}");
            }
            else if (day == DayOfWeek.Sunday)
            {
                var dueDay = dt.AddDays(12);
                log.LogInformation($"The actual date of loan receipt is, " + $"{dueDay}");
            }



            //TODO use new values to populate letter values per the following:

            //Body:"Really need help: I need $5523.23 by December 12,2020"
            //ExpectedDate = calculated date
            //RequestedDate = howsoon
            //Heading=Greeting
            //Likelihood = calculated likelihood

            //for this I created a new FormLetter and defined some variables that I would need inside.

            FormLetter help = new FormLetter();

            dt  = DateTime.Now;
            day = dt.DayOfWeek;

            {
                var expected = dt;

                if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday || day == DayOfWeek.Wednesday || day == DayOfWeek.Thursday || day == DayOfWeek.Friday)
                {
                    var dueDay = dt.AddDays(14);
                    /*  log.LogInformation($"The actual date of loan receipt is, " + $"{dueDay}");*/

                    expected = dueDay;
                }
                else if (day == DayOfWeek.Saturday)
                {
                    var dueDay = dt.AddDays(13);

                    expected = dueDay;
                }
                else if (day == DayOfWeek.Sunday)
                {
                    var dueDay = dt.AddDays(12);

                    expected = dueDay;
                }
                log.LogInformation($"This is in calculaeDates, {expected}");
                string   reallyNeedHelp = "Really need help: I need $5523.23 by December 12,2020";
                DateTime requestDate    = new DateTime(2020, 12, 12);
                //Then I applied all these variables into the FormLetter format.
                {
                    help.Heading       = $"{myQueueItem.Greeting}";
                    help.Likelihood    = (100 - (10000 / 5523.23));
                    help.ExpectedDate  = expected;
                    help.RequestedDate = requestDate;
                    help.Body          = reallyNeedHelp;
                };
                log.LogInformation($"This is the expected date, { expected}");
            }
            await letterCollector.AddAsync(help);

            log.LogInformation($"{help.Heading}" + $"The likelihood of being about to make a loan in that amount is, " + $"{help.Likelihood}");
        }