本文整理汇总了C#中IProgressReporter.ChildOperation方法的典型用法代码示例。如果您正苦于以下问题:C# IProgressReporter.ChildOperation方法的具体用法?C# IProgressReporter.ChildOperation怎么用?C# IProgressReporter.ChildOperation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IProgressReporter
的用法示例。
在下文中一共展示了IProgressReporter.ChildOperation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadFiles
void UploadFiles(IProgressReporter ui)
{
ui.Maximum = newFiles.Sum(uf => uf.Length);
foreach (var file in newFiles) {
ui.Caption = "Uploading " + file.RelativePath;
var ftpRequest = FtpClient.Default.CreateRequest(Combine(UpdateConfig.Standard.RemotePath, file.RemoteUrl));
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
using (var transform = UpdateChecker.CreateFileEncryptor())
using (var requestStream = ftpRequest.GetRequestStream())
using (var encryptingStream = new CryptoStream(requestStream, transform, CryptoStreamMode.Write))
using (var zipper = new GZipStream(encryptingStream, CompressionMode.Compress, true))
using (var fileStream = File.Open(Path.Combine(basePath, file.RelativePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
fileStream.CopyTo(zipper, file.Length, ui.ChildOperation());
}
ftpRequest.GetResponse().Close();
}
}
示例2: DownloadFiles
///<summary>Downloads the update and extracts its files to a temporary directory.</summary>
///<param name="existingFiles">The path to the existing files that should be updated.
/// Any files in this directory that match files in the update will not be re-downloaded.</param>
///<param name="organizationId">The organization ID to match organization-specific directories (see <see cref="OrganizationDirectoryPattern"/>).</param>
///<param name="ui">An optional IProgressReporter implementation to report the progress of the download.</param>
///<returns>The path to the extracted files.</returns>
public string DownloadFiles(string existingFiles, string organizationId, IProgressReporter ui)
{
if (!Directory.Exists(existingFiles)) throw new DirectoryNotFoundException(existingFiles + " does not exist");
ui = ui ?? new EmptyProgressReporter();
ui.CanCancel = true;
var path = Path.GetTempFileName();
File.Delete(path);
Directory.CreateDirectory(path);
try {
var newFiles = Files
// Extract files from this organization to the root
.Select(f => organizationId == null ? f : f.StripPrefix(OrganizationPrefix + organizationId + "\\"))
// Skip other organization directories
.Where(f => !OrganizationDirectoryPattern.IsMatch(f.RelativePath))
.Where(f => !f.Matches(existingFiles))
.ToList();
ui.Maximum = newFiles.Sum(f => f.Length);
foreach (var file in newFiles) {
ui.Caption = "Downloading " + file.RelativePath;
file.DownloadFile(path, ui.ChildOperation());
if (ui.WasCanceled) {
Directory.Delete(path, true);
return null;
}
}
} catch (Exception ex) {
Directory.Delete(path, true);
if (ui.WasCanceled) return null; //If it was canceled, we'll get a CryptoException because the CryptoStream was closed
throw new UpdateErrorException(ex);
}
return path;
}