Esempio n. 1
0
 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
         var conflictMessage = string.Format(CultureInfo.CurrentCulture,
                                             Strings.FileConflictMessage, path, msBuildNuGetProjectSystem.ProjectName);
         var fileConflictAction = msBuildNuGetProjectSystem.NuGetProjectContext.ResolveFileConflict(conflictMessage);
         if (fileConflictAction == FileConflictAction.Overwrite ||
             fileConflictAction == FileConflictAction.OverwriteAll)
         {
             // overwrite
             msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Info, Strings.Info_OverwritingExistingFile, path);
             using (var stream = content())
             {
                 msBuildNuGetProjectSystem.AddFile(path, stream);
             }
         }
         else
         {
             // ignore
             msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_FileAlreadyExists, path);
         }
     }
     else
     {
         msBuildNuGetProjectSystem.AddFile(path, content());
     }
 }
 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());
     }
 }
Esempio n. 3
0
 internal static void DeleteFileSafe(string path, Func <Stream> streamFactory, IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem)
 {
     // Only delete the file if it exists and the checksum is the same
     if (msBuildNuGetProjectSystem.FileExistsInProject(path))
     {
         var fullPath = Path.Combine(msBuildNuGetProjectSystem.ProjectFullPath, path);
         if (FileSystemUtility.ContentEquals(fullPath, streamFactory))
         {
             PerformSafeAction(() => msBuildNuGetProjectSystem.RemoveFile(path), msBuildNuGetProjectSystem.NuGetProjectContext);
         }
         else
         {
             // This package installed a file that was modified so warn the user
             msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_FileModified, fullPath);
         }
     }
 }
 public static void DeleteFileSafe(string path, Func<Stream> streamFactory, IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem)
 {
     // Only delete the file if it exists and the checksum is the same
     if (msBuildNuGetProjectSystem.FileExistsInProject(path))
     {
         var fullPath = Path.Combine(msBuildNuGetProjectSystem.ProjectFullPath, path);
         if (FileSystemUtility.ContentEquals(fullPath, streamFactory))
         {
             PerformSafeAction(() => msBuildNuGetProjectSystem.RemoveFile(path), msBuildNuGetProjectSystem.NuGetProjectContext);
         }
         else
         {
             // This package installed a file that was modified so warn the user
             msBuildNuGetProjectSystem.NuGetProjectContext.Log(MessageLevel.Warning, Strings.Warning_FileModified, fullPath);
         }
     }
 }