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


C# Request.AddMetadata方法代码示例

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


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

示例1: YieldPackage

        private bool YieldPackage(ProductInstallation package, string searchKey, Request request) {
            if (request.YieldSoftwareIdentity(package.ProductCode, package.ProductName, package.ProductVersion.ToString(), "multipartnumeric", package["Summary"], package.InstallSource, searchKey, package.InstallLocation, "?") != null) {
                if (request.AddMetadata(package.ProductCode, "ProductCode", package.ProductCode) == null) {
                    return false;
                }

                if (request.AddMetadata(package.ProductCode, "UpgradeCode", package["UpgradeCode"]) == null) {
                    return false;
                }
                return true;
            }
            return false;
        }
开发者ID:vairam-svs,项目名称:oneget,代码行数:13,代码来源:MsiProvider.cs

示例2: 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

示例3: YieldPackage

        /// <summary>
        /// Yields package information to OneGet Core
        /// </summary>
        /// <param name="searchKey"></param>
        /// <param name="request"></param>
        /// <param name="title"></param>
        /// <param name="supportUrl"></param>
        /// <param name="date"></param>
        /// <param name="resultCode"></param>
        /// <param name="description"></param>
        /// <returns>Whether operation succeeded or was interrupted</returns>
        private bool YieldPackage(string searchKey, Request request, string title, string supportUrl, DateTime? date, int? resultCode, string description)
        {
            if (request.YieldSoftwareIdentity(title, title, null, null, description, null, searchKey, "?", "?") != null)
            {
                if (request.AddMetadata("SupportUrl", supportUrl) == null)
                {
                    return false;
                }

                if (date != null && request.AddMetadata("Date", ((DateTime)date).ToString(CultureInfo.CurrentCulture)) == null)
                {
                    return false;
                }

                if (resultCode != null && request.AddMetadata("ResultCode", resultCode.ToString()) == null)
                {
                    return false;
                }
                return true;
            }
            return false;
        }
开发者ID:vairam-svs,项目名称:oneget,代码行数:33,代码来源:MsuProvider.cs

示例4: 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())
            {
                var info = new CabInfo(file);

                request.YieldSoftwareIdentity(file, info.Name, null, null, null, null, null, file, info.Name);

                var files = info.GetFiles();
                foreach (var i in files) {
                    // read the properties file
                    if (i.FullNameExtension == ".txt")
                    {
                        request.Debug("Reading properties file {0}", i.FullName);
                        using (var reader = i.OpenText())
                        {
                            var contents = reader.ReadToEnd();
                            Dictionary<string, string> keyValuePairs = contents.Split('\n').Select(line => line.Split('=')).Where(v => v.Count() == 2).ToDictionary(pair => pair[0], pair => pair[1]);

                            foreach (var pair in keyValuePairs)
                            {
                                request.AddMetadata(pair.Key.Replace(' ', '_'), pair.Value.Replace("\"", "").Replace("\r", ""));
                            }
                        }
                    }
                }
            }
        }
开发者ID:vairam-svs,项目名称:oneget,代码行数:51,代码来源:MsuProvider.cs

示例5: YieldPackage

        private bool YieldPackage(string path, string searchKey, Dictionary<string, string> properties, Request request) {
            var productName = properties.Get("DisplayName") ?? "";
            var productVersion = properties.Get("DisplayVersion") ?? "";
            var publisher = properties.Get("Publisher") ?? "";
            var uninstallString = properties.Get("QuietUninstallString") ?? properties.Get("UninstallString") ?? "";
            var comments = properties.Get("Comments") ?? "";

            if (request.YieldSoftwareIdentity(path, productName, productVersion, "unknown", comments, "", searchKey, "", "") != null) {
                if (properties.Keys.Where(each => !string.IsNullOrWhiteSpace(each)).Any(k => request.AddMetadata(path, k.MakeSafeFileName(), properties[k]) == null)) {
                    return false;
                }
            }
            return true;
        }
开发者ID:vairam-svs,项目名称:oneget,代码行数:14,代码来源:ProgramsProvider.cs

