예제 #1
0
        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;
                    }
                }
            }
        }