Пример #1
0
        public async Task SaveCalendar(CalendarBase calendar)
        {
            var entity = ICalendarToEntity(calendar);

            using (var context = new CalendarCacheContext())
            {
                await context.CalendarCache.AddAsync(entity);

                await context.SaveChangesAsync();
            }
        }
Пример #2
0
        private CalendarCacheEntity ICalendarToEntity(CalendarBase calendar)
        {
            var entity = new CalendarCacheEntity();

            entity.CalendarId    = calendar.Id;
            entity.CalendarName  = calendar.Name;
            entity.IsEnabled     = calendar.IsEnabled;
            entity.AccountType   = calendar.AccountType;
            entity.UserId        = calendar.UserId;
            entity.OverrideColor = calendar.OverrideColor;

            return(entity);
        }
Пример #3
0
        public override int GetHashCode()
        {
            int baseHash = 0;

            if (CalendarBase != null)
            {
                baseHash = CalendarBase.GetHashCode();
            }

            return(rangeStartingHourOfDay.GetHashCode() + rangeEndingHourOfDay.GetHashCode() +
                   2 * (rangeStartingMinute.GetHashCode() + rangeEndingMinute.GetHashCode()) +
                   3 * (rangeStartingSecond.GetHashCode() + rangeEndingSecond.GetHashCode()) +
                   4 * (rangeStartingMillis.GetHashCode() + rangeEndingMillis.GetHashCode())
                   + 5 * baseHash);
        }
Пример #4
0
        public async Task <Models.Microsoft.EventList> GetEventList(CalendarBase calendar, DateTime month)
        {
            var start     = new DateTime(month.Year, month.Month, 1).ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ss");
            var nextMonth = month.AddMonths(1);
            var end       = new DateTime(nextMonth.Year, nextMonth.Month, 1).ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ss");
            var url       = "https://graph.microsoft.com/v1.0/me/calendars/" + calendar.Id + "/events?$filter=start/dateTime ge \'" + start + "\' and start/dateTime lt \'" + end + "\'";

            var events = await GetAsyncWithType <Models.Microsoft.EventList>(url);

            foreach (var obj in events.value)
            {
                obj.OverrideColor = calendar.Color;
            }
            return(events);
        }
Пример #5
0
 /// <summary>
 /// This method checks if the calendar item is enabled for display.
 /// Add calendar entity to DB if the item doesn't exist.
 /// </summary>
 /// <param name="calendar">the calendar item to check</param>
 /// <returns>True if it doens't exist on cache or exists and enabled. False if disabled.</returns>
 public bool CheckIfEnabled(CalendarBase calendar)
 {
     using (var context = new CalendarCacheContext())
     {
         var match = from item in context.CalendarCache
                     where item.CalendarId == calendar.Id && item.UserId == calendar.UserId
                     select item;
         if (match.Any())
         {
             calendar.IsEnabled     = match.First().IsEnabled;
             calendar.OverrideColor = match.First().OverrideColor;
             return(match.First().IsEnabled);
         }
     }
     calendar.IsEnabled = true;
     return(true);
 }
Пример #6
0
        public bool Equals(DailyCalendar obj)
        {
            if (obj == null)
            {
                return(false);
            }
            bool baseEqual = CalendarBase == null || CalendarBase.Equals(obj.CalendarBase);

            return(baseEqual && InvertTimeRange == obj.InvertTimeRange &&
                   rangeStartingHourOfDay == obj.rangeStartingHourOfDay &&
                   rangeStartingMinute == obj.rangeStartingMinute &&
                   rangeStartingSecond == obj.rangeStartingSecond &&
                   rangeStartingMillis == obj.rangeStartingMillis &&
                   rangeEndingHourOfDay == obj.rangeEndingHourOfDay &&
                   rangeEndingMinute == obj.rangeEndingMinute &&
                   rangeEndingSecond == obj.rangeEndingSecond &&
                   rangeEndingMillis == obj.rangeEndingMillis);
        }
        public async Task <EventList> GetEventList(CalendarBase calendar, DateTime month)
        {
            var url        = calendarEndpoint + "/calendars/" + calendar.Id + "/events?timeMin=" + new DateTime(month.Year, month.Month, 1).ToString("yyyy-MM-ddThh:mm:ssZ") + "&timeMax=" + new DateTime(month.Year, month.Month, DateTime.DaysInMonth(month.Year, month.Month)).ToString("yyyy-MM-ddThh:mm:ssZ");
            var jsonString = await GetAsync(url);

            if (string.IsNullOrEmpty(jsonString))
            {
                return(null);
            }
            else
            {
                var events = JsonSerializer.Deserialize <EventList>(jsonString);
                foreach (var obj in events.items)
                {
                    obj.OverrideColor = calendar.OverrideColor;
                }
                return(events);
            }
        }
Пример #8
0
        /// <summary>
        /// Add or Update calendar.
        /// </summary>
        /// <param name="calendar">The calaendar item to Add or Update</param>
        /// <returns></returns>
        public async Task AddUpdateCalendarCache(CalendarBase calendar)
        {
            using (var context = new CalendarCacheContext())
            {
                var match = from item in context.CalendarCache
                            where item.CalendarId == calendar.Id && item.UserId == calendar.UserId
                            select item;

                if (match.Any())
                {
                    var entity = match.First();
                    entity.IsEnabled     = calendar.IsEnabled;
                    entity.OverrideColor = calendar.OverrideColor;
                    context.Update(entity);

                    await context.SaveChangesAsync();

                    return;
                }
            }

            await SaveCalendar(calendar);
        }
