Inheritance: RangeQueryOptions
        public Task LoadBookHighlightsAsync(CancellationToken cancelToken = default(CancellationToken))
        {
            IDictionary<decimal, Highlight> highlights = new Dictionary<decimal, Highlight>();

            ReadingsQueryOptions readingOptions = new ReadingsQueryOptions() { CountValue = 100 };
            RangeQueryOptions highlightOptions = new RangeQueryOptions() { CountValue = 100 };
            //int hCount = 0;

            //Get all readings
            return Task.Factory.StartNew(() =>
            {
                List<Reading> readings = client.Books.GetBookReadingsAsync(
                    SelectedBook.Id, readingOptions, cancellationToken:cancelToken).Result;

                foreach (Reading reading in readings)
                {
                    //foreach reading, Get all Highlights
                    foreach (Highlight h in client.Readings.GetReadingHighlightsAsync(reading.Id, highlightOptions, cancellationToken:cancelToken).Result)
                    {
                        //ToDo: Better heuristics? Remove duplicates?
                        if (h.Content.Length >= 20)
                            if (!highlights.ContainsKey(h.Locators.Position))
                            {
                                highlights.Add(h.Locators.Position, h);
                            }
                    }
                }

                BookHighlights = highlights.Values.ToList<Highlight>();
            }, cancelToken, TaskCreationOptions.None, TaskScheduler.Default);
        }
Ejemplo n.º 2
0
        public void TestGetHighlights()
        {
            ReadmillClient client = new ReadmillClient(this.clientId);

            SortedList<decimal, Highlight> highlights = new SortedList<decimal, Highlight>();

            //Get a book
            BookMatchOptions options = new BookMatchOptions();
            options.AuthorValue = "Chad Fowler";//"Edward Rutherfurd";
            options.TitleValue = "The Passionate Programmer";//"New York: The Novel";

            Book book = client.Books.GetBestMatchAsync(options).Result;

            ReadingsQueryOptions readingOptions = new ReadingsQueryOptions();
            //Get all readings
            List<Reading> readings = client.Books.GetBookReadingsAsync(book.Id, readingOptions).Result;

            foreach (Reading reading in readings)
            {
                //Foreach reading, Get all (100 latest) Highlights
                RangeQueryOptions highlightOptions = new RangeQueryOptions() { CountValue = 100 };

                foreach (Highlight h in client.Readings.GetReadingHighlightsAsync(reading.Id, highlightOptions).Result)
                {
                    if(!highlights.ContainsKey(h.Locators.Position))
                        highlights.Add(h.Locators.Position, h);
                }
            }

            //Now do something with the sorted list of highlights. E.g. Print a summary of the book
        }
Ejemplo n.º 3
0
        public Task LoadRecentlyReadBooksAsync(CancellationToken cancelToken = default(CancellationToken))
        {
            //BooksQueryOptions booksOptions = new BooksQueryOptions() { CountValue = 25 };
            ReadingsQueryOptions readingsOptions = new ReadingsQueryOptions() { CountValue = 50 };

            Task<List<Reading>> readingsTask = client.Readings.GetReadingsAsync(readingsOptions, cancelToken);

            return readingsTask.ContinueWith(task =>
            {
                foreach (Reading r in task.Result)
                {
                    if (!readableBooks.ContainsKey(r.Book.Id))
                        readableBooks.Add(r.Book.Id, r.Book);
                }

                BookList = readableBooks.Values;
                ListState = State.RecentlyRead;
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get readings associated with the specified book
        /// </summary>
        /// <param name="bookId">Readmill Id of the book for which readings need to be retrieved</param>
        /// <param name="?"></param>
        /// <returns></returns>
        public Task<List<Reading>> GetBookReadingsAsync(
            string bookId, 
            ReadingsQueryOptions options = null, 
            string accessToken = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            IDictionary<string, string> parameters = GetInitializedParameterCollection();
            parameters.Add(BooksClient.BookId, bookId);
            parameters.Add(ReadmillConstants.AccessToken, accessToken);

            if (options != null)
            {
                parameters.Add(ReadingsQueryOptions.From, options.FromValue);
                parameters.Add(ReadingsQueryOptions.To, options.ToValue);
                parameters.Add(ReadingsQueryOptions.Count, options.CountValue.ToString());
                parameters.Add(ReadingsQueryOptions.OrderBy, options.OrderByValue);
                parameters.Add(ReadingsQueryOptions.HighlightsCountFrom, options.HighlightsCountFromValue);
                parameters.Add(ReadingsQueryOptions.HighlightsCountTo, options.HighlightsCountToValue);
                parameters.Add(ReadingsQueryOptions.Status, options.StatusValue);
            }

            //Remove extraneous parameters because Readmill doesn't like empty pairs
            IDictionary<string, string> tmpParams = new Dictionary<string, string>();
            foreach (string key in parameters.Keys)
            {
                if (!string.IsNullOrEmpty(parameters[key]))
                    tmpParams.Add(key, parameters[key]);
            }
            parameters = tmpParams;

            var bookReadingsUrl = booksUriTemplates[BooksUriTemplateType.BookReadings].BindByName(this.readmillBaseUri, parameters);
            return GetAsync<List<Reading>>(bookReadingsUrl, cancellationToken);
        }
Ejemplo n.º 5
0
        public void TestRangeQuery()
        {
            ReadmillClient client = new ReadmillClient(this.clientId);

            ReadingsQueryOptions options = new ReadingsQueryOptions()
                                           {
                                               FromValue = XmlConvert.ToString(new DateTime(2012, 7, 1)),
                                               ToValue = XmlConvert.ToString(new DateTime(2012, 7, 31)),
                                               OrderByValue = "created_at"
                                           };

            List<Reading> jul2012Readings = client.Readings.GetReadingsAsync(options).Result;
            foreach (Reading reading in jul2012Readings)
            {
                //There shouldn't be any reading not created in July 2012
                Assert.IsTrue(DateTime.Parse(reading.CreatedAt) < new DateTime(2012, 8, 7));
                Assert.IsTrue(DateTime.Parse(reading.CreatedAt) > new DateTime(2012, 6, 30));
            }
        }
Ejemplo n.º 6
0
        public void TestGetReadings()
        {
            ReadmillClient client = new ReadmillClient(this.clientId);

            ReadingsQueryOptions options = new ReadingsQueryOptions() { CountValue = 30 };

            List<Reading> readings = client.Readings.GetReadingsAsync(options).Result;

            foreach (Reading r in readings)
            {
                //Periods
                List<Period> sessions = client.Readings.GetReadingPeriodsAsync(r.Id).Result;
                Console.WriteLine("Reading {0} has {1} sessions.", r.Id, sessions.Count);

                //Locaions
                List<Location> locations = client.Readings.GetReadingLocationsAsync(r.Id).Result;
                Console.WriteLine("Reading {0} has {1} locations.", r.Id, locations.Count);
            }

            if (readings.Count != 30)
                throw new InternalTestFailureException("Expected 30 Readings. Got: " + readings.Count);
        }