コード例 #1
0
 private void OnChanged(object sender, FileSystemEventArgs e)
 {
     try
     {
         if (!string.IsNullOrEmpty(WatchFilter) && (WatchFilter.Contains(",") || WatchFilter.Contains("|")))
         {
             bool cont  = false;
             var  array = WatchFilter.Split(new Char[] { ',', '|' });
             foreach (var ext in array)
             {
                 if (PatternMatcher.FitsMask(e.FullPath, ext))
                 {
                     cont = true;
                 }
             }
             if (!cont)
             {
                 return;
             }
         }
         TimeSpan timepassed = DateTime.Now - lastTriggered;
         if (timepassed.Milliseconds < 100)
         {
             return;
         }
         lastTriggered = DateTime.Now;
         var _e = new DetectorEvent(e.FullPath);
         OnDetector?.Invoke(this, _e, EventArgs.Empty);
     }
     catch (Exception ex)
     {
         Log.Error(ex.ToString());
     }
 }
コード例 #2
0
        protected bool IsWatchFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            return(Path.GetExtension(filePath).Equals(WatchFilter.Replace("*", string.Empty), StringComparison.CurrentCultureIgnoreCase));
        }
コード例 #3
0
        protected virtual void HandleFileEvent(object sender, FileSystemEventArgs e)
        {
            if (File.Exists(e.FullPath) == true)
            {
                string[] filterItems = WatchFilter.Split('*');
                string   targetName  = Path.GetFileNameWithoutExtension(e.Name);
                string   devCssText  = ReadAllTextFromFile(e.FullPath);

                if (filterItems.Length > 0 && targetName.StartsWith(filterItems[0], StringComparison.CurrentCultureIgnoreCase))
                {
                    targetName = targetName.Substring(filterItems[0].Length);
                }

                string targetFilePath = Path.Combine(TargetPath, $"{targetName}{TargetExt}");
                string cssText        = TranslateDevCssToCss(devCssText);

                File.WriteAllText(targetFilePath, cssText, Encoding.UTF8);
            }
        }
コード例 #4
0
        public void Start()
        {
            try
            {
                watcher.Path         = Watchpath;
                watcher.NotifyFilter = NotifyFilters.LastWrite;
                if (!string.IsNullOrEmpty(WatchFilter) && (WatchFilter.Contains(",") || WatchFilter.Contains("|")))
                {
                    watcher.Filter = "*";
                }
                else
                {
                    watcher.Filter = WatchFilter;
                }

                watcher.Changed              += new FileSystemEventHandler(OnChanged);
                watcher.EnableRaisingEvents   = true;
                watcher.IncludeSubdirectories = IncludeSubdirectories;
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
コード例 #5
0
 public static bool GetDirectoryChanges(IntPtr handle, byte[] buffer, bool watchSubdirectories, WatchFilter filters, out uint bytesReturned, ref AsyncInfo info)
 {
     return(GetDirectoryChanges(handle, buffer, (uint)buffer.Length, watchSubdirectories, filters, out bytesReturned, ref info, IntPtr.Zero));
 }
コード例 #6
0
 private static extern bool GetDirectoryChanges(IntPtr handle, byte[] buffer, uint bufferLength, bool watchSubdirectories, WatchFilter filters, out uint bytesReturned, ref AsyncInfo asyncInfo, IntPtr asyncDoneRoutine);
コード例 #7
0
 public static extern IntPtr WatchDirectory(string directoryPath, bool watchSubdirectories, WatchFilter filters);