Ejemplo n.º 1
0
        /// <summary>
        /// Creates the block item.
        /// </summary>
        /// <param name="sample">The sample.</param>
        /// <param name="date">The date.</param>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        private static IDayTimeBlockAssignable CreateBlockItem(IDayTimeBlockAssignable sample, Date date, int index)
        {
            var item = sample.Clone() as IDayTimeBlockAssignable;

            item.UtcDate           = date;
            item.DayTimeBlockIndex = index;
            return(item);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Detects the block hit.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="sample">The sample.</param>
        /// <returns></returns>
        public List <IDayTimeBlockAssignable> DetectBlockHit(TimeRange range, IDayTimeBlockAssignable sample)
        {
            List <IDayTimeBlockAssignable> result = new List <IDayTimeBlockAssignable>();

            if (sample != null && range != null && range.From.HasValue && range.To.HasValue)
            {
                Date startDate     = new Date(range.From.Value);
                Date endDate       = new Date(range.To.Value);
                var  maxBlockIndex = dayMinutes / BlockMinutes;

                var startIndexOfDay = GetBlockIndexOfDay(range.From.Value);
                var endIndexOfDay   = GetBlockIndexOfDay(range.To.Value.AddMilliseconds(-1));

                if (startDate == endDate)
                {
                    for (var i = startIndexOfDay; i <= endIndexOfDay; i++)
                    {
                        result.Add(CreateBlockItem(sample, startDate, i));
                    }
                }
                else
                {
                    //Start day blocks
                    for (var i = startIndexOfDay; i <= maxBlockIndex; i++)
                    {
                        result.Add(CreateBlockItem(sample, startDate, i));
                    }

                    // Day block between start date and end date.
                    for (var i = 1; i < (endDate - startDate); i++)
                    {
                        var date = startDate + i;
                        for (var j = 1; j <= maxBlockIndex; j++)
                        {
                            result.Add(CreateBlockItem(sample, date, j));
                        }
                    }

                    //End day blocks
                    for (var i = 1; i <= endIndexOfDay; i++)
                    {
                        result.Add(CreateBlockItem(sample, endDate, i));
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the day time block indexes.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="timeRange">The time range.</param>
        /// <param name="sample">The sample.</param>
        /// <param name="size">The size.</param>
        /// <returns></returns>
        public static List <T> CreateDayTimeBlockIndexes <T>(this TimeRange timeRange, IDayTimeBlockAssignable sample, TimeBlockSize size)
            where T : class, IDayTimeBlockAssignable
        {
            var result = new List <T>();

            if (timeRange != null && size != null)
            {
                foreach (var one in size.DetectBlockHit(timeRange, sample))
                {
                    result.AddIfNotNull(one as T);
                }
            }

            return(result);
        }