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


C# Wrapper.ReportProgress方法代码示例

本文整理汇总了C#中Wrapper.ReportProgress方法的典型用法代码示例。如果您正苦于以下问题:C# Wrapper.ReportProgress方法的具体用法?C# Wrapper.ReportProgress怎么用?C# Wrapper.ReportProgress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Wrapper的用法示例。


在下文中一共展示了Wrapper.ReportProgress方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Build

		/// <summary>
		/// 创建指定包
		/// </summary>
		/// <param name="e"></param>
		public void Build(Wrapper.RunworkEventArgs e)
		{
			e.ReportProgress(0, 0, "正在准备信息...");
			AutoLoadInformations();

			UpdateInfo ui = null;
			using (var ms = new MemoryStream())
			{
				UpdateInfo.XmlSerializeToStream(ms);
				ms.Flush();
				ms.Seek(0, SeekOrigin.Begin);
				ui = ms.XmlDeserializeFromStream<UpdateInfo>();
			}
			if (ui == null)
				throw new ApplicationException("准备升级信息时发生异常");

			Result = new Dictionary<string, string>();
			BuildPackages(e, ui);


			//保存信息文件
			var xmlPath = GetXmlFilePath(false);
			ui.XmlSerilizeToFile(xmlPath);
			if (!AuProject.CompressPackage || AuProject.CreateCompatiblePackage)
			{
				Result.Add(Path.GetFileName(xmlPath), "兼容升级模式(或未开启增量更新时)的升级信息文件");
			}

			//压缩?
			if (AuProject.CompressPackage)
			{
				var xmlCompressPath = GetXmlFilePath(true);
				CompressFile(xmlPath, xmlCompressPath);
				Result.Add(Path.GetFileName(xmlCompressPath), "已压缩的升级信息文件");

				if (!AuProject.CreateCompatiblePackage)
				{
					File.Delete(xmlPath);
				}
			}

			BuiltUpdateInfo = ui;
		}
开发者ID:shuax,项目名称:FSLib.App.SimpleUpdater,代码行数:47,代码来源:UpdatePackageBuilder.cs

