Esempio n. 1
0
        /// <summary>
        /// NOTE: fixes RRULE25
        /// </summary>
        /// <param name="TC"></param>
        protected void FillYearDays(TimeCalculation TC)
        {
            DateTime baseDate = new DateTime(TC.StartDate.Value.Year, 1, 1);

            foreach (int day in TC.YearDays)
            {
                DateTime currDate;
                if (day > 0)
                {
                    currDate = baseDate.AddDays(day - 1);
                }
                else if (day < 0)
                {
                    currDate = baseDate.AddYears(1).AddDays(day);
                }
                else
                {
                    throw new Exception("BYYEARDAY cannot contain 0");
                }

                TC.Month = currDate.Month;
                TC.Day   = currDate.Day;
                FillHours(TC);
            }
        }
Esempio n. 2
0
 protected void FillDays(TimeCalculation TC)
 {
     foreach (int day in TC.Days)
     {
         TC.Day = day;
         FillHours(TC);
     }
 }
Esempio n. 3
0
 protected void FillMonths(TimeCalculation TC)
 {
     foreach (int month in TC.Months)
     {
         TC.Month = month;
         FillDays(TC);
     }
 }
Esempio n. 4
0
 protected void FillMinutes(TimeCalculation TC)
 {
     foreach (int minute in TC.Minutes)
     {
         TC.Minute = minute;
         FillSeconds(TC);
     }
 }
Esempio n. 5
0
 protected void FillHours(TimeCalculation TC)
 {
     foreach (int hour in TC.Hours)
     {
         TC.Hour = hour;
         FillMinutes(TC);
     }
 }
Esempio n. 6
0
 protected void FillSeconds(TimeCalculation TC)
 {
     foreach (int second in TC.Seconds)
     {
         TC.Second = second;
         TC.Calculate();
     }
 }
Esempio n. 7
0
        public List <CPointInWay> GetPointsInWay(int idSource, int idTarget, DateTime flightTime)
        {
            //מציאת 2 קודקודי קצה של המסלול-מקור ויעד
            CPoint        s = pointService.GetPointById(idSource);
            CPoint        t = pointService.GetPointById(idTarget);
            List <CPoint> sourceAndTarget = new List <CPoint>()
            {
                s, t
            };
            List <Points> points = mapper.Map <List <Points> >(sourceAndTarget);

            vertexSource = new Vertex(points[0]); //יצירת צומת לקודקוד המקור
            vertexTarget = new Vertex(points[1]); //יצירת צומת לקודקוד היעד

            //שליחה לפונקצית האלגוריתם הראשי שמוצאת את הדרך הקצרה
            List <Vertex> pointsInWay = new List <Vertex>();

            pointsInWay = algoritmService.FindWay(vertexSource, vertexTarget, flightTime);

            //רשימה שבה יש את השמות של הנקודות המרכיבות את המסלול
            List <CPointInWay> lstPointsInWay = new List <CPointInWay>();

            //אם יש מספיק זמן ללכת את המסלול עד לזמן הטיסה
            if (pointsInWay.Count() > 0)
            {
                for (int i = 0; i < pointsInWay.Count() - 1; i++)
                {
                    int sId    = pointsInWay[i].GetIndex();
                    int tId    = pointsInWay[i + 1].GetIndex();
                    int length = edgeService.GetEdgeBySourceAndTarget(sId, tId).Weight;
                    if (i == 0)
                    {
                        lstPointsInWay.Add(new CPointInWay()
                        {
                            Name        = pointsInWay[0].GetName(),
                            Length      = 0,
                            WalkingTime = 0
                        });
                    }
                    TimeSpan time = TimeCalculation.CalculateTime(length);
                    lstPointsInWay.Add(new CPointInWay()
                    {
                        Name        = pointsInWay[i + 1].GetName(),
                        Length      = length,
                        WalkingTime = time.Hours * 3600 + time.Minutes * 60 + time.Seconds
                    });;
                }
            }
            //אחרת-התרעה למשתמש
            else
            {
                lstPointsInWay.Add(new CPointInWay()
                {
                    Name = "no time", Length = 0, WalkingTime = 0
                });
            }
            return(lstPointsInWay);
        }
