Exemple #1
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        public static void Main()
        {
            var options = new StartupOptions(Environment.GetCommandLineArgs());

            IsRunningAsService = options.ContainsOption("-service");

            if (IsRunningAsService)
            {
                //_canRestartService = CanRestartWindowsService();
            }

            var currentProcess = Process.GetCurrentProcess();

            ApplicationPath = currentProcess.MainModule.FileName;
            var architecturePath = Path.Combine(Path.GetDirectoryName(ApplicationPath), Environment.Is64BitProcess ? "x64" : "x86");

            Wand.SetMagickCoderModulePath(architecturePath);

            var success = SetDllDirectory(architecturePath);

            SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());

            var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService);

            var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");

            logManager.ReloadLogger(LogSeverity.Debug);
            logManager.AddConsoleOutput();

            var logger = _logger = logManager.GetLogger("Main");

            ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);

            // Install directly
            if (options.ContainsOption("-installservice"))
            {
                logger.Info("Performing service installation");
                InstallService(ApplicationPath, logger);
                return;
            }

            // Restart with admin rights, then install
            if (options.ContainsOption("-installserviceasadmin"))
            {
                logger.Info("Performing service installation");
                RunServiceInstallation(ApplicationPath);
                return;
            }

            // Uninstall directly
            if (options.ContainsOption("-uninstallservice"))
            {
                logger.Info("Performing service uninstallation");
                UninstallService(ApplicationPath, logger);
                return;
            }

            // Restart with admin rights, then uninstall
            if (options.ContainsOption("-uninstallserviceasadmin"))
            {
                logger.Info("Performing service uninstallation");
                RunServiceUninstallation(ApplicationPath);
                return;
            }

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            RunServiceInstallationIfNeeded(ApplicationPath);

            if (IsAlreadyRunning(ApplicationPath, currentProcess))
            {
                logger.Info("Shutting down because another instance of Emby Server is already running.");
                return;
            }

            if (PerformUpdateIfNeeded(appPaths, logger))
            {
                logger.Info("Exiting to perform application update.");
                return;
            }

            try
            {
                RunApplication(appPaths, logManager, IsRunningAsService, options);
            }
            finally
            {
                OnServiceShutdown();
            }
        }
Exemple #2
0
 public void TestInitialize()
 {
     Wand.SetMagickCoderModulePath("Libraries\\x86\\Coders");
     Wand.SetMagickConfigurePath("MagickConfig");
     Wand.SetMagickFontPath("Fonts");
 }