当前位置: 首页>>代码示例>>C#>>正文


C# IO.FileSystemWatcher类代码示例

本文整理汇总了C#中System.IO.FileSystemWatcher的典型用法代码示例。如果您正苦于以下问题:C# FileSystemWatcher类的具体用法?C# FileSystemWatcher怎么用?C# FileSystemWatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FileSystemWatcher类属于System.IO命名空间,在下文中一共展示了FileSystemWatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TemplateFile

        public TemplateFile(string templatePath, TransformationData data)
        {
            this.nonDynamicHTMLOutput = data.NonDynamicHTMLOutput;
            this.publishFlags = data.Markdown.PublishFlags;
            ParsedTemplate = null;

            if (string.IsNullOrWhiteSpace(templatePath))
            {
                throw new System.ArgumentException("Template path should be valid path.");
            }

            ReparseTemplate(templatePath);

            var templatePathDir = Path.GetDirectoryName(templatePath);
            var templatePathFileName = Path.GetFileName(templatePath);

            if (templatePathDir != null && templatePathFileName != null)
            {
                fileWatcher = new FileSystemWatcher(templatePathDir, templatePathFileName)
                    {
                        EnableRaisingEvents = true
                    };

                fileWatcher.Changed += (sender, args) =>
                    {
                        ReparseTemplate(templatePath);
                        if (TemplateChanged != null)
                        {
                            TemplateChanged();
                        }
                    };
            }
        }
开发者ID:Art1stical,项目名称:AHRUnrealEngine,代码行数:33,代码来源:Templates.cs

示例2: InputTranParser

        public InputTranParser(LuaFixTransactionMessageAdapter transAdapter, FixMessageAdapter messAdapter, List<Security> securities)
        {
            _transAdapter = transAdapter;
            _messAdapter = messAdapter;
            _securities = securities;

            _watcher = new FileSystemWatcher(_tranFilePath, "*.tri");

            _tranKeys = new List<TransactionKey>
            {
                new TransIdKey(),
                new AccountKey(),
                new ClientCodeKey(),
                new ClassCodeKey(),
                new SecCodeKey(),
                new ActionKey(),
                new OperationKey(),
                new PriceKey(),
                new StopPriceKey(),
                new QuantityKey(),
                new TypeKey(),
                new OrderKeyKey(),
                new OriginalTransIdKey(),
                new CommentKey()
            };
        }
开发者ID:RakotVT,项目名称:StockSharp,代码行数:26,代码来源:InputTranParser.cs

示例3: FileWatcher

 public FileWatcher(bool initDirvers, bool subDirector, bool throwException)
 {
     try
     {
         if (initDirvers)
         {
             foreach (DriveInfo di in DriveInfo.GetDrives())
             {
                 try
                 {
                     FileSystemWatcher fsw = new FileSystemWatcher();
                     fsw.Path = di.Name;
                     fsw.IncludeSubdirectories = subDirector;
                     fsw.Changed += new FileSystemEventHandler(fsw_Changed);
                     fsw.Created += new FileSystemEventHandler(fsw_Created);
                     fsw.Deleted += new FileSystemEventHandler(fsw_Deleted);
                     fsw.Renamed += new RenamedEventHandler(fsw_Renamed);
                     _watcherArr.Add(fsw);
                 }
                 catch { if (throwException) throw new Exception(di.Name + "�̷���ʧ�ܣ�"); }
             }
         }
     }
     catch (Exception e) { MessageBox.Show(e.Message); MessageBox.Show(e.ToString()); }
 }
开发者ID:wykoooo,项目名称:copy-dotnet-library,代码行数:25,代码来源:FileWatcher.cs

