コード例 #1
0
ファイル: AppManager.cs プロジェクト: yangkf1985/DotSpatial
        /// <summary>
        /// Activates the extensions. This should be called only once.
        /// </summary>
        public virtual void LoadExtensions()
        {
            if (DesignMode)
            {
                return;
            }

            if (Extensions.Any())
            {
                throw new InvalidOperationException("LoadExtensions() should only be called once. Subsequent calls should be made to RefreshExtensions(). ");
            }

            // We need to uninstall any outstanding extensions before loading ...
            PackageManager.RemovePendingPackagesAndExtensions();

            splashScreen = SplashScreenHelper.GetSplashScreenManager();

            UpdateSplashScreen("Discovering Extensions...");

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            _catalog = GetCatalog();

            CompositionContainer = new CompositionContainer(_catalog);

            try
            {
                IDataManager dataManager = DataManager.DefaultDataManager;
                CompositionContainer.ComposeParts(this, dataManager, this.SerializationManager);
            }
            catch (CompositionException compositionException)
            {
                Trace.WriteLine(compositionException.Message);
                throw;
            }

            UpdateSplashScreen("Loading Extensions...");

            OnExtensionsActivating(EventArgs.Empty);

            ActivateAllExtensions();

            OnExtensionsActivated(EventArgs.Empty);

            if (splashScreen != null)
            {
                splashScreen.Deactivate();
                splashScreen = null;
            }

            // Set the DefaultDataManager progress handler.
            // It doesn’t seem like the solution is as simple as adding the
            //        [Import(typeof(IProgressHandler), AllowDefault = true)]
            // Attribute to the ProgressHandler property on DataManager, because the ProgressHandler we are typically
            // using only export IStatusControl and we would require each IStatusControl to
            //    [Export(typeof(DotSpatial.Data.IProgressHandler))]
            // To get that working.
            DataManager.DefaultDataManager.ProgressHandler = this.ProgressHandler;
        }
コード例 #2
0
        /// <summary>
        /// Loads Extensions using MEF and then activates them.
        /// Should only be called once on startup.
        /// </summary>
        public virtual void LoadExtensions()
        {
            if (DesignMode)
            {
                return;
            }

            if (Extensions.Any())
            {
                throw new InvalidOperationException("LoadExtensions() should only be called once. Subsequent calls should be made to RefreshExtensions(). ");
            }

            PackageManager.RemovePendingPackagesAndExtensions();
            _splashScreen = SplashScreenHelper.GetSplashScreenManager();

            Thread updateThread = new Thread(AppLoadExtensions);

            updateThread.Start();

            // Update splash screen's progress bar while thread is active.
            while (updateThread.IsAlive)
            {
                UpdateSplashScreen(_message);
            }

            updateThread.Join();

            ActivateAllExtensions();
            OnExtensionsActivated(EventArgs.Empty);

            if (_splashScreen != null)
            {
                _splashScreen.Deactivate();
                _splashScreen = null;
            }

            // Set the DefaultDataManager progress handler.
            // It doesn’t seem like the solution is as simple as adding the
            //        [Import(typeof(IProgressHandler), AllowDefault = true)]
            // Attribute to the ProgressHandler property on DataManager, because the ProgressHandler we are typically
            // using only export IStatusControl and we would require each IStatusControl to
            //    [Export(typeof(DotSpatial.Data.IProgressHandler))]
            // To get that working.
            DataManager.DefaultDataManager.ProgressHandler = ProgressHandler;
        }