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


C# ConfigFile.GetXml方法代码示例

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


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

示例1: TestLoadSaveSamples

        public void TestLoadSaveSamples()
        {
            // \todo: don't use an embedded stream, this is a chicken/egg problem with rewriting sample xmls when configuration changes
            // make sure that every sample configuration loads and saves
            string[] manifestResourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
            foreach (string manifestResourceName in manifestResourceNames)
            {
                if (! manifestResourceName.EndsWith(".Configuration.xml"))
                    continue;

                // fetch the configuration from the resource
                Console.WriteLine(manifestResourceName);
                Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName);
                StreamReader r = new StreamReader(s);
                XmlDocument configXml = new XmlDocument();
                configXml.LoadXml(r.ReadToEnd());
                // load as a configuration
                ConfigFile configFile = new ConfigFile();
                configFile.LoadXml(configXml);
                // compare trivial properties
                Assert.AreEqual("1.0.0.0", configFile.productversion, configFile.productversion);
                Assert.AreEqual(InstallUILevel.full, configFile.ui_level);
                // compare contents
                Assert.AreEqual(configFile.GetXml(null).OuterXml, configXml.OuterXml);
            }
        }
开发者ID:ramiklein,项目名称:dotnetinstaller,代码行数:26,代码来源:SamplesUnitTests.cs

