• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IO.FileSystemWatcher类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: FileWatcher

        public FileWatcher(string path, string[] filter)
        {
            if (filter == null || filter.Length == 0)
            {
                FileSystemWatcher mWather = new FileSystemWatcher(path);
                mWather.Changed += new FileSystemEventHandler(fileSystemWatcher_Changed);
                mWather.Deleted += new FileSystemEventHandler(fileSystemWatcher_Changed);
                mWather.Created += new FileSystemEventHandler(fileSystemWatcher_Changed);
                mWather.EnableRaisingEvents = true;
                mWather.IncludeSubdirectories = false;
                mWathers.Add(mWather);
            }
            else
            {
                foreach (string item in filter)
                {
                    FileSystemWatcher mWather = new FileSystemWatcher(path, item);
                    mWather.Changed += new FileSystemEventHandler(fileSystemWatcher_Changed);
                    mWather.Deleted += new FileSystemEventHandler(fileSystemWatcher_Changed);
                    mWather.Created += new FileSystemEventHandler(fileSystemWatcher_Changed);
                    mWather.EnableRaisingEvents = true;
                    mWather.IncludeSubdirectories = false;
                    mWathers.Add(mWather);
                }
            }
            mTimer = new System.Threading.Timer(OnDetect, null, 5000, 5000);

        }
开发者ID:hdxhan,项目名称:IKendeLib,代码行数:28,代码来源:FileWatcher.cs


示例17: WillReindexAfterCrashing

        public async Task WillReindexAfterCrashing(string storage)
        {
            int port = 9999;
            var filesystem = Path.GetRandomFileName();
            var nameof = "WillReindexAfterCrashing-" + DateTime.Now.Ticks;

            string dataDirectoryPath;
            using (var server = CreateServer(port, dataDirectory: nameof, runInMemory: false, requestedStorage: storage))
            {
                dataDirectoryPath = server.Configuration.DataDirectory;

                var store = server.FilesStore;
                await store.AsyncFilesCommands.Admin.EnsureFileSystemExistsAsync(filesystem);

                using (var session = store.OpenAsyncSession(filesystem))
                {
                    session.RegisterUpload("test1.file", CreateUniformFileStream(128));
                    session.RegisterUpload("test2.file", CreateUniformFileStream(128));
                    session.RegisterUpload("test3.file.deleting", CreateUniformFileStream(128));
                    await session.SaveChangesAsync();
                }
            }

            // Simulate a rude shutdown.
            var filesystemDirectoryPath = Path.Combine(dataDirectoryPath, "FileSystems");
            var crashMarkerPath = Path.Combine(filesystemDirectoryPath, filesystem, "indexing.crash-marker");
            using (var file = File.Create(crashMarkerPath)) { };
            var writingMarkerPath = Path.Combine(filesystemDirectoryPath, filesystem, "Indexes", "writing-to-index.lock");
            using (var file = File.Create(writingMarkerPath)) { };

            bool changed = false;

            // Ensure the index has been reseted.            
            var watcher = new FileSystemWatcher(Path.Combine(filesystemDirectoryPath, filesystem));
            watcher.IncludeSubdirectories = true;
            watcher.Deleted += (sender, args) => changed = true;
            watcher.EnableRaisingEvents = true;

            using (var server = CreateServer(port, dataDirectory: nameof, runInMemory: false, requestedStorage: storage))
            {
                var store = server.FilesStore;

                using (var session = store.OpenAsyncSession(filesystem))
                {
                    // Ensure the files are there.
                    var file1 = await session.LoadFileAsync("test1.file");
                    Assert.NotNull(file1);

                    // Ensure the files are indexed.
                    var query = await session.Query()
                                             .WhereStartsWith(x => x.Name, "test")
                                             .ToListAsync();

                    Assert.True(query.Any());
                    Assert.Equal(2, query.Count());
                }
            }

            Assert.True(changed);
        }
开发者ID:felipeleusin,项目名称:ravendb,代码行数:60,代码来源:SearchIndexes.cs


示例18: ScriptManager

        public ScriptManager()
        {
            LoadScripts();

            watcher = new FileSystemWatcher(Config.GetValue(ConfigSections.DEV, ConfigValues.SCRIPT_LOCATION))
                          {
                              NotifyFilter =
                                  NotifyFilters
                                      .LastAccess
                                  | NotifyFilters
                                        .LastWrite
                                  | NotifyFilters
                                        .FileName
                                  | NotifyFilters
                                        .DirectoryName,
                              Filter =
                                  "*.cs"
                          };

            watcher.Changed += ReloadScript;
            watcher.Created += LoadScript;
            watcher.Renamed += LoadScript;
            watcher.Deleted += UnloadScript;

            watcher.EnableRaisingEvents = true;
        }
开发者ID:Refuge89,项目名称:Vanilla,代码行数:26,代码来源:ScriptManager.cs


示例19: Setup

        public void Setup(int delay, System.Collections.IList assemblies)
#endif
		{
            log.Info("Setting up watcher");

			files = new FileInfo[assemblies.Count];
			fileWatchers = new FileSystemWatcher[assemblies.Count];

			for (int i = 0; i < assemblies.Count; i++)
			{
                log.Debug("Setting up FileSystemWatcher for {0}", assemblies[i]);
                
				files[i] = new FileInfo((string)assemblies[i]);

				fileWatchers[i] = new FileSystemWatcher();
				fileWatchers[i].Path = files[i].DirectoryName;
				fileWatchers[i].Filter = files[i].Name;
				fileWatchers[i].NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite;
				fileWatchers[i].Changed += new FileSystemEventHandler(OnChanged);
				fileWatchers[i].EnableRaisingEvents = false;
			}

			timer = new System.Timers.Timer(delay);
			timer.AutoReset = false;
			timer.Enabled = false;
			timer.Elapsed += new ElapsedEventHandler(OnTimer);
		}
开发者ID:rmterra,项目名称:AutoTest.Net,代码行数:27,代码来源:AssemblyWatcher.cs


示例20: Main

        static void Main(string[] args)
        {
            FileSystemWatcher watcher = new FileSystemWatcher();
            try
            {
                watcher.Path = @"C:\_test\photos\";
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            watcher.Filter = "*.txt";
            watcher.Created += (source, e) => Console.WriteLine("{0} -- {1}", e.FullPath, e.ChangeType);
            watcher.Changed += (source, e) => Console.WriteLine("{0} -- {1}", e.FullPath, e.ChangeType);
            watcher.Deleted += (source, e) => Console.WriteLine("{0} -- {1}", e.FullPath, e.ChangeType);
            watcher.Renamed += (source, e) => Console.WriteLine("{0} -- {1}", e.FullPath, e.ChangeType);
            // Begin watching the directory.
            watcher.EnableRaisingEvents = true;

            ReadAndWrite();

            // Wait for the user to quit the program.
            Console.WriteLine(@"Press 'q' to quit app.");
            while (Console.Read() != 'q')
                ;
        }
开发者ID:wordtinker,项目名称:c-sharp,代码行数:30,代码来源:Program.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IO.FileType类代码示例发布时间:2022-05-26
下一篇:
C# IO.FileSystemInfo类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap