Exemplo n.º 1
0
 public MainWindowViewModel()
 {
     _domObject = new FileInformation();
     _informations = new ObservableCollection<FileInformation>();
     _toggleWatchingCmd = new RelayCommand(ToggleWatching, CanToggleWatching);
     _openSettingWindowCmd = new RelayCommand(OpenSettingWindow, CanOpenSettingWindow);
     _clearCollectionCmd = new RelayCommand(ClearCollection, CanClearCollection);
     _saveCollectionCmd = new RelayCommand(SaveCollection, CanSaveCollection);
     _toggleShowPreviewCmd = new RelayCommand(ToggleShowPreview, CanToggleShowPreview);
     _deleteFileCmd = new RelayCommand(DeleteFile, CanDeleteFile);
     _openFileCmd = new RelayCommand(OpenFile, CanOpenFile);
     _openContaingFolderCmd = new RelayCommand(OpenContaingFolder, CanOpenContaingFolder);
     _fileSystemWatcher = createWatcher();
     updateWatcherFromConfigFile();
 }
Exemplo n.º 2
0
        /// <summary>
        /// FileSystemEventHandler Delegate
        /// </summary>
        private void fileSystemWatching(object sender, FileSystemEventArgs e)
        {
            Application.Current.Dispatcher.Invoke((Action)(() =>
            {
                string[] strArr = e.FullPath.Split(new char[] { '\\' });
                if (strArr.Length < 2 || strArr[1].Equals("$RECYCLE.BIN"))
                    return;

                //Filter Watching Files.
                var ext = (Path.GetExtension(e.FullPath) ?? string.Empty).ToLower();
                var all = ".*";
                if (_watchingFilter.Any(ext.Equals) || _watchingFilter.Any(all.Equals) || _watchingFilter.Length == 0)
                {
                    //Always create a new instance of patient before adding.
                    //Otherwise we will endup sending the same instance that is binded, to the BL which will cause complications
                    var information = new FileInformation
                    {
                        Id = FileInformations.Count,
                        TimeStamp = DateTime.Now.ToString(),
                        EventType = e.ChangeType.ToString(),
                        FileName = strArr[strArr.Length - 1],
                        FilePath = e.FullPath
                    };
                    FileInformations.Add(information);
                    SelectLastFileInformation();
                }
            }));
        }