示例6: YieldPackages

        private bool YieldPackages(string hive, RegistryKey regkey, string name,string requiredVersion, string minimumVersion, string maximumVersion, Request request) {
            if (regkey != null) {
                var includeWindowsInstaller = request.GetOptionValue("IncludeWindowsInstaller").IsTrue();
                var includeSystemComponent = request.GetOptionValue("IncludeSystemComponent").IsTrue();

                foreach (var key in regkey.GetSubKeyNames()) {
                    var subkey = regkey.OpenSubKey(key);
                    if (subkey != null) {
                        var properties = subkey.GetValueNames().ToDictionaryNicely(each => each.ToString(), each => (subkey.GetValue(each) ?? string.Empty).ToString(), StringComparer.OrdinalIgnoreCase);

                        if (!includeWindowsInstaller && properties.ContainsKey("WindowsInstaller") && properties["WindowsInstaller"] == "1") {
                            continue;
                        }

                        if (!includeSystemComponent && properties.ContainsKey("SystemComponent") && properties["SystemComponent"] == "1") {
                            continue;
                        }

                        var productName = "";

                        if (!properties.TryGetValue("DisplayName", out productName)) {
                            // no product name?
                            continue;
                        }

                        if (string.IsNullOrWhiteSpace(name) || productName.IndexOf(name, StringComparison.OrdinalIgnoreCase) > -1) {
                            var productVersion = properties.Get("DisplayVersion") ?? "";
                            var publisher = properties.Get("Publisher") ?? "";
                            var uninstallString = properties.Get("QuietUninstallString") ?? properties.Get("UninstallString") ?? "";
                            var comments = properties.Get("Comments") ?? "";

                            var fp = hive + @"\" + subkey;

                            if (!string.IsNullOrEmpty(requiredVersion)) {
                                if (SoftwareIdentityVersionComparer.CompareVersions("unknown", requiredVersion, productVersion) != 0) {
                                    continue;
                                }
                            } else {
                                if (!string.IsNullOrEmpty(minimumVersion) && SoftwareIdentityVersionComparer.CompareVersions("unknown", productVersion, minimumVersion) < 0) {
                                    continue;
                                }
                                if (!string.IsNullOrEmpty(maximumVersion) && SoftwareIdentityVersionComparer.CompareVersions("unknown", productVersion, maximumVersion) > 0) {
                                    continue;
                                }
                            }

                            if (request.YieldSoftwareIdentity(fp, productName, productVersion, "unknown", comments, "", name, "", "") != null) {
                                if (properties.Keys.Where(each => !string.IsNullOrWhiteSpace(each)).Any(k => request.AddMetadata(fp, k.MakeSafeFileName(), properties[k]) == null)) {
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
            return true;
        }
开发者ID:vairam-svs,项目名称:oneget,代码行数:57,代码来源:ProgramsProvider.cs

示例7: FindPackage

        public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, Request request)
        {
            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::FindPackage' '{1}','{2}','{3}','{4}'", PackageProviderName, requiredVersion, minimumVersion, maximumVersion, id);

            if (name == "test") {
                // this just returns packages so we can test the calls for creating software identity objects back in the core.
                var pkg = request.YieldSoftwareIdentity("firstpackage", "first", "1.0", "multipartnumeric", "first package", "built-in", "test", "", "");
                if (pkg != null) {
                    if (request.IsCanceled) {
                        return;
                    } // check early, check often.

                    // add a dependency to another package.
                    var link = request.AddDependency(PackageProviderName, "second", "1.1", null, null);
                    if (request.IsCanceled) {
                        return;
                    } // check early, check often.

                    var entity = request.AddEntity("garrett", "http://fearthecowboy.com", Iso19770_2.Role.Publisher, null);
                    if (request.IsCanceled) {
                        return;
                    } // check early, check often.

                    var icon = request.AddLink(new Uri("http://contoso.com/icon.png"), "icon", "image/icon", null, null, null, null);
                    if (request.IsCanceled) {
                        return;
                    } // check early, check often.

                    request.AddMetadata("Something", "Shiny");
                    request.AddMetadata(pkg, "SomeKey", "SomeValue");
                    request.AddMetadata(pkg, new Uri("http://oneget.org/oneget"), "testkey", "testvalue");
                    if (request.IsCanceled) {
                        return;
                    } // check early, check often.

                    // some expected payload data
                    var payload = request.AddPayload();
                    request.Debug("Payload:{0}", payload);
                    if (request.IsCanceled) {
                        return;
                    } // check early, check often.

                    var dir = request.AddDirectory(payload, "installDir", "", "PROGRAMFILES", false);
                    request.Debug("Directory:{0}", dir);
                    if (request.IsCanceled) {
                        return;
                    } // check early, check often.

                    var file = request.AddFile(dir, "foo.txt", null, null, true, 10240, "1.0");
                    request.Debug("File:{0}", file);
                    if (request.IsCanceled) {
                        return;
                    } // check early, check often.

                    var regkey = request.AddResource(payload, "regkey");
                    request.AddMetadata(regkey, "key", "hklm/software/testing/foo");
                    request.AddMetadata(regkey, "value", "hklm/software/testing/foo");
                    if (request.IsCanceled) {
                        return;
                    } // check early, check often.
                }

                pkg = request.YieldSoftwareIdentity("secondpackage", "second", "1.1", "multipartnumeric", "second package", "built-in", "test", "", "");
                if (pkg != null) {
                    if (request.IsCanceled) {
                        return;
                    } // check early, check often.

                    var entity = request.AddEntity("garrett", "http://fearthecowboy.com", Iso19770_2.Role.Publisher, null);
                    if (request.IsCanceled) {
                        return;
                    } // check early, check often.

                    // show some evidence (yeah, this should have been in the getinstalledpackages but ... lazy.)
                    var evidence = request.AddEvidence(DateTime.Now, "thispc");
                    request.AddProcess(evidence, "foo.exe", 100);

                    var meta = request.AddMeta(pkg);
                    request.AddMetadata(meta, "sample", "value");
                    request.AddMetadata(meta, new Uri("http://oneget.org/oneget"), "testkey", "testvalue");

                    var link = request.AddDependency(PackageProviderName, "third", "[1.0]", null, null);
                }
            }
        }
开发者ID:notgerry,项目名称:oneget,代码行数:86,代码来源:SwidTestProvider.cs


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