本文整理汇总了C#中InstallerLib.ConfigFile.Load方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigFile.Load方法的具体用法?C# ConfigFile.Load怎么用?C# ConfigFile.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InstallerLib.ConfigFile
的用法示例。
在下文中一共展示了ConfigFile.Load方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestConfigReadWrite
public void TestConfigReadWrite()
{
// generate a configuration with as many changed values as possible, write/read and compare
// ensures that all fields are property read and written to/from configuration files
string configFilenameOriginal = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
string configFilenameLoaded = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
// original file
ConfigFile configFileOriginal = new ConfigFile();
GenerateChildren(configFileOriginal);
Console.WriteLine("Writing '{0}'", configFilenameOriginal);
configFileOriginal.SaveAs(configFilenameOriginal);
// loaded file
ConfigFile configFileLoaded = new ConfigFile();
configFileLoaded.Load(configFilenameOriginal);
Console.WriteLine("Writing '{0}'", configFilenameLoaded);
configFileLoaded.SaveAs(configFilenameLoaded);
// compare
XmlDocument originalXml = new XmlDocument();
originalXml.Load(configFilenameOriginal);
XmlDocument loadedXml = new XmlDocument();
loadedXml.Load(configFilenameLoaded);
// compare contents
Assert.AreEqual(originalXml.OuterXml, loadedXml.OuterXml);
// delete files on success, otherwise keep for diff
File.Delete(configFilenameOriginal);
File.Delete(configFilenameLoaded);
}
示例2: Main
public static int Main(string[] args)
{
int rc = 0;
Console.WriteLine("InstallerConfig: dotNetInstaller configuration (re)writer ({0})", Assembly.GetExecutingAssembly().GetName().Version);
Console.WriteLine();
InstallerConfigArguments i_args = new InstallerConfigArguments();
if (Parser.ParseArgumentsWithUsage(args, i_args))
{
try
{
ConfigFile configFile = new ConfigFile();
configFile.Load(i_args.configfile);
configFile.SaveAs(string.IsNullOrEmpty(i_args.outputfile)
? i_args.configfile
: i_args.outputfile);
}
catch (Exception ex)
{
Console.Error.WriteLine("ERROR: {0}", ex.Message);
#if DEBUG
Console.Error.WriteLine(ex.StackTrace);
#endif
rc = -2;
}
}
else
{
rc = -1;
}
return rc;
}
示例3: TestSaveConfiguration
public void TestSaveConfiguration()
{
ConfigFile configFile = new ConfigFile();
SetupConfiguration setupConfiguration = new SetupConfiguration();
configFile.Children.Add(setupConfiguration);
string configFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
Console.WriteLine("Writing '{0}'", configFileName);
configFile.SaveAs(configFileName);
try
{
ProcessStartInfo pi = new ProcessStartInfo(InstallerEditorExeUtils.Executable, "\"" + configFileName + "\"");
using (Application installerEditor = Application.Launch(pi))
{
Window mainWindow = installerEditor.GetWindow(
string.Format("Installer Editor - {0}", configFileName), InitializeOption.NoCache);
StatusStrip statusStrip = UIAutomation.Find<StatusStrip>(mainWindow, "statusStrip");
WinFormTextBox statusLabel = (WinFormTextBox)statusStrip.Items[0];
Assert.AreEqual(string.Format("Loaded {0}", configFileName), statusLabel.Text);
UIAutomation.Find<MenuBar>(mainWindow, "Application").MenuItem("Edit", "Add", "Configurations", "Setup Configuration").Click();
UIAutomation.Find<MenuBar>(mainWindow, "Application").MenuItem("File", "Save").Click();
Assert.AreEqual(string.Format("Written {0}", configFileName), statusLabel.Text);
ConfigFile savedConfigFile = new ConfigFile();
savedConfigFile.Load(configFileName);
Assert.AreEqual(2, savedConfigFile.Children.Count);
}
}
finally
{
File.Delete(configFileName);
}
}
示例4: TestSaveAsConfiguration
public void TestSaveAsConfiguration()
{
string configFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
try
{
using (Application installerEditor = Application.Launch(InstallerEditorExeUtils.Executable))
{
Window mainWindow = installerEditor.GetWindow("Installer Editor", InitializeOption.NoCache);
UIAutomation.Find<MenuBar>(mainWindow, "Application").MenuItem("File", "New").Click();
UIAutomation.Find<MenuBar>(mainWindow, "Application").MenuItem("Edit", "Add", "Configurations", "Setup Configuration").Click();
Menu mainMenuFile = UIAutomation.Find<MenuBar>(mainWindow, "Application").MenuItem("File");
mainMenuFile.Click();
Assert.IsFalse(mainMenuFile.ChildMenus.Find("Save").Enabled);
mainMenuFile.ChildMenus.Find("Save As...").Click();
Window openWindow = mainWindow.ModalWindow("Save As");
TextBox filenameTextBox = openWindow.Get<TextBox>("File name:");
filenameTextBox.Text = configFileName;
openWindow.KeyIn(KeyboardInput.SpecialKeys.RETURN);
openWindow.WaitWhileBusy();
mainWindow.WaitWhileBusy();
Assert.IsTrue(File.Exists(configFileName));
Assert.IsTrue(UIAutomation.Find<MenuBar>(mainWindow, "Application").MenuItem("File", "Save").Enabled);
StatusStrip statusStrip = UIAutomation.Find<StatusStrip>(mainWindow, "statusStrip");
WinFormTextBox statusLabel = (WinFormTextBox)statusStrip.Items[0];
Assert.AreEqual(string.Format("Written {0}", configFileName), statusLabel.Text);
ConfigFile savedConfigFile = new ConfigFile();
savedConfigFile.Load(configFileName);
Assert.AreEqual(1, savedConfigFile.Children.Count);
}
}
finally
{
if (File.Exists(configFileName))
File.Delete(configFileName);
}
}
示例5: 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));
//.........这里部分代码省略.........