本文整理汇总了C#中IFileSystem.CopyFile方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystem.CopyFile方法的具体用法?C# IFileSystem.CopyFile怎么用?C# IFileSystem.CopyFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileSystem
的用法示例。
在下文中一共展示了IFileSystem.CopyFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessImage
public static void ProcessImage(GalleryImage galleryImage, IFileSystem fileSystem, string virtualRoot, string originalFileName, Color backgroundColor)
{
string originalPath = virtualRoot + "FullSizeImages/" + galleryImage.ImageFile;
string webSizeImagePath = virtualRoot + "WebImages/" + galleryImage.WebImageFile;
string thumbnailPath = virtualRoot + "Thumbnails/" + galleryImage.ThumbnailFile;
using (Stream stream = fileSystem.GetAsStream(originalPath))
{
using (Bitmap originalImage = new Bitmap(stream))
{
SetExifData(galleryImage, originalImage, originalFileName);
}
}
fileSystem.CopyFile(originalPath, webSizeImagePath, true);
mojoPortal.Web.ImageHelper.ResizeImage(
webSizeImagePath,
IOHelper.GetMimeType(Path.GetExtension(webSizeImagePath)),
galleryImage.WebImageWidth,
galleryImage.WebImageHeight,
backgroundColor);
fileSystem.CopyFile(originalPath, thumbnailPath, true);
mojoPortal.Web.ImageHelper.ResizeImage(
thumbnailPath,
IOHelper.GetMimeType(Path.GetExtension(thumbnailPath)),
galleryImage.ThumbNailWidth,
galleryImage.ThumbNailHeight,
backgroundColor);
}
示例2: EnsureList
/// <summary>
/// Ensures the list.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="file">The file.</param>
/// <param name="httpClient">The HTTP client.</param>
/// <param name="fileSystem">The file system.</param>
/// <param name="semaphore">The semaphore.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
public static async Task EnsureList(string url, string file, IHttpClient httpClient, IFileSystem fileSystem, SemaphoreSlim semaphore, CancellationToken cancellationToken)
{
var fileInfo = fileSystem.GetFileInfo(file);
if (!fileInfo.Exists || (DateTime.UtcNow - fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays > 1)
{
await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
var temp = await httpClient.GetTempFile(new HttpRequestOptions
{
CancellationToken = cancellationToken,
Progress = new Progress<double>(),
Url = url
}).ConfigureAwait(false);
fileSystem.CreateDirectory(Path.GetDirectoryName(file));
fileSystem.CopyFile(temp, file, true);
}
finally
{
semaphore.Release();
}
}
}
示例3: ExtractFont
internal static string ExtractFont(string name, IApplicationPaths paths, IFileSystem fileSystem)
{
var filePath = Path.Combine(paths.ProgramDataPath, "fonts", name);
if (fileSystem.FileExists(filePath))
{
return filePath;
}
var namespacePath = typeof(PlayedIndicatorDrawer).Namespace + ".fonts." + name;
var tempPath = Path.Combine(paths.TempDirectory, Guid.NewGuid().ToString("N") + ".ttf");
fileSystem.CreateDirectory(Path.GetDirectoryName(tempPath));
using (var stream = typeof(PlayedIndicatorDrawer).Assembly.GetManifestResourceStream(namespacePath))
{
using (var fileStream = new FileStream(tempPath, FileMode.Create, FileAccess.Write, FileShare.Read))
{
stream.CopyTo(fileStream);
}
}
fileSystem.CreateDirectory(Path.GetDirectoryName(filePath));
try
{
fileSystem.CopyFile(tempPath, filePath, false);
}
catch (IOException)
{
}
return tempPath;
}
示例4: PerformFileModificationOperation
/// <summary>
/// Performs a file modification.
/// </summary>
/// <param name="sourceFileSystem">The source file system.</param>
/// <param name="targetFileSystem">The target file system.</param>
/// <param name="sourceFile">The source file.</param>
/// <param name="targetDirectory">The target directory.</param>
/// <param name="execute">if set to true, the operation gets executed.</param>
private void PerformFileModificationOperation(IFileSystem sourceFileSystem, IFileSystem targetFileSystem, IFileInfo sourceFile, IDirectoryInfo targetDirectory, bool execute)
{
var eventArgs = new FileCopyEventArgs(sourceFile, sourceFile.Directory, targetDirectory);
this.OnModifyingFile(eventArgs);
if (execute)
{
EventHandler<DataTransferEventArgs> handler = (sender, e) =>
{
e.Cancel = this.IsStopped; //Stop the copy operation if the job is stopped
this.OnFileProgressChanged(e);
};
targetFileSystem.FileCopyProgressChanged += handler;
try
{
targetFileSystem.CopyFile(sourceFileSystem, sourceFile, targetDirectory);
this.OnModifiedFile(eventArgs);
}
catch (AccessException)
{
this.OnFileCopyError(new FileCopyErrorEventArgs(sourceFile, targetDirectory));
}
targetFileSystem.FileCopyProgressChanged -= handler;
}
}
示例5: DownloadFont
internal static async Task<string> DownloadFont(string name, string url, IApplicationPaths paths, IHttpClient httpClient, IFileSystem fileSystem)
{
var filePath = Path.Combine(paths.ProgramDataPath, "fonts", name);
if (fileSystem.FileExists(filePath))
{
return filePath;
}
var tempPath = await httpClient.GetTempFile(new HttpRequestOptions
{
Url = url,
Progress = new Progress<double>()
}).ConfigureAwait(false);
fileSystem.CreateDirectory(Path.GetDirectoryName(filePath));
try
{
fileSystem.CopyFile(tempPath, filePath, false);
}
catch (IOException)
{
}
return tempPath;
}