コード例 #1
0
ファイル: DocCov.cs プロジェクト: Centny/cswf.doc
 public DocCov(string name, FCfg cfg, netw.rc.EvnListener evn = null) : base(name, cfg, evn)
 {
     this.builder = () =>
     {
         throw new NotImplementedException("NetwBaseBuilder is not implemented");
     };
 }
コード例 #2
0
ファイル: FCfg.cs プロジェクト: Centny/cswf
 public virtual FCfg Clone()
 {
     var tcfg = new FCfg();
     tcfg.data = new Dictionary<string, object>(this.data); ;
     tcfg.Secs = new HashSet<string>(this.Secs);
     return tcfg;
 }
コード例 #3
0
ファイル: FCfgTest.cs プロジェクト: Centny/cswf
 public void FCfgLoad2Test()
 {
     var cfg = new FCfg();
     cfg.Load("./test/fcfg_data.properties");
     Console.WriteLine(cfg);
     Assert.AreEqual("b/", cfg.Val("wxk", ""));
     
 }
コード例 #4
0
ファイル: DTM_C.cs プロジェクト: Centny/cswf
 public DTM_C(string name, FCfg cfg, rc.EvnListener evn = null)
     : base(name, evn)
 {
     this.Tasks = new Dictionary<String, Process>();
     this.Cfg = cfg;
     this.Srv = new Server();
     this.addH("start_task", this.StartTask);
     this.addH("wait_task", this.WaitTask);
     this.addH("stop_task", this.StopTask);
     this.Srv.AddF("^/proc(\\?.*)?", this.OnProc);
     this.Token = cfg.Val("token", "");
 }
コード例 #5
0
ファイル: DTM_C_jTest.cs プロジェクト: Centny/cswf
        public void TestDTMC()
        {
            var cfg = new FCfg();
            DTM_C_j rc = new DTM_C_j("Test", cfg, new SckDailer("127.0.0.1", 13424).Dail);
            rc.Start();
            rc.Login("abc");
            try
            {
                new DTM_C_j("Test", cfg).builder();
            }
            catch (Exception)
            {

            }
            rc.Stop();
            Thread.Sleep(2000);
        }
コード例 #6
0
ファイル: DocCovTest.cs プロジェクト: Centny/cswf.doc
        public void TestDoWord()
        {
            TaskPool.Shared.MaximumConcurrency = 3;
            FCfg cfg = new FCfg();
            DocCovT cov;
            cov = new DocCovT("DocCov", cfg);
            cov.DoCmd("a1", cfg, "Word test\\xx.docx docx_00-{0}.jpg 768 1024");
            while (cov.done == null)
            {
                Thread.Sleep(500);
            }

            var data_ = cov.done as IDictionary<string, object>;
            var data = new Dict(data_);
            Assert.AreEqual(0, data.Val("code", -1));
            Assert.AreEqual("a1", data.Val("tid", ""));
            var res = data["data"] as CovRes;
            Assert.AreEqual(true, res.Count > 0 && res.Count == res.Files.Count);
            Assert.AreNotEqual(0, cov.rate);
            //
            cov = new DocCovT("DocCov", cfg);
            cov.DoCmd("a2", cfg, "Word test\\xx.docxx docx_00-{0}.jpg 768 1024");
            while (cov.done == null)
            {
                Thread.Sleep(500);
            }
            data_ = cov.done as IDictionary<string, object>;
            data = new Dict(data_);
            Assert.AreNotEqual(0, data.Val("code", 0));
            Assert.AreEqual("a2", data.Val("tid", ""));
            var err = data["err"] as String;
            Assert.AreNotEqual(0, err.Length);
            //
            //
            cov = new DocCovT("DocCov", cfg);
            cov.error = true;
            cov.DoCmd("a2", cfg, "Word test\\xx.docx docx_01-{0}.jpg 768 1024");
            while (!cov.do_err)
            {
                Thread.Sleep(500);
            }
        }
