Exemplo n.º 1
0
        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.Send(new Net.StartPlanMessage(_ctrl.Name, planName));
                }
                else if (type.ToLower() == "LaunchApp".ToLower())
                {
                    var appIdTupleStr = X.getStringAttr(actXml, "AppIdTuple");

                    log.DebugFormat("Running action: LauchApp '{0}'", appIdTupleStr);

                    var(appIdTuple, planName) = Tools.ParseAppIdWithPlan(appIdTupleStr);

                    _ctrl.Send(new Net.StartAppMessage(_ctrl.Name, appIdTuple, planName));
                }
            }
        }
Exemplo n.º 2
0
        void loadScripts()
        {
            cfg.Scripts.Clear();

            var scripts = from e in doc.Element("Shared")?.Descendants("Script")
                          select e;

            int index = 0;

            foreach (var p in scripts)
            {
                index++;
                var id     = X.getStringAttr(p, "Name", "");
                var file   = X.getStringAttr(p, "File", "");
                var args   = X.getStringAttr(p, "Args", "");
                var groups = X.getStringAttr(p, "Groups", "");

                if (string.IsNullOrEmpty(id))
                {
                    throw new ConfigurationErrorException($"Missing script name in script #{index}");
                }

                cfg.Scripts.Add(
                    new ScriptDef()
                {
                    Id       = id,
                    FileName = file,
                    Args     = args,
                    Groups   = groups
                }
                    );
            }
        }
Exemplo n.º 3
0
        public FolderWatcher(System.Xml.Linq.XElement rootXml, IDirig ctrl, string rootForRelativePaths)
        {
            this._ctrl              = ctrl;
            this._conditions        = X.getStringAttr(rootXml, "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 '{absPath}' does not exist! FolderWatcher not installed.");
                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;
        }
Exemplo n.º 4
0
            public override void Execute(AppDef appDef, Process proc)
            {
                base.Execute(appDef, proc);

                string keys = X.getStringAttr(xel, "Keys", "", ignoreCase: true);

                #if Windows
                IntPtr h = proc.MainWindowHandle;
                SetForegroundWindow(h);
                System.Windows.Forms.SendKeys.SendWait(keys);
                #endif
            }
Exemplo n.º 5
0
        // args example: titleregexp=".*?\s-\sNotepad"
        void parseArgs(XElement xml)
        {
            _titleRegExpString = X.getStringAttr(xml, "TitleRegExp", ignoreCase: true);

            _titleRegExp = new Regex(_titleRegExpString);
        }
