本文整理汇总了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();
}
};
}
}
示例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()
};
}
示例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()); }
}
示例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);
};
}
示例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;
}
示例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));
}
示例7: XmlHotDocument
// ************************************************
// Class constructor
public XmlHotDocument()
: base()
{
m_watcher = new FileSystemWatcher();
HasChanges = false;
EnableFileChanges = false;
}
示例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));
}
}
示例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;
}
示例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);
}
示例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);
}
}
示例12: Close
public override void Close ()
{
if (file_watcher != null) {
file_watcher.EnableRaisingEvents = false;
file_watcher = null; // force creation of new FileSystemWatcher
}
}
示例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
}
示例14: Init
public static void Init()
{
watcher = new FileSystemWatcher(Folder.GetWatcherPath());
watcher.IncludeSubdirectories = false;
watcher.Created += new FileSystemEventHandler(OnCreate);
watcher.EnableRaisingEvents = true;
}
示例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);
}
}