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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves a list of highlights.
        /// </summary>
        /// <param name="options">Query options for retrieving the highlights (optional)</param>
        /// <returns></returns>
        public Task<List<Highlight>> GetHighlightsAsync(RangeQueryOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            IDictionary<string, string> parameters = GetInitializedParameterCollection();

            if (options != null)
            {
                parameters.Add(RangeQueryOptions.From, options.FromValue);
                parameters.Add(RangeQueryOptions.To, options.ToValue);
                parameters.Add(RangeQueryOptions.Count, options.CountValue.ToString());
                parameters.Add(RangeQueryOptions.OrderBy, options.OrderByValue);
            }

            //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 highlightsUrl = highlightsUriTemplates[HighlightsUriTemplateType.PublicHighlights].BindByName(this.readmillBaseUri, parameters);
            return GetAsync<List<Highlight>>(highlightsUrl, cancellationToken);
        }
Exemplo n.º 3
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
        }
Exemplo n.º 4
0
        public Task<List<Comment>> GetHighlightCommentsAsync(string highlightId, RangeQueryOptions options = null, string accessToken = null)
        {
            IDictionary<string, string> parameters = GetInitializedParameterCollection();
            parameters.Add(HighlightsClient.HighlightId, highlightId);
            parameters.Add(ReadmillConstants.AccessToken, accessToken);

            if (options != null)
            {
                parameters.Add(RangeQueryOptions.From, options.FromValue);
                parameters.Add(RangeQueryOptions.To, options.ToValue);
                parameters.Add(RangeQueryOptions.Count, options.CountValue.ToString());
                parameters.Add(RangeQueryOptions.OrderBy, options.OrderByValue);
            }

            //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 commentsUrl = highlightsUriTemplates[HighlightsUriTemplateType.HighlightComments].BindByName(this.readmillBaseUri, parameters);
            return GetAsync<List<Comment>>(commentsUrl);
        }