Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     if (Array.Exists(args, delegate(string arg) { return(arg == "/install"); }))
     {
         System.Configuration.Install.TransactedInstaller ti = null;
         ti = new System.Configuration.Install.TransactedInstaller();
         ti.Installers.Add(new ProjectInstaller());
         ti.Context = new System.Configuration.Install.InstallContext("", null);
         string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
         ti.Context.Parameters["assemblypath"] = path;
         ti.Install(new System.Collections.Hashtable());
         return;
     }
     if (Array.Exists(args, delegate(string arg) { return(arg == "/uninstall"); }))
     {
         System.Configuration.Install.TransactedInstaller ti = null;
         ti = new System.Configuration.Install.TransactedInstaller();
         ti.Installers.Add(new ProjectInstaller());
         ti.Context = new System.Configuration.Install.InstallContext("", null);
         string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
         ti.Context.Parameters["assemblypath"] = path;
         ti.Uninstall(null);
         return;
     }
     if (Array.Exists(args, delegate(string arg) { return(arg == "/service"); }))
     {
         ServiceBase[] ServicesToRun;
         ServicesToRun = new ServiceBase[] { new MyService() };
         ServiceBase.Run(ServicesToRun);
     }
     else
     {
         Console.ReadKey();
     }
 }
        public static void Uninstall()
        {
            System.Configuration.Install.TransactedInstaller ti = null;
            ti = new System.Configuration.Install.TransactedInstaller();
            ti.Installers.Add(new ProjectInstaller());
            ti.Context = new System.Configuration.Install.InstallContext("", null);
            var path = System.Reflection.Assembly.GetExecutingAssembly().Location;

            ti.Context.Parameters["assemblypath"] = path;
            ti.Uninstall(null);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.ProcessExit        += new EventHandler(CurrentDomain_ProcessExit);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            if (Array.Exists(args, delegate(string arg) { return(arg.ToLower() == "/install"); }))
            {
                try
                {
                    System.Configuration.Install.TransactedInstaller ti = new System.Configuration.Install.TransactedInstaller();
                    ti.Installers.Add(new ProjectInstaller());
                    ti.Context = new System.Configuration.Install.InstallContext("", null);
                    ti.Context.Parameters["assemblypath"] = System.Reflection.Assembly.GetExecutingAssembly().Location;
                    ti.Install(new System.Collections.Hashtable());
                    return;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    if (!IsAdministrator)
                    {
                        Console.WriteLine("Install requires administrator rights");
                    }
                }
                return;
            }

            if (Array.Exists(args, delegate(string arg) { return(arg.ToLower() == "/uninstall"); }))
            {
                try
                {
                    System.Configuration.Install.TransactedInstaller ti = new System.Configuration.Install.TransactedInstaller();
                    ti.Installers.Add(new ProjectInstaller());
                    ti.Context = new System.Configuration.Install.InstallContext("", null);
                    ti.Context.Parameters["assemblypath"] = System.Reflection.Assembly.GetExecutingAssembly().Location;
                    ti.Uninstall(null);
                    return;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    if (!IsAdministrator)
                    {
                        Console.WriteLine("Unnstall requires administrator rights");
                    }
                }
                return;
            }

            if (Array.Exists(args, delegate(string arg) { return(arg.ToLower() == "/service"); }))
            {
                ServiceBase[] ServicesToRun;

                // 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()};
                //
                ServicesToRun = new ServiceBase[] { new SystemService(ProgramStart) };

                ServiceBase.Run(ServicesToRun);
            }
            else
            {
                bool serviceRunning = true;
                try
                {
                    ProgramStart(ref serviceRunning);
                }
                catch (Exception ex)
                {
                    if (Trace.Listeners.Count > 1)
                    {
                        Trace.WriteLine("Program Failed: " + ex.Message);
                        if (ex.InnerException != null)
                        {
                            Trace.WriteLine(ex.InnerException.Message);
                        }
                        Trace.WriteLine(ex.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Program Failed: " + ex.Message);
                        if (ex.InnerException != null)
                        {
                            Console.WriteLine(ex.InnerException.Message);
                        }
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private bool UninstallSystemServic(string service,string servicePath,string commandLineOptions)
        {
            if (!System.IO.File.Exists(servicePath))
                return false;
            if (SystemServiceExists(service))
                return false;
            try
            {
                System.Configuration.Install.TransactedInstaller tranInstaller = new System.Configuration.Install.TransactedInstaller();
                System.Configuration.Install.AssemblyInstaller assemInstaller = new System.Configuration.Install.AssemblyInstaller(servicePath, new string[] { commandLineOptions });
                tranInstaller.Installers.Add(assemInstaller);
                System.Configuration.Install.InstallContext installContext = new System.Configuration.Install.InstallContext("install.log", new string[] { commandLineOptions });
                tranInstaller.Context=installContext;
                tranInstaller.Uninstall(null);
                return true;
            }
            catch(Exception e)
            {
                ShowError(e.StackTrace.ToString());
                return false;
            }

        }
Ejemplo n.º 5
0
        static int Main(string[] args)
        {
            ShowVersion();

            if (3 < args.Length)
            {
                return ShowUsage();
            }

            string strServerIP = string.Empty;
            if (0 == args.Length)
            {
                ShowUsage();
            }
            else
            {
                strServerIP = args[0];
            }

            if ("/ca-setup" == strServerIP)
            {
                string strIPAddr = string.Empty;
                if (args.Length > 1)
                {
                    strIPAddr = args[1];
                }

                if (strIPAddr.Length > 0)
                {
                    if ('*' == strIPAddr[0])
                    {
                        if (1 == strIPAddr.Length)
                        {
                            strIPAddr += ":";
                            strIPAddr += CAHTTPProxy.DEFAULT_PORT.ToString();
                        }

                        CAHTTPProxy proxy = new CAHTTPProxy(string.Empty);
                        strIPAddr = strIPAddr.Replace("*", proxy._strDnsHostName);
                    }
                }
                else
                {
                    strIPAddr = string.Format("localhost:{0}", CAHTTPProxy.DEFAULT_PORT);
                }

                string strMacAddr = string.Empty;
                if (args.Length > 2)
                {
                    strMacAddr = args[2];
                }

                string strUDevNum = Console.ReadLine();
                string strUDevPin = Console.ReadLine();
                if ("*" == strMacAddr)
                {
                    strMacAddr = Console.ReadLine();
                }

                new CAWebClient.CAAuthData(strUDevNum, strUDevPin, string.Format("http://{0}/ca/", strIPAddr), strMacAddr);
            }
            else if ("/m3u-setup" == strServerIP)
            {
                TextReader iniReader = Console.In;
                if (args.Length > 1)
                {
                    iniReader = new StreamReader(File.Open(args[1], FileMode.Open), Encoding.Default);
                }

                string strRndMacAddress = _strMacAddress;
                CAHTTPProxy proxy = new CAHTTPProxy(string.Empty);

                string strAppParam;
                IPAddress mifaceIP = IPAddress.None;
                if (null != (strAppParam = ConfigurationManager.AppSettings["mifaceIP"]))
                {
                    mifaceIP = IPAddress.Parse(strAppParam);
                }

                proxy.Start(mifaceIP);

                int ndx = 0x100;
                while (strRndMacAddress == proxy.MacAddress && ndx-- > 0)
                {
                    proxy.Loop(80);
                }

                CAWebClient client = new CAWebClient(proxy.MacAddress);
                string xmlCA = client.CAXmlString;

                TVGMapConfigWriter writerTVG = new TVGMapConfigWriter(iniReader, xmlCA);
                int iCount = writerTVG.WriteCA(Stream.Null);
                Log.Message(string.Format("{0} tvg names successfully added to configuration.", iCount));

                proxy.Stop();
            }
            else if ("/stream-setup" == strServerIP)
            {
                string strclass;
                if (args.Length > 1)
                {
                    switch (args[1])
                    {
                        case StreamProxy.CLASS_NAME:
                            strclass = StreamProxy.Name;
                            break;
                        case MemoryCacheClass16.CLASS_NAME:
                            strclass = StreamProxyEx<MemoryCacheClass16>.Name;
                            break;
                        case MemoryCacheClass32.CLASS_NAME:
                            strclass = StreamProxyEx<MemoryCacheClass32>.Name;
                            break;
                        case MemoryCacheClass64.CLASS_NAME:
                            strclass = StreamProxyEx<MemoryCacheClass64>.Name;
                            break;
                        case MemoryCacheClass128.CLASS_NAME:
                            strclass = StreamProxyEx<MemoryCacheClass128>.Name;
                            break;
                        case MemoryCacheClass256.CLASS_NAME:
                            strclass = StreamProxyEx<MemoryCacheClass256>.Name;
                            break;
                        case MemoryCacheClass512.CLASS_NAME:
                            strclass = StreamProxyEx<MemoryCacheClass512>.Name;
                            break;
                        case MemoryCacheClass1024.CLASS_NAME:
                            strclass = StreamProxyEx<MemoryCacheClass1024>.Name;
                            break;
                        case MemoryCacheClass2048.CLASS_NAME:
                            strclass = StreamProxyEx<MemoryCacheClass2048>.Name;
                            break;

                        default:
                            strclass = string.Empty;
                            break;
                    }
                }
                else
                {
                    strclass = StreamProxyEx<MemoryCacheClass32>.Name;
                }

                if (strclass.Length > 0)
                {
                    new ProxyStreamConfig(strclass);
                }
                else
                {
                    Log.Message(string.Format("Proxy stream {0} not found.", args[1]));
                }
            }
            else if ("/process-setup" == strServerIP)
            {
                ProcessTuneSection.PriorityLevel? prPriority = ProcessTuneSection.PriorityLevel.High;
                if (args.Length > 1)
                {
                    if (0 == string.Compare(ProcessTuneSection.PriorityLevel.Low.ToString(), args[1], true))
                    {
                        prPriority = ProcessTuneSection.PriorityLevel.Low;
                    }
                    else if (0 != string.Compare(ProcessTuneSection.PriorityLevel.High.ToString(), args[1], true))
                    {
                        prPriority = null;
                    }
                }

                if (prPriority.HasValue)
                {
                    new ProcessTuneSection(prPriority.Value);
                }
                else
                {
                    Log.Message(string.Format("Unknown process tune setting {0}, allowed only \"low\" or \"high\".", args[1]));
                }
            }
            else if ("/service-install" == strServerIP)
            {
                System.Configuration.Install.TransactedInstaller ti = null;
                ti = new System.Configuration.Install.TransactedInstaller();
                ti.Installers.Add(new ProjectInstaller());
                ti.Context = new System.Configuration.Install.InstallContext("", null);
                string path = Assembly.GetExecutingAssembly().Location;
                ti.Context.Parameters["assemblypath"] = path;
                ti.Install(new Hashtable());
            }
            else if ("/service-uninstall" == strServerIP)
            {
                System.Configuration.Install.TransactedInstaller ti = null;
                ti = new System.Configuration.Install.TransactedInstaller();
                ti.Installers.Add(new ProjectInstaller());
                ti.Context = new System.Configuration.Install.InstallContext("", null);
                string path = Assembly.GetExecutingAssembly().Location;
                ti.Context.Parameters["assemblypath"] = path;
                ti.Uninstall(null);
            }
            else if ("/service-run" == strServerIP)
            {
                RedirectStd();
                System.ServiceProcess.ServiceBase.Run(new CAHTTPProxy(string.Empty));
            }
            else
            {
                string strAppParam;
                IPAddress mifaceIP = IPAddress.None;
                if (args.Length > 1)
                {
                    mifaceIP = IPAddress.Parse(args[1]);
                }
                else if (null != (strAppParam = ConfigurationManager.AppSettings["mifaceIP"]))
                {
                    mifaceIP = IPAddress.Parse(strAppParam);
                }

                CAHTTPProxy CAHTTPProxy = new CAHTTPProxy(strServerIP);
                CAHTTPProxy.Start(mifaceIP);

                while (!Console.KeyAvailable)
                {
                    CAHTTPProxy.Loop(125);
                }

                CAHTTPProxy.Stop();
            }

            return 0;
        }