Пример #1
0
        public void Run(Assembly startingAssembly, string[] args)
        {
            this.AssertThisIsTheOnlyRunningContext();

            // create a new application context
            _appContext = new PluginApplicationContext();

            // save the command line args
            _commandLineArgs = args;

            if (CarbonConfig.SingleInstance)
            {
                // create a new instance manager, don't dispose of it just yet as we'll need to have our ui plugin
                // grab it and listen for events until the plugin context is destroyed...
                _instanceManager = new InstanceManager(CarbonConfig.SingleInstancePort, CarbonConfig.SingleInstanceMutexName);

                // check to see if this one is the only instance running
                if (!_instanceManager.IsOnlyInstance)
                {
                    // if not, forward our command line, and then instruct the
                    _instanceManager.SendCommandLineToPreviousInstance(PluginContext.Current.CommandLineArgs);
                    return;
                }
            }

            // load the Carbon core sub-system providers
            _windowProviders        = CarbonConfig.GetWindowProviders();
            _configurationProviders = CarbonConfig.GetConfigurationProviders();
            //_encryptionProviders = CarbonConfig.GetEncryptionProviders();
            _pluginProviders = CarbonConfig.GetPluginProviders();

            // show the splash _splashWindow if the config specifies
            if (CarbonConfig.ShowSplashWindow)
            {
                /*
                 * Not-Threaded
                 * */
                using (WindowProvider splashWindowProvider = this.GetSplashWindowProvider())
                {
                    _splashWindow = splashWindowProvider.CreateWindow(null);
                }

                _splashWindow.Show();
                _splashWindow.Refresh();
                _progressViewer = _splashWindow as IProgressViewer;
            }

            ProgressViewer.SetExtendedDescription(_progressViewer, "Initializing Carbon Framework System Providers.");

            // start configuration providers
            ConfigurationProvidersManager.InstructConfigurationProvidersToLoad(_progressViewer, _configurationProviders);

            // use the plugin manager to load the plugin types that the plugin providers want loaded
            using (TypeCollection pluginTypes = PluginManager.LoadPluginTypes(_progressViewer, _pluginProviders))
            {
                // use the plugin manager to create descriptors for all of the plugins
                using (_pluginDescriptors = PluginManager.CreatePluginDescriptors(_progressViewer, pluginTypes))
                {
                    // validate the plugin dependencies
                    PluginManager.ValidatePluginDependencies(_progressViewer, _pluginDescriptors);

                    // sort plugins to have the least dependent plugins first
                    // NOTE: Always sort first because the dependencies are taken into account during instance construction!
                    _pluginDescriptors = PluginManager.Sort(_pluginDescriptors, true);

                    // create the plugins
                    PluginManager.CreatePluginInstances(_progressViewer, _pluginDescriptors);

                    // start plugins
                    PluginManager.StartPlugins(_progressViewer, _pluginDescriptors);

                    // if we are supposed to run a message loop, do it now
                    if (CarbonConfig.RunApplicationContext)
                    {
                        this.OnEnteringMainMessageLoop(new PluginContextEventArgs(this));

                        // run the plugin context's main message loop
                        Application.Run(this.ApplicationContext);

                        this.OnExitingMainMessageLoop(new PluginContextEventArgs(this));
                    }

                    // sort plugins to have the most dependent plugins first
                    _pluginDescriptors = PluginManager.Sort(_pluginDescriptors, false);

                    // stop plugins
                    PluginManager.StopPlugins(null, _pluginDescriptors);
                }
            }

            // stop configuration providers
            // start configuration providers
            ConfigurationProvidersManager.InstructConfigurationProvidersToSave(_configurationProviders);
        }
Пример #2
0
        /// <summary>
        /// The background thread's entry method
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HandleThreadRun(object sender, BackgroundThreadStartEventArgs e)
        {
            try
            {
                // first try the Type var, if we can create one using Reflection we don't need the provider
                if (_type != null)
                {
                    // make sure that the type specified inherits from Form or is directly a Form class
                    TypeUtilities.AssertTypeIsSubclassOfBaseType(_type, typeof(Form));

                    // create a new instance of the window using the Type specified
                    _window = TypeUtilities.CreateInstanceOfType(_type, Type.EmptyTypes, new object[] {}) as Form;
                }
                else
                {
                    // use the provider to create an instance of the window
                    _window = _provider.CreateWindow(e.Args);
                }

                // make sure we have a window instance
                if (_window == null)
                {
                    throw new ArgumentNullException("InnerWindow", "No window instance was created.");
                }

                // raise an event so that we can modify the window as needed before it is shown
                this.OnWindowCreated(this, new AsyncWindowManagerEventArgs(this));

                // release the start method by signalling we have created the window
                _createdEvent.Set();

                // see if an owner was specified
                IWin32Window owner = null;
                if (e.Args != null)
                {
                    if (e.Args.Length > 0)
                    {
                        owner = (IWin32Window)e.Args[0];
                    }
                }

                // show the window modally on this thread
                if (owner != null)
                {
                    _window.Owner = owner as Form;
                    _window.ShowDialog(owner);
                }
                else
                {
                    _window.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                _failed = true;
                Log.WriteLine(ex);
                this.OnException(this, new AsyncWindowManagerExceptionEventArgs(this, ex));
            }
            finally
            {
                _window = null;
                _createdEvent.Set();
            }
        }