Ejemplo n.º 1
0
        public static DateTime getNextRunningTime(ScheduleTime st, DateTime currentTime)
        {
            DateTime nextTimes = currentTime;

            if (st.monthOfYear > 0)
            {
                // Get next Time for Yearly task
                nextTimes = currentTime.Date.AddDays(-currentTime.Day + 1);
                nextTimes = nextTimes.Date.AddMonths(-currentTime.Month + 1);
                nextTimes = nextTimes.Date.AddMonths(st.monthOfYear - 1);
                nextTimes = nextTimes.AddDays(Convert.ToDouble(st.dayOfMonth) - 1);
                nextTimes = nextTimes.AddHours(Convert.ToDouble(st.hour));
                nextTimes = nextTimes.AddMinutes(Convert.ToDouble(st.minute));
                if (nextTimes < currentTime)
                {
                    nextTimes = nextTimes.AddYears(1);
                }
            }
            else if (st.dayOfMonth > 0)
            {
                // Get next Time for Monthly task
                nextTimes = currentTime.Date.AddDays(-currentTime.Day);
                nextTimes = nextTimes.AddDays(Convert.ToDouble(st.dayOfMonth));
                nextTimes = nextTimes.AddHours(Convert.ToDouble(st.hour));
                nextTimes = nextTimes.AddMinutes(Convert.ToDouble(st.minute));
                if (nextTimes < currentTime)
                {
                    nextTimes = nextTimes.AddMonths(1);
                }
            }
            else if (st.dayOfWeek > 0)
            {
                // Get next Time for Weekly task
                nextTimes = currentTime.Date;
                while (nextTimes.Date.DayOfWeek != DayOfWeek.Monday)
                {
                    nextTimes = nextTimes.AddDays(-1);
                }
                nextTimes = nextTimes.AddDays(Convert.ToDouble(st.dayOfWeek - 1));
                nextTimes = nextTimes.AddHours(Convert.ToDouble(st.hour));
                nextTimes = nextTimes.AddMinutes(Convert.ToDouble(st.minute));
                if (nextTimes < currentTime)
                {
                    nextTimes = nextTimes.AddDays(7);
                }
            }
            else if (st.dayOfWeek == 0 &&
                     st.dayOfMonth == 0)
            {
                // Get next Time for Daily task
                nextTimes = currentTime.Date;
                nextTimes = nextTimes.AddHours(Convert.ToDouble(st.hour));
                nextTimes = nextTimes.AddMinutes(Convert.ToDouble(st.minute));
                if (nextTimes < currentTime)
                {
                    nextTimes = nextTimes.AddDays(1);
                }
            }
            return(nextTimes);
        }
Ejemplo n.º 2
0
        //public static int FindKeyByValue(IDictionary<int, int> dictionary, int value)
        //{
        //    if (dictionary != null)
        //    {
        //        foreach (KeyValuePair<int, int> pair in dictionary)
        //            if (value.Equals(pair.Value)) return pair.Key;
        //    }
        //    return 0;
        //}

        public static ScheduleTime convertTimer(string U_Timer)
        {
            ScheduleTime st = new ScheduleTime();

            string[] timer = U_Timer.Split(ConstantValues.DELIMITER);

            if (timer.Length > 1)
            {
                string t = timer[0];
                if (t.Equals(ConstantValues.TIMER_DAILY))
                {
                    try
                    {
                        st.hour   = Convert.ToInt32(timer[1]);
                        st.minute = Convert.ToInt32(timer[2]);
                    }
                    catch (Exception) { }
                }
                else if (t.Equals(ConstantValues.TIMER_WEEKLY))
                {
                    st.dayOfWeek = 1;
                    try
                    {
                        string dayOfWeek = timer[1];
                        if (dayOfWeek.Equals(ConstantValues.TIMER_WEEK_MONDAY))
                        {
                            st.dayOfWeek = 1;
                        }
                        else if (dayOfWeek.Equals(ConstantValues.TIMER_WEEK_TUESDAY))
                        {
                            st.dayOfWeek = 2;
                        }
                        else if (dayOfWeek.Equals(ConstantValues.TIMER_WEEK_WEDNESDAY))
                        {
                            st.dayOfWeek = 3;
                        }
                        else if (dayOfWeek.Equals(ConstantValues.TIMER_WEEK_THUSDAY))
                        {
                            st.dayOfWeek = 4;
                        }
                        else if (dayOfWeek.Equals(ConstantValues.TIMER_WEEK_FRIDAY))
                        {
                            st.dayOfWeek = 5;
                        }
                        else if (dayOfWeek.Equals(ConstantValues.TIMER_WEEK_SATURDAY))
                        {
                            st.dayOfWeek = 6;
                        }
                        else if (dayOfWeek.Equals(ConstantValues.TIMER_WEEK_SUNDAY))
                        {
                            st.dayOfWeek = 7;
                        }

                        st.hour   = Convert.ToInt32(timer[2]);
                        st.minute = Convert.ToInt32(timer[3]);
                    }
                    catch (Exception) { }
                }
                else if (t.Equals(ConstantValues.TIMER_MONTHLY))
                {
                    st.dayOfMonth = 1;
                    try
                    {
                        st.dayOfMonth = Convert.ToInt32(timer[1]);
                        st.hour       = Convert.ToInt32(timer[2]);
                        st.minute     = Convert.ToInt32(timer[3]);
                    }
                    catch (Exception) { }
                }
                else if (t.Equals(ConstantValues.TIMER_YEARLY))
                {
                    st.monthOfYear = 1;
                    st.dayOfMonth  = 1;
                    try
                    {
                        st.monthOfYear = Convert.ToInt32(timer[1]);
                        st.dayOfMonth  = Convert.ToInt32(timer[2]);
                        st.hour        = Convert.ToInt32(timer[3]);
                        st.minute      = Convert.ToInt32(timer[4]);
                    }
                    catch (Exception) { }
                }
            }
            return(st);
        }