示例4: StartListening

        public void StartListening(string directory, string filter, Func<string, Task> updated)
        {
            _fileSystemWatcher?.Dispose();

            _fileSystemWatcher = new FileSystemWatcher(directory, filter)
            {
                EnableRaisingEvents = true,
                IncludeSubdirectories = true
            };

            _fileSystemWatcher.Created += async (sender, eventArgs) =>
            {
                await updated(eventArgs.FullPath).ConfigureAwait(false);
            };

            _fileSystemWatcher.Changed += async (sender, eventArgs) =>
            {
                await updated(eventArgs.FullPath).ConfigureAwait(false);
            };

            _fileSystemWatcher.Deleted += async (sender, eventArgs) =>
            {
                await updated(eventArgs.FullPath).ConfigureAwait(false);
            };

            _fileSystemWatcher.Renamed += async (sender, eventArgs) =>
            {
                await updated(eventArgs.FullPath).ConfigureAwait(false);
            };
        }
开发者ID:SuperGlueFx,项目名称:SuperGlue.CommandLine,代码行数:30,代码来源:FileListener.cs

示例5: StartWatch

 internal void StartWatch()
 {
     m_FileWatcher = new FileSystemWatcher();
     m_FileWatcher.Path =this.sourceFolder;
     m_FileWatcher.Created += new FileSystemEventHandler(FileWatcher_Created);
     m_FileWatcher.EnableRaisingEvents = true;
 }
开发者ID:micro-potato,项目名称:mwc2015Hall1,代码行数:7,代码来源:FileManager.cs

示例6: Run

        public override void Run(IBuildContext context)
        {
            Context = context;
            Context.IsAborted = true;

            var include = context.Configuration.GetString(Constants.Configuration.WatchProjectInclude, "**");
            var exclude = context.Configuration.GetString(Constants.Configuration.WatchProjectExclude, "**");
            _pathMatcher = new PathMatcher(include, exclude);

            _publishDatabase = context.Configuration.GetBool(Constants.Configuration.WatchProjectPublishDatabase, true);

            _fileWatcher = new FileSystemWatcher(context.ProjectDirectory)
            {
                IncludeSubdirectories = true,
                NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName
            };

            _fileWatcher.Changed += FileChanged;
            _fileWatcher.Deleted += FileChanged;
            _fileWatcher.Renamed += FileChanged;
            _fileWatcher.Created += FileChanged;
            _fileWatcher.Created += FileChanged;

            _fileWatcher.EnableRaisingEvents = true;

            Console.WriteLine(Texts.Type__q__to_quit___);

            string input;
            do
            {
                input = Console.ReadLine();
            }
            while (!string.Equals(input, "q", StringComparison.OrdinalIgnoreCase));
        }
开发者ID:pveller,项目名称:Sitecore.Pathfinder,代码行数:34,代码来源:WatchProject.cs

示例7: XmlHotDocument

 // ************************************************
 // Class constructor
 public XmlHotDocument()
     : base()
 {
     m_watcher = new FileSystemWatcher();
     HasChanges = false;
     EnableFileChanges = false;
 }
开发者ID:rjgodia30,项目名称:bcit-courses,代码行数:9,代码来源:XMLHotDocument.cs

示例8: ViewLabels

        public ViewLabels()
        {
            _labelTemplateManager = FirstFloor.ModernUI.App.App.Container.GetInstance<ILabelTemplateManager>();
            _labelManager = FirstFloor.ModernUI.App.App.Container.GetInstance<ILabelManager>();
            _bitmapGenerator = FirstFloor.ModernUI.App.App.Container.GetInstance<IBitmapGenerator>();
            _fileManager = FirstFloor.ModernUI.App.App.Container.GetInstance<IFileManager>();

            _labelLocation = new CommandLineArgs()["location"];
            LabelImages = new ObservableCollection<DisplayLabel>();
     
            InitializeComponent();

            DataContext = this;

            var configDirectory = [email protected]"{AppDomain.CurrentDomain.BaseDirectory}\Config\";
            if (_fileManager.CheckDirectoryExists(configDirectory))
            {
                _fsWatcher = new FileSystemWatcher
                {
                    NotifyFilter = NotifyFilters.LastWrite,
                    Path = configDirectory,
                    Filter = "labels.json",
                    EnableRaisingEvents = true
                };
                _fsWatcher.Changed += FsWatcherOnChanged;

                GetImages();
            }
            else
            {
                ModernDialog.ShowMessage($"An error occurred. The '{configDirectory}' directory could not be found.", "Error", MessageBoxButton.OK, Window.GetWindow(this));

            }
            
        }
