From f54cf32057d8d9f79d531171cbf3c7fdd2b74cae Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 19 Dec 2013 11:06:00 +1100 Subject: [PATCH] Converted spell checker deserialization to json.net and changed the deserialized object to internal with correct naming conventions. --- src/Umbraco.Web/Umbraco.Web.csproj | 1 + .../plugins/tinymce3/GoogleSpellChecker.cs | 21 ++++----- .../tinymce3/JsonSpellCheckerResult.cs | 44 +++++++++++++++++++ .../plugins/tinymce3/SpellCheckerResult.cs | 30 ------------- 4 files changed, 56 insertions(+), 40 deletions(-) create mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/plugins/tinymce3/JsonSpellCheckerResult.cs diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index c1d56a5031..d494e52178 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -425,6 +425,7 @@ ASPXCodeBehind + ASPXCodeBehind diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/plugins/tinymce3/GoogleSpellChecker.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/plugins/tinymce3/GoogleSpellChecker.cs index ef3a6376b0..45f90a1726 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/plugins/tinymce3/GoogleSpellChecker.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/plugins/tinymce3/GoogleSpellChecker.cs @@ -6,6 +6,7 @@ using System.Net; using System.Text; using System.Xml; using System.Collections.Generic; +using Newtonsoft.Json; // NB: This class was moved out of the client tinymce folder to aid with upgrades // but we'll keep the old namespace to make things easier for now (MB) @@ -70,16 +71,16 @@ namespace umbraco.presentation.umbraco_client.tinymce3.plugins.spellchecker public override SpellCheckerResult CheckWords(string language, string[] words) { string data = string.Join(" ", words); //turn them into a space-separated string as that's what google takes - string json = SendRequest(language, data); - var jsonRes = new JavaScriptSerializer().Deserialize(json); + string json = SendRequest(language, data); + var jsonRes = JsonConvert.DeserializeObject(json); var res = new SpellCheckerResult(); // Get list of misspelled words - if (jsonRes.result != null && jsonRes.result.spellingCheckResponse != null) + if (jsonRes.Result != null && jsonRes.Result.SpellingCheckResponse != null) { - foreach (var misspelling in jsonRes.result.spellingCheckResponse.misspellings) + foreach (var misspelling in jsonRes.Result.SpellingCheckResponse.Misspellings) { - res.result.Add(data.Substring(misspelling.charStart, misspelling.charLength)); + res.result.Add(data.Substring(misspelling.CharStart, misspelling.CharLength)); } } @@ -95,17 +96,17 @@ namespace umbraco.presentation.umbraco_client.tinymce3.plugins.spellchecker public override SpellCheckerResult GetSuggestions(string language, string word) { string json = SendRequest(language, word); - var jsonRes = new JavaScriptSerializer().Deserialize(json); + var jsonRes = JsonConvert.DeserializeObject(json); var res = new SpellCheckerResult(); // Get list of suggestions - if (jsonRes.result != null && jsonRes.result.spellingCheckResponse != null) + if (jsonRes.Result != null && jsonRes.Result.SpellingCheckResponse != null) { - foreach (var misspelling in jsonRes.result.spellingCheckResponse.misspellings) + foreach (var misspelling in jsonRes.Result.SpellingCheckResponse.Misspellings) { - foreach (var suggestion in misspelling.suggestions) + foreach (var suggestion in misspelling.Suggestions) { - res.result.Add(suggestion.suggestion); + res.result.Add(suggestion.Suggestion); } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/plugins/tinymce3/JsonSpellCheckerResult.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/plugins/tinymce3/JsonSpellCheckerResult.cs new file mode 100644 index 0000000000..fe861e2c80 --- /dev/null +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/plugins/tinymce3/JsonSpellCheckerResult.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace umbraco.presentation.umbraco_client.tinymce3.plugins.spellchecker +{ + /// + /// Object used to deserialise the Google Json response + /// + internal class JsonSpellCheckerResult + { + [JsonProperty("result")] + public GoogleResponseResult Result { get; set; } + + public class GoogleResponseResult + { + [JsonProperty("spellingCheckResponse")] + public GoogleResponseSpellingCheckResponse SpellingCheckResponse { get; set; } + + } + public class GoogleResponseSpellingCheckResponse + { + [JsonProperty("misspellings")] + public List Misspellings { get; set; } + + } + public class GoogleResponseMisspelling + { + [JsonProperty("charStart")] + public int CharStart { get; set; } + + [JsonProperty("charLength")] + public int CharLength { get; set; } + + [JsonProperty("suggestions")] + public List Suggestions { get; set; } + + } + public class GoogleResponseSuggestion + { + [JsonProperty("suggestion")] + public string Suggestion { get; set; } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/plugins/tinymce3/SpellCheckerResult.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/plugins/tinymce3/SpellCheckerResult.cs index fc5f7a0bfd..1372629cf8 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/plugins/tinymce3/SpellCheckerResult.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/plugins/tinymce3/SpellCheckerResult.cs @@ -32,34 +32,4 @@ namespace umbraco.presentation.umbraco_client.tinymce3.plugins.spellchecker /// The error. public string error { get; set; } } - - /// - /// Object used to deserialise the Google Json response - /// - public class JsonSpellCheckerResult - { - public GoogleResponseResult result { get; set; } - - public class GoogleResponseResult - { - public GoogleResponseSpellingCheckResponse spellingCheckResponse { get; set; } - - } - public class GoogleResponseSpellingCheckResponse - { - public List misspellings { get; set; } - - } - public class GoogleResponseMisspelling - { - public int charStart { get; set; } - public int charLength { get; set; } - public List suggestions { get; set; } - - } - public class GoogleResponseSuggestion - { - public string suggestion { get; set; } - } - } }