コード例 #1
0
 private void SearchImages(string title)
 {
     try
     {
         var flicrRepository = new FlickrRepository();
         Photos = new ScrollableObservableCollection(flicrRepository.LoadImages(CurrentPage, title).Result, title);
     }
     catch (Exception ex)
     {
         exManager.PublishError(ex.Message);
     }
 }
コード例 #2
0
        public Windows.Foundation.IAsyncOperation <LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
        {
            if (isRunning) //not thread safe
            {
                throw new InvalidOperationException("Only one operation in flight at a time");
            }

            isRunning = true;

            int itemsCount = 0;

            return(AsyncInfo.Run(async c =>
            {
                try
                {
                    currentPage++;
                    FlickrRepository repository = new FlickrRepository();
                    var result = await repository.LoadImages(currentPage, title);

                    var photos = new PhotoCollection();
                    if (result != null)
                    {
                        photos = result;
                        HasMoreItems = result.Any();
                        itemsCount = result.Count;
                    }

                    foreach (var item in photos)
                    {
                        this.Add(item);
                    }

                    isRunning = false;
                }
                catch (Exception ex)
                {
                    HasMoreItems = false;
                    exManager.PublishError(ex.Message);
                }

                LoadMoreItemsResult res = new LoadMoreItemsResult()
                {
                    Count = (uint)itemsCount
                };
                return res;
            }));
        }