Example #1
0
        public static bool EditEvent(string commandline, ref int index, ref NewUi.EventInfo info)
        {
            Debug.Assert(commandline != null, "Commandline was null in EditEvent function in Parser");
            string[] words = SplitWords(commandline);
            int j=0;
            bool found = false;
            if (Int32.TryParse(words[0], out index))
            {
                j = 1;
                for (int i = 1; i < words.Length; i = j)
                {
                    found = false;
                    if (dateKey.Contains(words[i].ToLower()) || days.Contains(words[i].ToLower()))
                    {
                        j = FoundDateKey(words, i, ref info.startDate, ref info.endDate);
                        found = INotEqualJ(i, j);
                    }
                    if (timeKey.Contains(words[i].ToLower()) && !found)
                    {
                        j = FoundTimeKey(words, i, ref info.startTime, ref info.endTime);
                        found = INotEqualJ(i, j);
                    }
                    if (otherKey.Contains(words[i].ToLower()) && !found)
                    {
                        j = FoundOtherKey(words, i, ref info.urgent, ref info.alarm, ref info.alarmTime, ref info.freeDay, ref info.startDate, ref info.endDate);
                        found = INotEqualJ(i, j);
                    }
                    else
                    {
                        if (char.IsDigit(words[i][0]))
                            if (IsTimeRelated(words, i))
                                j = FoundTimeKey(words, i, ref info.startTime, ref info.endTime);
                            else
                                j = j = FoundDateKey(words, i, ref info.startDate, ref info.endDate);
                    }

                    if (i == j)
                        if (info.eventName == null)
                            info.eventName = words[j++];
                        else info.eventName += ' ' + words[j++];
                }

                return true;
            }
            else return false;
        }
Example #2
0
        public static bool AddEvent(string commandline, ref NewUi.EventInfo info)
        {
            string[] words = SplitWords(commandline);
            int length = words.Length;
            int j = 0;
            bool found = false;
            for (int i = 0; i < length; i = j)
            {
                found = false;
                if (dateKey.Contains(words[i].ToLower()) || days.Contains(words[i].ToLower()))
                {
                    j = FoundDateKey(words, i, ref info.startDate, ref info.endDate);
                    found = INotEqualJ(i, j);
                }
                if (timeKey.Contains(words[i].ToLower()) && !found)
                {
                    j = FoundTimeKey(words, i, ref info.startTime, ref info.endTime);
                    found = INotEqualJ(i, j);
                }
                if (otherKey.Contains(words[i].ToLower()) && !found)
                {
                    j = FoundOtherKey(words, i, ref info.urgent, ref info.alarm, ref info.alarmTime, ref info.freeDay, ref info.startDate, ref info.endDate);
                    found = INotEqualJ(i, j);
                }
                else
                {
                    if (char.IsDigit(words[i][0]))
                        if (IsTimeRelated(words, i))
                            j = FoundTimeKey(words, i, ref info.startTime, ref info.endTime);
                        else
                            j = j = FoundDateKey(words, i, ref info.startDate, ref info.endDate);
                }

                if (i == j)
                    if (info.eventName == null)
                        info.eventName = words[j++];
                    else info.eventName += ' ' + words[j++];
            }

            if (ValidEventInfo(ref info))
                return true;
            else return false;
        }
Example #3
0
        private static bool ValidEventInfo(ref NewUi.EventInfo info)
        {
            bool isValid = true;
            if (info.startDate == empty || info.endDate.CompareTo(DateOnly(DateTime.Now)) >= 0)
            {
                if (string.IsNullOrWhiteSpace(info.eventName))
                    info.eventName = "<unknown>";
                if (info.startTime == empty)
                {
                    if (info.endTime != empty)
                        info.startTime = info.endTime;
                    else if (info.alarmTime != empty)
                        info.startTime = info.alarmTime;
                    else info.endTime = EndOfDay();
                }
                if (info.alarm && info.alarmTime == empty)
                    info.alarmTime = info.startTime;

                if (info.endTime == empty && info.startTime != empty)
                    info.endTime = info.startTime;
                if (info.endDate == empty)
                    info.startDate = info.endDate = DateOnly(DateTime.Now);
                else
                {
                    if (info.startDate == empty)
                        info.startDate = DateOnly(DateTime.Now);
                }
                if (info.alarm)
                {
                    info.alarmTime = info.alarmTime.AddDays(info.endDate.Day-1);
                    info.alarmTime = info.alarmTime.AddMonths(info.endDate.Month-1);
                    info.alarmTime = info.alarmTime.AddYears(info.endDate.Year-1);
                }
            }
            else isValid = false;
            if (info.endDate.CompareTo(info.startDate) < 0)
                isValid = false;
            if (info.endTime.CompareTo(info.startTime) < 0)
                isValid = false;
            return isValid;
        }