Esempio n. 1
0
        public MainPresenter(
            IAppContext context,
            IMainView view,
            IProjectService projectService,
            IConfigService configService,
            LegendPresenter legendPresenter,
            ToolboxPresenter toolboxPresenter,
            IRepository repository)
            : base(view)
        {
            Logger.Current.Trace("Start MainPresenter");
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }
            if (projectService == null)
            {
                throw new ArgumentNullException("projectService");
            }
            if (configService == null)
            {
                throw new ArgumentNullException("configService");
            }
            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }

            // PM 2016-03-02 Added:
            if (legendPresenter == null)
            {
                throw new ArgumentNullException("legendPresenter");
            }
            if (toolboxPresenter == null)
            {
                throw new ArgumentNullException("toolboxPresenter");
            }

            _context        = context;
            _projectService = projectService;
            _configService  = configService;

            GlobalListeners.Attach(Logger.Current);

            view.Map.Lock();
            try
            {
                var appContext = context as AppContext;
                if (appContext == null)
                {
                    throw new InvalidCastException("Invalid type of IAppContext instance");
                }

                appContext.Init(view, projectService, configService, legendPresenter, toolboxPresenter, repository);

                view.Map.Initialize();
                view.Map.ApplyConfig(configService);

                view.ViewClosing  += OnViewClosing;
                view.ViewUpdating += OnViewUpdating;
                view.BeforeShow   += OnBeforeShow;

                var container = context.Container;
                _statusBarListener  = container.GetSingleton <StatusBarListener>();
                _menuGenerator      = container.GetSingleton <MenuGenerator>();
                _menuListener       = container.GetSingleton <MenuListener>();
                _mapListener        = container.GetSingleton <MapListener>();
                _mainPluginListener = container.GetSingleton <MainPluginListener>();
                _legendListener     = container.GetSingleton <LegendListener>();

                _menuUpdater = new MenuUpdater(_context, PluginIdentity.Default);

                SplashView.Instance.ShowStatus("Loading plugins");
                // must be called after docking is initialized:
                appContext.InitPlugins(configService, p => SplashView.Instance.ShowStatus($"Loading plugins: {p.Name}"));

                // this will display progress updates and debug window
                // file based-logger is already working
                Logger.Current.Init(appContext);
            }
            finally
            {
                view.Map.Unlock();
                context.Legend.Unlock();
            }

            View.AsForm.Shown += ViewShown;
            Logger.Current.Trace("End MainPresenter");
        }
Esempio n. 2
0
        /// <summary>
        /// Sets all the necessary references from the main view.
        /// </summary>
        /// <remarks>We don't use contructor injection here since most of other services use this one as a parameter.
        /// Perhaps property injection can be used.</remarks>
        internal void Init(
            IMainView mainView,
            IProjectService project,
            IConfigService configService,
            LegendPresenter legendPresenter,
            ToolboxPresenter toolboxPresenter,
            IRepository repository)
        {
            Logger.Current.Trace("Start AppContext.Init()");
            if (mainView == null)
            {
                throw new ArgumentNullException("mainView");
            }
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            if (legendPresenter == null)
            {
                throw new ArgumentNullException("legendPresenter");
            }
            if (toolboxPresenter == null)
            {
                throw new ArgumentNullException("toolboxPresenter");
            }

            _toolboxPresenter = toolboxPresenter;
            _legendPresenter  = legendPresenter;
            var legend = _legendPresenter.Legend;

            mainView.Map.Legend = legend;
            legend.Map          = mainView.Map;

            // it's expected here that we are on the UI thread
            SynchronizationContext = SynchronizationContext.Current;

            PluginManager = _container.GetSingleton <IPluginManager>();
            Broadcaster   = _container.GetSingleton <IBroadcasterService>();
            _container.RegisterInstance <IMuteMap>(mainView.Map);

            _mainView      = mainView;
            View           = new AppView(mainView, _styleService);
            _project       = project;
            _map           = mainView.Map;
            _configService = configService;
            Repository     = repository;

            Legend.Lock();

            DockPanels = new DockPanelCollection(mainView.DockingManager, mainView as Form, Broadcaster, _styleService);
            Menu       = MenuFactory.CreateMainMenu(mainView.MenuManager);
            Toolbars   = MenuFactory.CreateMainToolbars(mainView.MenuManager);
            StatusBar  = MenuFactory.CreateStatusBar(mainView.StatusBar, PluginIdentity.Default);

            _projectionDatabase.ReadFromExecutablePath(Application.ExecutablePath);

            Repository.Initialize(this);

            // comment this line to prevent locator loading
            // may be useful for ocx debugging to not create additional
            // instance of map
            _locator = new LocatorPresenter(_map);

            this.InitDocking();

            Initialized = true;
            Logger.Current.Trace("End AppContext.Init()");
        }