private bool ShouldBeMarkedExecuted(ProcessScheduledEvent existingPSE, ScheduledEvent.ExecutedCalculationType executedCalculationType, DateTime eventDate, DateTime cutoffDate)
 {
     switch (executedCalculationType)
     {
         case ScheduledEvent.ExecutedCalculationType.UsePreviousValue:
             //Note - use previous value only if the eventDate has not been changed!
             if (existingPSE == null || !Utility.DateHelper.SameDay(existingPSE.EventDate,eventDate))
                 return (eventDate < cutoffDate);
             return existingPSE.Executed;
         case ScheduledEvent.ExecutedCalculationType.SetAsNotExecuted:
             return false;
         case ScheduledEvent.ExecutedCalculationType.SetAsExecuted:
             return true;
         case ScheduledEvent.ExecutedCalculationType.UseGracePeriod:
             return (eventDate < cutoffDate);
         default:
             throw new ArgumentOutOfRangeException("Invalid value for executedCalculationType argument: " + executedCalculationType.ToString());
     }
 }
		private List<ProcessScheduledEvent> RenewalScheduledEvents(Event eachEvent, ScheduledEvent.ExecutedCalculationType executedCalculationType, DateTime cutoffDate)
        {
            List<ProcessScheduledEvent> processScheduledEvents = new List<ProcessScheduledEvent>();
            RenewalTerm renewalTerm = FindBasicTerm(TermType.Renewal) as RenewalTerm;
            if (renewalTerm != null)
            {
                if (renewalTerm.SendNotification ?? true)
                {
                    if (renewalTerm.RenewalEvent != null && renewalTerm.RenewalEvent.ScheduledEvents != null)
                    {
                        if (renewalTerm.ExpirationDate.HasValue)
                        {
                            int baseOffsetDays = GetBaseOffsetDays(eachEvent, renewalTerm);
                            foreach (ScheduledEvent scheduledEvent in eachEvent.ScheduledEvents)
                            {
                                DateTime eventDate = ScheduledEvent.GetEventDate(renewalTerm.ExpirationDate.Value.AddDays(-1 * baseOffsetDays), scheduledEvent.DateOffset);
                                ProcessScheduledEvent existingPSE = ProcessScheduledEvents.Find(pse => pse.ScheduledEventId == scheduledEvent.ID);
								processScheduledEvents.Add(new ProcessScheduledEvent(scheduledEvent.ID, scheduledEvent.EventId, eventDate, ShouldBeMarkedExecuted(existingPSE, executedCalculationType, eventDate, cutoffDate)));
                            }
                        }
                    }
                }
            }
            return processScheduledEvents;
        }
		private List<ProcessScheduledEvent> CustomScheduledEvents(Event eachEvent, ScheduledEvent.ExecutedCalculationType executedCalculationType, DateTime cutoffDate)
        {
            List<ProcessScheduledEvent> processScheduledEvents = new List<ProcessScheduledEvent>();
            Term term = FindTerm(eachEvent.BaseDateTermID, eachEvent.BaseDateTermName);
            int baseOffsetDays = GetBaseOffsetDays(eachEvent);
            if (term != null)
            {
                switch (term.TermType)
                {
                    case TermType.Date:
                        DateTerm dateTerm = term as DateTerm;
                        if (dateTerm == null)
                            throw new Exception(string.Format("Term '{0}' is not a Date Term.", term.Name));
                        if (dateTerm.Value.HasValue)
                        {
                            foreach (ScheduledEvent scheduledEvent in eachEvent.ScheduledEvents)
                            {
                                DateTime eventDate = ScheduledEvent.GetEventDate(dateTerm.Value.Value.AddDays(-1 * baseOffsetDays), scheduledEvent.DateOffset);
                                ProcessScheduledEvent existingPSE = ProcessScheduledEvents.Find(pse => pse.ScheduledEventId == scheduledEvent.ID);
								processScheduledEvents.Add(new ProcessScheduledEvent(scheduledEvent.ID, scheduledEvent.EventId, eventDate, ShouldBeMarkedExecuted(existingPSE, executedCalculationType, eventDate, cutoffDate)));
                            }
                        }
                        break;

                    case TermType.Renewal:
                        RenewalTerm renewalTerm = term as RenewalTerm;
                        if (renewalTerm == null)
                            throw new Exception(string.Format("Term '{0}' is not a Renewal Term.", term.Name));
                        DateTime? dtBaseDate = null;
                        switch (eachEvent.BaseDateTermPart)
                        {
                            case XMLNames._TPS_EffectiveDate:
                                if (renewalTerm.EffectiveDate.HasValue)
                                    dtBaseDate = renewalTerm.EffectiveDate.Value;
                                break;
                            case XMLNames._TPS_ExpirationDate:
                            case "":
                            case null:
                            default:
                                if (renewalTerm.ExpirationDate.HasValue)
                                    dtBaseDate = renewalTerm.ExpirationDate.Value;
                                break;
                        }
                        if (dtBaseDate.HasValue)
                        {
                            foreach (ScheduledEvent scheduledEvent in eachEvent.ScheduledEvents)
                            {
                                DateTime eventDate = ScheduledEvent.GetEventDate(dtBaseDate.Value.AddDays(-1 * baseOffsetDays), scheduledEvent.DateOffset);
                                ProcessScheduledEvent existingPSE = ProcessScheduledEvents.Find(pse => pse.ScheduledEventId == scheduledEvent.ID);
								processScheduledEvents.Add(new ProcessScheduledEvent(scheduledEvent.ID, scheduledEvent.EventId, eventDate, ShouldBeMarkedExecuted(existingPSE, executedCalculationType, eventDate, cutoffDate)));

                            }
                        }
                        break;

                    default:
                        throw new Exception(string.Format("Tried to assign basic term '{0}' of type {1} to Custom Event '{2}'", term.Name, term.TermType.ToString(), eachEvent.Name));
                }
            }
            return processScheduledEvents;
        }
        private List<ProcessScheduledEvent> WorkflowRevertToDraftScheduledEvents(Event eachEvent, ScheduledEvent.ExecutedCalculationType executedCalculationType, DateTime cutoffDate)
        {
            List<ProcessScheduledEvent> scheduledEvents = new List<ProcessScheduledEvent>();
            DateTime renewalTermEffectiveDate = DateTime.MinValue;
            RenewalTerm renewalTerm = FindBasicTerm(TermType.Renewal) as RenewalTerm;
            if (renewalTerm != null)
                if (renewalTerm.EffectiveDate.HasValue)
                    renewalTermEffectiveDate = renewalTerm.EffectiveDate.Value;

            DateTime dtRevertEvent;
            //Currently, WorkflowRevertToDraft event forces State to be the 'IsBase' state.
            //TODO - Just added this logic to inhibit the creation of the RevertToBaseStateEvent if the current State is an Exit state.
            if (Workflow.GetRevertToBaseStateEventDate(renewalTermEffectiveDate, out dtRevertEvent))
                if (!State.IsExit ?? false)
                    foreach (ScheduledEvent scheduledEvent in Workflow.RevertEvent.ScheduledEvents)
                        scheduledEvents.Add(new ProcessScheduledEvent(scheduledEvent.ID, eachEvent.ID, dtRevertEvent, false));  

            return scheduledEvents;
        }
		public bool UpdateScheduledEvents(ScheduledEvent.ExecutedCalculationType executedCalculationType)
        {
            DateTime cutoffDate = DateTime.Today;
            if (executedCalculationType == ScheduledEvent.ExecutedCalculationType.UseGracePeriod)
            {
                ITATSystem system = ITATSystem.Get(this.SystemID);
                cutoffDate = cutoffDate.AddDays(-1 * system.RetroEventGracePeriodDays);
            }

            //Create a collection of all the Events from all of the event object sources 
            //within this ManagedItem.  From that collection, create a collection of objects
            //that store the newly calculated event dates for each of the ScheduledEvents.
            //Once the new collection is created, pass the information to the database in xml
            //form and update the ScheduledEvent table.  In that table, copy all of the
            //executed events for this ManagedItem to the ScheduledEventArchive table, delete
            //all of the events for this ManagedItem, and re-add only the non-executed events to the
            //ScheduledEvent table.

            List<ProcessScheduledEvent> procScheduledEvents = new List<ProcessScheduledEvent>();
            List<Event> tempEvents = new List<Event>(Events.Count);

            //Create a temporary collection of Events that contains all of the events from whatever sources there are.
            foreach (Business.Event eachEvent in Events)
                if (eachEvent.EventType != EventType.WorkflowRevertToDraft)
                    tempEvents.Add(eachEvent);
            if (WorkflowRevertEvent != null && (Workflow.UseFunction ?? false))
                tempEvents.Add(WorkflowRevertEvent);

            foreach (Business.Event eachEvent in tempEvents)
            {
                switch (eachEvent.EventType)
                {
                    case EventType.Custom:
                        procScheduledEvents.AddRange(CustomScheduledEvents(eachEvent, executedCalculationType, cutoffDate));
                        break;
                    case EventType.Renewal:
						procScheduledEvents.AddRange(RenewalScheduledEvents(eachEvent, executedCalculationType, cutoffDate));
                        break;
                    case EventType.WorkflowRevertToDraft:
						procScheduledEvents.AddRange(WorkflowRevertToDraftScheduledEvents(eachEvent, executedCalculationType, cutoffDate));
                        break;
                    case EventType.Workflow:
                    case EventType.RetroRevertToDraft:
                    default:
                        break;
                }
            }
            Data.ManagedItem.UpdateProcessScheduledEvents(ManagedItemID, ScheduledEvent.BuildSqlUdt(ManagedItemID, procScheduledEvents), true);
            return true;
        }
        public static ScheduledEvent FindEquivalent(List<ScheduledEvent> scheduledEvents, ScheduledEvent scheduledEvent)
        {
            if (scheduledEvents == null)
                return null;

            return scheduledEvents.Find(se => se.DateOffset == scheduledEvent.DateOffset);
        }
