Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            _leadPublisher =
                new Publisher <string>(
                    new INotificationChannel <string>[]
                    { new RedisNotificationChannel("LMS", "Redis", "LMS") }, true);
            //{ new RedisNotificationChannel("LMS", "Redis", "LMS", new MockLogger())}, true);

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

            var customerToLMS = CreateCustomerLeads();

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

            // Process the lead
            while (leadChoice >= 1 && leadChoice <= customerToLMS.Count)
            {
                leadChoice--; //Since array indices start at 0
                WriteToConsole("\n_______________________________________________________________________________________________________________________________\n\n", LogColors);
                var serializedEntity = JsonConvert.SerializeObject(customerToLMS[leadChoice], Formatting.Indented);
                WriteToConsole(serializedEntity, ObjectLogColors);
                _leadPublisher.BroadcastMessage(serializedEntity);

                Console.ReadLine();
                WriteToConsole($"{GetLeadDirectory()}Select a lead [1-{customerToLMS.Count}] to process: ", LogColors);
                int.TryParse(Console.ReadLine(), out leadChoice);
            }


            WriteToConsole("The End.  Press any key to continue...", LogColors);
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Publish Lead to ...... POE?
        /// </summary>
        /// <param name="leadEntity"></param>
        public void PublishLead(ILeadEntity leadEntity)
        {
            var processContext = "PublishLead";

            // TODO - this will publish to a component outside of LMS
            _loggerClient.Log(new DefaultLoggerClientObject {
                OperationContext = JsonConvert.SerializeObject(leadEntity, Newtonsoft.Json.Formatting.Indented), ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information
            });
            // Pass leadEntity onto channel to be picked up by Entity sending the notification
            _notificationChannelPublisher.BroadcastMessage(leadEntity);
        }
Ejemplo n.º 3
0
        public void PublishLead(ILeadEntity leadEntity)
        {
            string processContext = "PublishLead";

            _loggerClient.Log(new DefaultLoggerClientObject
            {
                OperationContext = "Publishing the Lead",
                ProcessContext   = processContext,
                SolutionContext  = solutionContext,
                EventType        = LoggerClientEventTypeControl.Interface.Constants.LoggerClientEventType.LoggerClientEventTypes.Information
            });

            _leadEntity = leadEntity;

            // Pass leadEntity onto channel to be picked up by Subscribed Campaign Managers
            //notificationChannelPublisher.BroadcastMessage(JsonConvert.SerializeObject(leadEntity));
            _notificationChannelPublisher.BroadcastMessage(leadEntity);
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            _leadPublisher =
                new Publisher <string>(
                    new INotificationChannel <string>[]
                    { new RedisNotificationChannel("LMS", "Redis", "LMS") }, true);
            //  { new RedisNotificationChannel("LMS", "Redis", "LMS", new MockLogger())}, true);

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

            var cjLeads           = CreateCJLeads();
            var cjLeadCount       = cjLeads.Count;
            var randomNbr         = new Random();
            var randomRunningFlag = false;
            DefaultClientObject newLead; // Used for creating a new lead object when the array of possible leads have been created.

            var randomCounter = 1;

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

            // Process the lead
            while ((leadChoice >= 1 && leadChoice <= cjLeadCount) || (randomRunningFlag))
            {
                leadChoice--; //Since array indices start at 0

                // Run Leads through at Random
                if ((leadChoice == (cjLeadCount - 1)) || (randomRunningFlag))
                {
                    leadChoice        = 5;
                    randomRunningFlag = true;

                    // Now select a random Lead from List
                    leadChoice = randomNbr.Next(0, (cjLeadCount - 1));
                    _CJLeadDirectory[leadChoice].CJLeadCnt++;
                    if (_CJLeadDirectory[leadChoice].guidList == null)
                    {
                        _CJLeadDirectory[leadChoice].guidList = new List <Guid>();
                    }

                    if (randomCounter == RandomMaxCount)
                    {
                        randomRunningFlag = false;
                        randomCounter     = 0;
                    }
                    else
                    {
                        randomCounter++;
                    }
                    // Unless it is the duplicate Guid - Assign a new CustomerActivity
                    if (!String.Equals(cjLeads[leadChoice].ClientObject
                                       .FirstOrDefault(item => item.Key == ClientObjectKeys.ActivityGuidKey).Value.ToString().ToUpper(),
                                       DuplicateGuidStr))
                    {
                        var newActivityGuid = Guid.NewGuid();
                        _CJLeadDirectory[leadChoice].guidList.Add(newActivityGuid);

                        // update the ActivityGuid
                        cjLeads[leadChoice].ClientObject.RemoveAll(item => item.Key == ClientObjectKeys.ActivityGuidKey);
                        cjLeads[leadChoice].ClientObject.Add(new KeyValuePair <string, object>(ClientObjectKeys.ActivityGuidKey, newActivityGuid));
                    }
                    else
                    {
                        _CJLeadDirectory[leadChoice].guidList.Add(new Guid(DuplicateGuidStr));
                    }
                }

                newLead = CreateNewLead(cjLeads[leadChoice]);

                //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()}: {leadChoice+1}: {_CJLeadDirectory[leadChoice].CJLeadType}", LogColors);
                //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);
                        randomCounter = 1;
                    }
                    Console.ReadLine();
                    WriteToConsole($"{GetCJLeadDirectory()}Select a lead [1-{cjLeads.Count}] to process: ", LogColors);
                    int.TryParse(Console.ReadLine(), out leadChoice);
                }

                Thread.Sleep(200);
            }

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