private void ExtractSearchParameters()
        {
            var qs = NavigationContext.QueryString;
            var searchParam = new EventSearchParams();

            searchParam.Keyword = qs["keyword"] != null ? qs["keyword"] : string.Empty;
            searchParam.Category = qs["category"] != null ? qs["category"] : "All";
            searchParam.Location = qs["location"] != null ? qs["location"] : string.Empty;
            searchParam.Date = qs["date"] != null ? qs["date"] : string.Empty;
            searchParam.Within = 0; //

            Messenger.Default.Send<EventSearchParams>(searchParam, "SearchParams");
        }
예제 #2
0
        public void GetEvents(EventSearchParams searchParams, Action<Api.EventSet> onGetCompleted = null, Action onBegin = null, Action<Exception> onError = null, Action onFinally = null)
        {
            if (onBegin != null)
                onBegin();

            if (onGetCompleted != null)
            {
                const int total = 20;

                Api.EventSet eventSet = new Api.EventSet();
                var events = new Event[total];
                for (int i = 0; i < total; i++)
                {
                    events[i] = new Event
                    {
                        Id = string.Format("{0} - {1}", "event", i),
                        CityName = "City " + i,
                        Country = "Country-" + i,
                        Description = "Description-" + i,
                        Latitude = "3430.0",
                        Longitude = "89.023",
                        PostalCode = "783" + i,
                        Price = i.ToString(),
                        RecurString = "Recuring String " + i,
                        StartTime = DateTime.Now.ToLongDateString(),
                        StopTime = DateTime.Now.AddDays(2).ToLongDateString(),
                        Title = "Title - " + i,
                        Url = "http://example.com",
                        VenueAddress = "Venue Address " + i,
                        VenueName = "Venue name " + i
                    };
                }
                eventSet.Events = events;
                onGetCompleted(eventSet);
            }

            if (onFinally != null)
                onFinally();
        }
        private void GetEvents(EventSearchParams esp = null)
        {
            if (esp == null) return;

            Events.Clear();
            this._service.GetEvents(esp, eventSet =>
            {
                NoEventsFound = false;
                if (eventSet != null && eventSet.Events.Length != 0)
                {
                    foreach (var e in eventSet.Events)
                    {
                        Events.Add(e);
                    }
                    IsDataLoaded = true;
                }
                else
                {
                    NoEventsFound = true;
                }
            },
            delegate()
            {
                IsEventsLoading = true;
            },
            delegate(Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception);
            },
            delegate()
            {
                IsEventsLoading = false;
            });
        }
 private void GetEvents(string date, string categoryId)
 {
     EventSearchParams searchParams = new EventSearchParams();
     searchParams.Category = categoryId;
     searchParams.Date = date;
     searchParams.Location = string.Format("{0},{1}", AppState.Latitude, AppState.Longitude);
     this._service.GetEvents(searchParams, eventSet =>
     {
         NoEventsFound = false;
         if (eventSet != null && eventSet.Events.Length != 0)
         {
             foreach (var e in eventSet.Events)
             {
                 Events.Add(e);
             }
             IsDataLoaded = true;
         }
         else
         {
             NoEventsFound = true;
         }
     },
     delegate()
     {
         IsEventsLoading = true;
     },
     delegate(Exception exception)
     {
         System.Diagnostics.Debug.WriteLine(exception);
     },
     delegate()
     {
         IsEventsLoading = false;
     });
 }
        private void LoadFeaturedEvents()
        {
            this.FeaturedEvents = new ObservableCollection<Event>();

            // Sample data; replace with real data
            if (DesignerProperties.IsInDesignTool || this.IsInDesignMode)
            {
                for (int i = 0; i < 10; i++)
                {
                    this.FeaturedEvents.Add(new Event
                    {
                        Title = "Featured event " + i.ToString(),
                        Country = "Finland" + i.ToString(),
                        CityName = "Helsinki",
                        StartTime = DateTime.Today.ToShortDateString()
                    });
                }
            }
            else
            {
                EventSearchParams searchParams = new EventSearchParams();
                searchParams.Location = string.Format("{0},{1}", AppState.Latitude, AppState.Longitude);
                searchParams.Within = 250;
                searchParams.Date = DateTime.Today.ToShortDateString();
                _service.GetEvents(searchParams, eventSet =>
                {
                    NoEventsFound = false;
                    if (eventSet != null && eventSet.Events.Length != 0)
                    {
                        foreach (var e in eventSet.Events)
                        {
                            FeaturedEvents.Add(e);
                        }
                    }
                    else
                    {
                        NoEventsFound = true;
                    }
                },
                delegate
                {
                    IsFeaturedEventsLoading = true;
                },
                delegate(Exception exception)
                {
                    System.Diagnostics.Debug.WriteLine(exception);
                },
                delegate
                {
                    IsFeaturedEventsLoading = false;
                });
            }
        }
        public void GetEvents(EventSearchParams searchParams, Action<EventSet> onGetCompleted = null, Action onBegin = null, Action<Exception> onError = null, Action onFinally = null)
        {
            if (searchParams == null)
                throw new ArgumentNullException("Search paramater cannot be null");

            WebClient webClient = new WebClient();
            webClient.OpenReadCompleted += delegate(object sender, OpenReadCompletedEventArgs e)
            {
                try
                {
                    if (e.Error != null)
                    {
                        if (onError != null)
                        {
                            onError(e.Error);
                        }
                        return;
                    }

                    using (XmlReader xmlReader = XmlReader.Create(e.Result))
                    {
                        var eventSet = (EventSet)_xmlSerializer.Deserialize(xmlReader);
                        if (onGetCompleted != null)
                        {
                            onGetCompleted(eventSet);
                        }
                    }
                }
                finally
                {
                    if (onFinally != null)
                    {
                        onFinally();
                    }
                }
            };

            if (onBegin != null)
            {
                onBegin();
            }

            var url = string.Empty;

            if (searchParams.Within != 0)
                url = GetEventSearchUrl(searchParams);
            else
                url = GetEventSearchUrl(searchParams, true);

            webClient.OpenReadAsync(new Uri(url));
        }
        private string GetEventSearchUrl(EventSearchParams esp, bool nonGeo = false)
        {
            if (string.IsNullOrEmpty(API_KEY))
                throw new InvalidOperationException("ApiKey is invalid.");

            if (!nonGeo)
                //var str = string.Format(_eventSearchUrlFormat, API_KEY, esp.Location, esp.Category, esp.Date, esp.SortOrder.ToString(), esp.SortDirection.ToString(), esp.PageSize, esp.Within);
                return string.Format(_eventSearchUrlFormat,
                    API_KEY, esp.Location,
                    esp.Category, esp.Date,
                    esp.SortOrder.ToString(),
                    esp.SortDirection.ToString(),
                    esp.PageSize,
                    esp.Within);
            else
                return string.Format(_eventSearchUrlFormatNonGeo,
                   API_KEY, esp.Location,
                   esp.Category, esp.Date,
                   esp.SortOrder.ToString(),
                   esp.SortDirection.ToString(),
                   esp.PageSize);
        }