using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI.Dictionaries;

public partial class Default2 : System.Web.UI.Page
{
    private DictionaryImporter _importer = null;
    private Dictionaries dictionaries;

    private DictionaryImporter importer
    {
        get
        {
            if (_importer == null)
                _importer = ImporterForDictionary(CurrentDictionaryFile());
            return _importer;
        }

    }

    private string CurrentDictionaryFile()
    {
        return dictionaries.AbsoluteDictionaryFileName("en-US.tdf");
    }

    private DictionaryImporter ImporterForDictionary(string absoluteDictionaryName)
    {
        DictionaryImporter importer = new DictionaryImporter();
        importer.Load(absoluteDictionaryName);
        return importer;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        dictionaries = new Dictionaries(HttpContext.Current);
    }

    protected void addButton_Click(object sender, System.EventArgs e)
    {
        //try
        //{
            string newWord = addWordBox.Text.Trim();
            if (newWord != string.Empty)
            {
                this.importer.AddWord(newWord);
                this.importer.Save(CurrentDictionaryFile());
                Response.Write(string.Format("Word '{0}' added to the dictionary.", newWord));
            }
        //}
        //catch (UnauthorizedAccessException)
        //{
        //    Response.Write(string.Format("Access denied to the {0} folder.  Please grant the ASP.NET user account write permissions to the folder.", dictionaries.DictionaryPath));
        //}
        //catch (Exception unknownError)
        //{
        //    Response.Write(unknownError.Message);
        //}
    }
}
