Example #1
0
        public static DefaultClientObject CreateNewLead(IClientObject source)
        {
            if (source == null)
            {
                return(null);
            }

            var destination = new DefaultClientObject();


            foreach (var valuePair in source.ClientObject)
            {
                destination.ClientObject.Add(new KeyValuePair <string, object>(valuePair.Key, valuePair.Value));
            }

            return(destination);
        }
Example #2
0
        public static void Main(string[] args)
        {
            var createOutputLogSuccess = SetupOutputFiles();

            if (!createOutputLogSuccess)
            {
                Console.WriteLine("Could not create output... Press any key to continue.");
                Console.ReadKey();
            }
            // Create the HttpClient
            _customerActivityHttpClient = new CustomerActivityHttpClient();

            _leadPublisher =
                new Publisher <string>(
                    new INotificationChannel <string>[]
                    { new RedisNotificationChannel("LMS", "localhost, allowAdmin=true", "LMS") }, true);


            Console.WriteLine($"Redis channel status: {_leadPublisher.ChannelStatus.First()}");

            // Retrieve customerActivityGuids from the database
            listOfGuids = GetCustomerActivitiesFromDb(RandomMaxCount);
            int activityGuidIx = 0;

            var  cjLeads = CreateCJLeads();
            var  numberOfLeadScenariosSetUp = cjLeads.Count;
            var  randomNbr         = new Random();
            var  randomRunningFlag = false;
            Guid customerActivityGuid;

            var randomCounter = 1;

            // Ask for user to select a lead to process
            WriteToConsole($"{GetCJLeadDirectory()}Select a lead [1-{numberOfLeadScenariosSetUp}] to process: ", LogColors);
            int.TryParse(Console.ReadLine(), out var choiceSelectedFromMenu);

            // Use the scenario selected - or continue if the randomRunningFlag is set
            while ((choiceSelectedFromMenu >= 1 && choiceSelectedFromMenu <= numberOfLeadScenariosSetUp) || (randomRunningFlag))
            {
                choiceSelectedFromMenu--; //Since array indices start at 0
                customerActivityGuid = listOfGuids[activityGuidIx];
                activityGuidIx++;
                // Run Leads through at Random if selected - This is the last choice on the menu
                if ((choiceSelectedFromMenu == (numberOfLeadScenariosSetUp - 1)) || (randomRunningFlag))
                {
                    // if first time through random
                    if (randomRunningFlag == false)
                    {
                        randomRunningFlag = true;
                        // Create the guidlist that keeps track of the guids within the scenarios
                        for (int i = 0; i < numberOfLeadScenariosSetUp - 1; i++)
                        {
                            _CJLeadDirectory[i].guidList = new List <Guid>();
                        }
                    }
                    // Now do a random selection from the scerios instead
                    choiceSelectedFromMenu = randomNbr.Next(0, (numberOfLeadScenariosSetUp - 1));
                    _CJLeadDirectory[choiceSelectedFromMenu].CJLeadCnt++;

                    // Keep track of what other info is being sent for the Customer.
                    _CJLeadDirectory[choiceSelectedFromMenu].guidList.Add(customerActivityGuid);

                    // Remove if previously added but then add the CustomerActivity Retrieved from the database
                    cjLeads[choiceSelectedFromMenu].ClientObject.RemoveAll(item => item.Key == ClientObjectKeys.ActivityGuidKey);
                    cjLeads[choiceSelectedFromMenu].ClientObject.Add(
                        new KeyValuePair <string, object>(ClientObjectKeys.ActivityGuidKey,
                                                          customerActivityGuid));

                    if (randomCounter == RandomMaxCount)
                    {
                        randomRunningFlag = false;  // STOP
                        randomCounter     = 0;
                    }
                    else
                    {
                        randomCounter++;
                    }
                }
                else
                {
                    // Remove if previously added but then add the CustomerActivity Retrieved from the database
                    cjLeads[choiceSelectedFromMenu].ClientObject.RemoveAll(item => item.Key == ClientObjectKeys.ActivityGuidKey);
                    cjLeads[choiceSelectedFromMenu].ClientObject.Add(
                        new KeyValuePair <string, object>(ClientObjectKeys.ActivityGuidKey,
                                                          customerActivityGuid));
                }

                var newLead =
                    new DefaultClientObject(
                        new List <KeyValuePair <string, object> >(cjLeads[choiceSelectedFromMenu].ClientObject));


                // Instead of Publishing the lead - get customerActivity using HttpClient
                //var customerActivityTask = _customerActivityHttpClient.GetCustomerActivity(customerActivityGuid);
                //if (customerActivityTask.Result != String.Empty)
                //{
                //    WriteToLogFile(customerActivityTask.Result);

                //}
                //else
                //{
                //    WriteToLogFile($"No CustomerActivity For {customerActivityGuid}.");
                //}

                //var newLead = CreateNewLead(cjLeads[choiceSelectedFromMenu]);

                //WriteToConsole($"Processing Activity ID {leadEntities[leadChoice].Context.First(ctx => ctx.Id == ContextKeys.ActivityGuidKey).Value}", LogColors);
                //                var serializedEntity = JsonConvert.SerializeObject(cjLeads[leadChoice], Formatting.Indented);
                var serializedEntity = JsonConvert.SerializeObject(newLead, Formatting.Indented);

                //if (!randomRunningFlag)
                //{
                //    WriteToConsole("\n_______________________________________________________________________________________________________________________________\n\n", LogColors);
                //    WriteToConsole(serializedEntity, ObjectLogColors);
                //}
                WriteToConsole($"Pulishing: {newLead.ClientObject.FirstOrDefault(item => item.Key == ClientObjectKeys.ActivityGuidKey).Value.ToString()}: {choiceSelectedFromMenu + 1}: {_CJLeadDirectory[choiceSelectedFromMenu].CJLeadType}", LogColors);
                WriteToLogFile($"Pulishing: {newLead.ClientObject.FirstOrDefault(item => item.Key == ClientObjectKeys.ActivityGuidKey).Value.ToString()}: {choiceSelectedFromMenu + 1}: {_CJLeadDirectory[choiceSelectedFromMenu].CJLeadType}");
                //WriteToConsole(_CJLeadDirectory[leadChoice], LogColors);
                // Ok send it on
                _leadPublisher.BroadcastMessage(serializedEntity);

                // If running through leads - do not stop - else show menu of leads
                if (!randomRunningFlag)
                {
                    // At the end write a
                    if (randomCounter == 0)
                    {
                        var summaryStr = Environment.NewLine + ("").PadRight(180, '_') + Environment.NewLine +
                                         $"SENT {RandomMaxCount} LEADS THROUGH...." + Environment.NewLine + "SUMMARY:" + Environment.NewLine;
                        var ix = 1;
                        foreach (var lead in _CJLeadDirectory)
                        {
                            summaryStr += $"{ix}. ({lead.CJLeadCnt}) : {lead.CJLeadType}" + Environment.NewLine;
                            if (lead.guidList != null)
                            {
                                foreach (var guid in lead.guidList)
                                {
                                    summaryStr += $"{guid}" + Environment.NewLine;
                                }
                            }
                            ix++;
                        }
                        WriteToConsole(summaryStr, LogColors);
                        WriteToLogFile(summaryStr);
                        randomCounter = 1;
                    }
                    Console.ReadLine();
                    WriteToConsole($"{GetCJLeadDirectory()}Select a lead [1-{cjLeads.Count}] to process: ", LogColors);
                    int.TryParse(Console.ReadLine(), out choiceSelectedFromMenu);
                }

                //Thread.Sleep(200);
            }

            WriteToConsole("The End.  Press any key to continue...", LogColors);
            Console.ReadKey();
        }