本文整理汇总了C#中System.Configuration.Install.AssemblyInstaller.Rollback方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyInstaller.Rollback方法的具体用法?C# AssemblyInstaller.Rollback怎么用?C# AssemblyInstaller.Rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Configuration.Install.AssemblyInstaller
的用法示例。
在下文中一共展示了AssemblyInstaller.Rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstallTheService
public void InstallTheService()
{
try
{
IDictionary state = new Hashtable();
using (AssemblyInstaller installer = new AssemblyInstaller(InstallersAssembly, Args))
{
installer.UseNewContext = true;
try
{
installer.Install(state);
installer.Commit(state);
InternalTrace("Installed the service");
}
catch (Exception installException)
{
try
{
installer.Rollback(state);
InternalTrace("Rolledback the service installation because:" + installException.ToString());
}
catch { }
throw;
}
}
}
catch (Exception exception)
{
InternalTrace("Failed to install the service " + exception.ToString());
}
}
示例2: Uninstall
public static void Uninstall(string[] args)
{
try
{
using (var installer = new AssemblyInstaller(typeof(InstallationManager).Assembly, args))
{
IDictionary state = new Hashtable();
// Install the service
installer.UseNewContext = true;
try
{
installer.Uninstall(state);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
try
{
installer.Rollback(state);
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
}
}
}
}
catch (Exception exception)
{
Console.WriteLine("Failed to install service. Error: " + exception.Message);
}
}
示例3: InstallService
public void InstallService(string user, string pass) {
using (AssemblyInstaller installer = new AssemblyInstaller(Path.Combine(Utils.GetApplicationPath(), Utils.GetExecutableName()), null)) {
installer.UseNewContext = true;
Hashtable savedState = new Hashtable();
UserPassCombination c = new UserPassCombination();
c.User = user;
c.Pass = pass;
_userPassCombination = c;
installer.BeforeInstall += new InstallEventHandler(installer_BeforeInstall);
//Rollback has to be called by user code. According msdn-doc for AssemblyInstaller.Install() is probably wrong.
try {
installer.Install(savedState);
installer.Commit(savedState);
}
catch (Exception ex) {
installer.Rollback(savedState);
throw new InstallException(String.Format("Install failed: {0}", ex.Message), ex);
}
installer.BeforeInstall -= installer_BeforeInstall;
}
}
示例4: TryRollback
private void TryRollback(AssemblyInstaller installer, IDictionary state)
{
try { installer.Rollback(state); }
catch (Exception ex )
{
_log.Write(LogLevel.Warning, "An error occured during rollback. {0}", ex);
}
}
示例5: Install
static void Install(bool undo, string[] args)
{
try
{
Console.WriteLine(undo ? "uninstalling" : "installing");
using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args))
{
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
if (undo)
{
inst.Uninstall(state);
}
else
{
inst.Install(state);
inst.Commit(state);
try
{
ServiceController service = new ServiceController("DpFamService");
TimeSpan timeout = TimeSpan.FromMilliseconds(1000);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch
{
Console.WriteLine("Could not start the server\n");
}
}
}
catch
{
try
{
inst.Rollback(state);
}
catch { }
throw;
}
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
}
示例6: Install
public static bool Install()
{
Tracker.StartServer();
bool result = true;
InstallContext context = null;
try
{
using (var inst = new AssemblyInstaller(typeof (ServerLifecycleManager).Assembly, null))
{
context = inst.Context;
LogMessage("Installing service " + AppSettings.ServiceName, inst.Context);
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
inst.Install(state);
inst.Commit(state);
Tracker.TrackEvent(TrackerEventGroup.Installations, TrackerEventName.Installed);
}
catch (Exception err)
{
Tracker.TrackException("WindowsServiceManager", "Install", err);
try
{
inst.Rollback(state);
}
catch (Exception innerErr)
{
throw new AggregateException(new List<Exception> {err, innerErr});
}
throw;
}
}
}
catch (Exception ex)
{
result = false;
WriteExceptions(ex, context);
}
finally
{
Tracker.Stop();
}
return result;
}
示例7: Install
// References http://stackoverflow.com/questions/1195478/how-to-make-a-net-windows-service-start-right-after-the-installation/1195621#1195621
public static void Install()
{
using (AssemblyInstaller installer =
new AssemblyInstaller(typeof(OpenVpnService).Assembly, null))
{
installer.UseNewContext = true;
var state = new System.Collections.Hashtable();
try
{
installer.Install(state);
installer.Commit(state);
} catch
{
installer.Rollback(state);
throw;
}
}
}
示例8: Install
static void Install(bool undo, string[] args)
{
try
{
Logger.Log(undo ? "Uninstalling ..." : "Installing ... ");
using (var inst = new AssemblyInstaller(typeof(Program).Assembly, args))
{
var state = new Hashtable();
inst.UseNewContext = true;
try
{
if (undo)
{
inst.Uninstall(state);
}
else
{
inst.Install(state);
inst.Commit(state);
StartService();
}
}
catch (Exception ex)
{
try
{
Logger.Log(ex);
inst.Rollback(state);
}
catch { }
throw;
}
inst.Dispose();
}
Logger.Log("... finished");
}
catch (Exception ex)
{
Logger.Log(ex);
}
}
示例9: Install
public static bool Install(bool undo, string[] args)
{
try
{
Console.WriteLine(undo ? "Uninstalling..." : "Installing...");
using (AssemblyInstaller inst = new AssemblyInstaller(typeof(WakeService).Assembly, args))
{
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
if (undo)
{
inst.Uninstall(state);
}
else
{
inst.Install(state);
inst.Commit(state);
}
}
catch
{
try
{
inst.Rollback(state);
}
catch { }
throw;
}
}
return true;
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
return false;
}
示例10: OnAction
public void OnAction(Hashtable parameters)
{
ArrayList temp = new ArrayList();
temp.Add("/LogToConsole=false");
StringBuilder tempString = new StringBuilder();
foreach (DictionaryEntry entry in parameters)
{
if (tempString.Length > 0)
tempString.Append(" ");
tempString.Append(entry.Key);
tempString.Append("=");
tempString.Append(entry.Value);
}
temp.Add("commandline=" + tempString.ToString());
string[] commandLine = (string[])temp.ToArray(typeof(string));
System.Configuration.Install.AssemblyInstaller asmInstaller = new AssemblyInstaller(Assembly.GetExecutingAssembly(), commandLine);
Hashtable rollback = new Hashtable();
if (GameServerService.GetDOLService() != null)
{
Console.WriteLine("DOL service is already installed!");
return;
}
Console.WriteLine("Installing Road as system service...");
try
{
asmInstaller.Install(rollback);
asmInstaller.Commit(rollback);
}
catch (Exception e)
{
asmInstaller.Rollback(rollback);
Console.WriteLine("Error installing as system service");
Console.WriteLine(e.Message);
return;
}
Console.WriteLine("Finished!");
}
示例11: Install
public static bool Install(bool undo, string[] args)
{
try
{
using(var inst = new AssemblyInstaller(typeof(Program).Assembly, args))
{
inst.AfterInstall += OnAfterInstall;
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
if(undo)
inst.Uninstall(state);
else
{
inst.Install(state);
inst.Commit(state);
}
}
catch
{
try
{
inst.Rollback(state);
}
catch
{
return false;
}
throw;
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex);
return false;
}
return true;
}
示例12: Install
/// <summary>
/// Actually installs/uninstalls this service.
/// </summary>
/// <param name="undo"></param>
/// <param name="args"></param>
private static void Install(bool undo, string[] args)
{
try
{
using (AssemblyInstaller installer = new AssemblyInstaller(
Assembly.GetEntryAssembly(), args))
{
IDictionary savedState = new Hashtable();
installer.UseNewContext = true;
try
{
if (undo)
{
installer.Uninstall(savedState);
}
else
{
installer.Install(savedState);
installer.Commit(savedState);
}
}
catch
{
try
{
installer.Rollback(savedState);
}
catch
{
}
throw;
}
}
}
catch (Exception exception)
{
Console.Error.WriteLine(exception.Message);
}
}
示例13: Install
static void Install(bool undo, string[] args)
{
try
{
Console.WriteLine(undo ? "uninstalling" : "installing");
using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args))
{
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
if (undo)
{
inst.Uninstall(state);
}
else
{
inst.Install(state);
inst.Commit(state);
}
}
catch
{
try
{
inst.Rollback(state);
}
catch { }
throw;
}
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
throw;
}
}
示例14: InstallService
private static void InstallService(bool undo, string[] args)
{
using (AssemblyInstaller inst = new AssemblyInstaller(Assembly.GetExecutingAssembly(), args)) {
var state = new Hashtable();
inst.UseNewContext = true;
try {
if (undo) {
inst.Uninstall(state);
}
else {
inst.Install(state);
inst.Commit(state);
}
}
catch {
try {
inst.Rollback(state);
}
catch { }
throw;
}
}
}
示例15: Install
public static void Install(bool undo, string openvpn)
{
try
{
using (AssemblyInstaller inst = new AssemblyInstaller(typeof(OpenVPNServiceRunner).Assembly, new String[0]))
{
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
if (undo)
{
inst.Uninstall(state);
}
else
{
inst.Install(state);
inst.Commit(state);
SetParameters(openvpn);
}
}
catch
{
try
{
inst.Rollback(state);
}
catch { }
throw;
}
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
}