Exemplo n.º 1
0
        void loadPlans()
        {
            var plans = from e in doc.Element("Shared")?.Descendants("Plan")
                        select e;

            int planIndex = 0;

            foreach (var p in plans)
            {
                planIndex++;
                var planName     = p.Attribute("Name")?.Value;
                var startTimeout = X.getDoubleAttr(p, "StartTimeout", -1, true);

                var apps = (from e in p.Descendants("App")
                            select readAppElement(e)).ToList();

                if (string.IsNullOrEmpty(planName))
                {
                    throw new ConfigurationErrorException($"Missing plan name in plan #{planIndex}");
                }

                var groups = p.Attribute("Groups")?.Value ?? string.Empty;

                var applyOnStart = X.getBoolAttr(p, "ApplyOnStart", false, true);

                var applyOnSelect = X.getBoolAttr(p, "ApplyOnSelect", false, true);

                // check if everything is valid
                int index = 1;
                foreach (var a in apps)
                {
                    a.PlanName = planName;

                    if (string.IsNullOrEmpty(a.Id.AppId) || string.IsNullOrEmpty(a.Id.MachineId))
                    {
                        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 PlanDef()
                {
                    Name          = planName,
                    AppDefs       = apps,
                    StartTimeout  = startTimeout,
                    Groups        = groups,
                    ApplyOnStart  = applyOnStart,
                    ApplyOnSelect = applyOnSelect
                }
                    );
            }
        }
Exemplo n.º 2
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;
        }