I wrote a little function that monitors some directories. If a file gets created, it will check in the extension list for a match. Can you please tell me if I could make my function better in any way?
private void sysWatcher_Created(object sender, FileSystemEventArgs e) {
try {
if (File.Exists(e.FullPath)) {
var fileName = Path.GetFileName(e.FullPath);
var fullPath = e.FullPath;
var changeType = e.ChangeType;
var fileExtension = Path.GetExtension(e.FullPath);
_extensionList.RemoveAll(r => string.IsNullOrEmpty(r.Trim()));
_ignoreList.RemoveAll(r => string.IsNullOrEmpty(r.Trim()));
// Checking for match in Extension List
bool _extResult = _extensionList.Any(s => e.FullPath.Contains(s));
if (_extResult) {
// Checking for match in Ignore List
bool _ignResult = _ignoreList.Any(s => e.FullPath.Contains(s));
if (!_ignResult) {
if (!GeneralSettings.autoMode) {
App.Current.Dispatcher.Invoke(delegate {
if (File.Exists(e.FullPath)) {
var fileInfo = new FileInfo(e.FullPath);
var wFunc = new WarningItem(e.FullPath, e.Name, AppSettings.SizeSuffix(fileInfo.Length),
fileInfo.CreationTime.ToString("g"), fileInfo.Extension);
var wWin = new WarningWin();
wWin.init(wFunc);
wWin.ShowDialog();
// Add to Warning List and List Box
_warningList.Add(new WarningItem {
DirName = Path.GetDirectoryName(e.FullPath),
CreationDate = DateTime.Now.ToString("g"),
Extension = fileInfo.Extension,
FullPath = e.FullPath,
FileName = e.Name,
FileSize = AppSettings.SizeSuffix(fileInfo.Length),
StatusImage = new Uri("/Images/inWatch.Folder.png", UriKind.RelativeOrAbsolute)
});
lstWarning.ItemsSource = _warningList;
tabWarning.IsSelected = true;
cmdSearchWarnings.Visibility = Visibility.Visible;
}
});
}
else {
Scan.scanFile(e.FullPath);
}
}
}
}
}
catch (Exception ex) {
GeneralSettings.LogException(ex);
}
}