示例#1
0
        /// <summary>
        /// Loads configuration settings while the slice lock is held.
        /// </summary>
        private void LoadConfiguration()
        {
            var configurationStorage = Factory.Singleton.ResolveSingleton <IConfigurationStorage>();
            var configuration        = configurationStorage.Load();

            var receiverRange = configuration.RawDecodingSettings.ReceiverRange;

            if (_SanityChecker == null || receiverRange != _ReceiverRange)
            {
                _ReceiverRange = receiverRange;
                _SanityChecker = Factory.Singleton.Resolve <IAircraftSanityChecker>();
                foreach (var slice in _Slices)
                {
                    slice.PolarPlots.Clear();
                }
            }

            if (!_HookedEvents)
            {
                _HookedEvents = true;
                configurationStorage.ConfigurationChanged += EventHandlerUtils.MakeWeak <EventArgs>(ConfigurationStorage_ConfigurationChanged, r => configurationStorage.ConfigurationChanged -= ConfigurationStorage_ConfigurationChanged);
            }
        }
        /// <summary>
        /// This creates the WPF window from a key.
        /// </summary>
        /// <param name="key">Key</param>
        /// <param name="dataContext">DataContext (state) object</param>
        /// <param name="owner">Owner of the Popup</param>
        /// <param name="completedProc">Callback</param>
        /// <param name="isModal">True if this is a ShowDialog request</param>
        /// <returns>Success code</returns>
        protected Window CreateWindow(string key, object dataContext, Window owner, EventHandler <UICompletedEventArgs> completedProc, bool isModal)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            Type type;

            lock (this.registeredWindows)
            {
                if (!this.registeredWindows.TryGetValue(key, out type))
                {
                    return(null);
                }
            }
            var window = (Window)Activator.CreateInstance(type);

            if (dataContext is IViewStatusAwareInjectionAware)
            {
                var viewAwareStatusService = ViewModelRepository.Instance.Resolver.Container.GetExport <IViewAwareStatus>().Value;
                viewAwareStatusService.InjectContext(window);
                ((IViewStatusAwareInjectionAware)dataContext).InitialiseViewAwareService(viewAwareStatusService);
            }
            if (dataContext is IViewStatusAwareWindowInjectionAware)
            {
                var viewAwareStatusServiceWindow = ViewModelRepository.Instance.Resolver.Container.GetExport <IViewAwareStatusWindow>().Value;
                viewAwareStatusServiceWindow.InjectContext(window);
                ((IViewStatusAwareWindowInjectionAware)dataContext).InitialiseViewAwareWindowService(viewAwareStatusServiceWindow);
            }
            window.DataContext = dataContext;

            window.Owner = owner;

            if (dataContext != null)
            {
                ViewModelBase bvm = dataContext as ViewModelBase;
                if (bvm != null)
                {
                    if (isModal)
                    {
                        bvm.CloseRequest += EventHandlerUtils.MakeWeak((s, e) =>
                        {
                            try
                            {
                                window.DialogResult = e.Result;
                            }
                            catch (InvalidOperationException exception_0)
                            {
                                window.Close();
                            }
                        }, (UnregisterCallback <CloseRequestEventArgs>)(eh => bvm.CloseRequest -= eh));
                    }
                    else
                    {
                        bvm.CloseRequest += EventHandlerUtils.MakeWeak((s, e) => window.Close(), (UnregisterCallback <CloseRequestEventArgs>)(eh => bvm.CloseRequest -= eh));
                    }
                    bvm.ActivateRequest += EventHandlerUtils.MakeWeak((s, e) => window.Activate(), (UnregisterCallback <EventArgs>)(eh => bvm.ActivateRequest -= eh));
                }
            }

            window.Closed += (EventHandler)((s, e) =>
            {
                window.DataContext = null;
                if (completedProc == null)
                {
                    return;
                }
                completedProc(this, new UICompletedEventArgs()
                {
                    State = dataContext,
                    Result = isModal ? window.DialogResult : new bool?()
                });
            });
            return(window);
        }