示例2: CreateInstaller

        public static void CreateInstaller(InstallerLinkerArguments args)
        {
            args.Validate();

            args.WriteLine(string.Format("Creating \"{0}\" from \"{1}\"", args.output, args.template));
            System.IO.File.Copy(args.template, args.output, true);
            System.IO.File.SetAttributes(args.output, System.IO.FileAttributes.Normal);

            string configFilename = args.config;

            #region Version Information

            ConfigFile configfile = new ConfigFile();
            configfile.Load(configFilename);

            // \todo: check XML with XSD, warn if nodes are being dropped

            // filter the configuration
            string configTemp = null;
            if (!string.IsNullOrEmpty(args.processorArchitecture))
            {
                int configurationCount = configfile.ConfigurationCount;
                int componentCount = configfile.ComponentCount;
                args.WriteLine(string.Format("Applying processor architecture filter \"{0}\"", args.processorArchitecture));
                ProcessorArchitectureFilter filter = new ProcessorArchitectureFilter(args.processorArchitecture);
                XmlDocument filteredXml = configfile.GetXml(filter);
                configTemp = configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
                filteredXml.Save(configTemp);
                configfile.LoadXml(filteredXml);
                args.WriteLine(string.Format(" configurations: {0} => {1}", configurationCount, configfile.ConfigurationCount));
                args.WriteLine(string.Format(" components: {0} => {1}", componentCount, configfile.ComponentCount));
            }

            args.WriteLine(string.Format("Updating binary attributes in \"{0}\"", args.output));
            VersionResource rc = new VersionResource();
            rc.LoadFrom(args.output);

            // version information
            StringFileInfo stringFileInfo = (StringFileInfo)rc["StringFileInfo"];
            if (!string.IsNullOrEmpty(configfile.productversion))
            {
                rc.ProductVersion = configfile.productversion;
                stringFileInfo["ProductVersion"] = configfile.productversion;
            }

            if (!string.IsNullOrEmpty(configfile.fileversion))
            {
                rc.FileVersion = configfile.fileversion;
                stringFileInfo["FileVersion"] = configfile.fileversion;
            }

            foreach (FileAttribute attr in configfile.fileattributes)
            {
                args.WriteLine(string.Format(" {0}: {1}", attr.name, attr.value));
                stringFileInfo[attr.name] = attr.value;
            }

            rc.Language = ResourceUtil.NEUTRALLANGID;
            rc.SaveTo(args.output);

            #endregion

            #region Optional Icon
            // optional icon
            if (!string.IsNullOrEmpty(args.icon))
            {
                args.WriteLine(string.Format("Embedding icon \"{0}\"", args.icon));
                IconFile iconFile = new IconFile(args.icon);
                List<string> iconSizes = new List<string>();
                foreach (IconFileIcon icon in iconFile.Icons)
                    iconSizes.Add(icon.ToString());
                args.WriteLine(string.Format(" {0}", string.Join(", ", iconSizes.ToArray())));
                IconDirectoryResource iconDirectory = new IconDirectoryResource(iconFile);
                iconDirectory.Name = new ResourceId(128);
                iconDirectory.Language = ResourceUtil.NEUTRALLANGID;
                iconDirectory.SaveTo(args.output);
            }
            #endregion

            #region Manifest
            if (!string.IsNullOrEmpty(args.manifest))
            {
                args.WriteLine(string.Format("Embedding manifest \"{0}\"", args.manifest));
                ManifestResource manifest = new ManifestResource();
                manifest.Manifest.Load(args.manifest);
                manifest.SaveTo(args.output);
            }
            #endregion

            string supportdir = string.IsNullOrEmpty(args.apppath)
                ? Environment.CurrentDirectory
                : args.apppath;

            string templatepath = Path.GetDirectoryName(Path.GetFullPath(args.template));

            // create a temporary directory for CABs
            string cabtemp = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            Directory.CreateDirectory(cabtemp);
            args.WriteLine(string.Format("Writing CABs to \"{0}\"", cabtemp));

//.........这里部分代码省略.........
开发者ID:kod3r,项目名称:dotnetinstaller,代码行数:101,代码来源:InstallerLinker.cs

示例3: TestProcessorArchitectureFilter

        public void TestProcessorArchitectureFilter()
        {
            // configurations
            SetupConfiguration nofilterConfiguration = new SetupConfiguration();
            SetupConfiguration x86Configuration = new SetupConfiguration();
            x86Configuration.processor_architecture_filter = "x86";
            SetupConfiguration x64Configuration = new SetupConfiguration();
            x64Configuration.processor_architecture_filter = "x64";
            SetupConfiguration mipsConfiguration = new SetupConfiguration();
            mipsConfiguration.processor_architecture_filter = "mips";
            // components
            ComponentCmd nofilterComponent = new ComponentCmd();
            ComponentCmd x86Component = new ComponentCmd();
            x86Component.processor_architecture_filter = "x86";
            ComponentCmd x64Component = new ComponentCmd();
            x64Component.processor_architecture_filter = "x64";
            ComponentCmd mipsComponent = new ComponentCmd();
            mipsComponent.processor_architecture_filter = "mips";
            // make a tree
            nofilterConfiguration.Children.Add(nofilterComponent);
            nofilterConfiguration.Children.Add(x86Component);
            nofilterConfiguration.Children.Add(x64Component);
            nofilterConfiguration.Children.Add(mipsComponent);
            x86Configuration.Children.Add(nofilterComponent);
            x86Configuration.Children.Add(x86Component);
            x86Configuration.Children.Add(x64Component);
            x86Configuration.Children.Add(mipsComponent);
            x64Configuration.Children.Add(nofilterComponent);
            x64Configuration.Children.Add(x86Component);
            x64Configuration.Children.Add(x64Component);
            x64Configuration.Children.Add(mipsComponent);
            mipsConfiguration.Children.Add(nofilterComponent);
            mipsConfiguration.Children.Add(x86Component);
            mipsConfiguration.Children.Add(x64Component);
            mipsConfiguration.Children.Add(mipsComponent);
            // configfile
            ConfigFile configFile = new ConfigFile();
            configFile.Children.Add(nofilterConfiguration);
            configFile.Children.Add(x86Configuration);
            configFile.Children.Add(x64Configuration);
            configFile.Children.Add(mipsConfiguration);

            // Console.WriteLine("Total : {0}x{1}", configFile.ConfigurationCount, configFile.ComponentCount);

            TestProcessorArchitectureFilter_TestData[] testdata =
            {
                new TestProcessorArchitectureFilter_TestData("", 4, 16),
                new TestProcessorArchitectureFilter_TestData("x86", 2, 4),
                new TestProcessorArchitectureFilter_TestData("x64", 2, 4),
                new TestProcessorArchitectureFilter_TestData("mips", 2, 4),
                new TestProcessorArchitectureFilter_TestData("sparc", 1, 1),
                new TestProcessorArchitectureFilter_TestData("x86,x64", 3, 9),
                new TestProcessorArchitectureFilter_TestData("alpha,x64", 2, 4),
            };

            foreach (TestProcessorArchitectureFilter_TestData test in testdata)
            {
                ProcessorArchitectureFilter filter = new ProcessorArchitectureFilter(test.Filter);
                XmlDocument filteredXml = configFile.GetXml(filter);
                ConfigFile filteredConfigFile = new ConfigFile();
                filteredConfigFile.LoadXml(filteredXml);
                //Console.WriteLine("{0} - {1}x{2}", test.Filter,
                //    filteredConfigFile.ConfigurationCount, filteredConfigFile.ComponentCount);
                Assert.AreEqual(test.ExpectedConfigs, filteredConfigFile.ConfigurationCount);
                Assert.AreEqual(test.ExpectedComponents, filteredConfigFile.ComponentCount);
            }
        }
开发者ID:ramiklein,项目名称:dotnetinstaller,代码行数:67,代码来源:XmlFilterUnitTests.cs


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