开发者ID:christopherwithers,项目名称:LabelPrinter,代码行数:35,代码来源:ViewLabels.xaml.cs

示例9: SingleFileWatcher

        public SingleFileWatcher(ToolStrip ui, string path, SingleFileWathcerChangedHandler callback)
        {
            singleFileWathcerChangedHandler = callback;

            delex = new DelayExecuter(1000, delegate() { singleFileWathcerChangedHandler(); });

            watcher = new System.IO.FileSystemWatcher();
            //監視するディレクトリを指定
            watcher.Path = Path.GetDirectoryName(path);
            //監視するファイルを指定
            watcher.Filter = Path.GetFileName(path);
            //最終更新日時、ファイルサイズの変更を監視する
            watcher.NotifyFilter =
                (System.IO.NotifyFilters.Size
                |System.IO.NotifyFilters.LastWrite);
            //UIのスレッドにマーシャリングする
            watcher.SynchronizingObject = ui;

            //イベントハンドラの追加
            watcher.Changed += new System.IO.FileSystemEventHandler(watcherChanged);
            watcher.Created += new System.IO.FileSystemEventHandler(watcherChanged);

            //監視を開始する
            watcher.EnableRaisingEvents = true;
        }
开发者ID:Dsnoi,项目名称:flashdevelopjp,代码行数:25,代码来源:SingleFileWatcher.cs

示例10: Form1

        public Form1()
        {
            InitializeComponent();
            //初始化得到配置文件中的SVN内网外网CheckOut地址
            string SVN_W = AppSettings.GetValue("SVN_W");
            string SVN_N = AppSettings.GetValue("SVN_N");
            string SVN_TIME = AppSettings.GetValue("SVN_TIME");
            string SlEEP_TIME = AppSettings.GetValue("SlEEP_TIME");

            textBox1.Text = SVN_W;
            textBox2.Text = SVN_N;
            textBox3.Text = SlEEP_TIME;
            textBox4.Text = SVN_TIME;
            //定时器打开
            InitalizeTimer();
            //监视外网文件
            this.watcher_W = new FileSystemWatcher();
            this.watcher_W.Deleted += new FileSystemEventHandler(watcher_Deleted);
            this.watcher_W.Renamed += new RenamedEventHandler(watcher_Renamed);
            this.watcher_W.Changed += new FileSystemEventHandler(watcher_Changed);
            this.watcher_W.Created += new FileSystemEventHandler(watcher_Created);
            //监视内网仓库
            this.watcher_N = new FileSystemWatcher();
            this.watcher_N.Deleted += new FileSystemEventHandler(watcher_Deleted_N);
            this.watcher_N.Renamed += new RenamedEventHandler(watcher_Renamed_N);
            this.watcher_N.Changed += new FileSystemEventHandler(watcher_Changed_N);
            this.watcher_N.Created += new FileSystemEventHandler(watcher_Created_N);
        }
开发者ID:305088020,项目名称:-SVN,代码行数:28,代码来源:Form1.cs

