Esempio n. 1
0
        public void Initialise()
        {
            try
            {
                Ticker.Tick();
                BusG.Init();
                alreadyRunning = Bus.Session.RequestName(BusName) != RequestNameReply.PrimaryOwner;

                if (alreadyRunning)
                {
                    commandParser = Bus.Session.GetObject <ICommandParser>(BusName, new ObjectPath(CommandParserPath));
                }
                else
                {
                    Bus.Session.Register(BusName, new ObjectPath(CommandParserPath), commandParser);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("**************************************");
                Console.WriteLine("* DBus support could not be started. *");
                Console.WriteLine("* Some functionality will be missing *");
                Console.WriteLine("**************************************");
            }
            finally
            {
                Initialised = true;
                Ticker.Tock("DBus");
            }
        }
Esempio n. 2
0
        public TorrentController()
        {
            this.defaultTorrentSettings = SettingsManager.DefaultTorrentSettings;
            this.SelectedDownloads      = new List <Download> ();

            Ticker.Tick();
            fastResume = LoadFastResume();
            Ticker.Tock("Fast Resume");

            Ticker.Tick();
            engine = new ClientEngine(SettingsManager.EngineSettings);
            Ticker.Tock("Client engine");

            allTorrents = new List <Download>();

            Added += delegate(object sender, DownloadAddedEventArgs e) {
                e.Download.Priority = allTorrents.Count + 1;
            };
            Removed += delegate(object sender, DownloadAddedEventArgs e) {
                for (int i = 0; i < allTorrents.Count; i++)
                {
                    if (allTorrents [i].Priority > e.Download.Priority)
                    {
                        allTorrents[i].Priority--;
                    }
                }
            };
        }
Esempio n. 3
0
        void LoadAddins()
        {
            try {
                Ticker.Tick();

                // Initialise the addin manager and listen for DHT nodes to be attached
                AddinManager.Initialize(Defines.AddinPath);
                AddinManager.AddExtensionNodeHandler("/monsoon/dht", DhtChanged);
                AddinManager.Registry.Update(null);
            } catch (Exception ex) {
                logger.Error("Could not load extensions: {0}", ex.Message);
            } finally {
                Ticker.Tock("Mono.Addins Initialised");
            }
        }
Esempio n. 4
0
        public MainClass(string [] args)
        {
            Ticker.Tick();

            // required for the MS .NET runtime that doesn't initialize glib automatically
            if (!GLib.Thread.Supported)
            {
                GLib.Thread.Init();
            }

            // Connect to dbus
            DBusInstance DBusInstance = ServiceManager.Get <DBusInstance> ();

            DBusInstance.Initialise();

            if (DBusInstance.AlreadyRunning)
            {
                Console.WriteLine("Already running");
                DBusInstance.CommandParser.ParseCommands(args);
                return;
            }

            DBusInstance.CommandParser.RunCommand += HandleCommand;

            Ticker.Tick();
            CheckDataFolders();
            Ticker.Tock("Checking folders");

            foreach (string arg in args)
            {
                HandleCommand(arg);
            }

            Ticker.Tick();
            if (DebugEnabled)
            {
                BuildNlogConfig();
            }
            logger = DebugEnabled ? NLog.LogManager.GetCurrentClassLogger() : new EmptyLogger();
            Ticker.Tock("NLog");

            logger.Info("Starting Monsoon");

            Ticker.Tick();
            SetProcessName("monsoon");
            Ticker.Tock("Setting process name");

            string localeDir = Path.Combine(Defines.ApplicationDirectory, "locale");

            if (!Directory.Exists(localeDir))
            {
                localeDir = Path.Combine(Defines.InstallPrefix, "share");
                localeDir = Path.Combine(localeDir, "locale");
            }

            Ticker.Tick();
            Mono.Unix.Catalog.Init("monsoon", localeDir);
            logger.Debug("Using locale data from: {0}", localeDir);

            Application.Init("monsoon", ref args);
            Ticker.Tock("Locale");

            try {
                SettingsManager.Restore <EngineSettings> (SettingsManager.EngineSettings);
                SettingsManager.Restore <PreferencesSettings> (SettingsManager.Preferences);
                SettingsManager.Restore <TorrentSettings> (SettingsManager.DefaultTorrentSettings);
            }
            catch (Exception ex) {
                logger.Error("Couldn't restore old settings: {0}", ex.Message);
            }

            try
            {
                Ticker.Tick();
                mainWindow = new MainWindow();
                Ticker.Tock("Instantiating window");
            }
            catch (Exception e)
            {
                logger.ErrorException(e.Message, e);
                Environment.Exit(0);
            }

            LoadAddins();

            GLib.ExceptionManager.UnhandledException += new GLib.UnhandledExceptionHandler(OnUnhandledException);

            Ticker.Tock("Total time:");
            Application.Run();

            try {
                SettingsManager.Store <EngineSettings> (SettingsManager.EngineSettings);
                SettingsManager.Store <PreferencesSettings> (SettingsManager.Preferences);
                SettingsManager.Store <TorrentSettings> (SettingsManager.DefaultTorrentSettings);
            }
            catch (Exception ex) {
                logger.Error("Could save engine settings: {0}", ex.Message);
            }
            ServiceManager.Get <ListenPortController> ().Stop();
            mainWindow.Destroy();
        }