Ejemplo n.º 1
0
        /// <summary>
        /// Init Service Thread
        /// </summary>
        private static void DoInitService()
        {
            ServiceScope.Get <ILogger>().GetLogger.Debug("Registering Script Manager");
            ServiceScope.Add <IScriptManager>(new ScriptManager());

            ServiceScope.Get <ILogger>().GetLogger.Debug("Registering Audio Encoder");
            ServiceScope.Add <IAudioEncoder>(new AudioEncoder());

            ServiceScope.Get <ILogger>().GetLogger.Debug("Registering Media Change Monitor");
            ServiceScope.Add <IMediaChangeMonitor>(new MediaChangeMonitor());

            ServiceScope.Get <ILogger>().GetLogger.Info("Finished registering services");
        }
        public async Task Basic()
        {
            ServiceProvider provider = new ServiceProvider();
            {
                ServiceScope scope = await provider.CreateScope("a");

                Assert.AreEqual("a", scope.Name);
                Assert.IsFalse(scope.TryGet <object>(out _));

                scope.Add("str");
                Assert.AreEqual("str", scope.Get <string>());
                Assert.AreEqual("a", scope.GetSource <string>());

                scope.Add("str-id", "id");
                Assert.AreEqual("str-id", scope.Get <string>("id"));

                scope.Remove <string>();
                Assert.IsFalse(scope.TryGet <string>(out _));
                Assert.IsTrue(scope.TryGet <string>(out _, "id"));

                scope.Replace(0);
                Assert.AreEqual(0, scope.Get <int>());

                scope.Replace(1);
                Assert.AreEqual(1, scope.Get <int>());

                scope.Add(1.2);
                scope.Remove <double>();
            }
            {
                ServiceScope scope = await provider.CreateScope("b");

                Assert.AreEqual("b", scope.Name);
                Assert.IsFalse(scope.TryGet <object>(out _));

                Assert.AreEqual("str-id", scope.Get <string>("id"));
                Assert.AreEqual(1, scope.Get <int>());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// When the Tab Page is clicked the first time, we want to fill the ribbon with the burner.
        /// Don't do it, when initially loading, as it might cause delays in displaying the Ui
        /// </summary>
        public void InitRibbon()
        {
            if (burnManager == null)
            {
                ServiceScope.Get <ILogger>().GetLogger.Debug("Registering Burn Manager");
                ServiceScope.Add <IBurnManager>(new BurnManager());

                mediaChangeMonitor = ServiceScope.Get <IMediaChangeMonitor>();
                mediaChangeMonitor.MediaInserted += mediaChangeMonitor_MediaInserted;
                mediaChangeMonitor.MediaRemoved  += mediaChangeMonitor_MediaRemoved;

                burnManager = ServiceScope.Get <IBurnManager>();
                GetDrives();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Init Service Thread
        /// </summary>
        private static void DoInitService()
        {
            ServiceScope.Get <ILogger>().GetLogger.Debug("Registering Script Manager");
            ServiceScope.Add <IScriptManager>(new ScriptManager());

            ServiceScope.Get <ILogger>().GetLogger.Debug("Registering Audio Encoder");
            ServiceScope.Add <IAudioEncoder>(new AudioEncoder());

            ServiceScope.Get <ILogger>().GetLogger.Debug("Registering Media Change Monitor");
            ServiceScope.Add <IMediaChangeMonitor>(new MediaChangeMonitor());

            ServiceScope.Get <ILogger>().GetLogger.Info("Finished registering services");

            byte[] buffer            = new byte[2048];
            var    messageWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "MPTagThat_IPC");

            ServiceScope.Get <ILogger>().GetLogger.Debug("Registering MemoryMappedFile");
            // Create named MMF
            using (var mmf = MemoryMappedFile.CreateOrOpen("MPTagThat", 2048))
            {
                // Create accessor to MMF
                using (var accessor = mmf.CreateViewAccessor(0, buffer.Length))
                {
                    // Wait for the Message to be fired
                    while (true)
                    {
                        ServiceScope.Get <ILogger>().GetLogger.Debug("Wait for Startup Event to be fired");
                        messageWaitHandle.WaitOne();
                        ServiceScope.Get <ILogger>().GetLogger.Debug("Startup Event fired");

                        // Read from MMF
                        accessor.ReadArray <byte>(0, buffer, 0, buffer.Length);

                        string startupFolder = Encoding.Default.GetString(buffer).Trim(new char[] { ' ', '\x00' });
                        SetCurrentFolder(startupFolder);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(params string[] args)
        {
            System.Threading.Thread.CurrentThread.Name = "Manager";
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Parse Command Line options
            CommandLineOptions mpArgs = new CommandLineOptions();

            try
            {
                CommandLine.Parse(args, mpArgs);
            }
            catch (ArgumentException)
            {
                mpArgs.DisplayOptions();
                return;
            }

            using (new ServiceScope(true)) //This is the first servicescope
            {
                ApplicationCore.RegisterCoreServices();

                IPathManager pathManager = ServiceScope.Get <IPathManager>();
                // Check if user wants to override the default Application Data location.
                if (mpArgs.IsOption(CommandLineOptions.Option.Data))
                {
                    pathManager.ReplacePath("DATA", (string)mpArgs.GetOption(CommandLineOptions.Option.Data));
                }

                //Check whether the user wants to log method names in the logger
                //This adds an extra 10 to 40 milliseconds to the log call, depending on the length of the stack trace
                bool     logMethods = mpArgs.IsOption(CommandLineOptions.Option.LogMethods);
                LogLevel level      = LogLevel.All;
                if (mpArgs.IsOption(CommandLineOptions.Option.LogLevel))
                {
                    level = (LogLevel)mpArgs.GetOption(CommandLineOptions.Option.LogLevel);
                }
                ILogger logger = ServiceScope.Get <ILogger>();
                logger.Level          = level;
                logger.LogMethodNames = logMethods;

                logger.Debug("Manager: Registering Strings Manager");
                ServiceScope.Add <ILocalisation>(new StringManager());

#if !DEBUG
                // Not in Debug mode (ie Release) then catch all Exceptions
                // In Debug mode these will be left unhandled.
                try
                {
#endif
                // Start the system
                logger.Debug("ApplicationLauncher: Starting MediaPortal manager");

                IPluginManager pluginManager = ServiceScope.Get <IPluginManager>();
                pluginManager.Initialize();
                pluginManager.Startup(true);
                Application.Run(new MainWindow());
                pluginManager.Shutdown();

#if !DEBUG
            }
            catch (Exception ex)
            {
                CrashLogger crash = new CrashLogger(pathManager.GetPath("<LOG>"));
                crash.CreateLog(ex);
                //Form frm =
                //  new YesNoDialogScreen("MediaPortal 2", "Unrecoverable Error",
                //                        "MediaPortal has encountered an unrecoverable error\r\nDetails have been logged\r\n\r\nRestart?",
                //                        BaseScreen.Image.bug);
                //restart = frm.ShowDialog() == DialogResult.Yes;
            }
#endif
            }
        }
Ejemplo n.º 6
0
        private static void Main(string[] args)
        {
            // Need to reset the Working directory, since when we called via the Explorer Context menu, it'll be different
            Directory.SetCurrentDirectory(Application.StartupPath);

            // Add our Bin and Bin\Bass Directory to the Path
            SetPath(Path.Combine(Application.StartupPath, "Bin"));
            SetPath(Path.Combine(Application.StartupPath, @"Bin\Bass"));

            _portable      = 0;
            _startupFolder = "";
            // Process Command line Arguments
            foreach (string arg in args)
            {
                if (arg.ToLower().StartsWith("/folder="))
                {
                    _startupFolder = arg.Substring(8);
                }
                else if (arg.ToLower() == "/portable")
                {
                    _portable = 1;
                }
            }

            // Read the Config file
            ReadConfig();

            // Register Bass
            BassRegistration.BassRegistration.Register();

            using (new ServiceScope(true))
            {
                ILogger logger = new FileLogger("MPTagThat.log", NLog.LogLevel.Debug, _portable);
                ServiceScope.Add(logger);

                NLog.Logger log = ServiceScope.Get <ILogger>().GetLogger;

                log.Info("MPTagThat is starting...");

                log.Info("Registering Services");
                log.Debug("Registering Settings Manager");
                ServiceScope.Add <ISettingsManager>(new SettingsManager());
                // Set the portable Indicator
                ServiceScope.Get <ISettingsManager>().SetPortable(_portable);

                try
                {
                    logger.Level = NLog.LogLevel.FromString(Options.MainSettings.DebugLevel);
                }
                catch (ArgumentException)
                {
                    Options.MainSettings.DebugLevel = "Info";
                    logger.Level = NLog.LogLevel.FromString(Options.MainSettings.DebugLevel);
                }

                log.Debug("Registering Localisation Services");
                ServiceScope.Add <ILocalisation>(new StringManager());

                log.Debug("Registering Message Broker");
                ServiceScope.Add <IMessageBroker>(new MessageBroker());

                log.Debug("Registering Theme Manager");
                ServiceScope.Add <IThemeManager>(new ThemeManager());

                log.Debug("Registering Action Handler");
                ServiceScope.Add <IActionHandler>(new ActionHandler());

                // Move Init of Services, which we don't need immediately to a separate thread to increase startup performance
                Thread initService = new Thread(DoInitService);
                initService.IsBackground = true;
                initService.Name         = "InitService";
                initService.Start();

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                try
                {
                    Main main = new Main();

                    // Set the Startup Folder we might have received via an argument, before invoking the form
                    main.CurrentDirectory = _startupFolder;
                    Application.Run(main);
                }
                catch (OutOfMemoryException)
                {
                    GC.Collect();
                    MessageBox.Show(ServiceScope.Get <ILocalisation>().ToString("message", "OutOfMemory"),
                                    ServiceScope.Get <ILocalisation>().ToString("message", "Error_Title"), MessageBoxButtons.OK);
                    log.Error("Running out of memory. Scanning aborted.");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ServiceScope.Get <ILocalisation>().ToString("message", "FatalError"),
                                    ServiceScope.Get <ILocalisation>().ToString("message", "Error_Title"), MessageBoxButtons.OK);
                    log.Error("Fatal Exception: {0}\r\n{1}", ex.Message, ex.StackTrace);
                }
            }
        }
Ejemplo n.º 7
0
        private static void Main(string[] args)
        {
            // Need to reset the Working directory, since when we called via the Explorer Context menu, it'll be different
            Directory.SetCurrentDirectory(Application.StartupPath);

            // Add our Bin and Bin\Bass Directory to the Path
            SetPath(Path.Combine(Application.StartupPath, "Bin"));
            SetPath(Path.Combine(Application.StartupPath, @"Bin\Bass"));

            _portable      = 0;
            _startupFolder = "";
            // Process Command line Arguments
            foreach (string arg in args)
            {
                if (arg.ToLower().StartsWith("/folder="))
                {
                    _startupFolder = arg.Substring(8);
                }
                else if (arg.ToLower() == "/portable")
                {
                    _portable = 1;
                }
            }

            try
            {
                // Let's see, if we already have an instance of MPTagThat open
                using (var mmf = MemoryMappedFile.OpenExisting("MPTagThat"))
                {
                    if (_startupFolder == string.Empty)
                    {
                        // Don't allow a second instance of MPTagThat running
                        return;
                    }

                    byte[] buffer            = Encoding.Default.GetBytes(_startupFolder);
                    var    messageWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "MPTagThat_IPC");

                    // Create accessor to MMF
                    using (var accessor = mmf.CreateViewAccessor(0, buffer.Length))
                    {
                        // Write to MMF
                        accessor.WriteArray <byte>(0, buffer, 0, buffer.Length);
                        messageWaitHandle.Set();

                        // End exit this instance
                        return;
                    }
                }
            }
            catch (FileNotFoundException)
            {
                // The Memorymap does not exist, so MPTagThat is not yet running
            }

            // Read the Config file
            ReadConfig();

            // Register Bass
            BassRegistration.BassRegistration.Register();

            using (new ServiceScope(true))
            {
                ILogger logger = new FileLogger("MPTagThat.log", NLog.LogLevel.Debug, _portable);
                ServiceScope.Add(logger);

                NLog.Logger log = ServiceScope.Get <ILogger>().GetLogger;

                log.Info("MPTagThat is starting...");

                log.Info("Registering Services");
                log.Debug("Registering Settings Manager");
                ServiceScope.Add <ISettingsManager>(new SettingsManager());
                // Set the portable Indicator
                ServiceScope.Get <ISettingsManager>().SetPortable(_portable);
                // Set the Max Songs number
                ServiceScope.Get <ISettingsManager>().SetMaxSongs(_maxSongs);

                try
                {
                    logger.Level = NLog.LogLevel.FromString(Options.MainSettings.DebugLevel);
                }
                catch (ArgumentException)
                {
                    Options.MainSettings.DebugLevel = "Info";
                    logger.Level = NLog.LogLevel.FromString(Options.MainSettings.DebugLevel);
                }

                log.Debug("Registering Localisation Services");
                ServiceScope.Add <ILocalisation>(new StringManager());

                log.Debug("Registering Message Broker");
                ServiceScope.Add <IMessageBroker>(new MessageBroker());

                log.Debug("Registering Theme Manager");
                ServiceScope.Add <IThemeManager>(new ThemeManager());

                log.Debug("Registering Action Handler");
                ServiceScope.Add <IActionHandler>(new ActionHandler());

                // Move Init of Services, which we don't need immediately to a separate thread to increase startup performance
                Thread initService = new Thread(DoInitService);
                initService.IsBackground = true;
                initService.Name         = "InitService";
                initService.Start();

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                try
                {
                    _main = new Main();

                    // Set the Startup Folder we might have received via an argument, before invoking the form
                    _main.CurrentDirectory = _startupFolder;
                    Application.Run(_main);
                }
                catch (OutOfMemoryException)
                {
                    GC.Collect();
                    MessageBox.Show(ServiceScope.Get <ILocalisation>().ToString("message", "OutOfMemory"),
                                    ServiceScope.Get <ILocalisation>().ToString("message", "Error_Title"), MessageBoxButtons.OK);
                    log.Error("Running out of memory. Scanning aborted.");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ServiceScope.Get <ILocalisation>().ToString("message", "FatalError"),
                                    ServiceScope.Get <ILocalisation>().ToString("message", "Error_Title"), MessageBoxButtons.OK);
                    log.Error("Fatal Exception: {0}\r\n{1}", ex.Message, ex.StackTrace);
                }
            }
        }