示例11: Run

        private static void Run()
        {
            try
            {
                // Check is valid directory
                if(string.IsNullOrEmpty(BaseConfig.Watcher.Path) && !Directory.Exists(BaseConfig.Watcher.Path))
                {
                    Console.WriteLine("Invalid directory. Please check configuration.");
                    return;
                }

                // Create watcher
                FileSystemWatcher watcher = new FileSystemWatcher()
                {
                    Path = BaseConfig.Watcher.Path,
                    NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName,
                    Filter = BaseConfig.Watcher.Filter,
                    EnableRaisingEvents = true,
                };

                // Add event handlers.
                watcher.Changed += new FileSystemEventHandler(OnChanged);
                watcher.Created += new FileSystemEventHandler(OnChanged);
                watcher.Deleted += new FileSystemEventHandler(OnChanged);
                watcher.Renamed += new RenamedEventHandler(OnRenamed);

                // Wait for the user to quit the program.
                Console.WriteLine("Press \'q\' to quit the sample.");
                while (Console.Read() != 'q') ;
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
开发者ID:linosousa86,项目名称:Projects,代码行数:35,代码来源:Program.cs

示例12: Close

		public override void Close ()
		{
			if (file_watcher != null) {
				file_watcher.EnableRaisingEvents = false;
				file_watcher = null; // force creation of new FileSystemWatcher
			}
		}
开发者ID:Xipas,项目名称:Symplified.Auth,代码行数:7,代码来源:LocalFileEventLog.cs

示例13: DummyDoc

        public DummyDoc()
        {
            InitializeComponent();

			Global.myDebug("after InitializeComponent()");

			#region MarkdownWin
			// MarkdownWin *21
			browser.DocumentCompleted += browser_DocumentCompleted;
			// browser.PreviewKeyDown += browser_PreviewKeyDown;
			browser.AllowWebBrowserDrop = false;
			// browser.IsWebBrowserContextMenuEnabled = false;		// ContextMenu Enabled
			//browser.WebBrowserShortcutsEnabled = false;			// Shortcuts Enabled
			//browser.AllowNavigation = false;
			browser.ScriptErrorsSuppressed = true;

			browser.StatusTextChanged += browser_StatusTextChange; // new DWebBrowserEvents2_StatusTextChangeEventHandler(AxWebBrowser_StatusTextChange)

			_fileWatcher = new FileSystemWatcher();		// need assign in Class constructor
			_fileWatcher.NotifyFilter = NotifyFilters.Size |  NotifyFilters.LastWrite;
			_fileWatcher.Changed += new FileSystemEventHandler(OnWatchedFileChanged);
			bgRefreshWorker.RunWorkerAsync();

			this.Disposed += new EventHandler(Watcher_Disposed);
			browser.AllowWebBrowserDrop = false;

			#endregion
		}
开发者ID:beZong,项目名称:bZmd,代码行数:28,代码来源:DummyDoc.cs

示例14: Init

 public static void Init()
 {
     watcher = new FileSystemWatcher(Folder.GetWatcherPath());
     watcher.IncludeSubdirectories = false;
     watcher.Created += new FileSystemEventHandler(OnCreate);
     watcher.EnableRaisingEvents = true;
 }
开发者ID:nikkw,项目名称:W2C,代码行数:7,代码来源:Watcher.cs

示例15: StartFileWatcher

        private void StartFileWatcher()
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.InfoFormat("BEGIN: {0}()", methodName);
            try
            {
                var configurationFileDirectory = new FileInfo(Configuration.FilePath).Directory;
                string fileName = Path.GetFileName(Configuration.FilePath);

                logger.InfoFormat("Monitor Configuration path:{0} file:{1}", configurationFileDirectory.FullName, fileName);
                _fileWatcher = new FileSystemWatcher(configurationFileDirectory.FullName);
                _fileWatcher.Filter = fileName;
                _fileWatcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite;
                _fileWatcher.Changed += ConfigFileWatcherOnChanged;
                _fileWatcher.EnableRaisingEvents = true;
            }
            catch (Exception e)
            {
                logger.Error(methodName, e);
            }
            finally
            {
                logger.InfoFormat("END: {0}()", methodName);
            }
        }
开发者ID:wra222,项目名称:testgit,代码行数:25,代码来源:WatchConfigFile.cs


注:本文中的System.IO.FileSystemWatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。