void RunActions() { // all actions from XML foreach (var actXml in actionXmls) { var type = X.getStringAttr(actXml, "Type"); if (type.ToLower() == "StartPlan".ToLower()) { var planName = X.getStringAttr(actXml, "PlanName"); log.DebugFormat("Running action: StartPlan '{0}'", planName); ctrl.StartPlan(planName); } else if (type.ToLower() == "LaunchApp".ToLower()) { var appIdTupleStr = X.getStringAttr(actXml, "AppIdTuple"); log.DebugFormat("Running action: LauchApp '{0}'", appIdTupleStr); var appIdTuple = new Common.AppIdTuple(appIdTupleStr); ctrl.LaunchApp(appIdTuple); } } }
// args example: titleregexp=".*?\s-\sNotepad" void parseArgs(XElement xml) { if (xml != null) { titleRegExpString = X.getStringAttr(xml, "TitleRegExp", null, ignoreCase: true); titleRegExp = new Regex(titleRegExpString); } }
public FolderWatcher(System.Xml.Linq.XElement rootXml, IDirigentControl ctrl, string rootForRelativePaths) { this.ctrl = ctrl; this.conditions = (string)rootXml.Attribute("Conditions"); this.RelativePathsRoot = rootForRelativePaths; if (String.IsNullOrEmpty(rootForRelativePaths)) { RelativePathsRoot = System.IO.Directory.GetCurrentDirectory(); } else { RelativePathsRoot = rootForRelativePaths; } var inclSubdirs = X.getBoolAttr(rootXml, "IncludeSubdirs"); var path = X.getStringAttr(rootXml, "Path"); var filter = X.getStringAttr(rootXml, "Filter"); if (String.IsNullOrEmpty(path)) { log.Error("Path not defined or empty!"); return; } var absPath = BuildAbsolutePath(path); if (!System.IO.Directory.Exists(absPath)) { log.Error("Path does not exist!"); return; } watcher.Path = absPath; watcher.IncludeSubdirectories = inclSubdirs; if (!String.IsNullOrEmpty(filter)) { watcher.Filter = filter; } if (conditions == "NewFile") { watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.CreationTime | NotifyFilters.LastWrite; watcher.Created += new FileSystemEventHandler(OnFileCreated); } foreach (var actXml in rootXml.Descendants("Action")) { actionXmls.Add(actXml); } log.DebugFormat("FolderWatcher initialized. Path={0}, Filter={1}, Conditions={2}", watcher.Path, watcher.Filter, conditions); Initialized = true; watcher.EnableRaisingEvents = true; }
// <WindowPos titleregexp=".*?\s-\sNotepad" rect="10,50,300,200" screen="1" keep="1" /> void parseXml(XElement xml) { pos = new WindowPos(); if (xml != null) { var xrect = X.Attribute(xml, "Rect", true); if (xrect != null) { var myRegex = new Regex(@"\s*(-?\d+)\s*,\s*(-?\d+)\s*,\s*(-?\d+)\s*,\s*(-?\d+)\s*"); var m = myRegex.Match((string)xrect); if (m != null && m.Success) { pos.Rect = new System.Drawing.Rectangle( int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value), int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value) ); } } pos.Screen = X.getIntAttr(xml, "Screen", 0, ignoreCase: true); pos.TitleRegExp = X.getStringAttr(xml, "TitleRegExp", null, ignoreCase: true); pos.Keep = X.getBoolAttr(xml, "Keep", false, ignoreCase: true); pos.Topmost = X.getBoolAttr(xml, "TopMost", false, ignoreCase: true); pos.BringToFront = X.getBoolAttr(xml, "BringToFront", false, ignoreCase: true); pos.SendToBack = X.getBoolAttr(xml, "SendToBack", false, ignoreCase: true); //pos.SetFocus = X.getBoolAttr(xml, "SetFocus", false, ignoreCase:true); string wsstr = X.getStringAttr(xml, "WindowStyle", null, ignoreCase: true); if (wsstr != null) { if (wsstr.ToLower() == "minimized") { pos.WindowStyle = EWindowStyle.Minimized; } else if (wsstr.ToLower() == "maximized") { pos.WindowStyle = EWindowStyle.Maximized; } else if (wsstr.ToLower() == "normal") { pos.WindowStyle = EWindowStyle.Normal; } else if (wsstr.ToLower() == "hidden") { pos.WindowStyle = EWindowStyle.Hidden; } } } }
void loadPlans() { var plans = from e in doc.Element("Shared").Descendants("Plan") select e; foreach (var p in plans) { var planName = (string)p.Attribute("Name"); var startTimeout = X.getDoubleAttr(p, "StartTimeout", -1, true); var apps = (from e in p.Descendants("App") select readAppElement(e)).ToList(); // check if everything is valid int index = 1; foreach (var a in apps) { if (a.AppIdTuple == null) { throw new ConfigurationErrorException(string.Format("App #{0} in plan '{1}' not having valid AppTupleId", index, planName)); } if (a.ExeFullPath == null) { throw new ConfigurationErrorException(string.Format("App #{0} in plan '{1}' not having valid ExeFullPath", index, planName)); } index++; } cfg.Plans.Add( new LaunchPlan( planName, apps, startTimeout ) ); } }
AppDef readAppElement(XElement e) { AppDef a; // first load templates var templateName = X.getStringAttr(e, "Template"); if (templateName != "") { XElement te = (from t in doc.Element("Shared").Elements("AppTemplate") where (string)t.Attribute("Name") == templateName select t).First(); a = readAppElement(te); } else { a = new AppDef(); } // read element content into memory, apply defaults var x = new { AppIdTuple = (string)e.Attribute("AppIdTuple"), ExeFullPath = (string)e.Attribute("ExeFullPath"), StartupDir = (string)e.Attribute("StartupDir"), CmdLineArgs = (string)e.Attribute("CmdLineArgs"), StartupOrder = (string)e.Attribute("StartupOrder"), Disabled = (string)e.Attribute("Disabled"), Volatile = (string)e.Attribute("Volatile"), RestartOnCrash = (string)e.Attribute("RestartOnCrash"), AdoptIfAlreadyRunning = (string)e.Attribute("AdoptIfAlreadyRunning"), InitCondition = (string)e.Attribute("InitCondition"), SeparationInterval = (string)e.Attribute("SeparationInterval"), Dependecies = (string)e.Attribute("Dependencies"), KillTree = (string)e.Attribute("KillTree"), KillSoftly = (string)e.Attribute("KillSoftly"), WindowStyle = (string)e.Attribute("WindowStyle"), WindowPos = e.Elements("WindowPos"), Env = e.Element("Env"), InitDetectors = e.Element("InitDetectors") != null?e.Element("InitDetectors").Elements() : null, }; // then overwrite templated values with current content if (x.AppIdTuple != null) { a.AppIdTuple = new AppIdTuple(x.AppIdTuple); } if (x.ExeFullPath != null) { a.ExeFullPath = x.ExeFullPath; } if (x.StartupDir != null) { a.StartupDir = x.StartupDir; } if (x.CmdLineArgs != null) { a.CmdLineArgs = x.CmdLineArgs; } if (x.StartupOrder != null) { a.StartupOrder = int.Parse(x.StartupOrder); } if (x.Disabled != null) { a.Disabled = (int.Parse(x.Disabled) != 0); } if (x.Volatile != null) { a.Volatile = (int.Parse(x.Volatile) != 0); } if (x.RestartOnCrash != null) { a.RestartOnCrash = (int.Parse(x.RestartOnCrash) != 0); } if (x.AdoptIfAlreadyRunning != null) { a.AdoptIfAlreadyRunning = (int.Parse(x.AdoptIfAlreadyRunning) != 0); } if (x.InitCondition != null) { a.InitializedCondition = x.InitCondition; } if (x.SeparationInterval != null) { a.SeparationInterval = double.Parse(x.SeparationInterval, CultureInfo.InvariantCulture); } if (x.Dependecies != null) { var deps = new List <string>(); foreach (var d in x.Dependecies.Split(';')) { var stripped = d.Trim(); if (stripped != "") { deps.Add(d); } } a.Dependencies = deps; } if (x.KillTree != null) { a.KillTree = (int.Parse(x.KillTree) != 0); } if (!String.IsNullOrEmpty(x.KillSoftly)) { a.KillSoftly = (int.Parse(x.KillSoftly) == 1); } if (x.WindowStyle != null) { if (x.WindowStyle.ToLower() == "minimized") { a.WindowStyle = ProcessWindowStyle.Minimized; } else if (x.WindowStyle.ToLower() == "maximized") { a.WindowStyle = ProcessWindowStyle.Maximized; } else if (x.WindowStyle.ToLower() == "normal") { a.WindowStyle = ProcessWindowStyle.Normal; } else if (x.WindowStyle.ToLower() == "hidden") { a.WindowStyle = ProcessWindowStyle.Hidden; } } if (x.WindowPos != null) { foreach (var elem in x.WindowPos) { a.WindowPosXml.Add(elem.ToString()); } } if (x.Env != null) { foreach (var elem in x.Env.Descendants()) { if (elem.Name == "Set") { // add/overwite variable var variable = (string)elem.Attribute("Variable"); var value = (string)elem.Attribute("Value"); a.EnvVarsToSet[variable] = value; } if (elem.Name == "Path") { // extend var toAppend = (string)elem.Attribute("Append"); if (!string.IsNullOrEmpty(toAppend)) { if (String.IsNullOrEmpty(a.EnvVarPathToAppend)) { a.EnvVarPathToAppend = toAppend; } else { a.EnvVarPathToAppend = a.EnvVarPathToAppend + ";" + toAppend; } } var toPrepend = (string)elem.Attribute("Prepend"); if (!string.IsNullOrEmpty(toPrepend)) { if (String.IsNullOrEmpty(a.EnvVarPathToPrepend)) { a.EnvVarPathToPrepend = toPrepend; } else { a.EnvVarPathToPrepend = toPrepend + ";" + a.EnvVarPathToPrepend; } } } } } if (x.InitDetectors != null) { foreach (var elem in x.InitDetectors) { a.InitDetectors.Add(elem.ToString()); } } return(a); }