public void FCfgLoad2Test() { var cfg = new FCfg(); cfg.Load("./test/fcfg_data.properties"); Console.WriteLine(cfg); Assert.AreEqual("b/", cfg.Val("wxk", "")); }
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); }
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", ""); }
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; }
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; }
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(); }