コード例 #1
0
        public static IEnumerable <ExigoService.Calendar> GetCalendars(GetCalendarsRequest request)
        {
            var context = Exigo.ODataCalendars();
            var query   = context.Calendars.AsQueryable();

            // Get a customer's calendars if applicable
            if (request.CustomerID != null)
            {
                query = query.Where(c => c.CustomerID == (int)request.CustomerID);

                // Include the customer's calendar subscriptions if applicable
                if (request.IncludeCalendarSubscriptions)
                {
                    var calendarSubscriptions    = GetCustomerCalendarSubscriptions((int)request.CustomerID);
                    var calendarSubscriptionsIDs = calendarSubscriptions.Select(c => c.CalendarID).ToList();

                    if (calendarSubscriptionsIDs.Count > 0)
                    {
                        query = query.Where(calendarSubscriptionsIDs.ToOrExpression <CalendarContext.Calendar, Guid>("CalendarID"));
                    }
                }
            }

            // Include any additional requested calendars
            if (request.CalendarIDs != null && request.CalendarIDs.Count() > 0)
            {
                query = query.Where(request.CalendarIDs.ToList().ToOrExpression <CalendarContext.Calendar, Guid>("CalendarID"));
            }


            // Get the calendars
            var calendars = query.ToList();


            // If we asked for a specific customer's calendars, and none of the calendars belong to that customer, create a default calendar and add it to the collection.
            if (request.CustomerID != null && calendars.Where(c => c.CustomerID == (int)request.CustomerID).Count() == 0)
            {
                yield return(CreateDefaultCalendar((int)request.CustomerID));
            }


            // Return the calendars
            foreach (var calendar in calendars)
            {
                yield return((ExigoService.Calendar)calendar);
            }
        }
コード例 #2
0
        public static IEnumerable<ExigoService.Calendar> GetCalendars(GetCalendarsRequest request)
        {
            var context = Exigo.ODataCalendars();
            var corporateCalendarContext = Exigo.OData();
            var calendars = new List<Calendar>();
            var cacheKey = "GetCalendars/{0}/{1}".FormatWith(request.CustomerID ?? 0, request.IncludeCalendarSubscriptions);
            var cache = (HttpContext.Current != null) ? HttpContext.Current.Cache : null;

            // Check the cache to see if we've already made this call recently
            if (cache == null || cache[cacheKey] == null)
            {
                GlobalUtilities.RunAsyncTasks(

                    // Add the customer's personal calendars
                    () =>
                    {
                        if (request.CustomerID != null)
                        {
                            var apiCalendars = context.Calendars
                                .Where(c => c.CustomerID == (int)request.CustomerID)
                                .ToList();
                            foreach (var apiCalendar in apiCalendars)
                            {
                                calendars.Add((ExigoService.Calendar)apiCalendar);
                            }
                        }
                    },

                    // Include the customer's calendar subscriptions if applicable
                    () =>
                    {
                        if (request.CustomerID != null && request.IncludeCalendarSubscriptions)
                        {
                            var calendarSubscriptions = GetCustomerCalendarSubscriptions((int)request.CustomerID);
                            var calendarSubscriptionsIDs = calendarSubscriptions.Select(c => c.CalendarID).ToList();

                            if (calendarSubscriptionsIDs.Count > 0)
                            {
                                var apiCalendars = context.Calendars
                                    .Where(calendarSubscriptionsIDs.ToOrExpression<CalendarContext.Calendar, Guid>("CalendarID"))
                                    .ToList();
                                foreach (var apiCalendar in apiCalendars)
                                {
                                    calendars.Add((ExigoService.Calendar)apiCalendar);
                                }
                            }
                        }
                    },

                    // Include any additional requested calendars
                    () =>
                    {
                        if (request.CalendarIDs != null && request.CalendarIDs.Count() > 0)
                        {
                            var apiCalendars = context.Calendars
                                .Where(request.CalendarIDs.ToList().ToOrExpression<CalendarContext.Calendar, Guid>("CalendarID"))
                                .ToList();
                            foreach (var apiCalendar in apiCalendars)
                            {
                                calendars.Add((ExigoService.Calendar)apiCalendar);
                            }
                        }
                    }
                );

                // If we asked for a specific customer's calendars, and none of the calendars belong to that customer, create a default calendar and add it to the collection.
                if (request.CustomerID != null && calendars.Where(c => c.CustomerID == (int)request.CustomerID).Count() == 0)
                {
                    var defaultCalendar = CreateDefaultCalendar((int)request.CustomerID);
                    calendars.Add(defaultCalendar);
                }

                if (cache != null)
                {
                    cache.Insert(cacheKey, calendars,
                        null,
                        DateTime.Now.AddMinutes(5),
                        Cache.NoSlidingExpiration,
                        CacheItemPriority.Normal,
                        null);
                }
            }
            else
            {
                calendars = (List<ExigoService.Calendar>)cache[cacheKey];
            }

            // Return the calendars
            foreach (var calendar in calendars)
            {
                yield return calendar;
            }
        }
