Ejemplo n.º 1
0
        } // makeBatchOp()

        /// <summary>
        /// Create a new batch operation to handle future node generation
        /// </summary>
        /// <param name="GenNode">Generator Node</param>
        /// <param name="FinalDate"></param>
        public CswNbtObjClassBatchOp makeBatchOp(CswNbtNode GenNode, DateTime FinalDate)
        {
            CswNbtObjClassBatchOp BatchNode = null;

            if (null != GenNode)
            {
                CswNbtObjClassGenerator GeneratorNode = (CswNbtObjClassGenerator)GenNode;


                // BZ 6752 - The first future node is the first node generated
                // after today + warning days, according to the time interval
                // But it has to include initial due date, no matter what the time interval.

                CswNbtNodePropTimeInterval NextDueDateTimeInterval = GeneratorNode.DueDateInterval;
                Double WarningDays = 0;
                if (GeneratorNode.WarningDays.Value > 0)
                {
                    WarningDays = GeneratorNode.WarningDays.Value;
                }
                DateTime StartDate = DateTime.Now.AddDays(WarningDays).Date;   //bz# 6937 (capture date only, not time)

                DateTime DateOfNextOccurance = DateTime.MinValue;
                if (GeneratorNode.DueDateInterval.getStartDate().Date >= StartDate)  //bz # 6937 (change gt to gteq)
                {
                    DateOfNextOccurance = GeneratorNode.DueDateInterval.getStartDate().Date;
                }
                else
                {
                    DateOfNextOccurance = NextDueDateTimeInterval.getNextOccuranceAfter(StartDate);
                }

                // Determine number of iterations
                Int32    StartingCount = 0;
                DateTime ThisDate      = DateOfNextOccurance;

                while (ThisDate != DateTime.MinValue &&
                       ThisDate.Date <= FinalDate &&
                       (GeneratorNode.FinalDueDate.Empty || ThisDate.Date <= GeneratorNode.FinalDueDate.DateTimeValue.Date))
                {
                    StartingCount++;
                    ThisDate = GeneratorNode.DueDateInterval.getNextOccuranceAfter(ThisDate);
                }

                FutureNodesBatchData BatchData = new FutureNodesBatchData(string.Empty);
                BatchData.GeneratorNodeId = GenNode.NodeId;
                BatchData.NextStartDate   = DateOfNextOccurance;
                BatchData.FinalDate       = FinalDate;
                BatchData.StartingCount   = StartingCount;
                BatchData.IterationCount  = 0;

                BatchNode = CswNbtBatchManager.makeNew(_CswNbtResources, _BatchOpName, BatchData.ToString());
            } // if(null != GeneratorNode)
            return(BatchNode);
        }     // makeBatchOp()
        public static DateTime getNextDueDate(CswNbtNode Node, CswNbtNodePropDateTime NodePropNextDueDate, CswNbtNodePropTimeInterval NodePropInterval, Int32 WarningDays = 0, bool ForceUpdate = false, bool DeleteFuture = false)
        {
            DateTime Ret = NodePropNextDueDate.DateTimeValue;

            if (NodePropInterval.wasAnySubFieldModified() ||
                Node.New ||
                ForceUpdate ||
                DeleteFuture)
            {
                if (NodePropInterval.RateInterval.RateType != CswResources.UnknownEnum)
                {
                    //If the first interval (minus warning days) is in the future, that's our first duedate
                    //else, we take the greater of the current next duedate and today and get the next occurance after that
                    Ret = NodePropInterval.RateInterval.getFirst();
                    if (Ret == DateTime.MinValue || Ret.AddDays(WarningDays * -1) <= DateTime.Now)
                    {
                        DateTime NextDueDate = NodePropNextDueDate.DateTimeValue;

                        if (NodePropInterval.wasAnySubFieldModified() ||
                            Node.New ||
                            DeleteFuture)
                        {
                            // Next Due Date might be invalid if the interval was altered
                            // This guarantees that we get the next due date after Today
                            // This is necessary to accommodate Warning Days when creating Tasks
                            NextDueDate = DateTime.Now;
                        }

                        Ret = NodePropInterval.getNextOccuranceAfter(NextDueDate);
                    }
                } // if( _Scheduler.DueDateInterval.RateInterval.RateType != CswEnumRateIntervalType.Unknown )
            }
            return(Ret);
        } // updateNextDueDate()