本文整理汇总了C#中Request.StartProgress方法的典型用法代码示例。如果您正苦于以下问题:C# Request.StartProgress方法的具体用法?C# Request.StartProgress怎么用?C# Request.StartProgress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Request
的用法示例。
在下文中一共展示了Request.StartProgress方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _UnpackArchive
private IEnumerable<string> _UnpackArchive(string localFilename, string destinationFolder, Request request) {
var info = new ZipInfo(localFilename);
var files = info.GetFiles();
var percent = 0;
var index = 0;
var processed = new List<string>();
// request.Debug("Unpacking {0} {1}", localFilename, destinationFolder);
var pid = request.StartProgress(0, "Unpacking Archive '{0}' ", Path.GetFileName(localFilename));
try {
info.Unpack(destinationFolder, (sender, args) => {
if (args.ProgressType == ArchiveProgressType.FinishFile) {
processed.Add(Path.Combine(destinationFolder, args.CurrentFileName));
index++;
var complete = (index*100)/files.Count;
if (complete != percent) {
percent = complete;
request.Progress(pid, percent, "Unpacked {0}", args.CurrentFileName);
}
/*
* Does not currently support cancellation .
* Todo: add cancellation support to DTF compression classes.
* */
if (request.IsCanceled) {
throw new OperationCanceledException("cancelling");
}
}
});
} catch (OperationCanceledException) {
// no worries.
}
// request.Debug("DONE Unpacking {0} {1}", localFilename, destinationFolder);
request.CompleteProgress(pid, true);
// return the list of files to the parent.
return processed.ToArray();
}
示例2: InstallPackage
/// <summary>
/// Installs a given package.
/// </summary>
/// <param name="fastPackageReference">A provider supplied identifier that specifies an exact package</param>
/// <param name="request">
/// An object passed in from the CORE that contains functions that can be used to interact with
/// the CORE and HOST
/// </param>
public void InstallPackage(string fastPackageReference, Request request) {
if( request == null ) {
throw new ArgumentNullException("request");
}
if( string.IsNullOrWhiteSpace(fastPackageReference) ) {
throw new ArgumentNullException("fastPackageReference");
}
// Nice-to-have put a debug message in that tells what's going on.
request.Debug("Calling '{0}::InstallPackage' '{1}'", ProviderName, fastPackageReference);
var file = fastPackageReference.CanonicalizePath(false);
if (!file.FileExists()) {
request.Error(ErrorCategory.OpenError, fastPackageReference, Constants.Messages.UnableToResolvePackage, fastPackageReference);
return;
}
try {
var package = new InstallPackage(file, DatabaseOpenMode.ReadOnly);
Installer.SetInternalUI(InstallUIOptions.UacOnly | InstallUIOptions.Silent);
// todo 1501: support additional parameters!
var handler = CreateProgressHandler(request);
_progressId = request.StartProgress(0, "Installing MSI '{0}'", file);
Installer.SetExternalUI(handler, InstallLogModes.Progress | InstallLogModes.Info);
Installer.InstallProduct(file, "REBOOT=REALLYSUPPRESS");
Installer.SetInternalUI(InstallUIOptions.Default);
Installer.SetExternalUI(handler, InstallLogModes.None);
YieldPackage(package, file, request);
package.Close();
if (Installer.RebootRequired) {
request.Warning("Reboot is required to complete Installation.");
}
} catch (Exception e) {
e.Dump();
request.Error(ErrorCategory.InvalidOperation, file, Constants.Messages.UnableToResolvePackage, file);
}
request.CompleteProgress(_progressId, true);
}
示例3: UninstallPackage
/// <summary>
/// Uninstalls a package
/// </summary>
/// <param name="fastPackageReference"></param>
/// <param name="request">
/// An object passed in from the CORE that contains functions that can be used to interact with
/// the CORE and HOST
/// </param>
public void UninstallPackage(string fastPackageReference, Request request) {
if( request == null ) {
throw new ArgumentNullException("request");
}
if( string.IsNullOrWhiteSpace(fastPackageReference) ) {
throw new ArgumentNullException("fastPackageReference");
}
// Nice-to-have put a debug message in that tells what's going on.
request.Debug("Calling '{0}::UninstallPackage' '{1}'", ProviderName, fastPackageReference);
try {
Guid guid;
if (!Guid.TryParse(fastPackageReference, out guid)) {
request.Error(ErrorCategory.InvalidArgument, fastPackageReference, Constants.Messages.UnableToResolvePackage, fastPackageReference);
return;
}
var product = ProductInstallation.GetProducts(fastPackageReference, null, UserContexts.All).FirstOrDefault();
if (product == null) {
request.Error(ErrorCategory.InvalidArgument, fastPackageReference, Constants.Messages.UnableToResolvePackage, fastPackageReference);
return;
}
var productVersion = product.ProductVersion.ToString();
var productName = product.ProductName;
var summary = product["Summary"];
Installer.SetInternalUI(InstallUIOptions.UacOnly | InstallUIOptions.Silent);
_progressId = request.StartProgress(0, "Uninstalling MSI '{0}'", productName);
var handler = CreateProgressHandler(request);
Installer.SetExternalUI(handler, InstallLogModes.Progress | InstallLogModes.Info);
Installer.InstallProduct(product.LocalPackage, "REMOVE=ALL REBOOT=REALLYSUPPRESS");
Installer.SetInternalUI(InstallUIOptions.Default);
Installer.SetExternalUI(handler, InstallLogModes.None);
// YieldPackage(product,fastPackageReference, request);
if (request.YieldSoftwareIdentity(fastPackageReference, productName, productVersion, "multipartnumeric", summary, "", fastPackageReference, "", "") != null) {
request.AddMetadata(fastPackageReference, "ProductCode", fastPackageReference);
}
request.Warning("Reboot is required to complete uninstallation.");
} catch (Exception e) {
e.Dump();
}
request.CompleteProgress(_progressId, true);
_progressId = 0;
}
示例4: InstallPackage
/// <summary>
/// Installs a given package.
/// </summary>
/// <param name="fastPackageReference">A provider supplied identifier that specifies an exact package</param>
/// <param name="request">
/// An object passed in from the CORE that contains functions that can be used to interact with
/// the CORE and HOST
/// </param>
public void InstallPackage(string fastPackageReference, Request request) {
if( request == null ) {
throw new ArgumentNullException("request");
}
if( string.IsNullOrWhiteSpace(fastPackageReference) ) {
throw new ArgumentNullException("fastPackageReference");
}
// Nice-to-have put a debug message in that tells what's going on.
request.Debug("Calling '{0}::InstallPackage' '{1}'", ProviderName, fastPackageReference);
var file = fastPackageReference.CanonicalizePath(false);
if (!file.FileExists()) {
request.Error(Microsoft.PackageManagement.Internal.ErrorCategory.OpenError, fastPackageReference, Constants.Messages.UnableToResolvePackage, fastPackageReference);
return;
}
string errorLogFolder = Path.GetTempPath() + Guid.NewGuid();
DirectoryInfo errorDir = Directory.CreateDirectory(errorLogFolder);
string errorLogPath = errorLogFolder + "\\msi.log";
try {
var package = new InstallPackage(file, DatabaseOpenMode.ReadOnly);
Installer.SetInternalUI(InstallUIOptions.UacOnly | InstallUIOptions.Silent);
// todo 1501: support additional parameters!
if (request.Sources != null && request.Sources.Any()) {
// The 'file' can be from a temp location downloaded by a chained provider. In that case, we can show
// the orignal package source specified in the request.Sources.
_progressId = request.StartProgress(0, Resources.Messages.InstallingMSIPackage, request.Sources.FirstOrDefault());
} else {
_progressId = request.StartProgress(0, Resources.Messages.InstallingMSIPackage, file);
}
var handler = CreateProgressHandler(request, Resources.Messages.Installing);
Installer.SetExternalUI(handler, InstallLogModes.Progress | InstallLogModes.Info);
Installer.EnableLog(InstallLogModes.Error, errorLogPath);
Installer.InstallProduct(file, "REBOOT=REALLYSUPPRESS");
Installer.SetInternalUI(InstallUIOptions.Default);
Installer.SetExternalUI(handler, InstallLogModes.None);
if (request.Sources != null && request.Sources.Any()) {
// The 'file' can be from a temp location downloaded by a chained provider. In that case, we can show
// the orignal package source specified in the request.Sources.
YieldPackage(package, request.Sources.FirstOrDefault(), request);
} else {
YieldPackage(package, file, request);
}
package.Close();
if (Installer.RebootRequired) {
request.Warning(Resources.Messages.InstallRequireReboot);
}
if (errorDir.Exists)
errorDir.Delete(true);
} catch (Exception e) {
e.Dump();
request.Error(Microsoft.PackageManagement.Internal.ErrorCategory.InvalidOperation, file, Constants.Messages.PackageFailedInstallErrorLog, file, errorLogPath);
}
request.CompleteProgress(_progressId, true);
}