コード例 #1
0
 private void tryLoad()
 {
     lock (this) {
         try {
             if (File.Exists(fileName))
             {
                 string      json       = File.ReadAllText(fileName);
                 var         serializer = Utils.getJsonSerializer();
                 IDictionary data       = serializer.DeserializeObject(json) as IDictionary;
                 userNames.Clear();
                 IList namesJson = data["names"] as IList;
                 foreach (IDictionary nameData in namesJson.Cast <IDictionary>())
                 {
                     string key      = nameData["key"] as string;
                     string sense    = nameData["sense"] as string;
                     string nameType = nameData["type"] as string;
                     addUserName(key, sense, nameType);
                 }
                 contextsEnabled.Clear();
                 IDictionary contextsJson = data["contexts"] as IDictionary;
                 foreach (DictionaryEntry kv in contextsJson)
                 {
                     contextsEnabled[long.Parse((string)kv.Key)] = (bool)kv.Value;
                 }
                 _newContextsBehavior = (MyContextFactory.NewContextsBehavior)Enum.Parse(typeof(MyContextFactory.NewContextsBehavior), (string)data["newContexts"]);
                 userHooks.Clear();
                 IList hooksJson = data["hooks"] as IList;
                 foreach (string code in hooksJson.Cast <string>())
                 {
                     UserHook hook = UserHook.fromCode(code);
                     if (hook != null)
                     {
                         userHooks.Add(hook);
                     }
                 }
                 _po = data["po"] as string;
                 if (data["sentenceDelay"] != null)
                 {
                     int sd = (int)data["sentenceDelay"];
                     _sentenceDelay = TimeSpan.FromMilliseconds(sd);
                 }
             }
         } catch (Exception e) {
             Logger.logException(e);
         }
         isDirty = false;
     }
 }
コード例 #2
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            string code = textBox1.Text;

            code = code.Trim().ToUpper();
            if (code == "")
            {
                return;
            }
            UserHook userHook = UserHook.fromCode(code);

            if (userHook == null)
            {
                Utils.error("Cannot parse hook code. Please verify code syntax and try again.");
                return;
            }
            if (!TextHook.instance.addUserHook(userHook))
            {
                Utils.error("Failed to install hook.");
                return;
            }
            listBox1.Items.Add(userHook);
            textBox1.Text = "";
        }