示例2: BuildPackages

		/// <summary>
		/// 创建指定包
		/// </summary>
		/// <param name="e"></param>
		public void BuildPackages(Wrapper.RunworkEventArgs e, UpdateInfo ui)
		{
			var targetDir = AuProject.ParseFullPath(AuProject.DestinationDirectory);
			var appDir = AuProject.ParseFullPath(AuProject.ApplicationDirectory);

			if (!Directory.Exists(appDir))
				throw new ApplicationException("无效的应用程序目录");
			if (!Directory.Exists(targetDir))
			{
				try
				{
					Directory.CreateDirectory(targetDir);
				}
				catch (Exception ex)
				{
					throw new ApplicationException("无法创建目标目录", ex);
				}
			}

			e.ReportProgress(0, 0, "正在扫描文件列表...");
			FileInfo[] allfiles;

			try
			{
				allfiles = new DirectoryInfo(appDir).GetFiles("*.*", SearchOption.AllDirectories);
			}
			catch (Exception ex)
			{
				throw new ApplicationException("无法扫描来源目录", ex);
			}

			//生成映射,排除忽略列表
			e.ReportProgress(0, 0, "正在准备文件列表...");
			var projectItems = AuProject.Files.ToDictionary(s => s.Path, StringComparer.OrdinalIgnoreCase);
			var targetfiles = allfiles.Select(s => new KeyValuePair<string, FileInfo>(s.FullName.Remove(0, appDir.Length).Trim(Path.DirectorySeparatorChar), s))
				.Where(s => (!projectItems.ContainsKey(s.Key) && AuProject.DefaultUpdateMethod != UpdateMethod.Ignore) || (projectItems.ContainsKey(s.Key) && projectItems[s.Key].UpdateMethod != UpdateMethod.Ignore))
				.ToArray();

			//古典版的安装包?
			if (!AuProject.EnableIncreaseUpdate || AuProject.CreateCompatiblePackage)
			{
				var mainPkgId = GetPackageName("main") + "."+AuProject.PackageExtension;
				var file = System.IO.Path.Combine(targetDir, mainPkgId);
				Result.Add(mainPkgId, "兼容升级模式(或未开启增量更新时)的升级包文件");
				e.Progress.TaskCount = targetfiles.Length;
				CreateZip("正在生成兼容版升级包,正在压缩 {0}", file, ui.PackagePassword, e, targetfiles);

				var fileInfo = new System.IO.FileInfo(file);
				ui.PackageSize = fileInfo.Length;
				e.ReportProgress(0, 0, "正在计算包文件Hash...");
				ui.MD5 = Wrapper.ExtensionMethod.GetFileHash(file);
				ui.Package = mainPkgId;
			}
			if (!AuProject.EnableIncreaseUpdate) return;

			//生成主文件包
			e.ReportProgress(targetfiles.Length, 0, "");
			ui.Packages = new List<PackageInfo>();
			var mainFiles = targetfiles
				.Where(s => (!projectItems.ContainsKey(s.Key) && AuProject.DefaultUpdateMethod == UpdateMethod.Always) || (projectItems.ContainsKey(s.Key) && projectItems[s.Key].UpdateMethod == UpdateMethod.Always))
				.ToArray();
			if (mainFiles.Length > 0)
			{
				var mainPkgId = GetPackageName("alwaysintall") + "." + AuProject.PackageExtension;
				var pkgName = Path.Combine(targetDir, mainPkgId);
				e.Progress.TaskCount = mainFiles.Length;
				CreateZip("正在生成全局升级包,正在压缩 {0}", pkgName, ui.PackagePassword, e, mainFiles);
				Result.Add(mainPkgId, "全局升级包,包含必须更新的文件");


				var fileInfo = new System.IO.FileInfo(pkgName);
				ui.Packages.Add(new PackageInfo()
				{
					Version = "0.0.0.0",
					VerificationLevel = FileVerificationLevel.None,
					FilePath = "",
					FileSize = 0L,
					FileHash = "",
					PackageHash = Wrapper.ExtensionMethod.GetFileHash(pkgName),
					PackageName = mainPkgId,
					PackageSize = fileInfo.Length,
					Method = UpdateMethod.Always,
					Files = mainFiles.Select(s => s.Key).ToArray()
				});
			}

			//针对单个文件生成包
			e.Progress.TaskCount = targetfiles.Length;
			e.Progress.TaskProgress = 0;
			foreach (var file in targetfiles)
			{
				ProjectItem config;
				if (!projectItems.ContainsKey(file.Key))
				{
					if (AuProject.DefaultUpdateMethod == UpdateMethod.Always || AuProject.DefaultUpdateMethod == UpdateMethod.Ignore)
						continue;
//.........这里部分代码省略.........
开发者ID:shuax,项目名称:FSLib.App.SimpleUpdater,代码行数:101,代码来源:UpdatePackageBuilder.cs

示例3: CreateZip

		/// <summary>
		/// 创建压缩包
		/// </summary>
		/// <param name="zipFile"></param>
		/// <param name="e"></param>
		public void CreateZip(string title, string zipFile, string pwd, Wrapper.RunworkEventArgs e, KeyValuePair<string, FileInfo>[] files)
		{
			using (var fs = new System.IO.FileStream(zipFile, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
			using (var zip = new ICCEmbedded.SharpZipLib.Zip.ZipOutputStream(fs))
			{
				zip.Password = pwd;
				zip.SetLevel(9);

				var entryFactory = new ICCEmbedded.SharpZipLib.Zip.ZipEntryFactory();

				//合并路径
				var fileGroups = files.GroupBy(s => System.IO.Path.GetDirectoryName(s.Key)).ToDictionary(s => s.Key, s => s.ToArray());
				var folders = fileGroups.Keys.OrderBy(s => s, StringComparer.OrdinalIgnoreCase).ToArray();

				folders.ForEach(s =>
				{
					if (!string.IsNullOrEmpty(s))
					{
						var fe = entryFactory.MakeDirectoryEntry(s);
						fe.IsUnicodeText = true;
						fe.DateTime = DateTime.Now;
						zip.PutNextEntry(fe);
						zip.CloseEntry();
					}

					foreach (var f in fileGroups[s])
					{
						if (e != null)
							e.ReportProgress(e.Progress.TaskCount, e.Progress.TaskProgress + 1, string.Format(title, f.Key));

						var ent = entryFactory.MakeFileEntry(f.Key);
						ent.IsUnicodeText = true;
						ent.DateTime = f.Value.LastWriteTime;

						//复制文件内容。简单起见,这里不返回进度显示。。。
						using (var sou = f.Value.OpenRead())
						{
							ent.Size = sou.Length;
							zip.PutNextEntry(ent);
							ICCEmbedded.SharpZipLib.Core.StreamUtils.Copy(sou, zip, new byte[0x400]);
						}
						zip.CloseEntry();
					}
				});
				zip.Flush();
				zip.Close();
			}
		}
开发者ID:shuax,项目名称:FSLib.App.SimpleUpdater,代码行数:53,代码来源:UpdatePackageBuilder.cs


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