Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 安装服务
 /// </summary>
 private void btnInstall_Click(object sender, EventArgs e)
 {
     if (!Vaild())
     {
         return;
     }
     try
     {
         string[] cmdline = { };
         string serviceFileName = txtPath.Text.Trim();
         string serviceName = GetServiceName(serviceFileName);
         if (string.IsNullOrEmpty(serviceName))
         {
             txtTip.Text = "指定文件不是Windows服务!";
             return;
         }
         if (ServiceIsExisted(serviceName))
         {
             txtTip.Text = "要安装的服务已经存在!";
             return;
         }
         TransactedInstaller transactedInstaller = new TransactedInstaller();
         AssemblyInstaller assemblyInstaller = new AssemblyInstaller(serviceFileName, cmdline);
         assemblyInstaller.UseNewContext = true;
         transactedInstaller.Installers.Add(assemblyInstaller);
         transactedInstaller.Install(new System.Collections.Hashtable());
         txtTip.Text = "服务安装成功!";
     }
     catch (Exception ex)
     {
         txtTip.Text = ex.Message;
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Installs the Windows service with the given "installer" object.
 /// </summary>
 /// <param name="pi"></param>
 /// <param name="pathToService"></param>
 public static void installService(Installer pi, string pathToService)
 {
     TransactedInstaller ti = new TransactedInstaller ();
     ti.Installers.Add (pi);
     string[] cmdline = {pathToService};
     InstallContext ctx = new InstallContext ("Install.log", cmdline );
     ti.Context = ctx;
     ti.Install ( new Hashtable ());
 }
Exemplo n.º 4
0
 public void Install()
 {
     _logger.Log(Tag, "Installing service {0}", ServiceName);
     using (var ti = new TransactedInstaller())
     {
         SetInstallers(ti);
         ti.Install(new Hashtable());
     }
 }
Exemplo n.º 5
0
      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();
      }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            // 运行服务
            if (args.Length == 0)
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] { new Servicesqlbackup() };
                ServiceBase.Run(ServicesToRun);

            }
            // 安装服务
            else if (args[0].ToLower() == "/i" || args[0].ToLower() == "-i")
            {
                try
                {
                    string[] cmdline = { };
                    string serviceFileName = System.Reflection.Assembly.GetExecutingAssembly().Location;

                    TransactedInstaller transactedInstaller = new TransactedInstaller();
                    AssemblyInstaller assemblyInstaller = new AssemblyInstaller(serviceFileName, cmdline);
                    transactedInstaller.Installers.Add(assemblyInstaller);
                    transactedInstaller.Install(new System.Collections.Hashtable());

                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                }
            }
            // 删除服务
            else if (args[0].ToLower() == "/u" || args[0].ToLower() == "-u")
            {
                try
                {
                    string[] cmdline = { };
                    string serviceFileName = System.Reflection.Assembly.GetExecutingAssembly().Location;

                    TransactedInstaller transactedInstaller = new TransactedInstaller();
                    AssemblyInstaller assemblyInstaller = new AssemblyInstaller(serviceFileName, cmdline);
                    transactedInstaller.Installers.Add(assemblyInstaller);
                    transactedInstaller.Uninstall(null);
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                }
            }
            //以窗口方式运行服务
            else if (args[0].ToLower() == "/f" || args[0].ToLower() == "-f" || args[0].ToLower() == "/form" || args[0].ToLower() == "-form")
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
Exemplo n.º 7
0
 protected void Register()
 {
     using( var transactedInstall = new TransactedInstaller() )
     {
         transactedInstall.Installers.Add( Installer );
         if ( ENTRY_ASSEMBLY != null )
         {
             transactedInstall.Context = new InstallContext( null, CommandLine );
             transactedInstall.Install( new Hashtable() );
         }
     }
 }
Exemplo n.º 8
0
 private static void InstallService(string[] args)
 {
     using (var ti = new TransactedInstaller())
     {
         using (var pi = new ProjectInstaller())
         {
             ti.Installers.Add(pi);
             ti.Context = new InstallContext("", null);
             string path = Assembly.GetExecutingAssembly().Location;
             ti.Context.Parameters["assemblypath"] = path;
             ti.Install(new Hashtable());
         }
     }
 }
 public static void Install(string[] args)
 {
     string name = args.Length == 2 ? args[1] : DEFAULT_NAME;
     try {
         TransactedInstaller ti = new TransactedInstaller();
         WindowsServiceProjectInstaller pi = WindowsServiceProjectInstaller.Create(name);
         ti.Installers.Add(pi);
         string path = string.Format("/assemblypath={0}",
             System.Reflection.Assembly.GetExecutingAssembly().Location);
         string[] cmdline = { path };
         InstallContext ctx = new InstallContext("", cmdline);
         ti.Context = ctx;
         ti.Install(new Hashtable());
     } catch (Exception ex) {
         Console.WriteLine("ERROR: {0}", ex.Message);
         Environment.Exit(1);
     }
 }
Exemplo n.º 10
0
        private static void Install(bool install, ServiceInfo serviceInfo)
        {
            using (TransactedInstaller transactedInstaller = new TransactedInstaller())
            {
                using (System.Configuration.Install.Installer installer = CreateInstaller(serviceInfo))
                {
                    transactedInstaller.Installers.Add(installer);

                    string path = string.Format("/assemblypath={0}", Assembly.GetEntryAssembly().Location);

                    transactedInstaller.Context = new InstallContext("", new[] { path });

                    if (install)
                        transactedInstaller.Install(new Hashtable());
                    else
                        transactedInstaller.Uninstall(null);
                }
            }

        }