コード例 #3
0
ファイル: Calendars.cs プロジェクト: Webalap/W-ALAP
        public static IEnumerable <ExigoService.Calendar> GetCalendars(GetCalendarsRequest request)
        {
            var context = Exigo.ODataCalendars();
            var corporateCalendarContext = Exigo.OData();
            var calendars = new List <Calendar>();
            var cacheKey  = "GetCalendars/{0}/{1}".FormatWith(request.CustomerID ?? 0, request.IncludeCalendarSubscriptions);
            var cache     = (HttpContext.Current != null) ? HttpContext.Current.Cache : null;

            // Check the cache to see if we've already made this call recently
            if (cache == null || cache[cacheKey] == null)
            {
                GlobalUtilities.RunAsyncTasks(

                    // Add the customer's personal calendars
                    () =>
                {
                    //if (request.CustomerID != null)
                    if (false)
                    {
                        var apiCalendars = context.Calendars
                                           .Where(c => c.CustomerID == (int)request.CustomerID)
                                           .ToList();
                        foreach (var apiCalendar in apiCalendars)
                        {
                            calendars.Add((ExigoService.Calendar)apiCalendar);
                        }
                    }
                },

                    // Include the customer's calendar subscriptions if applicable
                    () =>
                {
                    if (request.CustomerID != null && request.IncludeCalendarSubscriptions)
                    {
                        var calendarSubscriptions    = GetCustomerCalendarSubscriptions((int)request.CustomerID);
                        var calendarSubscriptionsIDs = calendarSubscriptions.Select(c => c.CalendarID).ToList();

                        if (calendarSubscriptionsIDs.Count > 0)
                        {
                            var apiCalendars = context.Calendars
                                               .Where(calendarSubscriptionsIDs.ToOrExpression <CalendarContext.Calendar, Guid>("CalendarID"))
                                               .ToList();
                            foreach (var apiCalendar in apiCalendars)
                            {
                                calendars.Add((ExigoService.Calendar)apiCalendar);
                            }
                        }
                    }
                },

                    // Include any additional requested calendars
                    () =>
                {
                    if (request.CalendarIDs != null && request.CalendarIDs.Count() > 0)
                    {
                        var apiCalendars = context.Calendars
                                           .Where(request.CalendarIDs.ToList().ToOrExpression <CalendarContext.Calendar, Guid>("CalendarID"))
                                           .ToList();
                        foreach (var apiCalendar in apiCalendars)
                        {
                            calendars.Add((ExigoService.Calendar)apiCalendar);
                        }
                    }
                }
                    );


                // If we asked for a specific customer's calendars, and none of the calendars belong to that customer, create a default calendar and add it to the collection.
                if (request.CustomerID != null && calendars.Where(c => c.CustomerID == (int)request.CustomerID).Count() == 0)
                {
                    var defaultCalendar = CreateDefaultCalendar((int)request.CustomerID);
                    calendars.Add(defaultCalendar);
                }

                if (cache != null)
                {
                    cache.Insert(cacheKey, calendars,
                                 null,
                                 DateTime.Now.AddMinutes(5),
                                 Cache.NoSlidingExpiration,
                                 CacheItemPriority.Normal,
                                 null);
                }
            }
            else
            {
                calendars = (List <ExigoService.Calendar>)cache[cacheKey];
            }


            // Return the calendars
            foreach (var calendar in calendars)
            {
                yield return(calendar);
            }
        }