Beispiel #7
0
		public Event Copy(bool IsManagedItem)
		{
			Event newEvent = new Event(EventType, IsManagedItem);

			newEvent.IsRef = IsRef;
			newEvent.Name = Name;
			newEvent.Description = Description;
			newEvent.BaseDateTermID = BaseDateTermID;
			newEvent.OffsetTermID = OffsetTermID;
			newEvent.BaseDateTermPart = BaseDateTermPart;
			newEvent.OffsetDefaultValue = OffsetDefaultValue;

			newEvent.Messages.Clear();
			foreach (Message message in Messages)
			{
				newEvent.Messages.Add(message);
			}

			newEvent.ScheduledEvents.Clear();
			foreach (ScheduledEvent scheduledEvent in ScheduledEvents)
			{
				ScheduledEvent newScheduledEvent = new ScheduledEvent(scheduledEvent.DateOffset, newEvent.ID, IsManagedItem);
				newEvent.ScheduledEvents.Add(newScheduledEvent);
			}

			return newEvent;
		}
Beispiel #8
0
		public Event(XmlNode scheduledEventNode, bool IsManagedItem)
		{
			_isManagedItem = IsManagedItem;

			string idString = Utility.XMLHelper.GetAttributeString(scheduledEventNode, XMLNames._A_ID);
			if (string.IsNullOrEmpty(idString))
				_id = Guid.NewGuid();
			else
				_id = new Guid(idString);
			_isRef = Utility.XMLHelper.GetAttributeBool(scheduledEventNode, XMLNames._A_IsRef);
			_name = Utility.XMLHelper.GetAttributeString(scheduledEventNode, XMLNames._A_Name);
			_description = Utility.XMLHelper.GetAttributeString(scheduledEventNode, XMLNames._A_Description);
			_eventType = (EventType)Enum.Parse(typeof(EventType), Utility.XMLHelper.GetAttributeString(scheduledEventNode, XMLNames._A_EventType));
			_baseDateTermName = Utility.XMLHelper.GetAttributeString(scheduledEventNode, XMLNames._A_BaseDateTermName);
			_offsetTermName = Utility.XMLHelper.GetAttributeString(scheduledEventNode, XMLNames._A_OffsetTermName);

			_baseDateTermID = Term.CreateID(scheduledEventNode, XMLNames._A_BaseDateTermID);
			_baseDateTermPart = Utility.XMLHelper.GetAttributeString(scheduledEventNode, XMLNames._A_BaseDateTermPart);
			_offsetTermID = Term.CreateID(scheduledEventNode, XMLNames._A_OffsetTermID);

			_offsetDefaultValue = 0;
			string sOffsetDefaultValue = Utility.XMLHelper.GetAttributeString(scheduledEventNode, XMLNames._A_OffsetDefaultValue);
			if (!string.IsNullOrEmpty(sOffsetDefaultValue))
			{
				try { _offsetDefaultValue += int.Parse(sOffsetDefaultValue); }
				catch { }
			}

			XmlNodeList listScheduledEvents = scheduledEventNode.SelectNodes(Utility.XMLHelper.GetXPath(false, XMLNames._E_ScheduledEvents, XMLNames._E_ScheduledEvent));
			if (listScheduledEvents != null && listScheduledEvents.Count > 0)
			{
				_scheduledEvents = new List<ScheduledEvent>(listScheduledEvents.Count);
				foreach (XmlNode nodeScheduledEvent in listScheduledEvents)
				{
					ScheduledEvent scheduledEvent = new ScheduledEvent(nodeScheduledEvent, _id, IsManagedItem);
					_scheduledEvents.Add(scheduledEvent);
				}
			}
			else
			{
				_scheduledEvents = new List<ScheduledEvent>();
			}

			XmlNodeList listMessages = scheduledEventNode.SelectNodes(Utility.XMLHelper.GetXPath(false, XMLNames._E_Messages,XMLNames._E_Message));
			if (listMessages != null && listMessages.Count > 0)
			{
				_messages = new List<Message>(listMessages.Count);
				foreach (XmlNode nodeMessage in listMessages)
				{
					Message message = new Message(nodeMessage);
					_messages.Add(message);
				}
			}
			else
			{
				_messages = new List<Message>();
			}
		}