void CreateLeadEntity() { _testLeadEntity = new TestLeadEntityClass() { Context = new IContext[] {}, Properties = new IProperty[] {}, Segments = new ISegment[] {}, ResultCollection = new DefaultResultCollection() }; }
public IList <IResult>[] ProcessCampaigns(ILeadEntity leadEntity) { var processContext = "ProcessCampaigns"; _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Checking for Campaigns to be Managed.", ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); // Start the various Campaigns as Tasks var campaignCnt = _campaignManagerConfig.CampaignCollection.Length; _campaignManagerResultList.Add(new DefaultResult(ResultKeys.CampaignManagerKeys.CampaignCountKey, campaignCnt)); _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = $"Campaign Count to be Managed: {campaignCnt}", ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); var processCampaignsTask = new Task <List <IResult>[]>(() => { var campaignResults = new List <IResult> [campaignCnt]; var campaignTasks = new Task <List <IResult> > [campaignCnt]; for (var ix = 0; ix < campaignCnt; ix++) { var ixClosure = ix; campaignTasks[ixClosure] = new Task <List <IResult> >(() => _campaignManagerConfig.CampaignCollection[ixClosure].ProcessLead(leadEntity)); campaignTasks[ixClosure].Start(); } for (var i = 0; i < campaignCnt; i++) { var ixClosure = i; campaignResults[ixClosure] = campaignTasks[ixClosure].Result; } return(campaignResults); }); _campaignManagerResultList.Add(new DefaultResult(ResultKeys.CampaignManagerKeys.CampaignsProcessedStatusKey, ResultKeys.ResultKeysStatusEnum.Processed.ToString())); // When all the campaigns are finished processing - call the function to Process all the Results from the different campaigns. processCampaignsTask.ContinueWith(async resultsCollection => CampaignManagerProcessResults(leadEntity, (await resultsCollection))); // Start all the campaign taskis processCampaignsTask.Start(); return(processCampaignsTask.Result); }
/// <summary> /// Campaign Manager Driver to control campaigns /// </summary> /// <param name="leadEntity"></param> public void CampaignManagerDriver(ILeadEntity leadEntity) { if (leadEntity == null) { throw new ArgumentNullException(nameof(leadEntity)); } var processContext = "CampaignManagerDriver"; _campaignManagerResultList = new List <IResult> { new DefaultResult(ResultKeys.DiagnosticKeys.TimeStampStartKey, DateTime.Now) }; _campaignManagerResultList.Add(new DefaultResult(ResultKeys.CampaignManagerKeys.CampaignManagerIdKey, CampaignManagerId)); // Check that there are Campaigns to be Managed if (_campaignManagerConfig.CampaignCollection?.Any() != true) { _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "There are no Campaigns to be Managed.", ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); _campaignManagerResultList.Add(new DefaultResult(ResultKeys.CampaignManagerKeys.CampaignCountKey, 0)); _campaignManagerConfig.CampaignManagerDecorator.DecorateLead(leadEntity, _campaignManagerResultList); return; } _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Validating Lead Within the Campaign Manager.", ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); // Validate the Lead to see if it should be sent through campaigns if (_campaignManagerConfig.CampaignManagerValidator != null) { if (_campaignManagerConfig.CampaignManagerValidator.ValidLead(leadEntity).Equals(false)) { _campaignManagerResultList.Add(new DefaultResult(ResultKeys.ValidatorStatusKey, ResultKeys.ResultKeysStatusEnum.Failed.ToString())); _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Lead is not valid for these Campaigns.", ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); _campaignManagerConfig.CampaignManagerDecorator.DecorateLead(leadEntity, _campaignManagerResultList); return; } } _campaignManagerResultList.Add(new DefaultResult(ResultKeys.ValidatorStatusKey, ResultKeys.ResultKeysStatusEnum.Processed.ToString())); _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Lead is valid for these Campaigns - Start Campaigns.", ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); // Kick off all the campaigns with a task and then resolve following. ProcessCampaigns(leadEntity); }
void CreateTestLeadEntity() { //_testLeadEntity = new DefaultLeadEntity() //{ // Context = new IContext[] { new DefaultContext(ContextKeys.ActivityGuidKey, Guid.NewGuid().ToString()) }, // Properties = new IProperty[] { new DefaultProperty(PropertyKeys.VehicleCountKey, "5") }, // Segments = new ISegment[] { new DefaultSegment(SegementKeys.HighPOPKey) } //}; _testLeadEntity = new DefaultLeadEntity() { Context = new IContext[] { }, Properties = new IProperty[] { }, Segments = new ISegment[] { } }; }
public bool ValidLead(ILeadEntity leadEntity) { if (leadEntity.Context == null) { if (leadEntity.ErrorList == null) { leadEntity.ErrorList = new List <string>(); } leadEntity.ErrorList.Add("LeadEntity Context is null.\n"); return(false); } return(true); }
public static void PrintProperties(ILeadEntity leadEntity) { Console.WriteLine("Properties:"); foreach (var prop in leadEntity.GetType().GetProperties()) { Console.WriteLine(prop.Name + ": " + prop.GetValue(leadEntity, null)); Console.WriteLine(); } Console.WriteLine("Fields:"); foreach (var field in leadEntity.GetType().GetFields()) { Console.WriteLine(field.Name + ": " + field.GetValue(leadEntity)); } }
static void Main(string[] args) { var _leadEntities = new ILeadEntity[5]; //var something = new Console.WriteLine("Enter the number lead you want to see: "); var lead = Console.ReadLine(); if (lead == "1") { _leadEntities.ToString(); Console.WriteLine("Processing Lead 1"); } else if (lead == "2") { _leadEntities.ToString(); Console.WriteLine("Processing Lead 2"); } else if (lead == "3") { _leadEntities.ToString(); Console.WriteLine("Processing Lead 3"); } else if (lead == "4") { _leadEntities.ToString(); Console.WriteLine("Processing Lead 4"); } else if (lead == "5") { _leadEntities.ToString(); Console.WriteLine("Processing Lead 5"); } else { Console.WriteLine("Bad Lead......... Goodbye"); } Console.ReadKey(); }
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); }
public bool ConstraintMet(ILeadEntity leadEntity) { string processContext = "ClearedFilter"; _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Filter the Lead", ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); var errorStr = string.Empty; try { //retrieve activityGuid from leadEntity var activityGuidValue = leadEntity.Context.SingleOrDefault(item => item.Id == ContextKeys.ActivityGuidKey)?.Value; if (activityGuidValue == null) { errorStr += "No activityGuid Found In Context of LeadEntityObject\n"; } else { Guid.TryParse(activityGuidValue.ToString(), out Guid activityGuid); //Check to see if leadEntity activity Guid exists in array if (_mockedActivityGuidArray.Count(ag => ag == activityGuid) != 0) { errorStr += $"Activity Guid Found in Duplicate Check Filter. Guid: {activityGuid}\n"; } } } catch (Exception ex) { _loggerClient.Log(new DefaultLoggerClientErrorObject { OperationContext = ex.Message, ProcessContext = processContext, SolutionContext = solutionContext, Exception = ex, ErrorContext = ex.Message, EventType = LoggerClientEventType.LoggerClientEventTypes.Error }); return(false); } if (errorStr != String.Empty) { _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = errorStr, ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); return(false); } return(true); }
public bool ConstraintMet(ILeadEntity leadEntity) { string processContext = "ValidateForRule"; _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Validating the Lead", ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); var errorStr = string.Empty; try { var priorInsuranceValue = leadEntity.Properties.SingleOrDefault(item => item.Id == PropertyKeys.PriorInsuranceKey)?.Value; if ((priorInsuranceValue == null) || (!bool.TryParse(priorInsuranceValue.ToString(), out bool priorInsurance))) { errorStr += "Prior Insurance not set In Properties of LeadEntityObject\n"; } else { if (priorInsurance == _mockedExcludePriorInsurance) { errorStr += $"Lead failed Rules Processing - Prior Insurance set to {_mockedExcludePriorInsurance}.\n"; } } } catch (Exception ex) { _loggerClient.Log(new DefaultLoggerClientErrorObject { OperationContext = "\nPrior Insurance", ProcessContext = processContext, SolutionContext = solutionContext, Exception = ex, ErrorContext = ex.Message, EventType = LoggerClientEventType.LoggerClientEventTypes.Error }); return(false); } if (errorStr != String.Empty) { _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = errorStr, ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); return(false); } return(true); }
/// <summary> /// Validate the Lead by checking that the Lead has a non empty/null and valid BuyOnlineBrand /// </summary> /// <param name="leadEntity"></param> /// <returns></returns> public bool ValidLead(ILeadEntity leadEntity) { var buyOnlineBrandValue = leadEntity.Context.SingleOrDefault(item => item.Id ==Modules.LeadEntity.Interface.Constants.ActivityKeys.BuyOnlineBrandKey)?.Value; if (buyOnlineBrandValue == null) { if (leadEntity.ErrorList == null) leadEntity.ErrorList = new List<string>(); leadEntity.ErrorList.Add("BuyOnlineBrand Not In Context.\n"); return false; } if (!Int32.TryParse(buyOnlineBrandValue.ToString(), out int buyOnlineBrand)) { if (leadEntity.ErrorList == null) leadEntity.ErrorList = new List<string>(); leadEntity.ErrorList.Add("BuyOnlineBrand Invalid.\n"); return false; } return true; }
/// <summary> /// Validate the lead using the Collection of Validators /// </summary> /// <param name="leadEntity"></param> /// <returns></returns> public bool ValidLead(ILeadEntity leadEntity) { string processContext = "ValidLead"; bool allValid = true; _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Validating the Lead", ProcessContext = processContext, SolutionContext = solutionContext }); try { // Validate the lead using the collection of validators // Process all validators before returning. foreach (var validator in _leadCollectorValidators) { var valid = validator.ValidLead(leadEntity); if (!valid) { allValid = false; } } if (!allValid) { _loggerClient.Log(new DefaultLoggerClientErrorObject { OperationContext = "Validation failed", ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventTypeControl.Interface.Constants.LoggerClientEventType.LoggerClientEventTypes.Error }); return(false); } } catch (Exception ex) { _loggerClient.Log(new DefaultLoggerClientErrorObject { OperationContext = "Exception in Validation of Lead", ProcessContext = processContext, SolutionContext = solutionContext, Exception = ex, ErrorContext = ex.Message, EventType = LoggerClientEventTypeControl.Interface.Constants.LoggerClientEventType.LoggerClientEventTypes.Error }); return(false); } return(true); }
/// <summary> /// Loop through the Validators and check if the lead is valid. This function /// loops through all the validators, even if it finds one that is not valide and /// collects all the reasons why a lead does not qualify for the campaign. /// </summary> /// <param name="leadEntity"></param> /// <returns></returns> public bool ValidLead(ILeadEntity leadEntity) { string processContext = "ValidLead"; bool allValid = true; string errorMsgs = String.Empty; _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Validating the Lead", ProcessContext = processContext, SolutionContext = solutionContext }); try { // Validate the lead using the collection of validators // Process all validators before returning. foreach (var validator in _campaignValidators) { var valid = validator.ValidLead(leadEntity); if (!valid) { allValid = false; } } if (!allValid) { _loggerClient.Log(new DefaultLoggerClientErrorObject { OperationContext = $"Validation failed. {leadEntity.ErrorList}", ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); return(false); } } catch (Exception ex) { _loggerClient.Log(new DefaultLoggerClientErrorObject { OperationContext = "Exception in Validation of Lead in Campaign Validator.", ProcessContext = processContext, SolutionContext = solutionContext, Exception = ex, ErrorContext = ex.Message, EventType = LoggerClientEventType.LoggerClientEventTypes.Error }); return(false); } return(true); }
/// <summary> /// Campaign Manager Function to Process the Results from the Various Campaigns /// </summary> /// <param name="leadEntity"></param> /// <param name="campaignResultCollectionList"></param> public void CampaignManagerProcessResults(ILeadEntity leadEntity, List <IResult>[] campaignResultCollectionList) { var processContext = "CampaignManagerProcessResults"; // Resolve the results collection from the Campaigns try { // Create array for the number of campaigns that executed. leadEntity.ResultCollection.CampaignCollection = new IResult[campaignResultCollectionList.Length][]; // Assign the results list to the leadEntity var ix = 0; foreach (var resultList in campaignResultCollectionList) { // LeadEntity now holds result for each Campaign it was processed through leadEntity.ResultCollection.CampaignCollection[ix] = new IResult[resultList.Count]; leadEntity.ResultCollection.CampaignCollection[ix] = (resultList.ToArray()); ix++; } // Resolve the lead _campaignManagerConfig.CampaignManagerResolver.ResolveLead(leadEntity); } catch (Exception exception) { _loggerClient.Log(new DefaultLoggerClientErrorObject() { OperationContext = "Exception occurred within CampaignManager.ResolveLeads.", ProcessContext = processContext, SolutionContext = SolutionContext, ErrorContext = exception.Message, Exception = exception, EventType = LoggerClientEventType.LoggerClientEventTypes.Error }); _campaignManagerResultList.Add(new DefaultResult(ResultKeys.ResolverResultCountKey, ResultKeys.ResultKeysStatusEnum.Failed)); _campaignManagerConfig.CampaignManagerDecorator.DecorateLead(leadEntity, _campaignManagerResultList); throw; } // Decorate the lead with the CampaignManager logs _campaignManagerConfig.CampaignManagerDecorator.DecorateLead(leadEntity, _campaignManagerResultList); // Publish the lead to .....POE? _campaignManagerConfig.CampaignManagerPublisher.PublishLead(leadEntity); }
/// <summary> /// Persist Lead into DB TBD. /// [ApprovedLeadID] // TODO //,[ProcessedLead_Id] ???????? - Insert into LeadEntity??? / Lookup? Done in Persistor of CM //,[LeadEntityGUID] //,[CustomerActivityGUID] //,[CustomerSessionGUID] //,[Brand_ID] // TODO //,[Insurer_ID] ??????? //,[Site_ID] //,[Product_ID] //,[Campaign_ID] //,[CampaignManager_ID] //,[LeadCreationTime] //,[CreationDate] /// </summary> /// <param name="leadEntity"></param> public void PersistLead(ILeadEntity leadEntity) { // TODO - Implementation & NULL CHECKING!!!! - Check for NULL for each of the collections & values that need to be persisted var processContext = "PersistLead..................... TBD"; var leadEntityGuid = leadEntity.Context.SingleOrDefault(item => item.Id == ContextKeys.LeadEntityGuidKey)?.Value; var activityGuid = leadEntity.Context.SingleOrDefault(item => item.Id == ContextKeys.ActivityGuidKey)?.Value; var sessionGuid = leadEntity.Context.SingleOrDefault(item => item.Id == ContextKeys.SessionGuidKey)?.Value; var brandId = leadEntity.Activity.SingleOrDefault(a => a.Id == ActivityKeys.BrandIdKey)?.Value; var siteId = leadEntity.Context.SingleOrDefault(item => item.Id == ContextKeys.SiteIDKey)?.Value; var productId = leadEntity.Context.SingleOrDefault(item => item.Id == ContextKeys.QuotedProductKey)?.Value; // TODO - the leads wont always have these ResultCollections - CHECK!!!!!!!! var cmId = leadEntity.ResultCollection.CampaignManagerCollection .SingleOrDefault(item => item.Id == ResultKeys.CampaignManagerKeys.CampaignManagerIdKey)?.Value; var cId = leadEntity.ResultCollection.PreferredCampaignCollection .SingleOrDefault(item => item.Id == ResultKeys.CampaignKeys.CampaignIdKey)?.Value; // TODO Check existence of collection var leadCreationTime = leadEntity.ResultCollection.LeadCollectorCollection .SingleOrDefault(item => item.Id == ResultKeys.DiagnosticKeys.TimeStampStartKey)?.Value; var tmpStrToDb = $"ApprovedLeadTable:\nLeadEntityGuid:{leadEntityGuid}\nActivitityGuid:{activityGuid}\n"; tmpStrToDb += $"SessionGuid:{sessionGuid}\nBrandId:{brandId}\nSiteId:{siteId}\nProductId:{productId}\n"; tmpStrToDb += $"CampaignManagerId:{cmId}\nCampaign:{cId}\nLeadCreation:{leadCreationTime}\n"; _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = JsonConvert.SerializeObject(leadEntity, Newtonsoft.Json.Formatting.Indented), ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = tmpStrToDb, ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = JsonConvert.SerializeObject(leadEntity, Newtonsoft.Json.Formatting.Indented), ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); }
/// <summary> /// ConstraintMet function to loop through all the Filters and Rules in the order as instantiated /// in the constructor. If any rule/filter constraint is not met, the function returns false, /// else the function returns true. /// </summary> /// <param name="leadEntity"></param> /// <returns></returns> public bool ConstraintMet(ILeadEntity leadEntity) { string processContext = "ConstraintMet"; _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Check Controller (Filter and Rule) Constraints", ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); try { // Check to see if the lead meets all the constraints set up for by campaign by looping through // the collection of controllers. // Return as soon as a constraint is not met for one of the rules/filters. foreach (var controller in _campaignControllers) { if (!controller.ConstraintMet(leadEntity)) { var errorStr = String.Join(",", leadEntity.ErrorList.ToArray()); _loggerClient.Log(new DefaultLoggerClientErrorObject { OperationContext = $"Controller constraint not met: {errorStr}.", ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); return(false); } } } catch (Exception ex) { _loggerClient.Log(new DefaultLoggerClientErrorObject { OperationContext = ex.Message, ProcessContext = processContext, SolutionContext = solutionContext, Exception = ex, ErrorContext = ex.Message, EventType = LoggerClientEventType.LoggerClientEventTypes.Error }); return(false); } return(true); }
public void PublishLead(ILeadEntity lead) { throw new NotImplementedException(); }
/// <summary> /// Resolve the leads /// Using the results collection list from each of the campaigns - assign the successful campaign to the /// Preferred ResultList where the campaign was successful. /// </summary> /// <param name="leadEntity"></param> public void ResolveLead(ILeadEntity leadEntity) { var processContext = "ResolveLead"; if ((leadEntity.ResultCollection.CampaignCollection == null) || leadEntity.ResultCollection.CampaignCollection.Length == 0) { _campaignManagerResultList = new List <IResult> { new DefaultResult(ResultKeys.DiagnosticKeys.TimeStampStartKey, DateTime.Now) }; _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "There are no Leads to resolve", ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); return; } _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Resolving the campaign results list", ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); // Choose the campaign info with the highest priority and successful var ix = 0; var priorityIx = 0; var highestPriority = Int32.MaxValue; var campaignResultCollectionList = leadEntity.ResultCollection.CampaignCollection.ToList(); foreach (var resultList in campaignResultCollectionList) { // If the campaign processed successfully, then seek the Campaign that was successful and has the highest priority var campaignSuccessStatus = resultList.SingleOrDefault(r => r.Id == ResultKeys.CampaignKeys.LeadSuccessStatusKey) ?.Value; if (campaignSuccessStatus != null) { if (campaignSuccessStatus.ToString() == ResultKeys.ResultKeysStatusEnum.Processed.ToString()) { var value = resultList .SingleOrDefault(r => r.Id == ResultKeys.CampaignKeys.CampaignPriorityKey) ?.Value; var priorityStr = value?.ToString(); if (priorityStr != null) { if (Int32.TryParse(priorityStr, out int priorityInt)) { if (priorityInt < highestPriority) { //This is the array position for the campaign with the highest priority priorityIx = ix; highestPriority = priorityInt; } } } } } ix++; } // Check that there was a preferred campaign and assign the PreferredCampaignCollection if (highestPriority != Int32.MaxValue) { leadEntity.ResultCollection.PreferredCampaignCollection = leadEntity.ResultCollection.CampaignCollection[priorityIx]; var campaignName = leadEntity.ResultCollection.PreferredCampaignCollection.SingleOrDefault(r => r.Id == ResultKeys.CampaignKeys.CampaignNameKey) ?.Value; _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = $"Lead selected is coming from Campaign: {campaignName} ", ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); } else { _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Did not find valid priority within Campaign Result List", ProcessContext = processContext, SolutionContext = SolutionContext, EventType = LoggerClientEventType.LoggerClientEventTypes.Information }); } }
/// <summary> /// Process the Lead Collected /// </summary> /// <param name="leadEntity"></param> public void CollectLead(ILeadEntity leadEntity) { if (leadEntity == null) { throw new ArgumentNullException(nameof(leadEntity)); } string processContext = "CollectLead"; _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Collected the Lead", ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventTypeControl.Interface.Constants.LoggerClientEventType.LoggerClientEventTypes.Information }); // Create the results list var leadCollectorResultCollectionList = new List <IResult> { new DefaultResult(ResultKeys.DiagnosticKeys.TimeStampStartKey, DateTime.Now) }; _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Validating the Lead", ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventTypeControl.Interface.Constants.LoggerClientEventType.LoggerClientEventTypes.Information }); try { //If the lead is valid, decorate and publish if (_leadValidator.ValidLead(leadEntity).Equals(true)) { leadCollectorResultCollectionList.Add(new DefaultResult(ResultKeys.ValidatorStatusKey, ResultKeys.ResultKeysStatusEnum.Processed.ToString())); // Broadcast to the Campaigns _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Publishing the Lead", ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventTypeControl.Interface.Constants.LoggerClientEventType.LoggerClientEventTypes.Information }); _leadPublisher.PublishLead(leadEntity); leadCollectorResultCollectionList.Add(new DefaultResult(ResultKeys.LeadCollectorKeys.PublisherStatusKey, ResultKeys.ResultKeysStatusEnum.Processed.ToString())); // Decorate _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Decorating the Lead", ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventTypeControl.Interface.Constants.LoggerClientEventType.LoggerClientEventTypes.Information }); leadCollectorResultCollectionList.Add(new DefaultResult(ResultKeys.DiagnosticKeys.TimeStampEndKey, DateTime.Now)); _leadDecorator.DecorateLead(leadEntity, leadCollectorResultCollectionList); } else { leadCollectorResultCollectionList.Add(new DefaultResult(ResultKeys.ValidatorStatusKey, ResultKeys.ResultKeysStatusEnum.Failed.ToString())); // Decorate _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = "Decorating the Lead", ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventTypeControl.Interface.Constants.LoggerClientEventType.LoggerClientEventTypes.Information }); leadCollectorResultCollectionList.Add(new DefaultResult(ResultKeys.DiagnosticKeys.TimeStampEndKey, DateTime.Now)); _leadDecorator.DecorateLead(leadEntity, leadCollectorResultCollectionList); // TODO - Show the lead for demo Remove afterwards and move "//Decorate part below if stmnt _loggerClient.Log(new DefaultLoggerClientObject { OperationContext = JsonConvert.SerializeObject(leadEntity, Newtonsoft.Json.Formatting.Indented), ProcessContext = processContext, SolutionContext = solutionContext, EventType = LoggerClientEventTypeControl.Interface.Constants.LoggerClientEventType.LoggerClientEventTypes.Information }); } } catch (Exception exception) { // Add results to Lead Entity _leadDecorator.DecorateLead(leadEntity, leadCollectorResultCollectionList); // Log an Error _loggerClient.Log(new DefaultLoggerClientErrorObject { OperationContext = "Collected the Lead", ProcessContext = processContext, SolutionContext = solutionContext, ErrorContext = exception.Message, Exception = exception, EventType = LoggerClientEventTypeControl.Interface.Constants.LoggerClientEventType.LoggerClientEventTypes.Error }); throw; } }
public bool ValidLead(ILeadEntity lead) { throw new NotImplementedException(); }
public bool ValidLead(ILeadEntity leadEntity) { return(false); }
public bool ValidLead(ILeadEntity leadEntity) { return(true); }
public bool ConstraintMet(ILeadEntity leadEntity) { throw new NotImplementedException(); }
public bool ConstraintMet(ILeadEntity leadEntity) { return(false); }
/// <summary> /// Create an Instance of the LeadEntity /// </summary> //private class TestLeadEntityClass : ILeadEntity //{ // public IContext[] Context { get; set; } // public IProperty[] Properties { get; set; } // public ISegment[] Segments { get; set; } // public IResultCollection ResultCollection { get; set; } // public List<string> ErrorList { get; set; } //} //struct TestLeadEntityResultClass : IResult //{ // public TestLeadEntityResultClass(string id, object value) // { // Id = id; // Value = value; // } // public string Id { get; private set; } // public object Value { get; private set; } //} void CreateLeadEntity() { _testLeadEntity = new DefaultLeadEntity(); }
static ILeadEntity[] CreateLeads() { //const int quotedProduct = 101; //const string additonalProducts = "None"; //const string priorBi = "100/300"; //const bool priorInsurance = true; //const int vehicleCount = 2; //const string quotedBi = "100/300"; //int[] displayedBrands = new int[] { 22, 58, 181, 218 }; //const string phoneNumber = "888-556-5456"; //const int pni_Age = 28; //const string emailAddress = "*****@*****.**"; //const string stateStr = "VA"; //const int brandID = 44; var leadEntities = new ILeadEntity[7]; //_leadDirectory = new string[7]; //_leadDirectory[0] = "Lead - NO IdentityGUID - LeadCollector Validator"; //leadEntities[0] = new DefaultLeadEntity //{ // Context = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(ContextKeys.LeadEntityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.ActivityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionGuidKey,Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.QuotedProductKey,quotedProduct.ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.AdditionalProductKey,additonalProducts) // }, // Properties = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorBIKey,priorBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorInsuranceKey,priorInsurance.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.VehicleCountKey,vehicleCount.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.QuotedBIKey,quotedBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.DisplayedBrandsKey,displayedBrands), // new DefaultLeadEntityObjectContainer(PropertyKeys.PhoneNumber,phoneNumber.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.PNI_Age,pni_Age.ToString()) // }, // Segments = new ISegment[] // { // new DefaultSegment(SegementKeys.HighPOPKey), // new DefaultSegment(SegementKeys.HomeownerKey) // }, //}; //_leadDirectory[1] = "Lead - Good "; //leadEntities[1] = new DefaultLeadEntity //{ // Context = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(ContextKeys.LeadEntityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.ActivityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.IdentityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionGuidKey,Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.QuotedProductKey,quotedProduct.ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionRequestSeqKey,"1"), // new DefaultLeadEntityObjectContainer(ContextKeys.SiteIDKey,"26328"), // new DefaultLeadEntityObjectContainer(ContextKeys.AdditionalProductKey,additonalProducts) // }, // Properties = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorBIKey,priorBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorInsuranceKey,priorInsurance.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.VehicleCountKey,vehicleCount.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.QuotedBIKey,quotedBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.DisplayedBrandsKey,displayedBrands), // new DefaultLeadEntityObjectContainer(PropertyKeys.PhoneNumber,phoneNumber.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.PNI_Age,pni_Age.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.EmailAddressKey,emailAddress), // new DefaultLeadEntityObjectContainer(PropertyKeys.StateKey,stateStr), // }, // Activity = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(ActivityKeys.BrandIdKey, brandID), // new DefaultLeadEntityObjectContainer(ActivityKeys.BuyType, BuyClickType.BuyOnLine), // }, // Segments = new ISegment[] // { // new DefaultSegment(SegementKeys.HighPOPKey), // new DefaultSegment(SegementKeys.HomeownerKey) // }, //}; //_leadDirectory[2] = "Lead - NO Email, No State - Campaign Manager Validator"; //leadEntities[2] = new DefaultLeadEntity //{ // Context = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(ContextKeys.LeadEntityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.ActivityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.IdentityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionGuidKey,Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.QuotedProductKey,quotedProduct.ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionRequestSeqKey,"1"), // new DefaultLeadEntityObjectContainer(ContextKeys.SiteIDKey,"26328"), // new DefaultLeadEntityObjectContainer(ContextKeys.AdditionalProductKey,additonalProducts) // }, // Properties = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorBIKey,priorBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorInsuranceKey,priorInsurance.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.VehicleCountKey,vehicleCount.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.QuotedBIKey,quotedBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.DisplayedBrandsKey,displayedBrands), // new DefaultLeadEntityObjectContainer(PropertyKeys.PhoneNumber,phoneNumber.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.PNI_Age,pni_Age.ToString()), // }, // Activity = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(ActivityKeys.BrandIdKey, brandID), // new DefaultLeadEntityObjectContainer(ActivityKeys.BuyType, BuyClickType.BuyOnLine), // }, // Segments = new ISegment[] // { // new DefaultSegment(SegementKeys.HighPOPKey), // new DefaultSegment(SegementKeys.HomeownerKey) // }, //}; //_leadDirectory[3] = "Lead - QuotedBIValidator - Campaign Validator"; //leadEntities[3] = new DefaultLeadEntity //{ // Context = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(ContextKeys.LeadEntityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.ActivityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.IdentityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionGuidKey,Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.QuotedProductKey,quotedProduct.ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionRequestSeqKey,"1"), // new DefaultLeadEntityObjectContainer(ContextKeys.SiteIDKey,"26328"), // new DefaultLeadEntityObjectContainer(ContextKeys.AdditionalProductKey,additonalProducts) // }, // Properties = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorBIKey,priorBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorInsuranceKey,priorInsurance.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.VehicleCountKey,vehicleCount.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.DisplayedBrandsKey,displayedBrands), // new DefaultLeadEntityObjectContainer(PropertyKeys.PhoneNumber,phoneNumber.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.PNI_Age,pni_Age.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.EmailAddressKey,emailAddress), // new DefaultLeadEntityObjectContainer(PropertyKeys.StateKey,stateStr), // }, // Activity = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(ActivityKeys.BrandIdKey, brandID), // new DefaultLeadEntityObjectContainer(ActivityKeys.BuyType, BuyClickType.BuyOnLine), // }, // Segments = new ISegment[] // { // new DefaultSegment(SegementKeys.HighPOPKey), // new DefaultSegment(SegementKeys.HomeownerKey) // }, //}; //_leadDirectory[4] = "Lead - Less than 2 Brands Displayed - Campaign Rule"; //leadEntities[4] = new DefaultLeadEntity //{ // Context = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(ContextKeys.LeadEntityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.ActivityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.IdentityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionGuidKey,Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.QuotedProductKey,quotedProduct.ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionRequestSeqKey,"1"), // new DefaultLeadEntityObjectContainer(ContextKeys.SiteIDKey,"26328"), // new DefaultLeadEntityObjectContainer(ContextKeys.AdditionalProductKey,additonalProducts) // }, // Properties = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorBIKey,priorBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorInsuranceKey,priorInsurance.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.VehicleCountKey,vehicleCount.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.QuotedBIKey,quotedBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.DisplayedBrandsKey,1), // new DefaultLeadEntityObjectContainer(PropertyKeys.PhoneNumber,phoneNumber.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.PNI_Age,pni_Age.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.EmailAddressKey,emailAddress), // new DefaultLeadEntityObjectContainer(PropertyKeys.StateKey,stateStr), // }, // Activity = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(ActivityKeys.BrandIdKey, brandID), // new DefaultLeadEntityObjectContainer(ActivityKeys.BuyType, BuyClickType.BuyOnLine), // }, // Segments = new ISegment[] // { // new DefaultSegment(SegementKeys.HighPOPKey), // new DefaultSegment(SegementKeys.HomeownerKey) // }, //}; //_leadDirectory[5] = "Lead - BF526BAF-F860-4530-BAA5-A205E285881A - Campaign Filter"; //leadEntities[5] = new DefaultLeadEntity //{ // Context = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(ContextKeys.LeadEntityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.ActivityGuidKey, new Guid("BF526BAF-F860-4530-BAA5-A205E285881A").ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.IdentityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionGuidKey,Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.QuotedProductKey,quotedProduct.ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionRequestSeqKey,"1"), // new DefaultLeadEntityObjectContainer(ContextKeys.SiteIDKey,"26328"), // new DefaultLeadEntityObjectContainer(ContextKeys.AdditionalProductKey,additonalProducts) // }, // Properties = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorBIKey,priorBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorInsuranceKey,priorInsurance.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.VehicleCountKey,vehicleCount.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.QuotedBIKey,quotedBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.DisplayedBrandsKey,1), // new DefaultLeadEntityObjectContainer(PropertyKeys.PhoneNumber,phoneNumber.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.PNI_Age,pni_Age.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.EmailAddressKey,emailAddress), // new DefaultLeadEntityObjectContainer(PropertyKeys.StateKey,stateStr), // }, // Segments = new ISegment[] // { // new DefaultSegment(SegementKeys.HighPOPKey), // new DefaultSegment(SegementKeys.HomeownerKey) // }, //}; //_leadDirectory[6] = "Lead - No POP - Good"; //leadEntities[6] = new DefaultLeadEntity //{ // Context = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(ContextKeys.LeadEntityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.ActivityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.IdentityGuidKey, Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionGuidKey,Guid.NewGuid().ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.QuotedProductKey,quotedProduct.ToString()), // new DefaultLeadEntityObjectContainer(ContextKeys.SessionRequestSeqKey,"1"), // new DefaultLeadEntityObjectContainer(ContextKeys.SiteIDKey,"26328"), // new DefaultLeadEntityObjectContainer(ContextKeys.AdditionalProductKey,additonalProducts) // }, // Properties = new ILeadEntityObjectContainer[] // { // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorBIKey,priorBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.PriorInsuranceKey,"false"), // new DefaultLeadEntityObjectContainer(PropertyKeys.VehicleCountKey,vehicleCount.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.QuotedBIKey,quotedBi), // new DefaultLeadEntityObjectContainer(PropertyKeys.DisplayedBrandsKey,displayedBrands), // new DefaultLeadEntityObjectContainer(PropertyKeys.PhoneNumber,phoneNumber.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.PNI_Age,pni_Age.ToString()), // new DefaultLeadEntityObjectContainer(PropertyKeys.EmailAddressKey,emailAddress), // new DefaultLeadEntityObjectContainer(PropertyKeys.StateKey,stateStr), // }, // Activity = new ILeadEntityObjectContainer[] // { // // new DefaultLeadEntityObjectContainer(ActivityKeys.BrandIdKey, brandID), // new DefaultLeadEntityObjectContainer(ActivityKeys.BuyType, BuyClickType.BuyOnLine), // }, // Segments = new ISegment[] // { // new DefaultSegment(SegementKeys.HighPOPKey), // new DefaultSegment(SegementKeys.HomeownerKey) // }, //}; return(leadEntities); }