Пример #1
0
        /// <summary> Tells the manager to do his job. </summary>
        public void DoWork()
        {
            _log.Debug("Doing my work");

            string applicationId = PlatformSettings.Instance["application"];

            if (string.IsNullOrEmpty(applicationId))
            {
                throw new NullReferenceException("Application definition is null or empty! Check the ini file!");
            }

            _application = GetApplicationInstance(applicationId);

            if (_application == null)
            {
                throw new NullReferenceException(string.Format("There is no application implementation for the given application id '{0}'. " +
                                                               "Check the ini file and the existence of the application annotation!", applicationId));
            }

            _application.OnStartup();

            // Creating and Starting UI-Thread
            Thread uiThread = new Thread(OnRunningUI);

            uiThread.TrySetApartmentState(ApartmentState.STA);
            uiThread.Name = "Motoi Application UI-Thread";
            uiThread.Start();

            _log.Debug("Time to get some coffee");

            // Wait here until the UI thread has been finished
            uiThread.Join();
        }
Пример #2
0
        /// <summary> Tells the manager to stop and to release all its resources (dispose). </summary>
        public void HomeTime()
        {
            _log.Debug("Time to go home");

            _application.OnShutdown();
            _application = null;

            _applicationController = null;
            _mainWindow            = null;

            _instance = null;

            _log.Debug("Goodbye");
        }
Пример #3
0
        /// <summary>
        /// Returns an instance of <see cref="IMotoiApplication"/> defined by the given extension point definition id.
        /// If no implementation could be found, null will be returned.
        /// </summary>
        /// <param name="id">Id of the implementation definition</param>
        /// <returns>Instance of <see cref="IMotoiApplication"/> or null</returns>
        private IMotoiApplication GetApplicationInstance(string id)
        {
            IConfigurationElement[] configurationElements           = ExtensionService.Instance.GetConfigurationElements(ApplicationExtensionPointId);
            IConfigurationElement   applicationConfigurationElement = Array.Find(configurationElements, el => el["id"] == id);

            if (applicationConfigurationElement == null)
            {
                return(null);
            }

            string className = applicationConfigurationElement["class"];

            if (string.IsNullOrEmpty(className))
            {
                throw new NullReferenceException($"Attribute 'class' is null or empty for the application id '{id}'!");
            }

            IBundle providingBundle = ExtensionService.Instance.GetProvidingBundle(applicationConfigurationElement);
            Type    type            = TypeLoader.TypeForName(providingBundle, className);

            IMotoiApplication application = Activator.CreateInstance(type) as IMotoiApplication;

            return(application);
        }