public FileViewModel(FileModel newFile) { _Initialize(newFile); }
private void _Initialize(FileModel newFile) { FullName = newFile.FileInfo.FullName; Extension = newFile.FileInfo.Extension; Name = newFile.Name; Path = newFile.FileInfo.DirectoryName; LastWriteTime = newFile.FileInfo.LastWriteTime; Size = newFile.FileInfo.Length; IsSplited = Extension.Contains(".part"); OpenCommand = new Command(argt => Open()); SetRenameEnableCommand = new Command(arg => IsNameReadOnly = !Convert.ToBoolean(arg)); RenameCommand = new Command(arg => { if (arg.ToString() != Name) try { FileSystem.RenameFile(FullName, arg.ToString() + Extension); } catch (ArgumentException) { NotifyPropertyChanged("Name"); IsWrongName = true; } catch (FileNotFoundException) { } }); SplitFileCommand = new Command(async arg => { _CTS = new CancellationTokenSource(); await SplitFileAsync(_CTS.Token); }); SplitFileCommand.CanExecuteDelegate = arg => !IsSplited && !IsProcessing; MergeCommand = new Command(async arg => { _CTS = new CancellationTokenSource(); await MergeFileAsync(_CTS.Token); }); MergeCommand.CanExecuteDelegate = arg => IsSplited && !IsProcessing; CancelProcessingCommand = new Command(arg => _CTS.Cancel()); CancelProcessingCommand.CanExecuteDelegate = arg => IsProcessing; }