Esempio n. 8
0
 protected void FillDays(TimeCalculation TC)
 {            
     foreach (int day in TC.Days)
     {
         TC.Day = day;
         FillHours(TC);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// NOTE: fixes RRULE26
        /// </summary>
        /// <param name="TC"></param>
        protected void FillByDay(TimeCalculation TC)
        {       
            // If BYMONTH is specified, offset each day into those months,
            // otherwise, use Jan. 1st as a reference date.
            // NOTE: fixes USHolidays.ics eval
            List<int> months = new List<int>();
            if (TC.Recur.ByMonth.Count == 0)
                months.Add(1);
            else months = TC.Months;

            foreach (int month in months)
            {
                DateTime baseDate = new DateTime(TC.StartDate.Value.Year, month, 1);
                foreach (DaySpecifier day in TC.ByDays)
                {
                    DateTime curr = baseDate;

                    int inc = (day.Num < 0) ? -1 : 1;
                    if (day.Num != int.MinValue &&
                        day.Num < 0)
                    {
                        // Start at end of year, or end of month if BYMONTH is specified
                        if (TC.Recur.ByMonth.Count == 0)
                            curr = curr.AddYears(1).AddDays(-1);
                        else curr = curr.AddMonths(1).AddDays(-1);
                    }

                    while (curr.DayOfWeek != day.DayOfWeek)
                        curr = curr.AddDays(inc);

                    if (day.Num != int.MinValue)
                    {
                        for (int i = 1; i < day.Num; i++)
                            curr = curr.AddDays(7 * inc);

                        TC.Month = curr.Month;
                        TC.Day = curr.Day;
                        FillHours(TC);
                    }
                    else
                    {
                        while (
                            (TC.Recur.Frequency == FrequencyType.Monthly &&
                            curr.Month == TC.StartDate.Value.Month) ||
                            (TC.Recur.Frequency == FrequencyType.Yearly &&
                            curr.Year == TC.StartDate.Value.Year))
                        {
                            TC.Month = curr.Month;
                            TC.Day = curr.Day;
                            FillHours(TC);
                            curr = curr.AddDays(7);
                        }
                    }
                }
            }
        }
Esempio n. 10
0
 protected void FillMonths(TimeCalculation TC)
 {
     foreach (int month in TC.Months)
     {
         TC.Month = month;
         FillDays(TC);
     }
 }
Esempio n. 11
0
 protected void FillSeconds(TimeCalculation TC)
 {
     foreach (int second in TC.Seconds)
     {
         TC.Second = second;
         TC.Calculate();
     }
 }
Esempio n. 12
0
        /// <summary>
        /// NOTE: fixes RRULE25
        /// </summary>
        /// <param name="TC"></param>
        protected void FillYearDays(TimeCalculation TC)
        {
            DateTime baseDate = new DateTime(TC.StartDate.Value.Year, 1, 1);
            foreach (int day in TC.YearDays)
            {
                DateTime currDate;
                if (day > 0)
                    currDate = baseDate.AddDays(day - 1);
                else if (day < 0)
                    currDate = baseDate.AddYears(1).AddDays(day);
                else throw new Exception("BYYEARDAY cannot contain 0");

                TC.Month = currDate.Month;
                TC.Day = currDate.Day;
                FillHours(TC);
            }
        }
Esempio n. 13
0
 protected void FillMinutes(TimeCalculation TC)
 {
     foreach (int minute in TC.Minutes)
     {
         TC.Minute = minute;
         FillSeconds(TC);
     }
 }
 public void Initialize()
 {
     _timeCalculation = new TimeCalculation();
 }
Esempio n. 15
0
 protected void FillSeconds(TimeCalculation TC)
 {
     if (TC.Seconds.Count > 0)
     {
         foreach (int second in TC.Seconds)
         {
             TC.Second = second;
             TC.Calculate();
         }
     }
     else
     {
         TC.Second = 0;
         TC.Calculate();
     }
 }
Esempio n. 16
0
 protected void FillHours(TimeCalculation TC)
 {
     if (TC.Hours.Count > 0)
     {
         foreach (int hour in TC.Hours)
         {
             TC.Hour = hour;
             FillMinutes(TC);
         }
     }
     else
     {
         TC.Hour = 0;
         FillMinutes(TC);
     }
 }
Esempio n. 17
0
        /// <summary>
        /// NOTE: fixes RRULE26
        /// </summary>
        /// <param name="TC"></param>
        protected void FillByDay(TimeCalculation TC)
        {
            // If BYMONTH is specified, offset each day into those months,
            // otherwise, use Jan. 1st as a reference date.
            // NOTE: fixes USHolidays.ics eval
            List <int> months = new List <int>();

            if (TC.Recur.ByMonth.Count == 0)
            {
                months.Add(1);
            }
            else
            {
                months = TC.Months;
            }

            foreach (int month in months)
            {
                DateTime baseDate = new DateTime(TC.StartDate.Value.Year, month, 1);
                foreach (DaySpecifier day in TC.ByDays)
                {
                    DateTime curr = baseDate;

                    int inc = (day.Num < 0) ? -1 : 1;
                    if (day.Num != int.MinValue &&
                        day.Num < 0)
                    {
                        // Start at end of year, or end of month if BYMONTH is specified
                        if (TC.Recur.ByMonth.Count == 0)
                        {
                            curr = curr.AddYears(1).AddDays(-1);
                        }
                        else
                        {
                            curr = curr.AddMonths(1).AddDays(-1);
                        }
                    }

                    while (curr.DayOfWeek != day.DayOfWeek)
                    {
                        curr = curr.AddDays(inc);
                    }

                    if (day.Num != int.MinValue)
                    {
                        for (int i = 1; i < day.Num; i++)
                        {
                            curr = curr.AddDays(7 * inc);
                        }

                        TC.Month = curr.Month;
                        TC.Day   = curr.Day;
                        FillHours(TC);
                    }
                    else
                    {
                        while (
                            (TC.Recur.Frequency == FrequencyType.MONTHLY &&
                             curr.Month == TC.StartDate.Value.Month) ||
                            (TC.Recur.Frequency == FrequencyType.YEARLY &&
                             curr.Year == TC.StartDate.Value.Year))
                        {
                            TC.Month = curr.Month;
                            TC.Day   = curr.Day;
                            FillHours(TC);
                            curr = curr.AddDays(7);
                        }
                    }
                }
            }
        }
Esempio n. 18
0
 protected void FillMinutes(TimeCalculation TC)
 {
     if (TC.Minutes.Count > 0)
     {
         foreach (int minute in TC.Minutes)
         {
             TC.Minute = minute;
             FillSeconds(TC);
         }
     }
     else
     {
         TC.Minute = 0;
         FillSeconds(TC);
     }
 }
Esempio n. 19
0
        protected List <Date_Time> CalculateChildOccurrences(Date_Time StartDate, Date_Time EndDate)
        {
            TimeCalculation TC = new TimeCalculation(StartDate, EndDate, this);

            switch (Frequency)
            {
            case FrequencyType.YEARLY:
                FillYearDays(TC);
                FillByDay(TC);
                FillMonths(TC);
                break;

            case FrequencyType.WEEKLY:     // Weeks can span across months, so we must fill months (Note: fixes RRULE10 eval)
                FillMonths(TC);
                break;

            case FrequencyType.MONTHLY:
                FillDays(TC);
                FillByDay(TC);
                break;

            case FrequencyType.DAILY:
                FillHours(TC);
                break;

            case FrequencyType.HOURLY:
                FillMinutes(TC);
                break;

            case FrequencyType.MINUTELY:
                FillSeconds(TC);
                break;

            default:
                throw new NotSupportedException("CalculateChildOccurrences() is not supported for a frequency of " + Frequency.ToString());
            }

            // Apply the BYSETPOS to the list of child occurrences
            // We do this before the dates are filtered by Start and End date
            // so that the BYSETPOS calculates correctly.
            // NOTE: fixes RRULE33 eval
            if (BySetPos.Count != 0)
            {
                List <Date_Time> newDateTimes = new List <Date_Time>();
                foreach (int pos in BySetPos)
                {
                    if (Math.Abs(pos) <= TC.DateTimes.Count)
                    {
                        if (pos > 0)
                        {
                            newDateTimes.Add(TC.DateTimes[pos - 1]);
                        }
                        else if (pos < 0)
                        {
                            newDateTimes.Add(TC.DateTimes[TC.DateTimes.Count + pos]);
                        }
                    }
                }

                TC.DateTimes = newDateTimes;
            }

            // Filter dates by Start and End date
            for (int i = TC.DateTimes.Count - 1; i >= 0; i--)
            {
                if ((Date_Time)TC.DateTimes[i] < StartDate ||
                    (Date_Time)TC.DateTimes[i] > EndDate)
                {
                    TC.DateTimes.RemoveAt(i);
                }
            }

            return(TC.DateTimes);
        }
Esempio n. 20
0
        protected List<iCalDateTime> CalculateChildOccurrences(iCalDateTime StartDate, iCalDateTime EndDate)
        {
            TimeCalculation TC = new TimeCalculation(StartDate, EndDate, this);                        
            switch (Frequency)
            {
                case FrequencyType.Yearly:
                    FillYearDays(TC);
                    FillByDay(TC);
                    FillMonths(TC);
                    break;
                case FrequencyType.Weekly: 
                    // Weeks can span across months, so we must
                    // fill months (Note: fixes RRULE10 eval)                    
                    FillMonths(TC);
                    break;
                case FrequencyType.Monthly:
                    FillDays(TC);
                    FillByDay(TC);
                    break;
                case FrequencyType.Daily:
                    FillHours(TC);
                    break;
                case FrequencyType.Hourly:
                    FillMinutes(TC);
                    break;
                case FrequencyType.Minutely:
                    FillSeconds(TC);
                    break;
                default:
                    throw new NotSupportedException("CalculateChildOccurrences() is not supported for a frequency of " + Frequency.ToString());                    
            }

            // Apply the BYSETPOS to the list of child occurrences
            // We do this before the dates are filtered by Start and End date
            // so that the BYSETPOS calculates correctly.
            // NOTE: fixes RRULE33 eval
            if (BySetPos.Count != 0)
            {
                List<iCalDateTime> newDateTimes = new List<iCalDateTime>();
                foreach (int pos in BySetPos)
                {
                    if (Math.Abs(pos) <= TC.DateTimes.Count)
                    {
                        if (pos > 0)
                            newDateTimes.Add(TC.DateTimes[pos - 1]);
                        else if (pos < 0)
                            newDateTimes.Add(TC.DateTimes[TC.DateTimes.Count + pos]);
                    }
                }

                TC.DateTimes = newDateTimes;
            }

            // Filter dates by Start and End date
            for (int i = TC.DateTimes.Count - 1; i >= 0; i--)
            {
                if ((iCalDateTime)TC.DateTimes[i] < StartDate ||
                    (iCalDateTime)TC.DateTimes[i] > EndDate)
                    TC.DateTimes.RemoveAt(i);
            }

            return TC.DateTimes;
        }
Esempio n. 21
0
 protected void FillHours(TimeCalculation TC)
 {
     foreach (int hour in TC.Hours)
     {
         TC.Hour = hour;
         FillMinutes(TC);
     }
 }