コード例 #7
0
ファイル: FCfgTest.cs プロジェクト: Centny/cswf
 public void FCfgLoadTest()
 {
     var cfg = new FCfg();
     cfg.Load("./test/fcfg_a.properties");
     Console.WriteLine(cfg);
     Assert.AreEqual("1", cfg.Val("a/a1", ""));
     Assert.AreEqual(1, cfg.Val("a/a1", 0));
     Assert.AreEqual("1", cfg.Val("b/b1", ""));
     Assert.AreEqual(1, cfg.Val("b/b1", 0));
     Assert.AreEqual(3, cfg.Secs.Count);
     //
     cfg = new FCfg();
     cfg.Load("file://" + Path.GetFullPath("test/fcfg_a.properties"));
     Assert.AreEqual("1", cfg.Val("a/a1", ""));
     Assert.AreEqual("1", cfg.Val("a/a1", ""));
     Assert.AreEqual(1, cfg.Val("a/a1", 0));
     Assert.AreEqual("1", cfg.Val("b/b1", ""));
     Assert.AreEqual(1, cfg.Val("b/b1", 0));
     Assert.AreEqual(3, cfg.Secs.Count);
 }
コード例 #8
0
ファイル: DTM_C.cs プロジェクト: Centny/cswf
 public virtual void DoCmd(String tid, FCfg cfg, String cmds)
 {
     var beg = Util.Now();
     var args = Exec.ParseArgs(cmds);
     L.I("DTM_C calling command(\n{0}\n) by tid({1})", cmds, tid);
     StringBuilder sb = new StringBuilder();
     Process proc = new Process();
     proc.StartInfo.UseShellExecute = false;
     proc.StartInfo.FileName = args[0];
     if (args.Length > 1)
     {
         proc.StartInfo.Arguments = Exec.Join(args, 1, args.Length - 1);
     }
     proc.StartInfo.RedirectStandardOutput = true;
     proc.StartInfo.RedirectStandardError = true;
     proc.StartInfo.CreateNoWindow = true;
     proc.StartInfo.WorkingDirectory = cfg.Val("proc_ws", ".");
     var envs = cfg.Val("proc_env", "");
     if (envs.Length > 0)
     {
         foreach (var key in Dict.parse(envs, ','))
         {
             proc.StartInfo.EnvironmentVariables.Add(key.Key, key.Value.ToString());
         }
     }
     this.AddTask(tid, proc);
     proc.Start();
     proc.OutputDataReceived += (sender, e) =>
     {
         lock (sb)
         {
             sb.Append(e.Data + "\n");
         }
     };
     proc.ErrorDataReceived += (sender, e) =>
     {
         lock (sb)
         {
             sb.Append(e.Data + "\n");
         }
     };
     proc.BeginOutputReadLine();
     proc.BeginErrorReadLine();
     proc.Exited += (sender, e) =>
     {
         try
         {
             var rargs = Util.NewDict();
             var used = Util.Now() - beg;
             var res = sb.ToString();
             if (proc.ExitCode == 0)
             {
                 L.I("DTM_C running command(\n{0}\n) by tid({1}) success, used({2}ms)->\n{3}\n", cmds, tid, used, res);
                 rargs["code"] = this.DoCmdRes(rargs, cmds, res);
             }
             else
             {
                 L.I("DTM_C running command(\n{0}\n) by tid({1}) error with exit code({2})->\n{3}\n", cmds, tid, proc.ExitCode, res);
                 rargs["code"] = proc.ExitCode;
                 rargs["err"] = String.Format("exit code is {0}", proc.ExitCode);
             }
             rargs["used"] = used;
             rargs["tid"] = tid;
             this.DelTask(tid);
             this.SendDone(rargs);
         }
         catch (Exception ex)
         {
             L.E("DTM_C running command(\n{0}\n) by tid({1}) on exit error ->\n{3}\n", cmds, tid, ex.Message);
         }
     };
     proc.EnableRaisingEvents = true;
 }
