2 using com.andoutomo.kybernetes.view;
\r
3 using com.andoutomo.kybernetes.data.accessor;
\r
4 using com.andoutomo.kybernetes.data.DAO;
\r
5 using com.andoutomo.kybernetes.command;
\r
6 using System.Reflection;
\r
7 using System.Collections.Generic;
\r
9 namespace com.andoutomo.kybernetes.control
\r
11 public class CmdDispatcher
\r
13 #region Singleton Setting
\r
14 private static CmdDispatcher singleton;
\r
15 private CmdDispatcher()
\r
18 public static CmdDispatcher getDispatcher(BaseForm form)
\r
20 if (singleton == null)
\r
22 singleton = new CmdDispatcher(form);
\r
27 private BaseForm baseForm;
\r
29 private CmdDispatcher(BaseForm form)
\r
31 form.onCmdDispatch += new BaseForm.CmdDispatchEventHandler(form_onCmdDispatch);
\r
32 this.baseForm = form;
\r
35 public BaseForm getForm()
\r
37 return this.baseForm;
\r
40 private void form_onCmdDispatch(object sender, CmdDispatchEventArg e)
\r
42 e.Result = dispatch(e.Command);
\r
47 /// コマンドをデータベースと照合して、処理の呼び出しを実施します。
\r
49 /// <param name="command"></param>
\r
50 /// <returns></returns>
\r
51 public string dispatch(string command)
\r
53 //空文字の場合は改行を入れる(Unixの仕様に準拠)
\r
54 if (string.IsNullOrEmpty(command))
\r
56 return string.Empty;
\r
59 string retStr = string.Empty;
\r
60 string commandTop = command.Split(' ')[0];
\r
61 CommandData data = CommandDataAccessor.getObject.getCommandData(commandTop);
\r
67 List<SimpleDataBean> dllList = CommandDataAccessor.getObject.getDllList();
\r
70 Type argsType = null;
\r
71 Type commandType = null;
\r
72 foreach (SimpleDataBean bean in dllList)
\r
74 asm = Assembly.LoadFrom(bean.Val);
\r
75 if (argsType == null)
\r
77 argsType = asm.GetType(data.ArgClass);
\r
79 if (commandType == null)
\r
81 commandType = asm.GetType(data.TargetClass);
\r
84 if (argsType != null && commandType != null)
\r
89 if (argsType == null || commandType == null)
\r
91 return "コマンドが見つかりません。";
\r
93 CommandArg args = (CommandArg)Activator.CreateInstance(argsType);
\r
94 AbCommand commandCls = (AbCommand)Activator.CreateInstance(commandType);
\r
96 args.split(command);
\r
97 commandCls.run(args,baseForm);
\r
99 retStr = commandCls.getMessage();
\r
101 catch (Exception e)
\r
103 retStr = "エラーが発生しました。";
\r
104 new KybernetesApplicationException(e);
\r
109 retStr = "不明なコマンドです。";
\r