本文整理汇总了C#中System.Configuration.Install.InstallContext类的典型用法代码示例。如果您正苦于以下问题:C# InstallContext类的具体用法?C# InstallContext怎么用?C# InstallContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InstallContext类属于System.Configuration.Install命名空间,在下文中一共展示了InstallContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Install
public virtual void Install(string serviceName)
{
Logger.Info("Installing service '{0}'", serviceName);
var installer = new ServiceProcessInstaller
{
Account = ServiceAccount.LocalSystem
};
var serviceInstaller = new ServiceInstaller();
String[] cmdline = { @"/assemblypath=" + Process.GetCurrentProcess().MainModule.FileName };
var context = new InstallContext("service_install.log", cmdline);
serviceInstaller.Context = context;
serviceInstaller.DisplayName = serviceName;
serviceInstaller.ServiceName = serviceName;
serviceInstaller.Description = "NzbDrone Application Server";
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServicesDependedOn = new[] { "EventLog", "Tcpip" };
serviceInstaller.Parent = installer;
serviceInstaller.Install(new ListDictionary());
Logger.Info("Service Has installed successfully.");
}
示例2: ItPersistsArgumentsInFile
public void ItPersistsArgumentsInFile(
string containerDirectory, string machineIp, string syslogHostIp, string syslogPort, string machineName)
{
var context = new InstallContext();
context.Parameters.Add("CONTAINER_DIRECTORY", containerDirectory);
context.Parameters.Add("MACHINE_IP", machineIp);
context.Parameters.Add("SYSLOG_HOST_IP", syslogHostIp);
context.Parameters.Add("SYSLOG_PORT", syslogPort);
context.Parameters.Add("MACHINE_NAME", machineName);
configurationManager.Context = context;
configurationManager.OnBeforeInstall(null);
var acl = Directory.GetAccessControl(tempDirectory.ToString());
var accessRules = acl.GetAccessRules(true, true, typeof(SecurityIdentifier));
Assert.Equal(accessRules.Count, 1);
var rule = (FileSystemAccessRule)accessRules[0];
Assert.Equal(rule.AccessControlType, AccessControlType.Allow);
Assert.Equal(new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null), rule.IdentityReference);
Assert.Equal(rule.FileSystemRights, FileSystemRights.FullControl);
var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var parametersPath = Path.Combine(tempDirectory.ToString(), "parameters.json");
var jsonString = File.ReadAllText(parametersPath);
var hash = javaScriptSerializer.Deserialize<Dictionary<string, string>>(jsonString);
Assert.Equal(hash["CONTAINER_DIRECTORY"], containerDirectory);
Assert.Equal(hash["MACHINE_IP"], machineIp);
Assert.Equal(hash["SYSLOG_HOST_IP"], syslogHostIp);
Assert.Equal(hash["SYSLOG_PORT"], syslogPort);
Assert.Equal(hash["MACHINE_NAME"], machineName);
}
示例3: Main
static void Main(string[] args)
{
string opt = null;
if (args.Length >= 1)
{
opt = args[0].ToLower();
}
if (opt == "/install" || opt == "/uninstall")
{
TransactedInstaller ti = new TransactedInstaller();
MonitorInstaller mi = new MonitorInstaller("OPC_FILE_WATCHER");
ti.Installers.Add(mi);
string path = String.Format("/assemblypath={0}", Assembly.GetExecutingAssembly().Location);
string[] cmdline = { path };
InstallContext ctx = new InstallContext("", cmdline);
ti.Context = ctx;
if (opt == "/install")
{
Console.WriteLine("Installing");
ti.Install(new Hashtable());
}
else if (opt == "/uninstall")
{
Console.WriteLine("Uninstalling");
try { ti.Uninstall(null); } catch (InstallException ie) { Console.WriteLine(ie.ToString()); }
}
}
else
{
ServiceBase[] services;
services = new ServiceBase[] { new OPCDataParser() }; ServiceBase.Run(services);
}
}
示例4: CustomInstaller
public CustomInstaller(Service service)
{
_service = service;
Installers.Add(GetServiceInstaller());
Installers.Add(GetServiceProcessInstaller());
var baseDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs");
Context = new InstallContext(
null,
new[]
{
"/LogToConsole=true",
"/InstallStateDir=" + Path.Combine(baseDir, "service-install.state"),
"/LogFile=" + Path.Combine(baseDir, "service-install.log")
});
foreach (string key in Context.Parameters.Keys)
{
Writer.WriteLine("{0}={1}", key, Context.Parameters[key]);
}
if (_service.StartMode == ServiceStartMode.Automatic)
{
Committed += (sender, args) => new ServiceController(service.ServiceName).Start();
}
}
示例5: RunPrecompiler
public void RunPrecompiler()
{
var appBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
var targetFile = Path.Combine(appBase, "RunPrecompiler.dll");
File.Delete(targetFile);
var parent = new ParentInstaller();
var precompile = new PrecompileInstaller();
precompile.TargetAssemblyFile = targetFile;
precompile.ViewPath = "MonoRail.Tests.Views";
precompile.DescribeBatch += ((sender, e) => e.Batch.For<StubController>().Include("*").Include("_*"));
var context = new InstallContext();
var state = new Hashtable();
parent.Installers.Add(precompile);
parent.Install(state);
parent.Commit(state);
Assert.That(File.Exists(targetFile), "File exists");
var result = Assembly.LoadFrom(targetFile);
Assert.AreEqual(3, result.GetTypes().Count());
}
示例6: ItPersistsArgumentsInFile
public void ItPersistsArgumentsInFile(
string containerDirectory, string machineIp, string syslogHostIp, string syslogPort, string machineName)
{
using(var tempDirectory = new TempDirectory())
{
var configurationManager = new ConfigurationManagerTest();
var context = new InstallContext();
context.Parameters.Add("CONTAINER_DIRECTORY", containerDirectory);
context.Parameters.Add("MACHINE_IP", machineIp);
context.Parameters.Add("SYSLOG_HOST_IP", syslogHostIp);
context.Parameters.Add("SYSLOG_PORT", syslogPort);
context.Parameters.Add("assemblypath", tempDirectory.ToString());
context.Parameters.Add("MACHINE_NAME", machineName);
configurationManager.Context = context;
configurationManager.OnBeforeInstall(null);
var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var jsonString = File.ReadAllText(Path.Combine(tempDirectory.ToString(), @"..\parameters.json"));
var hash = javaScriptSerializer.Deserialize<Dictionary<string, string>>(jsonString);
Assert.Equal(hash["CONTAINER_DIRECTORY"], containerDirectory);
Assert.Equal(hash["MACHINE_IP"], machineIp);
Assert.Equal(hash["SYSLOG_HOST_IP"], syslogHostIp);
Assert.Equal(hash["SYSLOG_PORT"], syslogPort);
Assert.Equal(hash["MACHINE_NAME"], machineName);
}
}
示例7: FrmConfig
public FrmConfig(System.Configuration.Install.InstallContext context, InstallController ctrl)
{
formContext = context;
this.ctrl = ctrl;
InitializeComponent();
this.CenterToScreen();
}
示例8: Install
public override void Install(IDictionary stateSaver)
{
string strAssPath = "/assemblypath=\"{0}\" \"" + this.Context.Parameters["path"]+"\"";
Context = new InstallContext("", new string[] { String.Format(strAssPath, System.Reflection.Assembly.GetExecutingAssembly().Location) });
base.Install(stateSaver);
}
示例9: DeleteService
public void DeleteService(string i_ServiceName)
{
ServiceInstaller ServiceInstallerObj = new ServiceInstaller();
InstallContext Context = new InstallContext(AppDomain.CurrentDomain.BaseDirectory + "\\uninstalllog.log", null);
ServiceInstallerObj.Context = Context;
ServiceInstallerObj.ServiceName = i_ServiceName;
ServiceInstallerObj.Uninstall(null);
}
示例10: uninstallService
/// <summary>
/// UnInstalls the Windows service with the given "installer" object.
/// </summary>
/// <param name="pi"></param>
/// <param name="pathToService"></param>
public static void uninstallService(Installer pi, string pathToService)
{
TransactedInstaller ti = new TransactedInstaller ();
ti.Installers.Add (pi);
string[] cmdline = {pathToService};
InstallContext ctx = new InstallContext ("Uninstall.log", cmdline );
ti.Context = ctx;
ti.Uninstall ( null );
}
示例11: InstallService
/// <summary>
/// Installs the Windows service with the given "installer" object.
/// </summary>
/// <param name="installer">The installer.</param>
/// <param name="pathToService">The path to service.</param>
public static void InstallService(Installer installer, string pathToService)
{
TransactedInstaller ti = new TransactedInstaller();
ti.Installers.Add(installer);
string[] cmdline = { pathToService };
InstallContext ctx = new InstallContext("Install.log", cmdline);
ti.Context = ctx;
ti.Install(new Hashtable());
}
示例12: FrmDbInstall
public FrmDbInstall(System.Configuration.Install.InstallContext context, InstallController ctrl)
{
Logger.info("FrmDbInstall");
formContext = context;
this.ctrl = ctrl;
InitializeComponent();
this.CenterToScreen();
}
示例13: StartForeground
public void StartForeground(string[] args)
{
if (args.Length > 0)
{
switch (args[0])
{
case "/install":
case "-install":
case "--install":
{
var directory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Barcodes");
if (args.Length > 1)
{
directory = Path.GetFullPath(args[1]);
}
if (!Directory.Exists(directory))
throw new ArgumentException(String.Format("The barcode directory {0} doesn't exists.", directory));
var transactedInstaller = new TransactedInstaller();
var serviceInstaller = new ServiceInstaller();
transactedInstaller.Installers.Add(serviceInstaller);
var ctx = new InstallContext();
ctx.Parameters["assemblypath"] = String.Format("{0} \"{1}\"", Assembly.GetExecutingAssembly().Location, directory);
transactedInstaller.Context = ctx;
transactedInstaller.Install(new Hashtable());
Console.WriteLine("The service is installed. Barcode images have to be placed into the directory {0}.", directory);
}
return;
case "/uninstall":
case "-uninstall":
case "--uninstall":
{
var transactedInstaller = new TransactedInstaller();
var serviceInstaller = new ServiceInstaller();
transactedInstaller.Installers.Add(serviceInstaller);
var ctx = new InstallContext();
ctx.Parameters["assemblypath"] = String.Format("{0}", Assembly.GetExecutingAssembly().Location);
transactedInstaller.Context = ctx;
transactedInstaller.Uninstall(null);
Console.WriteLine("The service is uninstalled.");
}
return;
default:
if (args[0][0] != '/' &&
args[0][0] != '-')
throw new ArgumentException(String.Format("The argument {0} isn't supported.", args[0]));
break;
}
}
OnStart(args);
Console.ReadLine();
}
示例14: InitializeInstaller
private TransactedInstaller InitializeInstaller(Dictionary<string, string> parameters)
{
SetupParameters(parameters);
var ti = new TransactedInstaller();
var ai = new AssemblyInstaller(Path.Combine(_sourcePath, _serviceExecutable), _parameters);
ti.Installers.Add(ai);
var ic = new InstallContext("Install.log", _parameters);
ti.Context = ic;
return ti;
}
示例15: SetupPerfmonCounters
/// <summary>
/// setup the Babalu perfmon counters
/// </summary>
/// <param name="context"></param>
public static void SetupPerfmonCounters(InstallContext context)
{
context.LogMessage("Perfmon Babalu counters installer begins");
#if !DEBUG
if (PerformanceCounterCategory.Exists(BabaluCounterDescriptions.CounterCategory))
PerformanceCounterCategory.Delete(BabaluCounterDescriptions.CounterCategory);
#endif
BabaluCounterDescriptions.InstallCounters();
context.LogMessage("Perfmon Babalu counters installer ends");
}