本文整理汇总了C#中INuGetProjectContext.Log方法的典型用法代码示例。如果您正苦于以下问题:C# INuGetProjectContext.Log方法的具体用法?C# INuGetProjectContext.Log怎么用?C# INuGetProjectContext.Log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INuGetProjectContext
的用法示例。
在下文中一共展示了INuGetProjectContext.Log方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstallPackageAsync
public async override Task<bool> InstallPackageAsync(PackageIdentity packageIdentity, Stream packageStream,
INuGetProjectContext nuGetProjectContext, CancellationToken token)
{
if (packageIdentity == null)
{
throw new ArgumentNullException("packageIdentity");
}
if (packageStream == null)
{
throw new ArgumentNullException("packageStream");
}
if (nuGetProjectContext == null)
{
throw new ArgumentNullException("nuGetProjectContext");
}
if (!packageStream.CanSeek)
{
throw new ArgumentException(Strings.PackageStreamShouldBeSeekable);
}
// 1. Check if the Package already exists at root, if so, return false
if (PackageExists(packageIdentity))
{
nuGetProjectContext.Log(MessageLevel.Warning, Strings.PackageAlreadyExistsInFolder, packageIdentity, Root);
return false;
}
nuGetProjectContext.Log(MessageLevel.Info, Strings.AddingPackageToFolder, packageIdentity, Root);
// 2. Call PackageExtractor to extract the package into the root directory of this FileSystemNuGetProject
packageStream.Seek(0, SeekOrigin.Begin);
var addedPackageFilesList = new List<string>(await PackageExtractor.ExtractPackageAsync(packageStream, packageIdentity, PackagePathResolver, nuGetProjectContext.PackageExtractionContext,
PackageSaveMode, token));
if (PackageSaveMode.HasFlag(PackageSaveModes.Nupkg))
{
var packageFilePath = GetInstalledPackageFilePath(packageIdentity);
if (File.Exists(packageFilePath))
{
addedPackageFilesList.Add(packageFilePath);
}
}
// Pend all the package files including the nupkg file
FileSystemUtility.PendAddFiles(addedPackageFilesList, Root, nuGetProjectContext);
nuGetProjectContext.Log(MessageLevel.Info, Strings.AddedPackageToFolder, packageIdentity, Root);
return true;
}
示例2: InstallPackageAsync
public async override Task<bool> InstallPackageAsync(Packaging.Core.PackageIdentity packageIdentity, System.IO.Stream packageStream,
INuGetProjectContext nuGetProjectContext, CancellationToken token)
{
if (!packageStream.CanSeek)
{
throw new ArgumentException(NuGet.ProjectManagement.Strings.PackageStreamShouldBeSeekable);
}
nuGetProjectContext.Log(MessageLevel.Info, Strings.InstallingPackage, packageIdentity);
packageStream.Seek(0, SeekOrigin.Begin);
var zipArchive = new ZipArchive(packageStream);
PackageReader packageReader = new PackageReader(zipArchive);
var packageSupportedFrameworks = packageReader.GetSupportedFrameworks();
var projectFrameworks = _project.GetSupportedFrameworksAsync(token)
.Result
.Select(f => NuGetFramework.Parse(f.FullName));
var args = new Dictionary<string, object>();
args["Frameworks"] = projectFrameworks.Where(
projectFramework =>
IsCompatible(projectFramework, packageSupportedFrameworks)).ToArray();
await _project.InstallPackageAsync(
new NuGetPackageMoniker
{
Id = packageIdentity.Id,
Version = packageIdentity.Version.ToNormalizedString()
},
args,
logger: null,
progress: null,
cancellationToken: token);
return true;
}
示例3: InstallPackageAsync
public override async Task<bool> InstallPackageAsync (
PackageIdentity packageIdentity,
DownloadResourceResult downloadResourceResult,
INuGetProjectContext nuGetProjectContext,
CancellationToken token)
{
return await Runtime.RunInMainThread (async () => {
// Check if this NuGet package is already installed and should be removed.
PackageReference existingPackageReference = project.FindPackageReference (packageIdentity);
if (existingPackageReference != null) {
if (ShouldRemoveExistingPackageReference (existingPackageReference, packageIdentity)) {
project.PackageReferences.Remove (existingPackageReference);
} else {
nuGetProjectContext.Log (
MessageLevel.Info,
GettextCatalog.GetString ("Package '{0}' already installed.", packageIdentity));
return true;
}
}
bool developmentDependency = false;
if (IsNuGetBuildPackagingPackage (packageIdentity)) {
await GlobalPackagesExtractor.Extract (project.ParentSolution, packageIdentity, downloadResourceResult, token);
developmentDependency = true;
GenerateNuGetBuildPackagingTargets (packageIdentity);
}
var packageReference = new PackageReference (packageIdentity);
if (developmentDependency)
packageReference.PrivateAssets = "All";
project.PackageReferences.Add (packageReference);
await SaveProject ();
return true;
});
}
示例4: PerformSafeAction
private static void PerformSafeAction(Action action, INuGetProjectContext nuGetProjectContext)
{
try
{
Attempt(action);
}
catch (Exception e)
{
nuGetProjectContext.Log(MessageLevel.Warning, e.Message);
}
}
示例5: ExecuteNuGetProjectActionsAsync
/// <summary>
/// Executes the list of <param name="nuGetProjectActions"></param> on <param name="nuGetProject"></param>, which is likely obtained by calling into PreviewInstallPackageAsync
/// <param name="nuGetProjectContext"></param> is used in the process
/// </summary>
public async Task ExecuteNuGetProjectActionsAsync(NuGetProject nuGetProject, IEnumerable<NuGetProjectAction> nuGetProjectActions,
INuGetProjectContext nuGetProjectContext, CancellationToken token)
{
if (nuGetProject == null)
{
throw new ArgumentNullException("nuGetProject");
}
if (nuGetProjectActions == null)
{
throw new ArgumentNullException("nuGetProjectActions");
}
if (nuGetProjectContext == null)
{
throw new ArgumentNullException("nuGetProjectContext");
}
Exception executeNuGetProjectActionsException = null;
Stack<NuGetProjectAction> executedNuGetProjectActions = new Stack<NuGetProjectAction>();
HashSet<PackageIdentity> packageWithDirectoriesToBeDeleted = new HashSet<PackageIdentity>(PackageIdentity.Comparer);
try
{
await nuGetProject.PreProcessAsync(nuGetProjectContext, token);
foreach (NuGetProjectAction nuGetProjectAction in nuGetProjectActions)
{
executedNuGetProjectActions.Push(nuGetProjectAction);
if (nuGetProjectAction.NuGetProjectActionType == NuGetProjectActionType.Uninstall)
{
await ExecuteUninstallAsync(nuGetProject, nuGetProjectAction.PackageIdentity, packageWithDirectoriesToBeDeleted, nuGetProjectContext, token);
}
else
{
using (var targetPackageStream = new MemoryStream())
{
await PackageDownloader.GetPackageStream(nuGetProjectAction.SourceRepository, nuGetProjectAction.PackageIdentity, targetPackageStream, token);
await ExecuteInstallAsync(nuGetProject, nuGetProjectAction.PackageIdentity, targetPackageStream, packageWithDirectoriesToBeDeleted, nuGetProjectContext, token);
}
}
string toFromString = nuGetProjectAction.NuGetProjectActionType == NuGetProjectActionType.Install ? Strings.To : Strings.From;
nuGetProjectContext.Log(MessageLevel.Info, Strings.SuccessfullyExecutedPackageAction,
nuGetProjectAction.NuGetProjectActionType.ToString().ToLowerInvariant(), nuGetProjectAction.PackageIdentity.ToString(), toFromString + " " + nuGetProject.GetMetadata<string>(NuGetProjectMetadataKeys.Name));
}
await nuGetProject.PostProcessAsync(nuGetProjectContext, token);
await OpenReadmeFile(nuGetProjectContext, token);
}
catch (Exception ex)
{
executeNuGetProjectActionsException = ex;
}
if(executeNuGetProjectActionsException != null)
{
await Rollback(nuGetProject, executedNuGetProjectActions, packageWithDirectoriesToBeDeleted, nuGetProjectContext, token);
}
// Delete the package directories as the last step, so that, if an uninstall had to be rolled back, we can just use the package file on the directory
// Also, always perform deletion of package directories, even in a rollback, so that there are no stale package directories
foreach(var packageWithDirectoryToBeDeleted in packageWithDirectoriesToBeDeleted)
{
await DeletePackage(packageWithDirectoryToBeDeleted, nuGetProjectContext, token);
}
// Clear direct install
SetDirectInstall(null, nuGetProjectContext);
if(executeNuGetProjectActionsException != null)
{
throw executeNuGetProjectActionsException;
}
}
示例6: PreviewUninstallPackageAsyncPrivate
private async Task<IEnumerable<NuGetProjectAction>> PreviewUninstallPackageAsyncPrivate(NuGetProject nuGetProject, PackageReference packageReference,
UninstallationContext uninstallationContext, INuGetProjectContext nuGetProjectContext, CancellationToken token)
{
if(SolutionManager == null)
{
throw new InvalidOperationException(Strings.SolutionManagerNotAvailableForUninstall);
}
if (nuGetProject is ProjectManagement.Projects.ProjectKNuGetProjectBase)
{
var action = NuGetProjectAction.CreateUninstallProjectAction(packageReference.PackageIdentity);
return new NuGetProjectAction[] { action };
}
// Step-1 : Get the metadata resources from "packages" folder or custom repository path
var packageIdentity = packageReference.PackageIdentity;
var packageReferenceTargetFramework = packageReference.TargetFramework;
nuGetProjectContext.Log(MessageLevel.Info, Strings.AttemptingToGatherDependencyInfo, packageIdentity, packageReferenceTargetFramework);
// TODO: IncludePrerelease is a big question mark
var installedPackageIdentities = (await nuGetProject.GetInstalledPackagesAsync(token)).Select(pr => pr.PackageIdentity);
var dependencyInfoFromPackagesFolder = await GetDependencyInfoFromPackagesFolder(installedPackageIdentities,
packageReferenceTargetFramework, includePrerelease: true);
nuGetProjectContext.Log(MessageLevel.Info, Strings.ResolvingActionsToUninstallPackage, packageIdentity);
// Step-2 : Determine if the package can be uninstalled based on the metadata resources
var packagesToBeUninstalled = UninstallResolver.GetPackagesToBeUninstalled(packageIdentity, dependencyInfoFromPackagesFolder, installedPackageIdentities, uninstallationContext);
var nuGetProjectActions = packagesToBeUninstalled.Select(p => NuGetProjectAction.CreateUninstallProjectAction(p));
nuGetProjectContext.Log(MessageLevel.Info, Strings.ResolvedActionsToUninstallPackage, packageIdentity);
return nuGetProjectActions;
}
示例7: PreviewInstallPackageAsync
public async Task<IEnumerable<NuGetProjectAction>> PreviewInstallPackageAsync(NuGetProject nuGetProject, PackageIdentity packageIdentity,
ResolutionContext resolutionContext, INuGetProjectContext nuGetProjectContext,
IEnumerable<SourceRepository> primarySources, IEnumerable<SourceRepository> secondarySources,
CancellationToken token)
{
if(nuGetProject == null)
{
throw new ArgumentNullException("nuGetProject");
}
if (packageIdentity == null)
{
throw new ArgumentNullException("packageIdentity");
}
if(resolutionContext == null)
{
throw new ArgumentNullException("resolutionContext");
}
if(nuGetProjectContext == null)
{
throw new ArgumentNullException("nuGetProjectContext");
}
if (primarySources == null)
{
throw new ArgumentNullException("primarySources");
}
if (secondarySources == null)
{
secondarySources = SourceRepositoryProvider.GetRepositories().Where(e => e.PackageSource.IsEnabled);
}
if(!primarySources.Any())
{
throw new ArgumentException("primarySources");
}
if(packageIdentity.Version == null)
{
throw new ArgumentNullException("packageIdentity.Version");
}
// TODO: BUGBUG: HACK: Multiple primary repositories is mainly intended for nuget.exe at the moment
// The following special case for ProjectK is not correct, if they used nuget.exe
// and multiple repositories in the -Source switch
if (nuGetProject is ProjectManagement.Projects.ProjectKNuGetProjectBase)
{
var action = NuGetProjectAction.CreateInstallProjectAction(packageIdentity, primarySources.First());
return new NuGetProjectAction[] { action };
}
var projectInstalledPackageReferences = await nuGetProject.GetInstalledPackagesAsync(token);
var oldListOfInstalledPackages = projectInstalledPackageReferences.Select(p => p.PackageIdentity);
if(oldListOfInstalledPackages.Any(p => p.Equals(packageIdentity)))
{
string projectName;
nuGetProject.TryGetMetadata<string>(NuGetProjectMetadataKeys.Name, out projectName);
throw new InvalidOperationException(String.Format(NuGet.ProjectManagement.Strings.PackageAlreadyExistsInProject, packageIdentity, projectName ?? String.Empty));
}
List<NuGetProjectAction> nuGetProjectActions = new List<NuGetProjectAction>();
// TODO: these sources should be ordered
// TODO: search in only the active source but allow dependencies to come from other sources?
var effectiveSources = GetEffectiveSources(primarySources, secondarySources);
if (resolutionContext.DependencyBehavior != DependencyBehavior.Ignore)
{
try
{
bool downgradeAllowed = false;
var packageTargetsForResolver = new HashSet<PackageIdentity>(oldListOfInstalledPackages, PackageIdentity.Comparer);
// Note: resolver needs all the installed packages as targets too. And, metadata should be gathered for the installed packages as well
var installedPackageWithSameId = packageTargetsForResolver.Where(p => p.Id.Equals(packageIdentity.Id, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
if(installedPackageWithSameId != null)
{
packageTargetsForResolver.Remove(installedPackageWithSameId);
if(installedPackageWithSameId.Version > packageIdentity.Version)
{
// Looks like the installed package is of higher version than one being installed. So, we take it that downgrade is allowed
downgradeAllowed = true;
}
}
packageTargetsForResolver.Add(packageIdentity);
// Step-1 : Get metadata resources using gatherer
var targetFramework = nuGetProject.GetMetadata<NuGetFramework>(NuGetProjectMetadataKeys.TargetFramework);
nuGetProjectContext.Log(MessageLevel.Info, Strings.AttemptingToGatherDependencyInfo, packageIdentity, targetFramework);
var primaryPackages = new List<PackageIdentity>() { packageIdentity };
// If any targets are prerelease we should gather with prerelease on and filter afterwards
bool includePrereleaseInGather = resolutionContext.IncludePrerelease || (packageTargetsForResolver.Any(p => (p.HasVersion && p.Version.IsPrerelease)));
ResolutionContext contextForGather = new ResolutionContext(resolutionContext.DependencyBehavior, includePrereleaseInGather, resolutionContext.IncludeUnlisted);
var availablePackageDependencyInfoWithSourceSet = await ResolverGather.GatherPackageDependencyInfo(contextForGather,
primaryPackages,
//.........这里部分代码省略.........
示例8: GetProjectActionsForUpdate
// TODO: Convert this to a generic GetProjectActions and use it from Install methods too
private List<NuGetProjectAction> GetProjectActionsForUpdate(IEnumerable<PackageIdentity> newListOfInstalledPackages,
IEnumerable<PackageIdentity> oldListOfInstalledPackages,
IEnumerable<SourceDependencyInfo> availablePackageDependencyInfoWithSourceSet,
INuGetProjectContext nuGetProjectContext)
{
// Step-3 : Get the list of nuGetProjectActions to perform, install/uninstall on the nugetproject
// based on newPackages obtained in Step-2 and project.GetInstalledPackages
List<NuGetProjectAction> nuGetProjectActions = new List<NuGetProjectAction>();
nuGetProjectContext.Log(MessageLevel.Info, Strings.ResolvingActionsToInstallOrUpdateMultiplePackages);
var newPackagesToUninstall = oldListOfInstalledPackages
.Where(op => newListOfInstalledPackages
.Where(np => op.Id.Equals(np.Id, StringComparison.OrdinalIgnoreCase) && !op.Version.Equals(np.Version)).Any());
var newPackagesToInstall = newListOfInstalledPackages.Where(p => !oldListOfInstalledPackages.Contains(p));
foreach (PackageIdentity newPackageToUninstall in newPackagesToUninstall)
{
nuGetProjectActions.Add(NuGetProjectAction.CreateUninstallProjectAction(newPackageToUninstall));
}
var comparer = PackageIdentity.Comparer;
foreach (PackageIdentity newPackageToInstall in newPackagesToInstall)
{
// find the package match based on identity
SourceDependencyInfo sourceDepInfo = availablePackageDependencyInfoWithSourceSet.Where(p => comparer.Equals(p, newPackageToInstall)).SingleOrDefault();
if (sourceDepInfo == null)
{
// this really should never happen
throw new InvalidOperationException(String.Format(Strings.PackageNotFound, newPackageToInstall));
}
nuGetProjectActions.Add(NuGetProjectAction.CreateInstallProjectAction(newPackageToInstall, sourceDepInfo.Source));
}
return nuGetProjectActions;
}
示例9: PreviewReinstallPackagesAsync
public async Task<IEnumerable<NuGetProjectAction>> PreviewReinstallPackagesAsync(IEnumerable<PackageIdentity> packagesToInstall, NuGetProject nuGetProject,
ResolutionContext resolutionContext, INuGetProjectContext nuGetProjectContext,
SourceRepository primarySourceRepository, IEnumerable<SourceRepository> secondarySources,
CancellationToken token)
{
if(packagesToInstall == null)
{
throw new ArgumentNullException("packagesToInstall");
}
if (nuGetProject == null)
{
throw new ArgumentNullException("nuGetProject");
}
if (resolutionContext == null)
{
throw new ArgumentNullException("resolutionContext");
}
if (nuGetProjectContext == null)
{
throw new ArgumentNullException("nuGetProjectContext");
}
if(packagesToInstall.Any(p => p.Version == null))
{
throw new ArgumentException("packagesToInstall");
}
if (primarySourceRepository == null)
{
throw new ArgumentNullException("primarySourceRepository");
}
var primarySources = new List<SourceRepository>() { primarySourceRepository };
if (secondarySources == null)
{
secondarySources = SourceRepositoryProvider.GetRepositories().Where(e => e.PackageSource.IsEnabled);
}
var projectInstalledPackageReferences = await nuGetProject.GetInstalledPackagesAsync(token);
var oldListOfInstalledPackages = projectInstalledPackageReferences.Select(p => p.PackageIdentity);
// Note: resolver needs all the installed packages as targets too. And, metadata should be gathered for the installed packages as well
var packageTargetsForResolver = new HashSet<PackageIdentity>(oldListOfInstalledPackages, PackageIdentity.Comparer);
foreach(var packageToInstall in packagesToInstall)
{
packageTargetsForResolver.Add(packageToInstall);
}
List<NuGetProjectAction> nuGetProjectActions = new List<NuGetProjectAction>();
// TODO: these sources should be ordered
// TODO: search in only the active source but allow dependencies to come from other sources?
var effectiveSources = GetEffectiveSources(primarySources, secondarySources);
try
{
// If any targets are prerelease we should gather with prerelease on and filter afterwards
bool includePrereleaseInGather = resolutionContext.IncludePrerelease || (packageTargetsForResolver.Any(p => (p.HasVersion && p.Version.IsPrerelease)));
ResolutionContext contextForGather = new ResolutionContext(resolutionContext.DependencyBehavior, includePrereleaseInGather, resolutionContext.IncludeUnlisted);
// Step-1 : Get metadata resources using gatherer
var targetFramework = nuGetProject.GetMetadata<NuGetFramework>(NuGetProjectMetadataKeys.TargetFramework);
nuGetProjectContext.Log(MessageLevel.Info, Strings.AttemptingToGatherDependencyInfoForMultiplePackages, targetFramework);
var availablePackageDependencyInfoWithSourceSet = await ResolverGather.GatherPackageDependencyInfo(contextForGather,
packagesToInstall,
packageTargetsForResolver,
targetFramework,
primarySources,
effectiveSources,
token);
if (!availablePackageDependencyInfoWithSourceSet.Any())
{
throw new InvalidOperationException(Strings.UnableToGatherDependencyInfoForMultiplePackages);
}
// Prune the results down to only what we would allow to be installed
IEnumerable<SourceDependencyInfo> prunedAvailablePackages = availablePackageDependencyInfoWithSourceSet;
// Keep only the target package we are trying to install for that Id
foreach (var packageIdentity in packagesToInstall)
{
prunedAvailablePackages = PrunePackageTree.RemoveAllVersionsForIdExcept(prunedAvailablePackages, packageIdentity);
}
if (!resolutionContext.IncludePrerelease)
{
prunedAvailablePackages = PrunePackageTree.PrunePreleaseForStableTargets(prunedAvailablePackages, packageTargetsForResolver);
}
// TODO: prune down level packages?
// Remove versions that do not satisfy 'allowedVersions' attribute in packages.config, if any
prunedAvailablePackages = PrunePackageTree.PruneDisallowedVersions(prunedAvailablePackages, projectInstalledPackageReferences);
// Step-2 : Call IPackageResolver.Resolve to get new list of installed packages
// TODO: Consider using IPackageResolver once it is extensible
//.........这里部分代码省略.........
示例10: RestorePackageAsync
/// <summary>
/// RestorePackage is only allowed on a folderNuGetProject. In most cases, one will simply use the packagesFolderPath from NuGetPackageManager
/// to create a folderNuGetProject before calling into this method
/// </summary>
public async Task<bool> RestorePackageAsync(PackageIdentity packageIdentity, INuGetProjectContext nuGetProjectContext,
IEnumerable<SourceRepository> sourceRepositories, CancellationToken token)
{
token.ThrowIfCancellationRequested();
if(PackageExistsInPackagesFolder(packageIdentity))
{
return false;
}
token.ThrowIfCancellationRequested();
nuGetProjectContext.Log(MessageLevel.Info, String.Format(Strings.RestoringPackage, packageIdentity));
var enabledSources = (sourceRepositories != null && sourceRepositories.Any()) ? sourceRepositories :
SourceRepositoryProvider.GetRepositories().Where(e => e.PackageSource.IsEnabled);
var sourceRepository = await GetSourceRepository(packageIdentity, enabledSources);
token.ThrowIfCancellationRequested();
using (var targetPackageStream = new MemoryStream())
{
await PackageDownloader.GetPackageStream(sourceRepository, packageIdentity, targetPackageStream, token);
// If you already downloaded the package, just restore it, don't cancel the operation now
await PackagesFolderNuGetProject.InstallPackageAsync(packageIdentity, targetPackageStream, nuGetProjectContext, token);
}
return true;
}
示例11: Rollback
private async Task Rollback(NuGetProject nuGetProject, Stack<NuGetProjectAction> executedNuGetProjectActions, HashSet<PackageIdentity> packageWithDirectoriesToBeDeleted,
INuGetProjectContext nuGetProjectContext, CancellationToken token)
{
if (executedNuGetProjectActions.Count > 0)
{
// Only print the rollback warning if we have something to rollback
nuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_RollingBack);
}
while(executedNuGetProjectActions.Count > 0)
{
NuGetProjectAction nuGetProjectAction = executedNuGetProjectActions.Pop();
try
{
if (nuGetProjectAction.NuGetProjectActionType == NuGetProjectActionType.Install)
{
// Rolling back an install would be to uninstall the package
await ExecuteUninstallAsync(nuGetProject, nuGetProjectAction.PackageIdentity, packageWithDirectoriesToBeDeleted, nuGetProjectContext, token);
}
else
{
packageWithDirectoriesToBeDeleted.Remove(nuGetProjectAction.PackageIdentity);
var packagePath = PackagesFolderNuGetProject.GetInstalledPackageFilePath(nuGetProjectAction.PackageIdentity);
if (File.Exists(packagePath))
{
using (var packageStream = File.OpenRead(packagePath))
{
await ExecuteInstallAsync(nuGetProject, nuGetProjectAction.PackageIdentity, packageStream, packageWithDirectoriesToBeDeleted, nuGetProjectContext, token);
}
}
}
}
catch (Exception)
{
// TODO: We are ignoring exceptions on rollback. Is this OK?
}
}
}
示例12: WriteAddedFileAndDirectory
private static void WriteAddedFileAndDirectory(string path, INuGetProjectContext nuGetProjectContext)
{
if (String.IsNullOrEmpty(path))
return;
string folderPath = Path.GetDirectoryName(path);
if (!String.IsNullOrEmpty(folderPath))
{
nuGetProjectContext.Log(MessageLevel.Debug, Strings.Debug_AddedFileToFolder, Path.GetFileName(path), folderPath);
}
else
{
nuGetProjectContext.Log(MessageLevel.Debug, Strings.Debug_AddedFile, Path.GetFileName(path));
}
}
示例13: DeleteDirectory
public static void DeleteDirectory(string fullPath, bool recursive, INuGetProjectContext nuGetProjectContext)
{
if (!Directory.Exists(fullPath))
{
return;
}
try
{
Directory.Delete(fullPath, recursive);
// The directory is not guaranteed to be gone since there could be
// other open handles. Wait, up to half a second, until the directory is gone.
for (int i = 0; Directory.Exists(fullPath) && i < 5; ++i)
{
System.Threading.Thread.Sleep(100);
}
nuGetProjectContext.Log(MessageLevel.Debug, Strings.Debug_RemovedFolder, fullPath);
}
catch (DirectoryNotFoundException)
{
}
}
示例14: DeleteFiles
public static void DeleteFiles(IEnumerable<ZipFilePair> packageFiles, string packagesDir, INuGetProjectContext nuGetProjectContext)
{
List<string> filesToDelete = new List<string>();
foreach(var packageFile in packageFiles)
{
if(packageFile != null && packageFile.Item1 != null && packageFile.Item2 != null && File.Exists(packageFile.Item1))
{
if(ContentEquals(packageFile.Item1, packageFile.Item2.Open))
{
MakeWriteable(packageFile.Item1);
filesToDelete.Add(packageFile.Item1);
}
else
{
nuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_FileModified, packageFile.Item1);
}
}
}
var sourceControlManager = SourceControlUtility.GetSourceControlManager(nuGetProjectContext);
if (sourceControlManager != null)
{
sourceControlManager.PendDeleteFiles(filesToDelete, packagesDir, nuGetProjectContext);
foreach (var fileToDelete in filesToDelete)
{
File.Delete(fileToDelete);
}
}
else
{
// When it is not SourceControl, it is a different scenario altogether
// First get all directories that contain files
var directoryLookup = filesToDelete.ToLookup(p => Path.GetDirectoryName(p));
// Get all directories that this package may have added
var directories = from grouping in directoryLookup
from directory in GetDirectories(grouping.Key, altDirectorySeparator: false)
orderby directory.Length descending
select directory;
// Remove files from every directory
foreach (var directory in directories)
{
var directoryFiles = directoryLookup.Contains(directory) ? directoryLookup[directory] : Enumerable.Empty<string>();
string dirPath = Path.Combine(packagesDir, directory);
if (!Directory.Exists(dirPath))
{
continue;
}
foreach (var file in directoryFiles)
{
string path = Path.Combine(packagesDir, file);
File.Delete(path);
}
// If the directory is empty then delete it
if (!GetFiles(packagesDir, dirPath, "*.*").Any() &&
!GetDirectories(packagesDir, dirPath).Any())
{
DeleteDirectorySafe(Path.Combine(packagesDir, dirPath), recursive: false, nuGetProjectContext: nuGetProjectContext);
}
}
}
}
示例15: DeleteFile
public static void DeleteFile(string fullPath, INuGetProjectContext nuGetProjectContext)
{
if (!File.Exists(fullPath))
{
return;
}
try
{
MakeWriteable(fullPath);
var sourceControlManager = SourceControlUtility.GetSourceControlManager(nuGetProjectContext);
if (sourceControlManager != null)
{
sourceControlManager.PendDeleteFiles(new List<string>() { fullPath }, String.Empty, nuGetProjectContext);
}
File.Delete(fullPath);
string folderPath = Path.GetDirectoryName(fullPath);
if (!String.IsNullOrEmpty(folderPath))
{
nuGetProjectContext.Log(MessageLevel.Debug, Strings.Debug_RemovedFileFromFolder, Path.GetFileName(fullPath), folderPath);
}
else
{
nuGetProjectContext.Log(MessageLevel.Debug, Strings.Debug_RemovedFile, Path.GetFileName(fullPath));
}
}
catch (FileNotFoundException)
{
}
}