コード例 #9
0
ファイル: DocCovTest.cs プロジェクト: Centny/cswf.doc
 public void TestDoPowerPoint()
 {
     FCfg cfg = new FCfg();
     DocCovT cov = new DocCovT("DocCov", cfg);
     cov.DoCmd("a1", cfg, "PowerPoint test\\xx.pptx pptx_00-{0}.jpg");
     while (cov.done == null)
     {
         Thread.Sleep(500);
     }
     var data_ = cov.done as IDictionary<string, object>;
     var data = new Dict(data_);
     Assert.AreEqual(0, data.Val("code", -1));
     Assert.AreEqual("a1", data.Val("tid", ""));
     var res = data["data"] as CovRes;
     Assert.AreEqual(true, res.Count > 0 && res.Count == res.Files.Count);
     Assert.AreNotEqual(0, cov.rate);
     //
     cov = new DocCovT("DocCov", cfg);
     cov.DoCmd("a2", cfg, "PowerPoint test\\xx.pptxx pptxx_00-{0}.jpg 768 1024");
     while (cov.done == null)
     {
         Thread.Sleep(500);
     }
     data_ = cov.done as IDictionary<string, object>;
     data = new Dict(data_);
     Assert.AreNotEqual(0, data.Val("code", 0));
     Assert.AreEqual("a2", data.Val("tid", ""));
     var err = data["err"] as String;
     Assert.AreNotEqual(0, err.Length);
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: Centny/ffcm
        static void Main(string[] args)
        {
            var conf = "conf/ffcm_c.properties";
            if (args.Length > 0)
            {
                conf = args[0];
            }
            var cfg = new FCfg();
            cfg.Load(conf, true);
            cfg.Print();
            var addr = cfg.Val("srv_addr", "");
            if (addr.Length < 1)
            {
                Console.WriteLine("the srv_addr is not setted");
                Environment.Exit(1);
                return;
            }
            L.I("starting ffcm...");

            //Samba.
            var lambah = new LambdaEvnH();
            var ffcm = new DocCov("FFCM", cfg, new SckDailer(addr).Dail, lambah);
            var ffcmh = new FFCM(ffcm, ffcm.Srv);
            ffcm.InitConfig();
            ffcm.StartMonitor();
            ffcm.StartWindowCloser();
            ffcm.Start();
            ffcm.StartProcSrv();
            var activated = false;
            if (cfg.Val("samba", "N") == "Y")
            {
                L.I("start initial samba...");
                var samba = Samba.AddVolume2(cfg.Val("samba_vol", ""), cfg.Val("samba_uri", ""),
                    cfg.Val("samba_user", ""), cfg.Val("samba_pwd", ""),
                    cfg.Val("samba_paths", ""));
                samba.Fail = (s, e) =>
                {
                    ffcm.ChangeStatus(DTM_C.DCS_UNACTIVATED);
                    activated = false;
                };
                samba.Success = (s) =>
                {
                    if (!activated)
                    {
                        ffcm.ChangeStatus(DTM_C.DCS_ACTIVATED);
                        activated = true;
                    }
                };
                new Thread(run_samba).Start();
            }
            else
            {
                activated = true;
            }
            lambah.OnLogin = (nr, token) =>
            {
                if (activated)
                {
                    ffcm.ChangeStatus(DTM_C.DCS_ACTIVATED);
                }
            };
            lambah.EndCon = (nr) =>
            {
                ffcm.ChangeStatus(DTM_C.DCS_UNACTIVATED);
            };
            var reboot = cfg.Val("reboot", "");
            if (reboot.Length > 0)
            {
                ProcKiller.Shared.OnHavingNotKill = (c) =>
                {
                    string output;
                    Exec.exec(out output, reboot);
                };
            }
            new Thread(run_hb).Start(ffcm);
            ffcm.Wait();
        }
コード例 #11
0
ファイル: DocCov.cs プロジェクト: Centny/cswf.doc
 protected virtual void RunSupportedProc(String tid, SupportedL sp, FCfg cfg, Args args, String cmds, String src, String dst_f)
 {
     L.I("DocCov calling Supported({2}) by (\n{0}\n) by tid({1})", cmds, tid, sp);
     var beg = Util.Now();
     var rargs = Util.NewDict();
     rargs["tid"] = tid;
     try
     {
         CovProc cov = this.RunSupported(tid, sp, cfg, args, src, dst_f);
         rargs["code"] = cov.Result.Code;
         if (cov.Fails.Count > 0)
         {
             rargs["err"] = String.Format("{0} exeception found, see DocCov log for detail", cov.Fails.Count);
             L.E("DocCov calling Supported({3}) by (\n{0}\n) by tid({1}) fail with->\n{2}\n", cmds, tid, cov.ToString(), sp);
         }
         else
         {
             rargs["data"] = cov.Result;
         }
     }
     catch (Exception e)
     {
         rargs["code"] = 500;
         rargs["err"] = String.Format("{0} exeception found, see DocCov log for detail", 1);
         L.E(e, "DocCov calling Supported({3}) by (\n{0}\n) by tid({1}) fail with error->{2}", cmds, tid, e.Message, sp);
     }
     var used = Util.Now() - beg;
     rargs["used"] = used;
     try
     {
         this.SendDone(rargs);
         L.I("DocCov calling Supported({2}) success by (\n{0}\n) by tid({1})", cmds, tid, sp);
     }
     catch (Exception e)
     {
         L.E(e, "DocCov calling Supported({3}) by (\n{0}\n) by tid({1}) fail with send done err->", cmds, tid, e.Message, sp);
     }
 }
コード例 #12
0
ファイル: DTM_C_jTest.cs プロジェクト: Centny/cswf
        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...");
        }
