示例#1
0
文件: ExecHm.cs 项目: Centny/cswf
 public void onCmd(NetwRunnable nr, Bys m)
 {
     try {
         string name;
         IDictionary<string, Object> args;
         this.vna(nr, this, m, out name, out args);
         var rc = new RCM_Cmd(m, name, args);
         bool next = false;
         foreach (var filter in this.filters)
         {
             if (!filter.Key.IsMatch(name))
             {
                 continue;
             }
             var res = filter.Value(rc, out next);
             if (next)
             {
                 continue;
             }
             else
             {
                 m.writev(res);
                 return;
             }
         }
         foreach (var handler in this.handler)
         {
             if (handler.Key.IsMatch(name))
             {
                 m.writev(handler.Value(rc));
                 return;
             }
         }
         m.writev(Util.dict("err", "function not found by name:" + name));
     }catch(Exception e)
     {
         L.E(e, "ExecHm exec error:{0}", e.Message);
         m.writev(Util.dict("err", "exec fail with " + e.Message));
     }
 }
示例#2
0
文件: DTM_C.cs 项目: Centny/cswf
 public virtual Object WaitTask(RCM_Cmd rc)
 {
     var tid = rc.Val("tid", "");
     var res = Util.NewDict();
     if (String.IsNullOrWhiteSpace(tid))
     {
         res["code"] = -1;
         res["err"] = "DTM_C the tid is requied";
         return res;
     }
     try
     {
         Process proc = null;
         if (this.Tasks.TryGetValue(tid, out proc))
         {
             proc.WaitForExit();
         }
         res["code"] = 0;
     }
     catch (Exception e)
     {
         res["code"] = -2;
         res["err"] = String.Format("DTM_C wait task fail with {0}", e.Message);
     }
     return res;
 }
示例#3
0
文件: DTM_C.cs 项目: Centny/cswf
 public virtual Object StopTask(RCM_Cmd rc)
 {
     var tid = rc.Val("tid", "");
     var res = Util.NewDict();
     if (String.IsNullOrWhiteSpace(tid))
     {
         res["code"] = -1;
         res["err"] = "DTM_C the tid is requied";
         return res;
     }
     try
     {
         Process proc = null;
         if (this.Tasks.TryGetValue(tid, out proc))
         {
             proc.Kill();
             res["code"] = 0;
         }
         else
         {
             res["code"] = -3;
             res["err"] = String.Format("DTM_C stop task fail with runner is not found by id({0})", tid);
         }
     }
     catch (Exception e)
     {
         res["code"] = -2;
         res["err"] = String.Format("DTM_C stop task fail with {0}", e.Message);
     }
     return res;
 }
示例#4
0
文件: DTM_C.cs 项目: Centny/cswf
 public virtual Object StartTask(RCM_Cmd rc)
 {
     var tid = rc.Val("tid", "");
     var cmds = rc.Val("cmds", "");
     var res = Util.NewDict();
     if (String.IsNullOrWhiteSpace(tid) || String.IsNullOrWhiteSpace(cmds))
     {
         res["code"] = -1;
         res["err"] = "DTM_C the tid/cmds is requied";
         return res;
     }
     try
     {
         this.RunCmd(tid, cmds);
         res["code"] = 0;
         res["tid"] = tid;
     }
     catch (Exception e)
     {
         res["code"] = -2;
         res["err"] = String.Format("DTM_C start command fail with {0}", e.Message);
         L.E(e, "DTM_C start command(\n{0}\n) fail with error {1}", cmds, e.Message);
     }
     return res;
 }
示例#5
0
        public void TestStartDTM_C()
        {
            var cfg = new FCfg();
            cfg["proc_env"] = "a=1,b=2";
            var dtmc = new DTM_C_t("c", cfg);
            var args = Util.NewDict();
            var res = Util.NewDict();
            var tres = new Dict();
            var tid = "xx1";
            args["tid"] = tid;
            args["cmds"] = "test/dtm_json.bat abc";
            //

            var bs = new PrintStream();
            RCM_Cmd cmd;
            //
            cmd = new RCM_Cmd(null, "", args);
            res = dtmc.StartTask(cmd) as Dictionary<String, object>;
            tres = new Dict(res);
            Console.WriteLine(Json.stringify(res));
            Assert.AreEqual(0, tres.Val("code", -1));
            while (dtmc.Tasks.Count > 0)
            {
                Thread.Sleep(500);
            }
            Assert.AreNotEqual(null, dtmc.Done);
            res = dtmc.Done as Dictionary<String, object>;
            tres = new Dict(res);
            Console.WriteLine(Json.stringify(res));
            Assert.AreEqual(0, tres.Val("code", -1));
            Assert.AreEqual(tid, tres.Val("tid", ""));
            //
            args["cmds"] = "test/dtm_json_err.bat abc";
            res = dtmc.StartTask(cmd) as Dictionary<String, object>;
            tres = new Dict(res);
            Console.WriteLine(Json.stringify(res));
            Assert.AreEqual(0, tres.Val("code", -1));
            while (dtmc.Tasks.Count > 0)
            {
                Thread.Sleep(500);
            }
            Assert.AreNotEqual(null, dtmc.Done);
            res = dtmc.Done as Dictionary<String, object>;
            tres = new Dict(res);
            Console.WriteLine(Json.stringify(res));
            Assert.AreNotEqual(0, tres.Val("code", 0));
            Assert.AreEqual(tid, tres.Val("tid", ""));
            //
            //
            args["cmds"] = "sdfkfk";
            res = dtmc.StartTask(cmd) as Dictionary<String, object>;
            tres = new Dict(res);
            Console.WriteLine(Json.stringify(res));
            Assert.AreNotEqual(0, tres.Val("code", 0));
            //Assert.AreEqual(tid, tres.Val("tid", ""));
            //
            args["cmds"] = "";
            res = dtmc.StartTask(cmd) as Dictionary<String, object>;
            tres = new Dict(res);
            Console.WriteLine(Json.stringify(res));
            Assert.AreNotEqual(0, tres.Val("code", 0));
            //Assert.AreEqual(tid, tres.Val("tid", ""));
            Console.WriteLine("Done...");
        }
示例#6
0
 public Object c_arg(RCM_Cmd rc)
 {
     return rc.data;
 }