コード例 #4
0
        public static IEnumerable <Calendar> GetCalendars(GetCalendarsRequest request)
        {
            var calendars = new List <Calendar>();
            var cacheKey  = "GetCalendars_{0}_{1}".FormatWith(request.CustomerID ?? 0,
                                                              request.IncludeCalendarSubscriptions);
            var cache = (HttpContext.Current != null) ? HttpContext.Current.Cache : null;

            // Check the cache to see if we've already made this call recently
            if (cache == null || cache[cacheKey] == null)
            {
                GlobalUtilities.RunAsyncTasks(

                    // Add the customer's personal calendars
                    () =>
                {
                    if (request.CustomerID != null)
                    {
                        var apiCalendars = new List <Calendar>();
                        using (var ctx = ExigoDAL.Sql())
                        {
                            apiCalendars = ctx.Query <Calendar>(@"
                                                select
                                                    CalendarID = c.CalendarID,
                                                    CustomerID = c.CustomerID,
                                                    Description = c.Description,
                                                    CalendarTypeID = c.CalendarTypeID,
                                                    CreatedDate = c.CreatedDate
                                                from ExigoWebContext.Calendars c
                                                where c.CustomerID = @customerID
                                                ", new { customerID = request.CustomerID }).ToList();
                        }

                        foreach (var apiCalendar in apiCalendars)
                        {
                            calendars.Add(apiCalendar);
                        }
                    }
                },

                    // Include the customer's calendar subscriptions if applicable
                    () =>
                {
                    if (request.CustomerID != null && request.IncludeCalendarSubscriptions)
                    {
                        var calendarSubscriptions    = GetCustomerCalendarSubscriptions((int)request.CustomerID);
                        var calendarSubscriptionsIDs = calendarSubscriptions.Select(c => c.CalendarID).ToList();

                        if (calendarSubscriptionsIDs.Count > 0)
                        {
                            var apiCalendars = new List <Calendar>();
                            using (var ctx = ExigoDAL.Sql())
                            {
                                apiCalendars = ctx.Query <Calendar>(@"
                                                select
                                                    CalendarID = c.CalendarID,
                                                    CustomerID = c.CustomerID,
                                                    Description = c.Description,
                                                    CalendarTypeID = c.CalendarTypeID,
                                                    CreatedDate = c.CreatedDate
                                                from ExigoWebContext.Calendars c
                                                where c.CalendarID in @calendarSubscriptionsIDs
                                                ", new { calendarSubscriptionsIDs }).ToList();
                            }


                            foreach (var apiCalendar in apiCalendars)
                            {
                                calendars.Add(apiCalendar);
                            }
                        }
                    }
                },

                    // Include any additional requested calendars
                    () =>
                {
                    if (request.CalendarIDs != null && request.CalendarIDs.Any())
                    {
                        var apiCalendars = new List <Calendar>();
                        using (var ctx = ExigoDAL.Sql())
                        {
                            apiCalendars = ctx.Query <Calendar>(@"
                                                select
                                                    CalendarID = c.CalendarID,
                                                    CustomerID = c.CustomerID,
                                                    Description = c.Description,
                                                    CalendarTypeID = c.CalendarTypeID,
                                                    CreatedDate = c.CreatedDate
                                                from ExigoWebContext.Calendars c
                                                where c.CalendarID in @calendarIDs
                                                ", new { calendarIDs = request.CalendarIDs.ToList() }).ToList();
                        }

                        foreach (var apiCalendar in apiCalendars)
                        {
                            calendars.Add(apiCalendar);
                        }
                    }
                }
                    );


                // If we asked for a specific customer's calendars, and none of the calendars belong to that customer, create a default calendar and add it to the collection.
                if (request.CustomerID != null && calendars.Any(c => c.CustomerID == (int)request.CustomerID) == false)
                {
                    var defaultCalendar = CreateDefaultCalendar((int)request.CustomerID);
                    calendars.Add(defaultCalendar);
                }

                if (cache != null)
                {
                    cache.Insert(cacheKey, calendars,
                                 null,
                                 DateTime.Now.AddMinutes(5),
                                 Cache.NoSlidingExpiration,
                                 CacheItemPriority.Normal,
                                 null);
                }
            }
            else
            {
                calendars = (List <Calendar>)cache[cacheKey];
            }


            // Return the calendars
            foreach (var calendar in calendars)
            {
                yield return(calendar);
            }
        }