Exemplo n.º 11
0
 private static void DoInstall(IDictionary<string, string> options)
 {
     if (options.ContainsKey(OPT_SERVICE_NAME))
     {
         ProjectInstaller.ServiceName = options[OPT_SERVICE_NAME];
     }
     TransactedInstaller ti = new TransactedInstaller();
     string[] cmdline =
     {
         Assembly.GetExecutingAssembly ().Location
     };
     AssemblyInstaller ai = new AssemblyInstaller(
         cmdline[0],
         new string[0]);
     ti.Installers.Add(ai);
     InstallContext ctx = new InstallContext("install.log",
                                              cmdline);
     ti.Context = ctx;
     ti.Install(new System.Collections.Hashtable());
 }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            string opt=null;
            if(args.Length >0 )
            {
                opt=args[0];
            }

            if(opt!=null && opt.ToLower()=="/install")
            {
                TransactedInstaller ti= new TransactedInstaller();
                MyInstaller pi = new MyInstaller();
                ti.Installers.Add(pi);
                String path=String.Format("/assemblypath={0}",
                    System.Reflection.Assembly.GetExecutingAssembly().Location);
                String[] cmdline={path};
                InstallContext ctx = new InstallContext("",cmdline);
                ti.Context =ctx;
                ti.Install(new Hashtable());
            }
            else if (opt !=null && opt.ToLower()=="/uninstall")
            {
                TransactedInstaller ti=new TransactedInstaller();
                MyInstaller mi=new MyInstaller();
                ti.Installers.Add(mi);
                String path = String.Format("/assemblypath={0}",
                    System.Reflection.Assembly.GetExecutingAssembly().Location);
                String[] cmdline={path};
                InstallContext ctx = new InstallContext("",cmdline);
                ti.Context=ctx;
                ti.Uninstall(null);

            }

            if(opt==null)  // e.g. ,nothing on the command line
            {
                System.ServiceProcess.ServiceBase[] ServicesToRun;
                ServicesToRun = new System.ServiceProcess.ServiceBase[] { new SiteMonitor() };
                System.ServiceProcess.ServiceBase.Run(ServicesToRun);
            }
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            if (args.Length > 0)
            {
                if (args[0] == "-i" || args[0] == "-u")
                {
                    ServiceInstaller serviceInstaller = new ServiceInstaller();
                    serviceInstaller.ServiceName = "Performance.Agent.Service";
                    serviceInstaller.StartType = ServiceStartMode.Automatic;
                    serviceInstaller.DisplayName = "Colourblind Performance Agent";
                    serviceInstaller.Description = "Agent for the Colourblind performance monitor";

                    ServiceProcessInstaller processInstaller = new ServiceProcessInstaller();
                    processInstaller.Account = ServiceAccount.LocalSystem;
                    processInstaller.Username = null;
                    processInstaller.Password = null;

                    TransactedInstaller installer = new TransactedInstaller();
                    installer.Installers.Add(processInstaller);
                    installer.Installers.Add(serviceInstaller);
                    installer.Context = new InstallContext("install.log", null);
                    installer.Context.Parameters.Add("assemblypath", Assembly.GetCallingAssembly().Location);

                    if (args[0] == "-i")
                        installer.Install(new Hashtable());
                    else if (args[0] == "-u")
                        installer.Uninstall(null);
                }
            }
            else
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
                {
                    new Service()
                };
                ServiceBase.Run(ServicesToRun);
            }
        }
Exemplo n.º 14
0
        public void InstallWith(WindowsServiceInstaller installer)
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

            using (var ti = new TransactedInstaller())
            {
                ti.Installers.Add(installer);

                var assembly = Assembly.GetEntryAssembly();
                if (assembly == null)
                {
                    throw new NullReferenceException("assembly");
                }

                var path = string.Format("/assemblypath={0}", assembly.Location);
                string[] commandLine = {path};

                var context = new InstallContext(null, commandLine);
                ti.Context = context;
                ti.Install(new Hashtable());
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// 安装服务。
 /// </summary>
 /// <param name="fileName">文件名称</param>
 /// <param name="args">命令行参数</param>
 public static void InstallService(string fileName, string[] args)
 {
     TransactedInstaller transactedInstaller = new TransactedInstaller();
     AssemblyInstaller assemblyInstaller = new AssemblyInstaller(fileName, args);
     transactedInstaller.Installers.Add(assemblyInstaller);
     transactedInstaller.Install(new System.Collections.Hashtable());
 }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            // Interop.CoInitializeSecurity(IntPtr.Zero, -1, null, IntPtr.Zero, Interop.RPC_C_AUTHN_LEVEL_NONE, Interop.RPC_C_IMP_LEVEL_IDENTIFY, IntPtr.Zero, Interop.EOAC_NONE, IntPtr.Zero);
            long hres;
            try
            {
                hres = Interop.CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, (uint)RpcAuthnLevel.None, (uint)RpcImpLevel.Identify, IntPtr.Zero, (uint)EoAuthnCap.None, IntPtr.Zero);
            }
            catch (COMException e)
            {
                Logger.LogMessage("CoInitializeSecurity Execption: " + e.Message, Logger.FATAL);
            }
            bool restartLogAppend = false;
            string opt = null;

            int dwResetPeriod = 60 * 60;
            //            Debugger.Break();

            try
            {
                ProjectInstaller.sServiceName = ConfigurationManager.AppSettings["ServiceName"];
                ProjectInstaller.dwResetPeriod = Convert.ToInt32(ConfigurationManager.AppSettings["ResetPeriod"]);
                ProjectInstaller.sServiceUser = ConfigurationManager.AppSettings["ServiceUser"];
                ProjectInstaller.sServicePassword = ConfigurationManager.AppSettings["ServicePassword"];
                restartLogAppend = Convert.ToBoolean(ConfigurationManager.AppSettings["RestartLogAppend"]);
            }
            catch (Exception)
            {
                dwResetPeriod = 60 * 60;
            }

            Logger.RestartLog(restartLogAppend);

            string version = Misc.VersionNumber();
            Logger.LogMessage("MTConnect 4 OPC Agent OPC Version 2.0 - Release " + version, Logger.FATAL);

            if (args.Length > 0)
            {

                // check for arguments
                opt = args[0];

                ProjectInstaller.dwResetPeriod = dwResetPeriod;
                try
                {
                    if (opt != null && opt.ToLower() == "/install")
                    {

                        TransactedInstaller ti = new TransactedInstaller();
                        ProjectInstaller pi = new ProjectInstaller();
                        ti.Installers.Add(pi);
                        String path = String.Format("/assemblypath={0}",
                                                    Assembly.GetExecutingAssembly().Location);
                        String[] cmdline = { path };
                        InstallContext ctx = new InstallContext("", cmdline);
                        ti.Context = ctx;
                        ti.Install(new Hashtable());
                    }
                    else if (opt != null && opt.ToLower() == "/uninstall")
                    {
                        TransactedInstaller ti = new TransactedInstaller();
                        ProjectInstaller mi = new ProjectInstaller();
                        ti.Installers.Add(mi);
                        String path = String.Format("/assemblypath={0}",
                                                    Assembly.GetExecutingAssembly().Location);

                        String[] cmdline = { path };
                        InstallContext ctx = new InstallContext("", cmdline);
                        ti.Context = ctx;
                        ti.Uninstall(null);
                    }
                }
                catch (Exception e)
                {
                    Logger.LogMessage(e.Message, Logger.FATAL);
                }
            }
            if (opt == null) // e.g. ,nothing on the command line
            {
            #if ( ! DEBUG )
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] {new Service1()};
                ServiceBase.Run(ServicesToRun);
            #else
                // debug code: allows the process to run as a non-service
                // will kick off the service start point, but never kill it
                // shut down the debugger to exit
                Service1 service = new Service1();
                service.OnStart(null);
                Thread.Sleep(Timeout.Infinite);
            #endif
            }
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            // Set up the crash dump handler.
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(unhandledException);

            cultureInfo = new System.Globalization.CultureInfo("en-GB");
            settingsManager = new SettingsManager();
            cloudFlareAPI = new CloudFlareAPI();

            if (!Environment.UserInteractive || args.Length > 0 && args[0] == "/service")
            {
                runService();
                return;
            }

            if (args.Length > 0)
            {
                if (args[0] == "/install")
                {
                    TransactedInstaller ti = new TransactedInstaller();
                    ti.Installers.Add(new ServiceInstaller());
                    ti.Context = new InstallContext("", null);
                    ti.Context.Parameters["assemblypath"] = "\"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\" /service";
                    ti.Install(new System.Collections.Hashtable());
                    ti.Dispose();
                    return;
                }

                if (args[0] == "/uninstall")
                {
                    TransactedInstaller ti = new TransactedInstaller();
                    ti.Installers.Add(new ServiceInstaller());
                    ti.Context = new System.Configuration.Install.InstallContext("", null);
                    ti.Context.Parameters["assemblypath"] = "\"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\" /service";
                    ti.Uninstall(null);
                    ti.Dispose();
                    return;
                }
            }

            runGUI();
        }
