using System.IO;
using System;
using System.Web.Script.Serialization;
using System.Collections.Generic;
namespace umbraco.presentation.umbraco_client.tinymce3.plugins.spellchecker
{
///
/// Object representation of the input from TinyMCE's spellchecker plugin
///
public class SpellCheckerInput
{
private SpellCheckerInput()
{
Words = new List();
}
///
/// Gets or sets the id from TinyMCE
///
/// The id.
public string Id { get; set; }
///
/// Gets or sets the spellchecking method. eg: checkWords, getSuggestions
///
/// The method.
public string Method { get; set; }
///
/// Gets or sets the language used by the content
///
/// The language.
public string Language { get; set; }
///
/// Gets or sets the words which are to be spell checked
///
/// The words.
public List Words { get; set; }
///
/// Parses the specified stream into the object
///
/// The stream.
///
public static SpellCheckerInput Parse(StreamReader inputStream)
{
if (inputStream == null)
{
throw new ArgumentNullException("stream");
}
if (inputStream.EndOfStream)
{
throw new ArgumentException("Stream end reached before we started!");
}
var jsonString = inputStream.ReadLine();
var deserialized = (Dictionary)new JavaScriptSerializer().DeserializeObject(jsonString);
var input = new SpellCheckerInput();
input.Id = (string)deserialized["id"];
input.Method = (string)deserialized["method"];
input.Language = (string)((object[])deserialized["params"])[0];
if (((object[])deserialized["params"])[1] is string)
{
input.Words.Add((string)((object[])deserialized["params"])[1]);
}
else
{
var words = ((object[])((object[])deserialized["params"])[1]);
foreach (var word in words)
{
input.Words.Add((string)word);
}
}
return input;
}
}
}