Exemplo n.º 6
0
        AppDef readAppElement(XElement e)
        {
            AppDef a;

            // first load templates
            var templateName = X.getStringAttr(e, "Template");

            if (!string.IsNullOrEmpty(templateName))
            {
                XElement?te = (from t in doc?.Element("Shared")?.Elements("AppTemplate")
                               where t.Attribute("Name")?.Value == templateName
                               select t).FirstOrDefault();

                if (te == null)
                {
                    // FIXME: tog that template is missing
                    var msg = String.Format("Template '{0}' not found", templateName);
                    log.ErrorFormat(msg);
                    throw new ConfigurationErrorException(msg);
                    //a = new AppDef();
                }
                else
                {
                    a = readAppElement(te);
                }
            }
            else
            {
                a = new AppDef();
            }

            // read element content into memory, apply defaults
            var x = new
            {
                Id                       = e.Attribute("AppIdTuple")?.Value,
                ExeFullPath              = e.Attribute("ExeFullPath")?.Value,
                StartupDir               = e.Attribute("StartupDir")?.Value,
                CmdLineArgs              = e.Attribute("CmdLineArgs")?.Value,
                StartupOrder             = e.Attribute("StartupOrder")?.Value,
                Disabled                 = e.Attribute("Disabled")?.Value,
                Volatile                 = e.Attribute("Volatile")?.Value,
                ReusePrevVars            = e.Attribute("ReusePrevVars")?.Value,
                LeaveRunningWithPrevVars = e.Attribute("LeaveRunningWithPrevVars")?.Value,
                RestartOnCrash           = e.Attribute("RestartOnCrash")?.Value,
                AdoptIfAlreadyRunning    = e.Attribute("AdoptIfAlreadyRunning")?.Value,
                PriorityClass            = e.Attribute("PriorityClass")?.Value,
                InitCondition            = e.Attribute("InitCondition")?.Value,
                SeparationInterval       = e.Attribute("SeparationInterval")?.Value,
                MinKillingTime           = e.Attribute("MinKillingTime")?.Value,
                Dependecies              = e.Attribute("Dependencies")?.Value,
                KillTree                 = e.Attribute("KillTree")?.Value,
                KillSoftly               = e.Attribute("KillSoftly")?.Value,
                WindowStyle              = e.Attribute("WindowStyle")?.Value,
                WindowPos                = e.Elements("WindowPos"),
                Restarter                = e.Element("Restarter"),
                SoftKill                 = e.Element("SoftKill"),
                Env                      = e.Element("Env"),
                InitDetectors            = e.Element("InitDetectors")?.Elements(),
                Groups                   = e.Attribute("Groups")?.Value,
            };

            // then overwrite templated values with current content
            if (x.Id != null)
            {
                a.Id = new AppIdTuple(x.Id);
            }
            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.ReusePrevVars != null)
            {
                a.ReusePrevVars = (int.Parse(x.ReusePrevVars) != 0);
            }
            if (x.LeaveRunningWithPrevVars != null)
            {
                a.LeaveRunningWithPrevVars = (int.Parse(x.LeaveRunningWithPrevVars) != 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.PriorityClass != null)
            {
                a.PriorityClass = x.PriorityClass;
            }
            if (x.InitCondition != null)
            {
                a.InitializedCondition = x.InitCondition;
            }
            if (x.SeparationInterval != null)
            {
                a.SeparationInterval = double.Parse(x.SeparationInterval, CultureInfo.InvariantCulture);
            }
            if (x.MinKillingTime != null)
            {
                a.MinKillingTime = double.Parse(x.MinKillingTime, 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) != 0);
            }

            if (x.WindowStyle != null)
            {
                if (x.WindowStyle.ToLower() == "minimized")
                {
                    a.WindowStyle = EWindowStyle.Minimized;
                }
                else if (x.WindowStyle.ToLower() == "maximized")
                {
                    a.WindowStyle = EWindowStyle.Maximized;
                }
                else if (x.WindowStyle.ToLower() == "normal")
                {
                    a.WindowStyle = EWindowStyle.Normal;
                }
                else if (x.WindowStyle.ToLower() == "hidden")
                {
                    a.WindowStyle = EWindowStyle.Hidden;
                }
            }

            if (x.WindowPos != null)
            {
                foreach (var elem in x.WindowPos)
                {
                    a.WindowPosXml.Add(elem.ToString());
                }
            }

            if (x.Restarter != null)
            {
                a.RestarterXml = x.Restarter.ToString();
            }

            if (x.SoftKill != null)
            {
                a.SoftKillXml = x.SoftKill.ToString();
            }

            if (x.Env != null)
            {
                foreach (var elem in x.Env.Descendants())
                {
                    if (elem.Name == "Set")
                    {
                        // add/overwite variable
                        var variable = elem.Attribute("Variable")?.Value;
                        var value    = elem.Attribute("Value")?.Value;

                        if (!string.IsNullOrEmpty(variable) && value != null)
                        {
                            a.EnvVarsToSet[variable] = value;
                        }
                    }

                    if (elem.Name == "Local")
                    {
                        // add/overwite variable
                        var variable = elem.Attribute("Variable")?.Value;
                        var value    = elem.Attribute("Value")?.Value;

                        if (!string.IsNullOrEmpty(variable) && value != null)
                        {
                            a.LocalVarsToSet[variable] = value;
                        }
                    }

                    if (elem.Name == "Path")
                    {
                        // extend
                        var toAppend = elem.Attribute("Append")?.Value;
                        if (!string.IsNullOrEmpty(toAppend))
                        {
                            if (String.IsNullOrEmpty(a.EnvVarPathToAppend))
                            {
                                a.EnvVarPathToAppend = toAppend;
                            }
                            else
                            {
                                a.EnvVarPathToAppend = a.EnvVarPathToAppend + ";" + toAppend;
                            }
                        }

                        var toPrepend = elem.Attribute("Prepend")?.Value;
                        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());
                }
            }

            if (!string.IsNullOrWhiteSpace(x.Groups))
            {
                if (!string.IsNullOrEmpty(a.Groups))
                {
                    a.Groups += ";";
                }
                a.Groups += x.Groups;
            }

            return(a);
        }