Exemplo n.º 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());
     }
 }
Exemplo n.º 2
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);
            }
        }