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


C# Request.Error方法代码示例

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


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

示例1: FindPackageByFile

        /// <summary>
        ///     Finds packages given a locally-accessible filename
        ///     Package information must be returned using <c>request.YieldPackage(...)</c> function.
        /// </summary>
        /// <param name="file">the full path to the file to determine if it is a package</param>
        /// <param name="id">
        ///     if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>,
        ///     the core is calling this multiple times to do a batch search request. The operation can be delayed until
        ///     <c>CompleteFind(...)</c> is called
        /// </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 FindPackageByFile(string file, int id, Request request)
        {
            if( request == null ) {
                throw new ArgumentNullException("request");
            }
            if( string.IsNullOrWhiteSpace(file) ) {
                throw new ArgumentNullException("file");
            }

            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::FindPackageByFile' '{1}','{2}'", ProviderName, file, id);

            if (!file.FileExists()) {
                request.Error(ErrorCategory.ObjectNotFound, file, Constants.Messages.UnableToResolvePackage, file);
                return;
            }
            try {
                var package = new InstallPackage(file, DatabaseOpenMode.ReadOnly);
                YieldPackage(package, file, request);
                package.Close();
            } catch (Exception e) {
                e.Dump();
                // any exception at this point really just means that
                request.Error(ErrorCategory.OpenError, file, Constants.Messages.UnableToResolvePackage, file);
            }
        }
开发者ID:notgerry,项目名称:oneget,代码行数:40,代码来源:MsiProvider.cs

示例2: RemovePackageSource

        public void RemovePackageSource(string name, Request request)
        {
            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::RemovePackageSource' '{1}'", PackageProviderName, name);
            var pkgSource = packageSources.FirstOrDefault(each => each.name.EqualsIgnoreCase(name));
            if (pkgSource == null) {
                pkgSource = packageSources.FirstOrDefault(each => each.location.EqualsIgnoreCase(name));
            }
            if (pkgSource == null) {
                request.Error(ErrorCategory.ObjectNotFound, name, Constants.Messages.UnableToResolveSource, name);
                return;
            }
            // tell the user what we removed.
            request.YieldPackageSource(pkgSource.name, pkgSource.location, pkgSource.isTrusted, true, pkgSource.isValidated);

            //remove it from the list.
            packageSources = packageSources.Where(each => each != pkgSource).ToArray();
        }
开发者ID:notgerry,项目名称:oneget,代码行数:18,代码来源:Happy1.cs

示例3: AddPackageSource

        public void AddPackageSource(string name, string location, bool trusted, Request request)
        {
            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::AddPackageSource' '{1}','{2}','{3}'", PackageProviderName, name, location, trusted);

            var pkgSource = packageSources.FirstOrDefault(each => each.name.EqualsIgnoreCase(name));
            if (pkgSource != null && !request.GetOptionValue(Constants.Parameters.IsUpdate).IsTrue()) {
                // pkgSource already exists.
                // this is an error.
                request.Error(ErrorCategory.ResourceExists, name, Constants.Messages.PackageSourceExists, name);
                return;
            }

            if (pkgSource != null) {
                //update
                pkgSource.location = location;
                pkgSource.isTrusted = trusted;
            } else {
                // add new
                pkgSource = new PkgSource {
                    name = name,
                    location = location,
                    isTrusted = trusted,
                    isValidated = true
                };
                // add to the array.
                packageSources = packageSources.ConcatSingleItem(pkgSource).ToArray();
            }

            request.YieldPackageSource(pkgSource.name, pkgSource.location, pkgSource.isTrusted, true, pkgSource.isValidated);
        }
开发者ID:notgerry,项目名称:oneget,代码行数:31,代码来源:Happy1.cs

示例4: 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;
        }
开发者ID:vairam-svs,项目名称:oneget,代码行数:55,代码来源:MsiProvider.cs

示例5: 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);
        }
开发者ID:vairam-svs,项目名称:oneget,代码行数:50,代码来源:MsiProvider.cs

示例6: UninstallPackage


