/// <summary> /// Dispatches the specified lead to agent scheduler. /// </summary> /// <param name="leadDetails">The lead details.</param> public IAgentDTO Dispatch(ILeadDTO leadDetails) { IAgentDataManager agentDataManager = new LeadDistributionDataFactory().GetAgentDataManager(DataComponentType.InMemoryData); ///Get the agent container for given territory using lead details INodeContainerIterator<IAgentDTO> agentContainerIterator = agentDataManager.GetAgentsContainerIterator(leadDetails); ///Schedule an agent using the agent container iterator return this.AgentScheduler.ScheduleAgent(leadDetails, agentContainerIterator); }
/// <summary> /// Schedules an agent using agent container iterator /// </summary> /// <param name="leadDetails">The lead to be given to an agent.</param> /// <param name="agentContainerIterator">Agent Container iterator.</param> /// <returns></returns> public IAgentDTO ScheduleAgent(ILeadDTO leadDetails, INodeContainerIterator<IAgentDTO> agentContainerIterator) { IAgentDTO assignedAgent = null; if (agentContainerIterator.HasNodes()) { ///Fetch the next available node assignedAgent = agentContainerIterator.PeekCurrent(); ///Assign lead to the agent in Datastore IAgentDataManager agentDataManager = new LeadDistributionDataFactory().GetAgentDataManager(DataComponentType.InMemoryData); agentDataManager.AssignLeadToAgent(leadDetails, assignedAgent); ///Move the iterator to the next node. agentContainerIterator.MoveNext(); } return assignedAgent; }
/// <summary> /// Process the lead details provided. /// </summary> /// <param name="leadDetails">The lead details.</param> /// <returns></returns> public OperationResult<IAgentDTO> ProcessLead(ILeadDTO leadDetails) { IAgentDTO assignedAgent = null; LeadDistributionFactory leadDistributionFactory = new LeadDistributionFactory(); IValidateLead validateLead = leadDistributionFactory.GetLeadValidator(LeadValidatorType.ValidateTerritory); ///Validate the lead validateLead.Validate(leadDetails); if (validateLead.IsValid) { ///Get the Lead-Dispatcher ILeadDispatcher leadDispatcher = leadDistributionFactory.GetDispatcher(DispatcherType.TerritoryDispatcher); ///Initialize the Agent-Scheduler algorithm leadDispatcher.InitializeAgentScheduler(leadDistributionFactory.GetAgentScheduler(AgentSchedulerType.LIFO)); ///Dispatch the lead for scheduling assignedAgent = leadDispatcher.Dispatch(leadDetails); } OperationResult<IAgentDTO> result = CreateOperationResult(validateLead, assignedAgent); return result; }
/// <summary> /// Validates the specified lead details. /// </summary> /// <param name="leadDetails">The lead details.</param> public void Validate(ILeadDTO leadDetails) { if (!string.IsNullOrWhiteSpace(leadDetails.Territory)) { LeadDistributionDataFactory leadDistributionDataFactory = new LeadDistributionDataFactory(); ITerritoryDataManager territoryDataManager = leadDistributionDataFactory.GetTerritoryDataManager(DataComponentType.InMemoryData); ITerritoryDTO territory = territoryDataManager.GetTerritoryByName(leadDetails.Territory); IAgentDataManager agentDataManager = leadDistributionDataFactory.GetAgentDataManager(DataComponentType.InMemoryData); if (territory == null) ///Check for valid territory { Message = InValidTerritoryMessage; } else if (agentDataManager.IsLeadAssociatedWithAgent(leadDetails.ID))///Check for already processed lead { Message = AlreadyAssociatedLeadMessage; } else { IsValid = true; Message = ValidLeadMessage; } } }
/// <summary> /// Gets the agents container iterator. /// </summary> /// <param name="leadDetails">The lead details.</param> /// <returns></returns> public INodeContainerIterator<IAgentDTO> GetAgentsContainerIterator(ILeadDTO leadDetails) { return ApplicationDataStore.TerritoryAgentDictionary[leadDetails.Territory]; }
/// <summary> /// Assigns the lead to agent. /// </summary> /// <param name="leadDetails">The lead details.</param> /// <param name="agentDTO">The agent DTO.</param> public void AssignLeadToAgent(ILeadDTO leadDetails, IAgentDTO agentDTO) { ApplicationDataStore.LeadAgentDictionary.Add(leadDetails.ID, agentDTO); }