本文整理汇总了C#中System.Configuration.Install.InstallException类的典型用法代码示例。如果您正苦于以下问题:C# InstallException类的具体用法?C# InstallException怎么用?C# InstallException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InstallException类属于System.Configuration.Install命名空间,在下文中一共展示了InstallException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Install
//引入命名空间
using System;
using System.ComponentModel;
using System.Collections;
using System.Configuration.Install;
using System.IO;
[RunInstaller(true)]
public class MyInstaller : Installer
{
public override void Install(IDictionary savedState)
{
base.Install(savedState);
Console.WriteLine("Install ...");
// Commit is called when install goes through successfully.
// Rollback is called if there is any error during Install.
// Uncommenting the code below will lead to 'RollBack' being called,
// currently 'Commit' shall be called.
// throw new IOException();
}
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
Console.WriteLine("Commit ...");
// Throw an error if a particular file doesn't exist.
if(!File.Exists("FileDoesNotExist.txt"))
throw new InstallException();
// Perform the final installation if the file exists.
}
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
Console.WriteLine("RollBack ...");
try
{
// Performing some activity during rollback that raises an 'IOException'.
throw new IOException();
}
catch(Exception e)
{
throw new InstallException("IOException raised", e);
}
// Perform the remaining rollback activites if no exception raised.
}
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
Console.WriteLine("UnInstall ...");
// Throw an error if a particular file doesn't exist.
if(!File.Exists("FileDoesNotExist.txt"))
throw new InstallException("The file 'FileDoesNotExist'" +
" does not exist");
// Perform the uninstall activites if the file exists.
}
}
// An Assembly that has its own installer.
public class MyAssembly1
{
public static void Main()
{
Console.WriteLine("This assembly is just an example for the Installer");
}
}
开发者ID:.NET开发者,项目名称:System.Configuration.Install,代码行数:70,代码来源:InstallException
注:本文中的System.Configuration.Install.InstallException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论