/// <summary> /// Конструктор. /// </summary> /// <param name="synchronizedItem">Элемент синхронизации, на основе которого создаётся модель представления.</param> public ItemViewModel(ISynchronizedItem synchronizedItem) { _synchronizedItem = synchronizedItem; _synchronizedItem.SyncErrorEvent += (string message) => { SyncErrorEvent?.Invoke(message); }; _synchronizedItem.StatusChangedEvent += () => { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Status))); }; _synchronizedItem.SyncCommand.CommandActionChangedEvent += RefreshAcceptCommand; RefreshAcceptCommand(); }
public async Task Delete() { await Task.Run(() => { var error = false; try { IO.Directory.Delete(FullPath, true); } catch (Exception exc) { SyncErrorEvent?.Invoke(exc.Message); error = true; } if (!error) { DeletedEvent?.Invoke(this); } }).ConfigureAwait(false); }
/// <summary> /// Копировать элемент в указанный путь с заменой. /// </summary> /// <param name="destinationPath">Путь куда копировать.</param> public async Task CopyTo(string destinationPath) { await Task.Run(() => { try { IO.File.Copy(FullPath, destinationPath, true); } catch (Exception exc) { SyncErrorEvent?.Invoke(exc.Message); } File destinationFile = null; try { destinationFile = new File(destinationPath); } catch { } CopiedFromToEvent?.Invoke(destinationFile, destinationPath); }).ConfigureAwait(false); }
private void SyncError(string error) { SyncErrorEvent?.Invoke(error); }
private void SetItemViewModelEvents(IItemViewModel itemViewModel) { itemViewModel.AcceptCommandChangedEvent += AcceptCommandChanged; itemViewModel.SyncErrorEvent += (string error) => { SyncErrorEvent?.Invoke(error); }; }