/// <summary>
        /// Processes the event
        /// </summary>
        /// <param name="args">An instance of the CompleteServiceProcessArgs class</param>
        /// <returns>A list of events that processing this event spawned</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the given args is null</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the given args is not the correct EventProcessArgs child type</exception>
        public override List <Event> Process(EventProcessArgs args)
        {
            //If the given args is not null
            if (args != null)
            {
                // Attempt to cast the args to the correct EventProcessArgs child type
                CompletedServiceProcessArgs pArgs = args as CompletedServiceProcessArgs;

                //If the cast worked
                if (pArgs != null)
                {
                    //Create the list of Events to return
                    List <Event> spawnedEvents = new List <Event>();

                    //Set this events entities finish time
                    entity.FinishTime = eventTime;

                    //GetProcessableProductTypes the salesrep that was assigned this entity
                    SalesRepresentative salesrep = entity.ProcessedBy;
                    //remove the salesRep's currentlly processing
                    salesrep.CurrentlyProcessing = null;

                    //Get a new call from the queue manager
                    Call nextCall = pArgs.QueueManager.GetCallForRepType(salesrep.RepType);

                    //If the above method returned a call
                    if (nextCall != null)
                    {
                        nextCall.BeganProcessing = eventTime;
                        //Assign them to each other
                        nextCall.ProcessedBy         = salesrep;
                        salesrep.CurrentlyProcessing = nextCall;

                        //Get the next calls product type
                        ProductType ncProductType = nextCall.ProductType;

                        //create the processing complete event
                        DateTime processingTime = eventTime;
                        double   timespanInMins = NormalDistributor.Roll() * ncProductType.ProcessingDelayMultiplier;
                        processingTime = processingTime.AddMinutes(timespanInMins);
                        Event processComplete = pArgs.EventFactory.CreateEvent(EEventType.CompletedService, processingTime, nextCall);
                        spawnedEvents.Add(processComplete);
                    }
                    //else No calls waiting in queue

                    //Return the list of spawned events
                    return(spawnedEvents);
                }
                else // The given args could not be cast to the correct type
                {
                    throw new ArgumentOutOfRangeException("args", "Attempted to pass invalid args to CompletedServiceEvent.Process");
                }
            }
            else // The given args was null
            {
                throw new ArgumentNullException("args", "Attempted to pass null args to CompletedServiceEvent.Process");
            }
        }
Пример #2
0
        /// <summary>
        /// Processes the event
        /// </summary>
        /// <param name="args">An instance of the SwitchCompleteProcessArgs</param>
        /// <returns>A list of events that processing this event spawned</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the given args is null or not of the correct type</exception>
        /// /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the given args is not the correct EventProcessArgs child type</exception>
        public override List <Event> Process(EventProcessArgs args)
        {
            // If the given args is not null
            if (args != null)
            {
                // Attempt to cast the args to the correct EventProcessArgs child type
                SwitchCompleteProcessArgs pArgs = args as SwitchCompleteProcessArgs;

                //If the cast worked
                if (pArgs != null)
                {
                    //Create the list of events to return
                    List <Event> spawnedEvents = new List <Event>();

                    //GetProcessableProductTypes the product type from the entity
                    ProductType entityProductType = entity.ProductType;
                    //GetProcessableProductTypes a sales representative from the Simulations SalesManager if one is available
                    SalesRepresentative salesRep = pArgs.SalesManager.GetRepresentativeForProductType(entityProductType);
                    //If a SalesRepresentative was returned above, assign the entity to it
                    if (salesRep != null)
                    {
                        entity.BeganProcessing       = eventTime;
                        salesRep.CurrentlyProcessing = entity;
                        entity.ProcessedBy           = salesRep;
                        //create the processing complete event
                        DateTime processingTime = eventTime;
                        double   timespanInMins = NormalDistributor.Roll() * entityProductType.ProcessingDelayMultiplier;
                        processingTime = processingTime.AddMinutes(timespanInMins);
                        Event processComplete = args.EventFactory.CreateEvent(EEventType.CompletedService, processingTime, entity);
                        spawnedEvents.Add(processComplete);
                    }
                    else //No representative was available
                    {
                        //Set the enitities begin wait
                        entity.BeginWait = eventTime;
                        //Add the call to the queue
                        args.QueueManager.AddToQueue(entity);
                    }

                    //Return the list of events spawned as a result of this
                    return(spawnedEvents);
                }
                else // The given args could not be cast to the correct type
                {
                    throw new ArgumentOutOfRangeException("args", "Attempted to pass invalid args to SwitchCompletedEvent.Process");
                }
            }
            else // The given args was null
            {
                throw new ArgumentNullException("args", "Attempted to pass null EventProcessArgs to SwitchCompletedEvent.Process");
            }
        }
 /// <summary>
 /// Adds the given SalesRepresentative to the salesforce, if the salesrep is of a known type
 /// </summary>
 /// <param name="representative">The SalesRepresentative to add</param>
 /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the given SalesRepresentative has a SalesRepType that is not already in the SalesForce</exception>
 /// <exception cref="System.ArgumentNullException">Thrown when the given representative is null</exception>
 public void AddSalesRepresentative(SalesRepresentative representative)
 {
     //Check that the given SalesRepresentative is not null
     if (representative != null)
     {
         //If the salesForce contains the an entry with the given representatives reptype
         if (salesForce.ContainsKey(representative.RepType))
         {
             //Add the representative to the correct list
             salesForce[representative.RepType].Add(representative);
             //Increase the number of salesReps for that type
             numberOfReps[representative.RepType]++;
         }
         else
         {
             throw new ArgumentOutOfRangeException("representative", "Attempted to add a representative with a SalesRepType that was not already in the salesForce");
         }
     }
     else //representative is null throw an exception
     {
         throw new ArgumentNullException("representative", "Attempted to pass null SalesRepresentative to SalesForceManager.AddSalesRepresentative");
     }
 }
        /// <summary>
        /// Gets the first free SalesRep of the given type, null if no SalesRep is available
        /// </summary>
        /// <param name="repType">The type of the sales rep to retrieve</param>
        /// <returns>A SalesRepresentative, null if no SalesRepresentative is available</returns>
        private SalesRepresentative GetFreeSalesRep(SalesRepType repType)
        {
            //Check if the given rep type is not null
            if (repType != null)
            {
                // Check that the given repType is a key in the dictionary
                if (salesForce.ContainsKey(repType))
                {
                    //Get the first free Sales rep of the given type
                    SalesRepresentative firstFree = salesForce[repType].FirstOrDefault(sr => sr.CurrentlyProcessing == null);

                    return(firstFree);
                }
                else // The given salesRepType is not in the dictionary
                {
                    throw new ArgumentOutOfRangeException("repType", "Attempted to pass SalesRepType that is not in the dictionary to SalesForceManager.GetFreeSalesRep");
                }
            }
            else //The repType is null
            {
                throw new ArgumentNullException("repType", "Attempted to pass null SalesRepType to SalesForceManager.GetFreeSalesRep");
            }
        }