当前位置: 首页>>代码示例>>C#>>正文


C# IProgressReporter.ChildOperation方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:ShomreiTorah,项目名称:Utilities,代码行数:22,代码来源:Publisher.cs

示例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;
        }
开发者ID:ShomreiTorah,项目名称:Libraries,代码行数:45,代码来源:UpdateInfo.cs


注:本文中的IProgressReporter.ChildOperation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。