コード例 #1
0
        public ReadingNotes BuildReadingNotes(string EditionNumber)
        {
            var notes        = StorageHelper.GetAllNotefromStorage();
            var readingNotes = new ReadingNotes();

            List <string> allTags = new List <string>();

            allTags.Add("readingnotes");

            foreach (var n in notes)
            {
                allTags    = KeepUniqueTag(allTags, n.Tags);
                n.Category = GetCategory(n.Tags);

                // little tweak because it's a pain to set the first caracter uppercase on the kindle.
                n.Comment = n.Comment.First().ToString().ToUpper() + String.Join("", n.Comment.Skip(1));

                if (readingNotes.Notes[n.Category] == null)
                {
                    readingNotes.Notes[n.Category] = new List <Note>();
                }

                ((List <Note>)readingNotes.Notes[n.Category]).Add(n);
            }

            readingNotes.Title = string.Concat("Reading Notes #", EditionNumber);
            readingNotes.Tags  = string.Join(",", allTags.OrderBy(c => c));

            StorageHelper.SaveJSonReadingNotesToStorage(readingNotes.Serialize());
            StorageHelper.SaveReadingNotesToStorage(readingNotes.ToMarkDown());

            return(readingNotes);
        }
コード例 #2
0
        public string ReProcessJSonReadingNotes(string Filename)
        {
            ReadingNotes readNotes = ReadingNotes.CreateFromString(StorageHelper.GetJSonReadingNotes(Filename));
            var          mdNotes   = readNotes.ToMarkDown();

            StorageHelper.SaveReadingNotesToStorage(mdNotes);

            return(mdNotes);
        }
コード例 #3
0
        /// <param name='editionNumber'>
        /// Required.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public async Task <HttpOperationResponse <ReadingNotes> > BuildReadingNotesWithOperationResponseAsync(string editionNumber, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            // Validate
            if (editionNumber == null)
            {
                throw new ArgumentNullException("editionNumber");
            }

            // Tracing
            bool   shouldTrace  = ServiceClientTracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("editionNumber", editionNumber);
                ServiceClientTracing.Enter(invocationId, this, "BuildReadingNotesAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/BuildReadingNotes";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("EditionNumber=" + Uri.EscapeDataString(editionNumber));
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = new HttpRequestMessage();

            httpRequest.Method     = HttpMethod.Get;
            httpRequest.RequestUri = new Uri(url);

            // Set Credentials
            if (this.Client.Credentials != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
            }

            // Send Request
            if (shouldTrace)
            {
                ServiceClientTracing.SendRequest(invocationId, httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            HttpResponseMessage httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

            if (shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(invocationId, httpResponse);
            }
            HttpStatusCode statusCode = httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (statusCode != HttpStatusCode.OK)
            {
                HttpOperationException <object> ex = new HttpOperationException <object>();
                ex.Request  = httpRequest;
                ex.Response = httpResponse;
                ex.Body     = null;
                if (shouldTrace)
                {
                    ServiceClientTracing.Error(invocationId, ex);
                }
                throw ex;
            }

            // Create Result
            HttpOperationResponse <ReadingNotes> result = new HttpOperationResponse <ReadingNotes>();

            result.Request  = httpRequest;
            result.Response = httpResponse;

            // Deserialize Response
            if (statusCode == HttpStatusCode.OK)
            {
                ReadingNotes resultModel = new ReadingNotes();
                JToken       responseDoc = null;
                if (string.IsNullOrEmpty(responseContent) == false)
                {
                    responseDoc = JToken.Parse(responseContent);
                }
                if (responseDoc != null)
                {
                    resultModel.DeserializeJson(responseDoc);
                }
                result.Body = resultModel;
            }

            if (shouldTrace)
            {
                ServiceClientTracing.Exit(invocationId, result);
            }
            return(result);
        }