Пример #9
0
        /// <summary>
        /// Determine whether the given time  is 'included' by the
        /// Calendar.
        /// </summary>
        /// <param name="timeUtc"></param>
        /// <returns></returns>
        public override bool IsTimeIncluded(DateTimeOffset timeUtc)
        {
            if (CalendarBase != null &&
                CalendarBase.IsTimeIncluded(timeUtc) == false)
            {
                return(false);
            }

            //Before we start, apply the correct timezone offsets.
            timeUtc = TimeZoneUtil.ConvertTime(timeUtc, TimeZone);

            DateTimeOffset startOfDayInMillis            = GetStartOfDay(timeUtc);
            DateTimeOffset endOfDayInMillis              = GetEndOfDay(timeUtc);
            DateTimeOffset timeRangeStartingTimeInMillis =
                GetTimeRangeStartingTimeUtc(timeUtc);
            DateTimeOffset timeRangeEndingTimeInMillis =
                GetTimeRangeEndingTimeUtc(timeUtc);

            if (!InvertTimeRange)
            {
                if (timeUtc > startOfDayInMillis &&
                    timeUtc < timeRangeStartingTimeInMillis ||
                    timeUtc > timeRangeEndingTimeInMillis &&
                    timeUtc < endOfDayInMillis)
                {
                    return(true);
                }
                return(false);
            }
            if (timeUtc >= timeRangeStartingTimeInMillis &&
                timeUtc <= timeRangeEndingTimeInMillis)
            {
                return(true);
            }
            return(false);
        }
Пример #10
0
        /// <summary>
        /// Determine the next time (in milliseconds) that is 'included' by the
        /// Calendar after the given time. Return the original value if timeStamp is
        /// included. Return 0 if all days are excluded.
        /// </summary>
        /// <param name="timeUtc"></param>
        /// <returns></returns>
        /// <seealso cref="ICalendar.GetNextIncludedTimeUtc"/>
        public override DateTimeOffset GetNextIncludedTimeUtc(DateTimeOffset timeUtc)
        {
            DateTimeOffset nextIncludedTime = timeUtc.AddMilliseconds(OneMillis);

            while (!IsTimeIncluded(nextIncludedTime))
            {
                if (!InvertTimeRange)
                {
                    //If the time is in a range excluded by this calendar, we can
                    // move to the end of the excluded time range and continue
                    // testing from there. Otherwise, if nextIncludedTime is
                    // excluded by the baseCalendar, ask it the next time it
                    // includes and begin testing from there. Failing this, add one
                    // millisecond and continue testing.
                    if (nextIncludedTime >=
                        GetTimeRangeStartingTimeUtc(nextIncludedTime) &&
                        nextIncludedTime <=
                        GetTimeRangeEndingTimeUtc(nextIncludedTime))
                    {
                        nextIncludedTime =
                            GetTimeRangeEndingTimeUtc(nextIncludedTime).AddMilliseconds(OneMillis);
                    }
                    else if (CalendarBase != null &&
                             !CalendarBase.IsTimeIncluded(nextIncludedTime))
                    {
                        nextIncludedTime =
                            CalendarBase.GetNextIncludedTimeUtc(nextIncludedTime);
                    }
                    else
                    {
                        nextIncludedTime = nextIncludedTime.AddMilliseconds(1);
                    }
                }
                else
                {
                    //If the time is in a range excluded by this calendar, we can
                    // move to the end of the excluded time range and continue
                    // testing from there. Otherwise, if nextIncludedTime is
                    // excluded by the baseCalendar, ask it the next time it
                    // includes and begin testing from there. Failing this, add one
                    // millisecond and continue testing.
                    if (nextIncludedTime <
                        GetTimeRangeStartingTimeUtc(nextIncludedTime))
                    {
                        nextIncludedTime =
                            GetTimeRangeStartingTimeUtc(nextIncludedTime);
                    }
                    else if (nextIncludedTime >
                             GetTimeRangeEndingTimeUtc(nextIncludedTime))
                    {
                        //(move to start of next day)
                        nextIncludedTime = GetEndOfDay(nextIncludedTime);
                        nextIncludedTime = nextIncludedTime.AddMilliseconds(1);
                    }
                    else if (CalendarBase != null &&
                             !CalendarBase.IsTimeIncluded(nextIncludedTime))
                    {
                        nextIncludedTime =
                            CalendarBase.GetNextIncludedTimeUtc(nextIncludedTime);
                    }
                    else
                    {
                        nextIncludedTime = nextIncludedTime.AddMilliseconds(1);
                    }
                }
            }

            return(nextIncludedTime);
        }
 public override void BuildCalendar(CalendarBase calendars)
 {
     Calendar = calendars;
     CreateCalendar3Month();
 }
Пример #12
0
 public abstract void BuildCalendar(CalendarBase calendars);