public void OnResolveFileConflict_NoEventSubscribers_ReturnsIgnoreAll() { CreateEvents(); FileConflictAction resolution = events.OnResolveFileConflict("message"); Assert.AreEqual(FileConflictAction.IgnoreAll, resolution); }
internal static void TryAddFile(IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem, string path, Func <Stream> content) { if (msBuildNuGetProjectSystem.FileExistsInProject(path)) { // file exists in project, ask user if he wants to overwrite or ignore string conflictMessage = String.Format(CultureInfo.CurrentCulture, Strings.FileConflictMessage, path, msBuildNuGetProjectSystem.ProjectName); FileConflictAction fileConflictAction = msBuildNuGetProjectSystem.NuGetProjectContext.ResolveFileConflict(conflictMessage); if (fileConflictAction == FileConflictAction.Overwrite || fileConflictAction == FileConflictAction.OverwriteAll) { // overwrite msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Info, Strings.Info_OverwritingExistingFile, path); using (Stream stream = content()) { msBuildNuGetProjectSystem.AddFile(path, stream); } } else { // ignore msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_FileAlreadyExists, path); } } else { msBuildNuGetProjectSystem.AddFile(path, content()); } }
private async Task PasteAsync(IDataObject dataObject) { bool move; var paths = dataObject.FromFileDropList(out move); conflictAction = FileConflictAction.None; var operations = paths .Select(path => CopyOrMoveOperation( path, Path.Combine(Navigation.FullPath, Path.GetFileName(path)), move )) .Where(o => o != null) .ToArray(); var dialog = new OperationProgressViewModel(operations) { Caption = $"{(move ? Properties.Resources.File_Moving : Properties.Resources.File_Copying)} {operations.Sum(o => o.Count)} files." }; await Messenger.SendAsync(dialog); if (move && dialog.IsCancellationRequested == false) { ClipboardManager.Clear(); } }
FileConflictAction INuGetProjectContext.ResolveFileConflict(string message) { if (overwriteAll) { return(FileConflictAction.OverwriteAll); } if (ignoreAll) { return(FileConflictAction.IgnoreAll); } if (ConflictAction != null && ConflictAction != FileConflictAction.PromptUser) { return((FileConflictAction)ConflictAction); } FileConflictAction result = PackageManagementServices.PackageManagementEvents.OnResolveFileConflict(message); switch (result) { case FileConflictAction.IgnoreAll: ignoreAll = true; break; case FileConflictAction.OverwriteAll: overwriteAll = true; break; } return(result); }
public void OnResolveFileConflict_OneEventSubscriberWhichChangesResolutionToOverwrite_ReturnsOverwrite() { CreateEvents(); events.ResolveFileConflict += (sender, e) => e.Resolution = FileConflictAction.Overwrite; FileConflictAction resolution = events.OnResolveFileConflict("message"); Assert.AreEqual(FileConflictAction.Overwrite, resolution); }
private void Button_Click(object sender, RoutedEventArgs e) { var button = (Button)sender; string tagValue = (string)button.Tag; UserSelection = (FileConflictAction)Enum.Parse(typeof(FileConflictAction), tagValue); DialogResult = true; }
FileConflictResolution GetFileConflictResolution (FileConflictAction fileConflictAction) { switch (fileConflictAction) { case FileConflictAction.Overwrite: return FileConflictResolution.Overwrite; default: return FileConflictResolution.Ignore; } }
public ConsoleHostFileConflictResolver ( IPackageManagementEvents packageEvents, FileConflictAction fileConflictAction) { this.packageEvents = packageEvents; conflictResolution = GetFileConflictResolution (fileConflictAction); packageEvents.ResolveFileConflict += ResolveFileConflict; }
private void Button_Click(object sender, RoutedEventArgs e) { var button = (Button)sender; var tagValue = (string)button.Tag; UserSelection = (FileConflictAction)Enum.Parse(typeof(FileConflictAction), tagValue); DialogResult = true; }
public ConsoleHostFileConflictResolver( IPackageManagementEvents packageEvents, FileConflictAction fileConflictAction) { this.packageEvents = packageEvents; conflictResolution = GetFileConflictResolution(fileConflictAction); packageEvents.ResolveFileConflict += ResolveFileConflict; }
public NuGetProjectContext(FileConflictAction fileConflictAction, IMessageDialogService messageDialogService, ILogger logger) { Argument.IsNotNull(() => messageDialogService); Argument.IsNotNull(() => logger); FileConflictAction = fileConflictAction; _messageDialogService = messageDialogService; _nugetLogger = logger; }
FileConflictResolution GetFileConflictResolution(FileConflictAction fileConflictAction) { switch (fileConflictAction) { case FileConflictAction.Overwrite: return(FileConflictResolution.Overwrite); default: return(FileConflictResolution.Ignore); } }
void ResolveFileConflict(object sender, ResolveFileConflictEventArgs e) { if (UserPreviouslySelectedOverwriteAllOrIgnoreAll()) { e.Resolution = lastFileConflictResolution; } else { GuiSyncDispatch(() => { e.Resolution = fileConflictResolver.ResolveFileConflict(e.Message); }); lastFileConflictResolution = e.Resolution; } }
public FileConflictAction ResolveFileConflict(string message) { if (FileConflictAction == FileConflictAction.PromptUser) { var resolution = ShowFileConflictResolution(message); if (resolution == FileConflictAction.IgnoreAll || resolution == FileConflictAction.OverwriteAll) { FileConflictAction = resolution; } return resolution; } return FileConflictAction; }
public FileConflictAction ResolveFileConflict(string message) { if (FileConflictAction == FileConflictAction.PromptUser) { var resolution = ShowFileConflictResolution(message); if (resolution == FileConflictAction.IgnoreAll || resolution == FileConflictAction.OverwriteAll) { FileConflictAction = resolution; } return(resolution); } return(FileConflictAction); }
public FileConflictAction ResolveFileConflict(string message) { if (context.FileConflictResolution.HasValue) { return(context.FileConflictResolution.Value); } // This should be using the PowerShell console host instead of a separate GUI. FileConflictAction conflictAction = Runtime.RunInMainThread(() => { var conflictResolver = new FileConflictResolver(); return(conflictResolver.ResolveFileConflict(message)); }).WaitAndGetResult(); if (conflictAction == FileConflictAction.IgnoreAll || conflictAction == FileConflictAction.OverwriteAll) { context.FileConflictResolution = conflictAction; } return(conflictAction); }
public static bool?CanWrite(this FileConflictAction action, string source, string destination) { if (File.Exists(source) == false) { return(null); } if (File.Exists(destination) == false) { return(true); } if (action.HasFlag(FileConflictAction.Overwrite)) { return(true); } if (action.HasFlag(FileConflictAction.Newer)) { return(new FileInfo(source).LastWriteTime > new FileInfo(destination).LastWriteTime); } return(false); }
void CreateResolver(FileConflictAction action) { packageEvents = new PackageManagementEvents(); resolver = new ConsoleHostFileConflictResolver(packageEvents, action); }
public IConsoleHostFileConflictResolver CreateFileConflictResolver(FileConflictAction fileConflictAction) { return(new ConsoleHostFileConflictResolver(packageEvents, fileConflictAction)); }
public IConsoleHostFileConflictResolver CreateFileConflictResolver(FileConflictAction fileConflictAction) { return new ConsoleHostFileConflictResolver(packageEvents, fileConflictAction); }
public FileConflictActionOptionItem(string text, FileConflictAction action) { Text = text; Action = action; }
public INuGetProjectContext GetProjectContext(FileConflictAction fileConflictAction) { var projectContext = _typeFactory.CreateInstanceWithParametersAndAutoCompletion <NuGetProjectContext>(fileConflictAction); return(projectContext); }
public IConsoleHostFileConflictResolver CreateFileConflictResolver(FileConflictAction fileConflictAction) { LastFileConflictActionUsedWhenCreatingResolver = fileConflictAction; return FakeFileConflictResolver; }
private FileTraverseOperation CopyOrMoveOperation(string from, string to, bool move) { if (from == to) { if (move) { return(null); } to = to.CopyableFileName(); } return(new FileTraverseOperation(from, async(path) => { var dest = path.Replace(from, to); if (path == dest) { return false; } if (new FileInfo(path).Attributes.HasFlag(FileAttributes.Directory)) { try { if (Directory.Exists(dest) == false) { Directory.CreateDirectory(dest); } if (move) { Directory.Delete(path); } } catch (UnauthorizedAccessException) { if (await ConfirmContinueOperationAsync(Properties.Resources.Copy_UnauthorizedException) == false) { return true; } } catch (IOException) { } return false; } if (conflictAction.HasFlag(FileConflictAction.ApplyToAll) == false) { if ((conflictAction = await ConfirmFileConflictActionAsync(path, dest)) == FileConflictAction.None) { return true; } } if (conflictAction.CanWrite(path, dest) == true) { var restoreReadOnly = false; if (File.Exists(dest)) { var attributes = new FileInfo(dest).Attributes; if (attributes.HasFlag(FileAttributes.ReadOnly)) { attributes &= ~FileAttributes.ReadOnly; File.SetAttributes(dest, attributes); restoreReadOnly = true; } } try { Directory.CreateDirectory(Path.GetDirectoryName(dest)); if (move) { if (path != dest) { File.Delete(dest); File.Move(path, dest); } } else { File.Copy(path, dest, true); } } catch (UnauthorizedAccessException) { return await ConfirmContinueOperationAsync(Properties.Resources.Copy_UnauthorizedException); } catch (IOException) { return await ConfirmContinueOperationAsync(Properties.Resources.Copy_UnauthorizedException); } if (restoreReadOnly) { var attributes = new FileInfo(dest).Attributes; attributes |= FileAttributes.ReadOnly; File.SetAttributes(dest, attributes); } } return false; })); }
void CreateResolver(FileConflictAction action) { packageEvents = new PackageManagementEvents(); resolver = new ConsoleHostFileConflictResolver(packageEvents, action); }
public IConsoleHostFileConflictResolver CreateFileConflictResolver(FileConflictAction fileConflictAction) { return null; }
public INuGetProjectContext GetProjectContext(FileConflictAction fileConflictAction) { //no project context return(null); }
public IConsoleHostFileConflictResolver CreateFileConflictResolver(FileConflictAction fileConflictAction) { LastFileConflictActionUsedWhenCreatingResolver = fileConflictAction; return(FakeFileConflictResolver); }
public IConsoleHostFileConflictResolver CreateFileConflictResolver(FileConflictAction fileConflictAction) { return(null); }
public FileConflictActionOptionItem(string text, FileConflictAction action) { Text = text; Action = action; }
void ResolveFileConflict(object sender, ResolveFileConflictEventArgs e) { if (UserPreviouslySelectedOverwriteAllOrIgnoreAll ()) { e.Resolution = lastFileConflictResolution; } else { GuiSyncDispatch (() => { e.Resolution = fileConflictResolver.ResolveFileConflict (e.Message); }); lastFileConflictResolution = e.Resolution; } }
public MyProjectContext(FileConflictAction fileConflictAction) { FileConflictAction = fileConflictAction; }