コード例 #1
0
        /// <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");
            }
        }
コード例 #3
0
        /// <summary>
        /// Processes the event
        /// </summary>
        /// <param name="args">An instance of the CallArriveProcessArgs 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
                CallArriveProcessArgs pArgs = args as CallArriveProcessArgs;

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

                    //Set up the call
                    entity.StartTime   = eventTime;
                    entity.ProductType = ChooseProductType(pArgs.ProductTypes);

                    //Check if there are to many calls waiting for this product type
                    if (args.QueueManager.IsQueueTooLong(entity.ProductType) == false)
                    {
                        //Calculate the time of the new SwitchCompletedEvent
                        DateTime switchCompleteTime = eventTime;
                        int      roll           = NormalDistributor.Roll();
                        double   timespanInMins = roll * pArgs.SwitchDelayMultiplier;
                        //Add the minutes to the switchCompleteTime
                        switchCompleteTime = switchCompleteTime.AddMinutes(timespanInMins);
                        //Use the event factory to create a switch complete event
                        Event switchComplete = args.EventFactory.CreateEvent(EEventType.SwitchCompleted, switchCompleteTime, entity);
                        spawnedEvents.Add(switchComplete);
                        hangUp = false;
                    }
                    else
                    {
                        hangUp = true;
                    }

                    //Create the next CallArrive event
                    DateTime nextCallArriveTime    = eventTime;
                    int      rollNewCall           = NormalDistributor.Roll();
                    double   timespanInMinsNewCall = rollNewCall * pArgs.CallArriveMultiplier;
                    nextCallArriveTime = nextCallArriveTime.AddMinutes(timespanInMinsNewCall);
                    //GetProcessableProductTypes a new blank call for the next event
                    Call newCall = pArgs.CallFactory.CreateCall();
                    //Use the event factory to create a call arrive event
                    Event callArrive = args.EventFactory.CreateEvent(EEventType.CallArrive, nextCallArriveTime, newCall);
                    spawnedEvents.Add(callArrive);

                    //Return all 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 CallArriveEvent.Process");
                }
            }
            else // The given args are null
            {
                throw new ArgumentNullException("args", "Attempted to pass null CallArriveProcessArgs to CallArriveEvent.Process");
            }
        }