/* サンプル1 - 変換・確定・削除の処理の雛形 */ using System; using System.Net; using System.Net.Sockets; using System.Text; using System.Reflection; using System.Windows.Forms; /// SKKゲート操作用 class SKKGate { object g; /// 生成時 public SKKGate() { g = Activator.CreateInstance(Type.GetTypeFromProgID("SKKGate")); } /// 呼出 object call(string name, object[] arg) { return g.GetType().InvokeMember(name, BindingFlags.InvokeMethod, null, g, arg); } /// 検索 public string Search(string index, int attr, int target) { return (string)call("Search", new object[] { index, attr, target }); } /// 補完 public string Abbrev(string index, int attr, int target) { return (string)call("Abbrev", new object[] { index, attr, target }); } /// 更新 public void Update(string index, string candidate, int attr, int target) { call("Update", new object[] { index, candidate, attr, target }); } /// 削除 public void Delete(string index, string candidate, int attr, int target) { call("Delete", new object[] { index, candidate, attr, target }); } /// 待機 public int Sync(int host, int target) { return (int)call("Sync", new object[] { host, target }); } /// 予約 public void Exec(int target) { call("Exec", new object[] { target }); } /// 情報取得 public string Get(int mode) { return (string)call("Get", new object[] { mode }); } /// 数値取得 public int GetInt(int mode) { return (int)call("Get", new object[] { mode }); } /// 候補追加 public void Put(string candidate, string capsule) { call("Put", new object[] { candidate, capsule }); } } /// プログラム class Program { /// メイン static void Main() { SKKGate Gate = new SKKGate(); const int myself = 0; ///< 自分のゲート番号 (ゲート0: フロントエンドからの要求) const int target = 1; ///< 接続先ゲート番号 (ゲート1: 辞書プロセスへの処理依頼) for (;;) { // 待機 int id = Gate.Sync(myself, 1); if (id < 0) { if (id == -2) { MessageBox.Show("停止します", "SKKGate実行中"); Gate.Sync(-1, myself); } break; } string index = Gate.Get(0); string cand = Gate.Get(1); int attr = Gate.GetInt(2); switch (id) { // 変換 case 0: string[] result = Gate.Search(index, attr, target).Split('\x03'); foreach (string one in result) Gate.Put(one, ""); break; // 補完 case 1: string[] result = Gate.Abbrev(index, attr, target).Split('\x03'); foreach (string one in result) Gate.Put(one, ""); break; // 確定 case 2: Gate.Update(index, cand, attr, target); break; // 削除 case 3: Gate.Delete(index, cand, attr, target); break; // // 予約 // default: // Gate.Exec(target); // break; } } } }