コード例 #13
0
ファイル: DTM_C_jTest.cs プロジェクト: Centny/cswf
 public DTM_C_t(string name, FCfg cfg)
     : base(name, cfg)
 {
 }
コード例 #14
0
ファイル: DocCov.cs プロジェクト: Centny/cswf.doc
 public override void DoCmd(string tid, FCfg fcfg, string cmds)
 {
     var args = Args.parseArgs(cmds);
     String cmd;
     if (!args.StringVal(0, out cmd))
     {
         throw new ArgumentException("DocCov receive emtpy command", "cmds");
     }
     SupportedL sp = parseSupported(cmd);
     if (SupportedL.None.Equals(sp))
     {
         base.DoCmd(tid, fcfg, cmds);
     }
     else
     {
         this.RunSupported(tid, sp, fcfg, args, cmds);
     }
 }
コード例 #15
0
ファイル: DocCovTest.cs プロジェクト: Centny/cswf.doc
 public void TestNormal()
 {
     FCfg cfg = new FCfg();
     DocCovT cov = new DocCovT("DocCov", cfg);
     cov.DoCmd("a1", cfg, "test\\dtm_json.bat");
     while (cov.done == null)
     {
         Thread.Sleep(500);
     }
     var data_ = cov.done as IDictionary<string, object>;
     var data = new Dict(data_);
     Assert.AreEqual(0, data.Val("code", -1));
     Assert.AreEqual("a1", data.Val("tid", ""));
     var res = data["data"] as IDictionary<string, object>;
     Assert.AreEqual(true, res.Count > 0);
 }
コード例 #16
0
ファイル: DocCov.cs プロジェクト: Centny/cswf.doc
 protected virtual void RunSupported(String tid, SupportedL sp, FCfg cfg, Args args, String cmds)
 {
     String src, dst_f;
     if (!(args.StringVal(1, out src) && args.StringVal(2, out dst_f)))
     {
         throw new ArgumentException("Word argument is invalid, please confirm arguments using by <src dst_f maxw maxh>");
     }
     ThreadPool.QueueUserWorkItem(this.RunSupportedProc_, new object[] { tid, sp, cfg, args, cmds, src, dst_f });
 }
