Пример #1
0
        public ActionResult GetEvents()
        {
            MeetupEventsModel model = new MeetupEventsModel {
                Items = new MeetupItem[0]
            };

            try {
                string configPath = Server.MapPath("~/config/MeetupUmbracoGroups.txt");
                if (!System.IO.File.Exists(configPath))
                {
                    LogHelper.Debug <MeetupsController>("Config file was not found: " + configPath);
                    return(PartialView("~/Views/Partials/Home/Meetups.cshtml", model));
                }

                // Get the alias (urlname) of each group from the config file
                string[] aliases = System.IO.File.ReadAllLines(configPath).Where(x => x.Trim() != "").Distinct().ToArray();

                model.Items =
                    ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem <MeetupItem[]>("UmbracoSearchedMeetups",
                                                                                                 () => {
                    // Initialize a new service instance (we don't specify an API key since we're accessing public data)
                    MeetupService service = new MeetupService();

                    List <MeetupItem> items = new List <MeetupItem>();

                    foreach (string alias in aliases)
                    {
                        try {
                            // Get information about the group
                            MeetupGroup group = service.Groups.GetGroup(alias).Body;

                            if (group.JObject.HasValue("next_event"))
                            {
                                string nextEventId = group.JObject.GetString("next_event.id");

                                // Make the call to the Meetup.com API to get upcoming events
                                MeetupGetEventsResponse res = service.Events.GetEvents(alias);

                                // Get the next event(s)
                                MeetupEvent nextEvent = res.Body.FirstOrDefault(x => x.Id == nextEventId);

                                // Append the first event of the group
                                if (nextEvent != null)
                                {
                                    items.Add(new MeetupItem(group, nextEvent));
                                }
                            }
                        } catch (Exception ex) {
                            LogHelper.Error <MeetupsController>("Could not get events from meetup.com for group with alias: " + alias, ex);
                        }
                    }

                    return(items.OrderBy(x => x.Event.Time).ToArray());
                }, TimeSpan.FromMinutes(30));
            } catch (Exception ex) {
                LogHelper.Error <MeetupsController>("Could not get events from meetup.com", ex);
            }

            return(PartialView("~/Views/Partials/Home/Meetups.cshtml", model));
        }
Пример #2
0
        public MeetupEventsModel GetUpcomingMeetups()
        {
            var meetups = new MeetupEventsModel
            {
                Items = new MeetupItem[0]
            };

            try
            {
                var configPath = HostingEnvironment.MapPath("~/config/MeetupUmbracoGroups.txt");
                if (File.Exists(configPath) == false)
                {
                    LogHelper.Debug <MeetupsController>("Config file was not found: " + configPath);
                    return(meetups);
                }

                // Get the alias (urlname) of each group from the config file
                var aliases = File.ReadAllLines(configPath).Where(x => x.Trim() != "").Distinct().ToArray();

                meetups.Items = UmbracoContext.Current.Application.ApplicationCache.RuntimeCache.GetCacheItem <MeetupItem[]>("UmbracoSearchedMeetups",
                                                                                                                             () =>
                {
                    // Initialize a new service instance (we don't specify an API key since we're accessing public data)
                    var service = new Skybrud.Social.Meetup.MeetupService();

                    var items = new List <MeetupItem>();

                    foreach (var alias in aliases)
                    {
                        try
                        {
                            // Get information about the group
                            var meetupGroup = service.Groups.GetGroup(alias).Body;

                            if (meetupGroup.JObject.HasValue("next_event") == false)
                            {
                                continue;
                            }

                            var nextEventId = meetupGroup.JObject.GetString("next_event.id");

                            // Make the call to the Meetup.com API to get upcoming events
                            var events = service.Events.GetEvents(alias);

                            // Get the next event(s)
                            var nextEvent = events.Body.FirstOrDefault(x => x.Id == nextEventId);

                            // Append the first event of the group
                            if (nextEvent != null)
                            {
                                items.Add(new MeetupItem(meetupGroup, nextEvent));
                            }
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Error <MeetupsController>("Could not get events from meetup.com for group with alias: " + alias, ex);
                        }
                    }

                    return(items.OrderBy(x => x.Event.Time).ToArray());
                }, TimeSpan.FromMinutes(30));
            }
            catch (Exception ex)
            {
                LogHelper.Error <MeetupsController>("Could not get events from meetup.com", ex);
            }

            return(meetups);
        }