//.........这里部分代码省略.........
                        }
                        break;
                    case "hkcu32":
                        using (var product = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32).OpenSubKey(path[2], RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey)) {
                            if (product == null) {
                                return;
                            }
                            properties = product.GetValueNames().ToDictionaryNicely(each => each.ToString(), each => (product.GetValue(each) ?? string.Empty).ToString(), StringComparer.OrdinalIgnoreCase);
                            uninstallCommand = properties.Get("QuietUninstallString") ?? properties.Get("UninstallString") ?? "";
                        }
                        break;
                }

                if (properties == null) {
                    return;
                }

                if (!string.IsNullOrWhiteSpace(uninstallCommand)) {
                    do {
                        if (File.Exists(uninstallCommand)) {
                            ExecStandalone(request, uninstallCommand);
                            break;
                        }

                        // not a single file.
                        // check if it's just quoted.
                        var c = uninstallCommand.Trim('\"');
                        if (File.Exists(c)) {
                            ExecStandalone(request, c);
                            break;
                        }

                        if (uninstallCommand.IndexOf("msiexec", StringComparison.OrdinalIgnoreCase) > -1) {
                            MsiUninstall(request, uninstallCommand);
                            break;
                        }

                        if (uninstallCommand.IndexOf("rundll32", StringComparison.OrdinalIgnoreCase) > -1) {
                            RunDll32(request, uninstallCommand);
                            break;
                        }

                        if (uninstallCommand.IndexOf("cmd.exe", StringComparison.OrdinalIgnoreCase) == 0) {
                            CmdCommand(request, uninstallCommand);
                            continue;
                        }

                        if (uninstallCommand.IndexOf("cmd ", StringComparison.OrdinalIgnoreCase) == 0) {
                            CmdCommand(request, uninstallCommand);
                            continue;
                        }

                        if (uninstallCommand[0] == '"') {
                            var p = uninstallCommand.IndexOf('"', 1);
                            if (p > 0) {
                                var file = uninstallCommand.Substring(1, p - 1);
                                var args = uninstallCommand.Substring(p + 1);
                                if (File.Exists(file)) {
                                    CommandWithParameters(request, file, args);
                                }
                            }
                        } else {
                            var p = uninstallCommand.IndexOf(' ');
                            if (p > 0) {
                                var file = uninstallCommand.Substring(0, p);
                                var args = uninstallCommand.Substring(p + 1);
                                if (File.Exists(file)) {
                                    CommandWithParameters(request, file, args);
                                    continue;
                                }

                                var s = 0;
                                do {
                                    s = uninstallCommand.IndexOf(' ', s + 1);
                                    if (s == -1) {
                                        break;
                                    }
                                    file = uninstallCommand.Substring(0, s);
                                    if (File.Exists(file)) {
                                        args = uninstallCommand.Substring(s + 1);
                                        CommandWithParameters(request, file, args);
                                        break;
                                    }
                                } while (s > -1);

                                if (s == -1) {
                                    // never found a way to parse the command :(
                                    request.Error(ErrorCategory.InvalidOperation, properties["DisplayName"], Constants.Messages.UnableToUninstallPackage);
                                    return;
                                }
                            }
                        }
                    } while (false);
                    YieldPackage(fastPackageReference, fastPackageReference, properties, request);
                    return;
                }
                request.Error(ErrorCategory.InvalidOperation, properties["DisplayName"], Constants.Messages.UnableToUninstallPackage);

            }
        }
开发者ID:vairam-svs,项目名称:oneget,代码行数:101,代码来源:ProgramsProvider.cs

示例7: 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);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:74,代码来源:MsiProvider.cs

示例8: 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");
            }

            string errorLogFolder = Path.GetTempPath() + Guid.NewGuid();
            DirectoryInfo errorDir = Directory.CreateDirectory(errorLogFolder);
            string errorLogPath = errorLogFolder + "\\msuLog.evtx";       

            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::InstallPackage' '{1}'", ProviderName, fastPackageReference);

            string output;
            string args = "\"" + fastPackageReference + "\"" + " /quiet /norestart /log:" + "\"" + errorLogPath + "\"";
            int exitCode = request.ProviderServices.StartProcess(WusaExecutableLocation, args, true, out output, request);
            if (exitCode == 0)
            {
                request.Verbose("Provider '{0}', Package '{1}': Installation succeeded", ProviderName, fastPackageReference);
            }
            else if (exitCode == 3010) //Exit code: 3010 (0xBC2) ERROR_SUCCESS_REBOOT_REQUIRED
            {                
                request.Warning(Resources.Messages.InstallRequiresReboot);
            }
            else
            {
                request.Error(Microsoft.PackageManagement.Internal.ErrorCategory.InvalidOperation, fastPackageReference, Resources.Messages.InstallFailed, fastPackageReference, String.Format(CultureInfo.CurrentCulture, "0x{0:X}", exitCode), errorLogPath);
            }

            try {
                if (exitCode == 0 || exitCode == 3010)
                {
                    if (errorDir.Exists)
                        errorDir.Delete(true);
                }
            } catch {
            }
            
        }
开发者ID:40a,项目名称:PowerShell,代码行数:49,代码来源:MsuProvider.cs


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