public async void Execute(object parameter) { TestViewModel _viewModel = (TestViewModel)parameter; DirectoryInfo _dir = new DirectoryInfo(_viewModel.FolderName); this.IsCanExecute = false; this.IsCanExecute = await Task.Run <bool>(() => { try { _viewModel.StatusString = String.Empty; _viewModel.ResultString = String.Empty; _viewModel.StatusString = String.Empty; int _count = 0; StringBuilder _sb = new StringBuilder(); SlfFile _slf = SlfFile.Create(_dir, this.FSearchPattern, SearchOption.TopDirectoryOnly); if (_slf != null) { string _fileName = String.Format("{0}.SLF", _dir.Name); string _fullFileName = Path.Combine(_dir.FullName, _fileName); _slf.Save(_fullFileName); } foreach (DirectoryInfo _subDir in _dir.GetDirectories()) { _viewModel.StatusString = String.Format("{0} processing ...", _subDir.Name); _slf = SlfFile.Create(_subDir, this.FSearchPattern, SearchOption.AllDirectories); if (_slf != null) { string _fileName = String.Format("{0}.SLF", _subDir.Name); string _fullFileName = Path.Combine(_subDir.Parent.FullName, _fileName); _slf.Save(_fullFileName); } _viewModel.ResultString = String.Format( "{0} directories processed.", ++_count); } _viewModel.StatusString = "Done"; } catch (Exception exc) { _viewModel.ErrorString = Common.GetErrorString(exc); } return(true); }); }
public async void Execute(object parameter) { TestViewModel _viewModel = (TestViewModel)parameter; DirectoryInfo _dir = new DirectoryInfo(_viewModel.FolderName); this.CanExecuteProperty = false; this.CanExecuteProperty = await Task.Run <bool>(() => { try { _viewModel.StatusString = String.Empty; _viewModel.ResultString = String.Empty; _viewModel.StatusString = String.Empty; SlfFile _slf = SlfFile.Create(_dir, SearchOption.AllDirectories); if (_slf != null) { string _fileName = String.Format("{0}.SLF", _dir.Name); string _fullFileName = Path.Combine(_dir.Parent.FullName, _fileName); _slf.Save(_fullFileName); } _viewModel.StatusString = "Done"; } catch (Exception exc) { _viewModel.ErrorString = Common.GetErrorString(exc); } return(true); }); }
public async void Execute(object parameter) { SlfTestViewModel _viewModel = (SlfTestViewModel)parameter; DirectoryInfo _dir = new DirectoryInfo(_viewModel.FolderName); this.CanExecuteProperty = false; this.CanExecuteProperty = await Task.Run <bool>(() => { try { _viewModel.StatusString = String.Empty; _viewModel.ResultString = String.Empty; _viewModel.StatusString = String.Empty; int _count = 0; foreach (FileInfo _file in _dir.GetFiles("*.SLF")) { SlfFile _slf = new SlfFile(_file.FullName); _viewModel.StatusString = String.Format("{0} processing ...", _file.Name); _slf.LoadRecords(); _slf.Save(); _viewModel.ResultString = String.Format("{0} files processed.", ++_count); } _viewModel.StatusString = "Done"; } catch (Exception exc) { _viewModel.ErrorString = Common.GetErrorString(exc); } return(true); }); }