Exemplo n.º 1
0
        /**********************************************************/
        public List <oadrDistributeEventTypeOadrEvent> checkEventStatusChanges(int serverOffsetSeconds)
        {
            var result = new List <oadrDistributeEventTypeOadrEvent>();

            foreach (KeyValuePair <string, OadrEventWrapper> eventKeyValue in m_idToEvent)
            {
                oadrDistributeEventTypeOadrEvent oadrEvent = eventKeyValue.Value.OadrEvent;

                if (oadrEvent.eiEvent.eventDescriptor.eventStatus == EventStatusEnumeratedType.cancelled)
                {
                    continue;
                }

                DateTime now = DateTime.Now.AddSeconds(serverOffsetSeconds);

                DateTime dtstart = oadrEvent.eiEvent.eiActivePeriod.properties.dtstart.datetime.ToLocalTime();

                TimeSpan duration = XmlConvert.ToTimeSpan(oadrEvent.eiEvent.eiActivePeriod.properties.duration.duration);

                TimeSpan rampUpDuration = new TimeSpan(0);

                if (oadrEvent.eiEvent.eiActivePeriod.properties.xeiRampUp != null)
                {
                    rampUpDuration = XmlConvert.ToTimeSpan(oadrEvent.eiEvent.eiActivePeriod.properties.xeiRampUp.duration);
                }

                EventStatusEnumeratedType oldEventStatus = oadrEvent.eiEvent.eventDescriptor.eventStatus;
                EventStatusEnumeratedType newEventStatus;

                if (now < dtstart)
                {
                    newEventStatus = (now + rampUpDuration >= dtstart) ? EventStatusEnumeratedType.near
                                                                           : EventStatusEnumeratedType.far;
                }
                // duration of 0 indicates an open ended event (no scheduled end time)
                else if (now >= dtstart && (now < dtstart + duration || duration.TotalSeconds == 0))
                {
                    newEventStatus = EventStatusEnumeratedType.active;
                }
                else
                {
                    newEventStatus = EventStatusEnumeratedType.completed;
                }

                // if an active event is cancelled and the event has the start after parameter set
                // the event will remain active for a random number of minutes before cancelling
                if (eventKeyValue.Value.DelayCancel)
                {
                    if (now >= eventKeyValue.Value.DelayCanceledEndTime)
                    {
                        newEventStatus = EventStatusEnumeratedType.cancelled;

                        m_callbacks.logSystemMessage("Cancelling active event after waiting a randomized minutes", UserControls.Log.WebLogView.eWebLogMessageStatus.INFO);
                    }
                }

                if (newEventStatus != oldEventStatus)
                {
                    oadrEvent.eiEvent.eventDescriptor.eventStatus = newEventStatus;

                    m_callbacks.logSystemMessage("Event status changed: " + oadrEvent.eiEvent.eventDescriptor.eventID + ", old=" + oldEventStatus.ToString() + ", new=" + newEventStatus.ToString(), UserControls.Log.WebLogView.eWebLogMessageStatus.INFO);

                    //oadrlib.lib.helper.Logger.logMessage(String.Format("event {0} status change: {1} to {2}",
                    //                                     eventKeyValue.Key, oldEventStatus, newEventStatus));

                    result.Add(oadrEvent);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        /**********************************************************/

        private void processExistingEvent(string requestID, CreatedEventHelper createdEventHelper, oadrDistributeEventTypeOadrEvent evt)
        {
            string eventID = evt.eiEvent.eventDescriptor.eventID;

            OadrEventWrapper existingEvent = m_idToEvent[eventID];

            if (existingEvent.OadrEvent.eiEvent.eventDescriptor.modificationNumber > evt.eiEvent.eventDescriptor.modificationNumber)
            {
                // the incoming event has an old modification number; keep tracking the old event
                // and report an error to the VTN
                m_callbacks.logSystemMessage("Event update received out of sequence and will be ignored: " + eventID + ", current=" + existingEvent.OadrEvent.eiEvent.eventDescriptor.modificationNumber.ToString() + ", incoming=" + evt.eiEvent.eventDescriptor.modificationNumber.ToString(), UserControls.Log.WebLogView.eWebLogMessageStatus.WARNING);
                createdEventHelper.addEvent(evt, requestID, existingEvent.OptType, 450, "Out of sequence");
                return;
            }

            // if the event was updated (modification numbers don't match), we must re-optin/out, provided
            // the event is still active
            if (existingEvent.OadrEvent.eiEvent.eventDescriptor.modificationNumber != evt.eiEvent.eventDescriptor.modificationNumber &&
                evt.oadrResponseRequired == ResponseRequiredType.always &&
                evt.eiEvent.eventDescriptor.eventStatus != EventStatusEnumeratedType.completed)
            {
                // the event was modified; need to send createdEvent again
                if (evt.eiEvent.eventDescriptor.eventStatus != EventStatusEnumeratedType.cancelled)
                {
                    m_callbacks.logSystemMessage("Opting modified event: " + existingEvent.OptType.ToString() + " , " + eventID, UserControls.Log.WebLogView.eWebLogMessageStatus.INFO);
                    createdEventHelper.addEvent(evt, requestID, existingEvent.OptType, 200, "OK");
                }
                // event was cancelled; need to optIn to indicate we ackowledge the cancellation
                // optOut indicates we cannot cancel
                else
                {
                    m_callbacks.logSystemMessage("Opting into cancelled event: " + eventID, UserControls.Log.WebLogView.eWebLogMessageStatus.INFO);
                    createdEventHelper.addEvent(evt, requestID, OptTypeType.optIn, 200, "OK");
                    m_idToEvent[eventID].OptType = OptTypeType.optIn;
                }
            }

            // if the event is active and is being cancelled and the Start After parameter was set,
            // delay cancelling the event by RandomizedMinutes minutes
            if (m_idToEvent[eventID].OadrEvent.eiEvent.eventDescriptor.eventStatus == EventStatusEnumeratedType.active &&
                m_idToEvent[eventID].RandomizedMinutes != 0 && evt.eiEvent.eventDescriptor.eventStatus == EventStatusEnumeratedType.cancelled)
            {
                // force the event to remain active
                evt.eiEvent.eventDescriptor.eventStatus = EventStatusEnumeratedType.active;

                // set the end time to be used to detemermine when the event will end
                m_idToEvent[eventID].initiateDelayCancel();

                m_callbacks.logSystemMessage(string.Format("Active event with randomized start time was cancelled.  event will be cancelled at ",
                                                           m_idToEvent[eventID].DelayCanceledEndTime.ToString()), UserControls.Log.WebLogView.eWebLogMessageStatus.INFO);
            }

            EventStatusEnumeratedType oldEventStatus = m_idToEvent[eventID].OadrEvent.eiEvent.eventDescriptor.eventStatus;
            EventStatusEnumeratedType newEventStatus = evt.eiEvent.eventDescriptor.eventStatus;

            // log event status changes
            if (oldEventStatus != evt.eiEvent.eventDescriptor.eventStatus)
            {
                m_callbacks.logSystemMessage("Server reported Event status changed: " + eventID + ", old=" + oldEventStatus.ToString() + ", new=" + newEventStatus.ToString(), UserControls.Log.WebLogView.eWebLogMessageStatus.INFO);
            }

            // replace the event
            m_idToEvent[eventID].OadrEvent = evt;
            return;
        }