コード例 #17
0
ファイル: DocCovTest.cs プロジェクト: Centny/cswf.doc
            public DocCovT(string name, FCfg cfg) : base(name, cfg)
            {

            }
コード例 #18
0
ファイル: DocCov.cs プロジェクト: Centny/cswf.doc
 protected virtual CovProc RunSupported(String tid, SupportedL sp, FCfg cfg, Args args, String src, String dst_f)
 {
     CovProc cov = null;
     String prefix = "";
     int maxw, maxh;
     switch (sp)
     {
         case SupportedL.Word:
             args.IntVal(3, out maxw, 768);
             args.IntVal(4, out maxh, 1024);
             args.StringVal(5, out prefix, "");
             cov = new WordCov(src, dst_f, maxw, maxh);
             break;
         case SupportedL.Excel:
             args.IntVal(3, out maxw, 768);
             args.IntVal(4, out maxh, 1024);
             args.StringVal(5, out prefix, "");
             cov = new ExcelCov(src, dst_f, maxw, maxh, cfg.Val("density_x", 96), cfg.Val("density_y", 96));
             break;
         case SupportedL.PowerPoint:
             args.StringVal(3, out prefix, "");
             cov = new PowerPointCov(src, dst_f);
             break;
         case SupportedL.Pdf:
             args.IntVal(3, out maxw, 768);
             args.IntVal(4, out maxh, 1024);
             args.StringVal(5, out prefix, "");
             cov = new PdfCov(src, dst_f, maxw, maxh, cfg.Val("density_x", 96), cfg.Val("density_y", 96));
             break;
         case SupportedL.Img:
             args.IntVal(3, out maxw, 768);
             args.IntVal(4, out maxh, 1024);
             args.StringVal(5, out prefix, "");
             cov = new ImgCov(src, dst_f, maxw, maxh);
             break;
         default:
             throw new ArgumentException("the not supported command", "sp");
     }
     cov.State = tid;
     cov.Proc = this.OnCovProc;
     cov.ShowLog = cfg.Val("showlog", 0) == 1;
     cov.Exec();
     cov.Dispose();
     if (prefix.Length > 0)
     {
         cov.Result.Trim(prefix);
     }
     return cov;
 }
コード例 #19
0
ファイル: DocCovTest.cs プロジェクト: Centny/cswf.doc
        public void TestErr()
        {
            DocCovT cov;
            FCfg cfg = new FCfg();
            cov = new DocCovT("DocCov", cfg);
            try
            {
                cov.DoCmd("a2", cfg, "");
                Assert.Fail();
            }
            catch (Exception)
            {

            }
            cov = new DocCovT("DocCov", cfg);
            try
            {
                cov.builder();
                Assert.Fail();
            }
            catch (Exception)
            {

            }
            new DocCov("DocCov", cfg, () =>
            {
                return null;
            });
            cov = new DocCovT("DocCov", cfg);
            try
            {
                cov.DoCmd("a2", cfg, "Word");
                Assert.Fail();
            }
            catch (Exception)
            {

            }
            cov = new DocCovT("DocCov", cfg);
            try
            {
                cov.runFailSupport();
                Assert.Fail();
            }
            catch (Exception)
            {

            }
        }
コード例 #20
0
ファイル: DocCov.cs プロジェクト: Centny/cswf.doc
 public DocCov(string name, FCfg cfg, NetwRunnerV.NetwBaseBuilder builder, netw.rc.EvnListener evn = null) : base(name, cfg, builder, evn)
 {
     this.builder = builder;
 }
コード例 #21
0
ファイル: DTM_C_j.cs プロジェクト: Centny/cswf
 public DTM_C_j(string name, FCfg cfg, NetwRunnerV.NetwBaseBuilder builder, rc.EvnListener evn = null)
     : base(name, cfg, evn)
 {
     this.builder = builder;
 }