/// <summary> /// Asynchronously reverses the transform on the targetPath, using all the potential source of change. /// </summary> /// <param name="streamTaskFactory">A factory for accessing the file to be reverted from the nupkg being uninstalled.</param> /// <param name="targetPath">A path to the file to be reverted.</param> /// <param name="matchingFiles">Other files in other packages that may have changed the <paramref name="targetPath" />.</param> /// <param name="projectSystem">The project where this change is taking place.</param> /// <param name="cancellationToken">A cancellation token.</param> /// <returns>A task that represents the asynchronous operation.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="streamTaskFactory" /> /// is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="projectSystem" /> /// is <c>null</c>.</exception> /// <exception cref="OperationCanceledException">Thrown if <paramref name="cancellationToken" /> /// is cancelled.</exception> public async Task RevertFileAsync( Func <Task <Stream> > streamTaskFactory, string targetPath, IEnumerable <InternalZipFileInfo> matchingFiles, IMSBuildProjectSystem projectSystem, CancellationToken cancellationToken) { if (streamTaskFactory == null) { throw new ArgumentNullException(nameof(streamTaskFactory)); } if (projectSystem == null) { throw new ArgumentNullException(nameof(projectSystem)); } cancellationToken.ThrowIfCancellationRequested(); await MSBuildNuGetProjectSystemUtility.DeleteFileSafeAsync( targetPath, async() => StreamUtility.StreamFromString(await ProcessAsync(streamTaskFactory, projectSystem, cancellationToken)), projectSystem, cancellationToken); }
public static bool ContentEquals(string path, Func <Stream> streamFactory) { using (Stream stream = streamFactory(), fileStream = File.OpenRead(path)) { return(StreamUtility.ContentEquals(stream, fileStream)); } }
/// <summary> /// Asynchronously determines if the contents of a file and stream are equal. /// </summary> /// <param name="path">The path to a file.</param> /// <param name="streamTaskFactory">A stream task factory.</param> /// <returns>A task that represents the asynchronous operation. /// The task result (<see cref="Task{TResult}.Result" />) returns a <see cref="bool" /> /// which is <c>true</c> if contents are equal; otherwise, <c>false</c>.</returns> /// <exception cref="ArgumentException">Thrown if <paramref name="path" /> is either /// <c>null</c> or an empty string.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="streamTaskFactory" /> /// is <c>null</c>.</exception> public static async Task <bool> ContentEqualsAsync(string path, Func <Task <Stream> > streamTaskFactory) { if (string.IsNullOrEmpty(path)) { throw new ArgumentException(Strings.Argument_Cannot_Be_Null_Or_Empty, nameof(path)); } if (streamTaskFactory == null) { throw new ArgumentNullException(nameof(streamTaskFactory)); } using (Stream stream = await streamTaskFactory(), fileStream = File.OpenRead(path)) { return(StreamUtility.ContentEquals(stream, fileStream)); } }
/// <summary> /// Asynchronously transforms a file. /// </summary> /// <param name="streamTaskFactory">A stream task factory.</param> /// <param name="targetPath">A path to the file to be transformed.</param> /// <param name="projectSystem">The project where this change is taking place.</param> /// <param name="cancellationToken">A cancellation token.</param> /// <returns>A task that represents the asynchronous operation.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="streamTaskFactory" /> /// is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="projectSystem" /> /// is <c>null</c>.</exception> /// <exception cref="OperationCanceledException">Thrown if <paramref name="cancellationToken" /> /// is cancelled.</exception> public async Task TransformFileAsync( Func <Task <Stream> > streamTaskFactory, string targetPath, IMSBuildProjectSystem projectSystem, CancellationToken cancellationToken) { if (streamTaskFactory == null) { throw new ArgumentNullException(nameof(streamTaskFactory)); } if (projectSystem == null) { throw new ArgumentNullException(nameof(projectSystem)); } cancellationToken.ThrowIfCancellationRequested(); await MSBuildNuGetProjectSystemUtility.TryAddFileAsync( projectSystem, targetPath, async() => StreamUtility.StreamFromString(await ProcessAsync(streamTaskFactory, projectSystem, cancellationToken)), cancellationToken); }
public void RevertFile(ZipArchiveEntry packageFile, string targetPath, IEnumerable <InternalZipFileInfo> matchingFiles, IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem) { MSBuildNuGetProjectSystemUtility.DeleteFileSafe(targetPath, () => StreamUtility.StreamFromString(Process(packageFile, msBuildNuGetProjectSystem)), msBuildNuGetProjectSystem); }
public void TransformFile(ZipArchiveEntry packageFile, string targetPath, IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem) { MSBuildNuGetProjectSystemUtility.TryAddFile(msBuildNuGetProjectSystem, targetPath, () => StreamUtility.StreamFromString(Process(packageFile, msBuildNuGetProjectSystem))); }
public void RevertFile(Func <Stream> fileStreamFactory, string targetPath, IEnumerable <InternalZipFileInfo> matchingFiles, IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem) { MSBuildNuGetProjectSystemUtility.DeleteFileSafe(targetPath, () => StreamUtility.StreamFromString(Process(fileStreamFactory, msBuildNuGetProjectSystem)), msBuildNuGetProjectSystem); }
public void TransformFile(Func <Stream> fileStreamFactory, string targetPath, IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem) { MSBuildNuGetProjectSystemUtility.TryAddFile(msBuildNuGetProjectSystem, targetPath, () => StreamUtility.StreamFromString(Process(fileStreamFactory, msBuildNuGetProjectSystem))); }