Exemplo n.º 18
0
        public static void InstallHelper(string[] args)
        {
            bool flag  = false;
            bool flag2 = false;
            TransactedInstaller installerWithHelp = new TransactedInstaller();
            bool flag3 = false;

            try
            {
                ArrayList list = new ArrayList();
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].StartsWith("/", StringComparison.Ordinal) || args[i].StartsWith("-", StringComparison.Ordinal))
                    {
                        string strA = args[i].Substring(1);
                        if ((string.Compare(strA, "u", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(strA, "uninstall", StringComparison.OrdinalIgnoreCase) == 0))
                        {
                            flag = true;
                        }
                        else if ((string.Compare(strA, "?", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(strA, "help", StringComparison.OrdinalIgnoreCase) == 0))
                        {
                            flag3 = true;
                        }
                        else if (string.Compare(strA, "AssemblyName", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            flag2 = true;
                        }
                        else
                        {
                            list.Add(args[i]);
                        }
                    }
                    else
                    {
                        Assembly assembly = null;
                        try
                        {
                            if (flag2)
                            {
                                assembly = Assembly.Load(args[i]);
                            }
                            else
                            {
                                assembly = Assembly.LoadFrom(args[i]);
                            }
                        }
                        catch (Exception exception)
                        {
                            if (args[i].IndexOf('=') != -1)
                            {
                                throw new ArgumentException(Res.GetString("InstallFileDoesntExistCommandLine", new object[] { args[i] }), exception);
                            }
                            throw;
                        }
                        AssemblyInstaller installer2 = new AssemblyInstaller(assembly, (string[])list.ToArray(typeof(string)));
                        installerWithHelp.Installers.Add(installer2);
                    }
                }
                if (flag3 || (installerWithHelp.Installers.Count == 0))
                {
                    flag3 = true;
                    installerWithHelp.Installers.Add(new AssemblyInstaller());
                    throw new InvalidOperationException(GetHelp(installerWithHelp));
                }
                installerWithHelp.Context = new InstallContext("InstallUtil.InstallLog", (string[])list.ToArray(typeof(string)));
            }
            catch (Exception exception2)
            {
                if (flag3)
                {
                    throw exception2;
                }
                throw new InvalidOperationException(Res.GetString("InstallInitializeException", new object[] { exception2.GetType().FullName, exception2.Message }));
            }
            try
            {
                string str2 = installerWithHelp.Context.Parameters["installtype"];
                if ((str2 != null) && (string.Compare(str2, "notransaction", StringComparison.OrdinalIgnoreCase) == 0))
                {
                    string str3 = installerWithHelp.Context.Parameters["action"];
                    if ((str3 != null) && (string.Compare(str3, "rollback", StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        installerWithHelp.Context.LogMessage(Res.GetString("InstallRollbackNtRun"));
                        for (int j = 0; j < installerWithHelp.Installers.Count; j++)
                        {
                            installerWithHelp.Installers[j].Rollback(null);
                        }
                    }
                    else if ((str3 != null) && (string.Compare(str3, "commit", StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        installerWithHelp.Context.LogMessage(Res.GetString("InstallCommitNtRun"));
                        for (int k = 0; k < installerWithHelp.Installers.Count; k++)
                        {
                            installerWithHelp.Installers[k].Commit(null);
                        }
                    }
                    else if ((str3 != null) && (string.Compare(str3, "uninstall", StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        installerWithHelp.Context.LogMessage(Res.GetString("InstallUninstallNtRun"));
                        for (int m = 0; m < installerWithHelp.Installers.Count; m++)
                        {
                            installerWithHelp.Installers[m].Uninstall(null);
                        }
                    }
                    else
                    {
                        installerWithHelp.Context.LogMessage(Res.GetString("InstallInstallNtRun"));
                        for (int n = 0; n < installerWithHelp.Installers.Count; n++)
                        {
                            installerWithHelp.Installers[n].Install(null);
                        }
                    }
                }
                else if (!flag)
                {
                    IDictionary stateSaver = new Hashtable();
                    installerWithHelp.Install(stateSaver);
                }
                else
                {
                    installerWithHelp.Uninstall(null);
                }
            }
            catch (Exception exception3)
            {
                throw exception3;
            }
        }
Exemplo n.º 19
0
        /// <include file='doc\ManagedInstaller.uex' path='docs/doc[@for="ManagedInstallerClass.InstallHelper"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static void InstallHelper(string[] args)
        {
            bool uninstall      = false;
            bool isAssemblyName = false;
            TransactedInstaller topLevelInstaller = new TransactedInstaller();
            bool showHelp = false;

            try {
                /*
                 * StreamWriter stream = new StreamWriter("c:\\installutilargs.txt", true);
                 * stream.WriteLine("----------");
                 * for (int i = 0; i < args.Length; i++)
                 *  stream.WriteLine(args[i]);
                 * stream.Close();
                 */


                // strategy: Use a TransactedInstaller to manage the top-level installation work.
                // It will perform rollback/commit as necessary. Go through the assemblies on the
                // command line and add an AssemblyInstaller for each of them to the TransactedInstaller's
                // Installers collection.
                //
                // as we walk the parameters, we'll encounter either a filename or a
                // parameter. If we get to a filename, create an assembly installer with
                // all of the parameters we've seen _so far_. This way parameters can
                // be different for the different assemblies.

                ArrayList parameters = new ArrayList();
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].StartsWith("/") || args[i].StartsWith("-"))
                    {
                        string str = args[i].Substring(1);
                        if (string.Compare(str, "u", true, CultureInfo.InvariantCulture) == 0 || string.Compare(str, "uninstall", true, CultureInfo.InvariantCulture) == 0)
                        {
                            uninstall = true;
                        }
                        else if (string.Compare(str, "?", true, CultureInfo.InvariantCulture) == 0 || string.Compare(str, "help", true, CultureInfo.InvariantCulture) == 0)
                        {
                            showHelp = true;
                        }
                        else if (string.Compare(str, "AssemblyName", true, CultureInfo.InvariantCulture) == 0)
                        {
                            isAssemblyName = true;
                        }
                        else
                        {
                            parameters.Add(args[i]);
                        }
                    }
                    else
                    {
                        Assembly asm = null;
                        try {
                            if (isAssemblyName)
                            {
                                asm = Assembly.Load(args[i]);
                            }
                            else
                            {
                                asm = Assembly.LoadFrom(args[i]);
                            }
                        }
                        catch (Exception e) {
                            if (args[i].IndexOf('=') != -1)
                            {
                                // probably a mistake where /key=value was written as key=value,
                                // try to explain that
                                throw new ArgumentException(Res.GetString(Res.InstallFileDoesntExistCommandLine, args[i]), e);
                            }
                            else
                            {
                                // the assembly.Load{From} gives a good descriptive error - pass it up
                                throw;
                            }
                        }

                        AssemblyInstaller installer = new AssemblyInstaller(asm, (string[])parameters.ToArray(typeof(string)));
                        topLevelInstaller.Installers.Add(installer);
                    }
                }

                if (showHelp || topLevelInstaller.Installers.Count == 0)
                {
                    // we may have seen some options, but they didn't tell us to do any
                    // work. Or they gave us /? or /help. Show the help screen.
                    showHelp = true;
                    topLevelInstaller.Installers.Add(new AssemblyInstaller());
                    throw new InvalidOperationException(GetHelp(topLevelInstaller));
                }

                topLevelInstaller.Context = new InstallContext("InstallUtil.InstallLog", (string[])parameters.ToArray(typeof(string)));
            }
            catch (Exception e) {
                if (showHelp)
                {
                    // it's just the help message
                    throw e;
                }
                else
                {
                    throw new InvalidOperationException(Res.GetString(Res.InstallInitializeException, e.GetType().FullName, e.Message));
                }
            }

            try {
                // MSI mode.
                // If the parameter /installtype=notransaction is specified, then we don't want to run
                // a TransactedInstaller. Instead, we just use that installer as a container for all
                // the AssemblyInstallers we want to run.
                string installType = topLevelInstaller.Context.Parameters["installtype"];
                if (installType != null && string.Compare(installType, "notransaction", true, CultureInfo.InvariantCulture) == 0)
                {
                    // this is a non-transacted install. Check the value of the Action parameter
                    // to see what to do
                    string action = topLevelInstaller.Context.Parameters["action"];
                    if (action != null && string.Compare(action, "rollback", true, CultureInfo.InvariantCulture) == 0)
                    {
                        topLevelInstaller.Context.LogMessage(Res.GetString(Res.InstallRollbackNtRun));
                        for (int i = 0; i < topLevelInstaller.Installers.Count; i++)
                        {
                            topLevelInstaller.Installers[i].Rollback(null);
                        }
                        return;
                    }
                    if (action != null && string.Compare(action, "commit", true, CultureInfo.InvariantCulture) == 0)
                    {
                        topLevelInstaller.Context.LogMessage(Res.GetString(Res.InstallCommitNtRun));
                        for (int i = 0; i < topLevelInstaller.Installers.Count; i++)
                        {
                            topLevelInstaller.Installers[i].Commit(null);
                        }
                        return;
                    }
                    if (action != null && string.Compare(action, "uninstall", true, CultureInfo.InvariantCulture) == 0)
                    {
                        topLevelInstaller.Context.LogMessage(Res.GetString(Res.InstallUninstallNtRun));
                        for (int i = 0; i < topLevelInstaller.Installers.Count; i++)
                        {
                            topLevelInstaller.Installers[i].Uninstall(null);
                        }
                        return;
                    }
                    // they said notransaction, and they didn't tell us to do rollback, commit,
                    // or uninstall. They must mean install.
                    topLevelInstaller.Context.LogMessage(Res.GetString(Res.InstallInstallNtRun));
                    for (int i = 0; i < topLevelInstaller.Installers.Count; i++)
                    {
                        topLevelInstaller.Installers[i].Install(null);
                    }
                    return;
                }

                // transacted mode - we'll only get here if /installtype=notransaction wasn't specified.
                if (!uninstall)
                {
                    IDictionary stateSaver = new Hashtable();
                    topLevelInstaller.Install(stateSaver);
                    // we don't bother writing out the saved state for this guy, because each assembly
                    // we're installing gets its own saved-state file.
                }
                else
                {
                    topLevelInstaller.Uninstall(null);
                }
            }

            catch (Exception e) {
                /*
                 * StreamWriter stream = new StreamWriter("c:\\installutilargs.txt", true);
                 * stream.WriteLine("Caught exception: " + e.GetType().FullName + ": " + e.Message);
                 * stream.WriteLine(e.StackTrace);
                 * stream.Close();
                 */

                throw e;
            }

            /*
             * StreamWriter stream2 = new StreamWriter("c:\\installutilargs.txt", true);
             * stream2.WriteLine("Caught no exceptions. Returning 0.");
             * stream2.Close();
             */

            return;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Installiert den Dienst
        /// </summary>
        static public void InstallPrinfoService()
        {
            using (TransactedInstaller ti = new TransactedInstaller())
            {

                if (BeforeInstall != null)
                    ti.BeforeInstall += new InstallEventHandler(BeforeInstall);
                if (AfterInstall != null)
                    ti.AfterInstall += new InstallEventHandler(AfterInstall);

                AssemblyInstaller asmi = new AssemblyInstaller(AppDomain.CurrentDomain.BaseDirectory + "\\Prinfo.Net Service.exe", null);

                ti.Installers.Add(asmi);
                ti.Install(new Hashtable());
            }
        }
Exemplo n.º 21
0
 /// <summary>Installs the provider service in interactive mode.</summary>
 public void Install() {
    if (Environment.UserInteractive) {
       var ti = new TransactedInstaller();
       var spi = new ServerInstaller(ServiceName, ServiceDisplayName, ServiceDescription, ServerBehavior);
       ti.Installers.Add(spi);
       var path = "/assemblypath=" + ExePath;
       var ctx = new InstallContext("", new string[] { path });
       ti.Context = ctx;
       ti.Install(new Hashtable());
    }
 }
Exemplo n.º 22
0
 public void Install()
 {
     using (var installer = new TransactedInstaller())
     {
         SetInstallers(installer);
         // There is a bug in .NET 3.5 where the image path will not be escaped correctly.
         installer.Context = new InstallContext(null, new[] { "/assemblypath=\"" + Process.GetCurrentProcess().MainModule.FileName + "\" " + _configuration.CommandLineArguments });
         installer.AfterInstall += ModifyImagePath;
         installer.Install(new Hashtable());
     }
 }
        private static void Main(String[] CommandLineArgs)
        {
            //Komandozeilenargumente eingegeben???		
            if (CommandLineArgs.Length > 0)
            {

                if (CommandLineArgs[0] == "/install")
                {
                    //Service hinzufügen

                    TransactedInstaller serviceInstaller;
                    Hashtable stateSaver;
                    InstallContext installContext;
                    ProjectInstaller mi;

                    serviceInstaller = new TransactedInstaller();
                    stateSaver = new Hashtable();

                    mi = new ProjectInstaller();
                    serviceInstaller.Installers.Add(mi);

                    string prgPfad = "\"" + Assembly.GetExecutingAssembly().Location + "\" " + "/service";
                    installContext = new InstallContext("ServiceInstall.log", null);
                    installContext.Parameters.Add("assemblyPath", prgPfad);



                    serviceInstaller.Context = installContext;
                    try
                    {
                        serviceInstaller.Install(stateSaver);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Fehler bein installieren des Service: " + ex.ToString());
                    }
                }
                    //serviceInstaller.Commit(stateSaver)

                else if (CommandLineArgs[0] == "/uninstall")
                {
                    //Service löschen...

                    TransactedInstaller serviceInstaller;
                    Hashtable stateSaver;
                    InstallContext installContext;
                    ProjectInstaller mi;

                    serviceInstaller = new TransactedInstaller();
                    stateSaver = new Hashtable();

                    mi = new ProjectInstaller();
                    serviceInstaller.Installers.Add(mi);

                    string prgPfad = "\"" + Assembly.GetExecutingAssembly().Location + "\" \"" + "/service\"";
                    installContext = new InstallContext("ServiceInstall.log", null);
                    installContext.Parameters.Add("assemblyPath", prgPfad);

                    serviceInstaller.Context = installContext;
                    try
                    {
                        serviceInstaller.Uninstall(null);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Fehler bein deinstallieren des Service: " + ex.ToString());
                    }

                }
                else if (CommandLineArgs[0] == "/service")
                {
                    Service service = new Service();
                    ServiceBase.Run(new ServiceBase[] {service});
                }
            }

                //Keine Komandozeilenargumente....			
            else
            {
                {
                    Application.Run(new ServiceConfig());
                }

            }

        }
Exemplo n.º 24
0
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    private static void Main(string[] args)
    {
      // Init Common logger -> this will enable TVPlugin to write in the Mediaportal.log file
      var loggerName = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]);
      var dataPath = Log.GetPathName();
      var loggerPath = Path.Combine(dataPath, "log");
#if DEBUG
      if (loggerName != null) loggerName = loggerName.Replace(".vshost", "");
#endif
      CommonLogger.Instance = new CommonLog4NetLogger(loggerName, dataPath, loggerPath);

      
      NameValueCollection appSettings = ConfigurationManager.AppSettings;
      appSettings.Set("GentleConfigFile", String.Format(@"{0}\gentle.config", PathManager.GetDataPath));

      string opt = null;
      if (args.Length >= 1)
      {
        opt = args[0];
      }

      if (opt != null && opt.ToUpperInvariant() == "/INSTALL")
      {
        TransactedInstaller ti = new TransactedInstaller();
        ProjectInstaller mi = new ProjectInstaller();
        ti.Installers.Add(mi);
        String path = String.Format("/assemblypath={0}",
                                    System.Reflection.Assembly.GetExecutingAssembly().Location);
        String[] cmdline = { path };
        InstallContext ctx = new InstallContext("", cmdline);
        ti.Context = ctx;
        ti.Install(new Hashtable());
        return;
      }
      if (opt != null && opt.ToUpperInvariant() == "/UNINSTALL")
      {
        TransactedInstaller ti = new TransactedInstaller();
        ProjectInstaller mi = new ProjectInstaller();
        ti.Installers.Add(mi);
        String path = String.Format("/assemblypath={0}",
                                    System.Reflection.Assembly.GetExecutingAssembly().Location);
        String[] cmdline = { path };
        InstallContext ctx = new InstallContext("", cmdline);
        ti.Context = ctx;
        ti.Uninstall(null);
        return;
      }
      // When using /DEBUG switch (in visual studio) the TvService is not run as a service
      // Make sure the real TvService is disabled before debugging with /DEBUG
      if (opt != null && opt.ToUpperInvariant() == "/DEBUG")
      {
        Service1 s = new Service1();
        s.DoStart(new string[] { "/DEBUG" });
        do
        {
          Thread.Sleep(100);
        } while (true);
      }

      // More than one user Service may run within the same process. To add
      // another service to this process, change the following line to
      // create a second service object. For example,
      //
      //   ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
      //
      ServiceBase[] ServicesToRun = new ServiceBase[] { new Service1() };
      ServicesToRun[0].CanShutdown = true;    // Allow OnShutdown() 
      ServiceBase.Run(ServicesToRun);
    }
 public static void InstallHelper(string[] args)
 {
     bool flag = false;
     bool flag2 = false;
     TransactedInstaller installerWithHelp = new TransactedInstaller();
     bool flag3 = false;
     try
     {
         ArrayList list = new ArrayList();
         for (int i = 0; i < args.Length; i++)
         {
             if (args[i].StartsWith("/", StringComparison.Ordinal) || args[i].StartsWith("-", StringComparison.Ordinal))
             {
                 string strA = args[i].Substring(1);
                 if ((string.Compare(strA, "u", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(strA, "uninstall", StringComparison.OrdinalIgnoreCase) == 0))
                 {
                     flag = true;
                 }
                 else if ((string.Compare(strA, "?", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(strA, "help", StringComparison.OrdinalIgnoreCase) == 0))
                 {
                     flag3 = true;
                 }
                 else if (string.Compare(strA, "AssemblyName", StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     flag2 = true;
                 }
                 else
                 {
                     list.Add(args[i]);
                 }
             }
             else
             {
                 Assembly assembly = null;
                 try
                 {
                     if (flag2)
                     {
                         assembly = Assembly.Load(args[i]);
                     }
                     else
                     {
                         assembly = Assembly.LoadFrom(args[i]);
                     }
                 }
                 catch (Exception exception)
                 {
                     if (args[i].IndexOf('=') != -1)
                     {
                         throw new ArgumentException(Res.GetString("InstallFileDoesntExistCommandLine", new object[] { args[i] }), exception);
                     }
                     throw;
                 }
                 AssemblyInstaller installer2 = new AssemblyInstaller(assembly, (string[]) list.ToArray(typeof(string)));
                 installerWithHelp.Installers.Add(installer2);
             }
         }
         if (flag3 || (installerWithHelp.Installers.Count == 0))
         {
             flag3 = true;
             installerWithHelp.Installers.Add(new AssemblyInstaller());
             throw new InvalidOperationException(GetHelp(installerWithHelp));
         }
         installerWithHelp.Context = new InstallContext("InstallUtil.InstallLog", (string[]) list.ToArray(typeof(string)));
     }
     catch (Exception exception2)
     {
         if (flag3)
         {
             throw exception2;
         }
         throw new InvalidOperationException(Res.GetString("InstallInitializeException", new object[] { exception2.GetType().FullName, exception2.Message }));
     }
     try
     {
         string str2 = installerWithHelp.Context.Parameters["installtype"];
         if ((str2 != null) && (string.Compare(str2, "notransaction", StringComparison.OrdinalIgnoreCase) == 0))
         {
             string str3 = installerWithHelp.Context.Parameters["action"];
             if ((str3 != null) && (string.Compare(str3, "rollback", StringComparison.OrdinalIgnoreCase) == 0))
             {
                 installerWithHelp.Context.LogMessage(Res.GetString("InstallRollbackNtRun"));
                 for (int j = 0; j < installerWithHelp.Installers.Count; j++)
                 {
                     installerWithHelp.Installers[j].Rollback(null);
                 }
             }
             else if ((str3 != null) && (string.Compare(str3, "commit", StringComparison.OrdinalIgnoreCase) == 0))
             {
                 installerWithHelp.Context.LogMessage(Res.GetString("InstallCommitNtRun"));
                 for (int k = 0; k < installerWithHelp.Installers.Count; k++)
                 {
                     installerWithHelp.Installers[k].Commit(null);
                 }
             }
             else if ((str3 != null) && (string.Compare(str3, "uninstall", StringComparison.OrdinalIgnoreCase) == 0))
             {
                 installerWithHelp.Context.LogMessage(Res.GetString("InstallUninstallNtRun"));
                 for (int m = 0; m < installerWithHelp.Installers.Count; m++)
                 {
                     installerWithHelp.Installers[m].Uninstall(null);
                 }
             }
             else
             {
                 installerWithHelp.Context.LogMessage(Res.GetString("InstallInstallNtRun"));
                 for (int n = 0; n < installerWithHelp.Installers.Count; n++)
                 {
                     installerWithHelp.Installers[n].Install(null);
                 }
             }
         }
         else if (!flag)
         {
             IDictionary stateSaver = new Hashtable();
             installerWithHelp.Install(stateSaver);
         }
         else
         {
             installerWithHelp.Uninstall(null);
         }
     }
     catch (Exception exception3)
     {
         throw exception3;
     }
 }
Exemplo n.º 26
0
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    private static void Main(string[] args)
    {
      NameValueCollection appSettings = ConfigurationManager.AppSettings;
      appSettings.Set("GentleConfigFile", String.Format(@"{0}\gentle.config", PathManager.GetDataPath));

      string opt = null;
      if (args.Length >= 1)
      {
        opt = args[0];
      }

      if (opt != null && opt.ToUpperInvariant() == "/INSTALL")
      {
        TransactedInstaller ti = new TransactedInstaller();
        ProjectInstaller mi = new ProjectInstaller();
        ti.Installers.Add(mi);
        String path = String.Format("/assemblypath={0}",
                                    System.Reflection.Assembly.GetExecutingAssembly().Location);
        String[] cmdline = {path};
        InstallContext ctx = new InstallContext("", cmdline);
        ti.Context = ctx;
        ti.Install(new Hashtable());
        return;
      }
      if (opt != null && opt.ToUpperInvariant() == "/UNINSTALL")
      {
        TransactedInstaller ti = new TransactedInstaller();
        ProjectInstaller mi = new ProjectInstaller();
        ti.Installers.Add(mi);
        String path = String.Format("/assemblypath={0}",
                                    System.Reflection.Assembly.GetExecutingAssembly().Location);
        String[] cmdline = {path};
        InstallContext ctx = new InstallContext("", cmdline);
        ti.Context = ctx;
        ti.Uninstall(null);
        return;
      }
      // When using /DEBUG switch (in visual studio) the TvService is not run as a service
      // Make sure the real TvService is disabled before debugging with /DEBUG
      if (opt != null && opt.ToUpperInvariant() == "/DEBUG")
      {
        Service1 s = new Service1();
        s.DoStart(new string[] {"/DEBUG"});
        do
        {
          Thread.Sleep(100);
        } while (true);
      }

      // More than one user Service may run within the same process. To add
      // another service to this process, change the following line to
      // create a second service object. For example,
      //
      //   ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
      //
      ServiceBase[] ServicesToRun = new ServiceBase[] {new Service1()};
      ServiceBase.Run(ServicesToRun);
    }
        public static void InstallHelper(string[] args)
        {
            bool flag1 = false;
            bool flag2 = false;
            TransactedInstaller transactedInstaller = new TransactedInstaller();
            bool flag3 = false;

            try
            {
                ArrayList arrayList = new ArrayList();
                for (int index = 0; index < args.Length; ++index)
                {
                    if (args[index].StartsWith("/", StringComparison.Ordinal) || args[index].StartsWith("-", StringComparison.Ordinal))
                    {
                        string strA = args[index].Substring(1);
                        if (string.Compare(strA, "u", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(strA, "uninstall", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            flag1 = true;
                        }
                        else if (string.Compare(strA, "?", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(strA, "help", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            flag3 = true;
                        }
                        else if (string.Compare(strA, "AssemblyName", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            flag2 = true;
                        }
                        else
                        {
                            arrayList.Add((object)args[index]);
                        }
                    }
                    else
                    {
                        Assembly assembly;
                        try
                        {
                            assembly = !flag2?Assembly.LoadFrom(args[index]) : Assembly.Load(args[index]);
                        }
                        catch (Exception ex)
                        {
                            if (args[index].IndexOf('=') != -1)
                            {
                                throw new ArgumentException(Res.GetString("InstallFileDoesntExistCommandLine", new object[1]
                                {
                                    (object)args[index]
                                }), ex);
                            }
                            else
                            {
                                throw;
                            }
                        }
                        AssemblyInstaller assemblyInstaller = new AssemblyInstaller(assembly, (string[])arrayList.ToArray(typeof(string)));
                        transactedInstaller.Installers.Add((Installer)assemblyInstaller);
                    }
                }
                if (flag3 || transactedInstaller.Installers.Count == 0)
                {
                    flag3 = true;
                    transactedInstaller.Installers.Add((Installer) new AssemblyInstaller());
                    throw new InvalidOperationException(ManagedInstallerClass.GetHelp((Installer)transactedInstaller));
                }
                else
                {
                    transactedInstaller.Context = new InstallContext("InstallUtil.InstallLog", (string[])arrayList.ToArray(typeof(string)));
                }
            }
            catch (Exception ex)
            {
                if (flag3)
                {
                    throw ex;
                }
                throw new InvalidOperationException(Res.GetString("InstallInitializeException", (object)ex.GetType().FullName, (object)ex.Message));
            }
            try
            {
                string strA1 = transactedInstaller.Context.Parameters["installtype"];
                if (strA1 != null && string.Compare(strA1, "notransaction", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    string strA2 = transactedInstaller.Context.Parameters["action"];
                    if (strA2 != null && string.Compare(strA2, "rollback", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        transactedInstaller.Context.LogMessage(Res.GetString("InstallRollbackNtRun"));
                        for (int index = 0; index < transactedInstaller.Installers.Count; ++index)
                        {
                            transactedInstaller.Installers[index].Rollback((IDictionary)null);
                        }
                    }
                    else if (strA2 != null && string.Compare(strA2, "commit", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        transactedInstaller.Context.LogMessage(Res.GetString("InstallCommitNtRun"));
                        for (int index = 0; index < transactedInstaller.Installers.Count; ++index)
                        {
                            transactedInstaller.Installers[index].Commit((IDictionary)null);
                        }
                    }
                    else if (strA2 != null && string.Compare(strA2, "uninstall", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        transactedInstaller.Context.LogMessage(Res.GetString("InstallUninstallNtRun"));
                        for (int index = 0; index < transactedInstaller.Installers.Count; ++index)
                        {
                            transactedInstaller.Installers[index].Uninstall((IDictionary)null);
                        }
                    }
                    else
                    {
                        transactedInstaller.Context.LogMessage(Res.GetString("InstallInstallNtRun"));
                        for (int index = 0; index < transactedInstaller.Installers.Count; ++index)
                        {
                            transactedInstaller.Installers[index].Install((IDictionary)null);
                        }
                    }
                }
                else if (!flag1)
                {
                    IDictionary stateSaver = (IDictionary) new Hashtable();
                    transactedInstaller.Install(stateSaver);
                }
                else
                {
                    transactedInstaller.Uninstall((IDictionary)null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 28
0
    private static void Main(string[] args)
    {
      if (ProcessHelper.IsProcessAlreadyRunning())
        return;

      Thread.CurrentThread.Name = "Main Thread";
      IrssLog.Open("IR Server.log");

      try
      {
        if (args.Length == 0)
        {
          IRServer = new IRServer();
          if (IRServer.DoStart())
          {
            SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(OnPowerModeChanged);

            ReceiverWindow receiverWindow = new ReceiverWindow(Shared.ServerWindowName);

            Application.Run();
            SystemEvents.PowerModeChanged -= new PowerModeChangedEventHandler(OnPowerModeChanged);

            receiverWindow.DestroyHandle();
            receiverWindow = null;
            IRServer.DoStop();
          }
        }
        else
        {
          foreach (string parameter in args)
          {
            switch (parameter.ToUpperInvariant().Replace("-", "/"))
            {
              case "/INSTALL":
                IrssLog.Info("Installing IR Server ...");
                using (TransactedInstaller transactedInstaller = new TransactedInstaller())
                {
                  using (IRServerInstaller IRServerInstaller = new IRServerInstaller())
                  {
                    transactedInstaller.Installers.Add(IRServerInstaller);

                    string path = "/assemblypath=" + Assembly.GetExecutingAssembly().Location;
                    string[] cmdline = { path };

                    InstallContext installContext = new InstallContext(String.Empty, cmdline);
                    transactedInstaller.Context = installContext;

                    transactedInstaller.Install(new Hashtable());
                  }
                }
                break;

              case "/UNINSTALL":
                IrssLog.Info("Uninstalling IR Server ...");
                using (TransactedInstaller transactedInstaller = new TransactedInstaller())
                {
                  using (IRServerInstaller IRServerInstaller = new IRServerInstaller())
                  {
                    transactedInstaller.Installers.Add(IRServerInstaller);

                    string path = "/assemblypath=" + Assembly.GetExecutingAssembly().Location;
                    string[] cmdline = { path };

                    InstallContext installContext = new InstallContext(String.Empty, cmdline);
                    transactedInstaller.Context = installContext;

                    transactedInstaller.Uninstall(null);
                  }
                }
                break;

              case "/START":
                IrssLog.Info("Starting IR Server ...");
                using (ServiceController serviceController = new ServiceController(Shared.ServerName))
                  if (serviceController.Status == ServiceControllerStatus.Stopped)
                    serviceController.Start();
                break;

              case "/STOP":
                IrssLog.Info("Stopping IR Server ...");
                using (ServiceController serviceController = new ServiceController(Shared.ServerName))
                  if (serviceController.Status == ServiceControllerStatus.Running)
                    serviceController.Stop();
                break;

              case "/RESTART":
                IrssLog.Info("Restarting IR Server ...");
                using (ServiceController serviceController = new ServiceController(Shared.ServerName))
                {
                  if (serviceController.Status == ServiceControllerStatus.Running)
                    serviceController.Stop();

                  serviceController.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 30));

                  if (serviceController.Status == ServiceControllerStatus.Stopped)
                    serviceController.Start();
                }
                break;

              case "/SERVICE":
                {
                  IRServer IRServer = new IRServer();
                  ServiceBase.Run(IRServer);
                }
                break;

              default:
                throw new InvalidOperationException(String.Format("Unknown command line parameter \"{0}\"", parameter));
            }
          }

          IrssLog.Info("Done.");
        }
      }
      catch (Exception ex)
      {
        IrssLog.Error(ex);
      }
      finally
      {
        IrssLog.Close();
      }
    }
	// Run the installation process for a specific assembly.
	private void RunInstall(String filename)
			{
				// Load the installer assembly.
				AssemblyInstaller inst;
				inst = new AssemblyInstaller(filename, options);

				// Wrap the installer in a transaction.
				TransactedInstaller trans;
				trans = new TransactedInstaller();
				trans.Installers.Add(inst);

				// Install the assembly.
				IDictionary dict = new Hashtable();
				trans.Install(dict);

				// Write the state information, for later uninstall.
				// TODO
			}
Exemplo n.º 30
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            string command;
            if (args.Length == 0)
            {
                ServiceBase[] ServicesToRun = new ServiceBase[] { new Service1() };
                ServiceBase.Run(ServicesToRun);
                return;
            }
            else if (args.Length == 1)
            {
                command = args[0].ToLower();
                string serviceName = string.Empty;

                string[] cmdArray = command.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (cmdArray.Length == 2)
                {
                    command = cmdArray[0];
                    serviceName = cmdArray[1];
                }

                TransactedInstaller ti = new TransactedInstaller();
                Installer1 ii = null;
                if (serviceName == string.Empty)
                {
                    ii = new Installer1();
                }
                else
                {
                    ii = new Installer1(serviceName);
                }

                ti.Installers.Add(ii);

                string path = string.Format("/assemblypath={0}", System.Reflection.Assembly.GetExecutingAssembly().Location);
                string[] cmd = { path };
                InstallContext context = new InstallContext(string.Empty, cmd);
                ti.Context = context;

                if (command == "-install" || command == "-i")
                {
                    ti.Install(new Hashtable());
                    return;
                }
                else if (command == "-uninstall" || command == "-u")
                {
                    ti.Uninstall(null);
                    return;
                }
            }
            else
            {
                Service1 service = new Service1();
                service.Test();

                while (true)
                {
                    Thread.Sleep(500);
                }
            }

            Console.Write("Help:\r\n-console: Run in Console mode\r\n-i -install Install as Server\r\n-u -uninstall Uninstall Server\r\n");
        }
Exemplo n.º 31
0
        public static void InstallService()
        {
            string[] cmdline = { };
            string serviceFileName = System.Reflection.Assembly.GetExecutingAssembly().Location;

            TransactedInstaller instutil = new TransactedInstaller();
            AssemblyInstaller assemblyInstaller = new AssemblyInstaller(serviceFileName, cmdline);

            Console.WriteLine(GetConfig.GetXMLValue(ConfigSource.Beijing, "ServiceName"));

            instutil.Installers.Add(assemblyInstaller);
            instutil.Install(new System.Collections.Hashtable());
            instutil.Dispose();
        }
Exemplo n.º 32
0
        static void Main(string[] args)
        {
            // Set up the crash dump handler.
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(unhandledException);

            cultureInfo = new System.Globalization.CultureInfo("en-GB");
            settingsManager = new SettingsManager();
            cloudFlareAPI = new CloudFlareAPI();

            if (args.Length > 0)
            {
                if (args[0] == "/service")
                {
                    runService();
                    return;
                }

                if (args[0] == "/install")
                {
                    if(!isAdmin)
                    {
                        AttachConsole( -1 /*ATTACH_PARENT_PROCESS*/ );
                        Console.WriteLine("Need to be running from an elevated (Administrator) command prompt.");
                        FreeConsole();
                        return;
                    }

                    TransactedInstaller ti = new TransactedInstaller();
                    ti.Installers.Add(new ServiceInstaller());
                    ti.Context = new InstallContext("", null);
                    ti.Context.Parameters["assemblypath"] = "\"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\" /service";
                    ti.Install(new System.Collections.Hashtable());
                    ti.Dispose();
                    return;
                }

                if (args[0] == "/uninstall")
                {
                    if (!isAdmin)
                    {
                        AttachConsole(-1 /*ATTACH_PARENT_PROCESS*/ );
                        Console.WriteLine("Need to be running from an elevated (Administrator) command prompt.");
                        FreeConsole();
                        return;
                    }

                    TransactedInstaller ti = new TransactedInstaller();
                    ti.Installers.Add(new ServiceInstaller());
                    ti.Context = new System.Configuration.Install.InstallContext("", null);
                    ti.Context.Parameters["assemblypath"] = "\"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\" /service";
                    ti.Uninstall(null);
                    ti.Dispose();
                    return;
                }
            }

            runGUI();
            return;

        }//end Main()
Exemplo n.º 33
0
        public static void Register(string fullServiceName, HostServiceInstaller installer)
        {
            _log.DebugFormat("Attempting to install '{0}'", fullServiceName);
            if (!IsInstalled(fullServiceName))
            {
                using (var ti = new TransactedInstaller())
                {
                    ti.Installers.Add(installer);

                    var assembly = Assembly.GetEntryAssembly();
                    if(assembly == null) throw new Exception("Assembly.GetEntryAssembly() is null for some reason.");

                    string path = string.Format("/assemblypath={0}", assembly.Location);
                    string[] commandLine = {path};

                    var context = new InstallContext(null, commandLine);
                    ti.Context = context;

                    var savedState = new Hashtable();

                    ti.Install(savedState);
                }
            }
            else
            {
                    _log.Info("Service is already installed");
            }
        }
Exemplo n.º 34
0
        /// <summary>Handles the functionality of the Installutil.exe (Installer Tool).</summary>
        /// <param name="args">The arguments passed to the Installer Tool.</param>
        public static void InstallHelper(string[] args)
        {
            var doUninstall         = false;
            var shouldLoadByName    = false;
            var transactedInstaller = new TransactedInstaller();
            var showHelp            = false;

            try
            {
                var arrayList = new ArrayList();
                foreach (var arg in args)
                {
                    if (arg.StartsWith("-", StringComparison.Ordinal))
                    {
                        var strA = arg.Substring(1);
                        if (string.Compare(strA, "u", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(strA, "uninstall", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            doUninstall = true;
                        }
                        else if (string.Compare(strA, "?", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(strA, "help", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            showHelp = true;
                        }
                        else if (string.Compare(strA, "AssemblyName", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            shouldLoadByName = true;
                        }
                        else
                        {
                            arrayList.Add(arg);
                        }
                    }
                    else
                    {
                        Assembly assembly;
                        try
                        {
                            assembly = shouldLoadByName ? Assembly.Load(arg) : Assembly.LoadFrom(arg);
                        }
                        catch (Exception innerException)
                        {
                            if (arg.IndexOf('=') != -1)
                            {
                                throw new ArgumentException(Res.GetString("InstallFileDoesntExistCommandLine", arg), innerException);
                            }
                            throw;
                        }
                        var value = new AssemblyInstaller(assembly, (string[])arrayList.ToArray(typeof(string)));
                        transactedInstaller.Installers.Add(value);
                    }
                }
                if (showHelp || transactedInstaller.Installers.Count == 0)
                {
                    showHelp = true;
                    transactedInstaller.Installers.Add(new AssemblyInstaller());
                    throw new InvalidOperationException(GetHelp(transactedInstaller));
                }
                transactedInstaller.Context = new InstallContext("InstallUtil.InstallLog", (string[])arrayList.ToArray(typeof(string)));
            }
            catch (Exception ex)
            {
                if (showHelp)
                {
                    throw ex;
                }
                throw new InvalidOperationException(Res.GetString("InstallInitializeException", ex.GetType().FullName, ex.Message));
            }
            var installType = transactedInstaller.Context.Parameters["installtype"];

            if (installType != null && string.Compare(installType, "notransaction", StringComparison.OrdinalIgnoreCase) == 0)
            {
                var action = transactedInstaller.Context.Parameters["action"];
                if (action != null && string.Compare(action, "rollback", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    transactedInstaller.Context.LogMessage(Res.GetString("InstallRollbackNtRun"));
                    for (var j = 0; j < transactedInstaller.Installers.Count; j++)
                    {
                        transactedInstaller.Installers[j].Rollback(null);
                    }
                }
                else if (action != null && string.Compare(action, "commit", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    transactedInstaller.Context.LogMessage(Res.GetString("InstallCommitNtRun"));
                    for (var k = 0; k < transactedInstaller.Installers.Count; k++)
                    {
                        transactedInstaller.Installers[k].Commit(null);
                    }
                }
                else if (action != null && string.Compare(action, "uninstall", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    transactedInstaller.Context.LogMessage(Res.GetString("InstallUninstallNtRun"));
                    for (var l = 0; l < transactedInstaller.Installers.Count; l++)
                    {
                        transactedInstaller.Installers[l].Uninstall(null);
                    }
                }
                else
                {
                    transactedInstaller.Context.LogMessage(Res.GetString("InstallInstallNtRun"));
                    for (var m = 0; m < transactedInstaller.Installers.Count; m++)
                    {
                        transactedInstaller.Installers[m].Install(null);
                    }
                }
            }
            else if (!doUninstall)
            {
                IDictionary stateSaver = new Hashtable();
                transactedInstaller.Install(stateSaver);
            }
            else
            {
                transactedInstaller.Uninstall(null);
            }
        }