コード例 #1
0
        private void OKButtonClicked(object sender, RoutedEventArgs e)
        {
            if (_CurrentModuleSetupView.IsEnteredUserDataValid())
            {
                if (ModuleRegistry.DefaultRegistry.IsModuleRegistered(ControlName.Text))
                {
                    MessageBox.Show("A module with that name is already declared. Module names must be unique.", "Duplicate Module");
                    return;
                }
                var modules = _CurrentModuleSetupView.CreateModules(null);
                // TODO: Handle more than one returned module here!
                var firstModule = modules[0];
                firstModule.ModuleName = ControlName.Text;

                ModuleRegistry.DefaultRegistry.RegisterModule(firstModule);

                var view = firstModule as IDashboardView;
                if (view != null)
                {
                    var anchorableService = new AnchorableViewService();
                    var newAnchorable     = anchorableService.GetAnchorableFromView(view);

                    newAnchorable.Hiding += (obj, args) =>
                    {
                        ModuleRegistry.DefaultRegistry.UnregisterModule(view);
                    };

                    DockHelper.RootAnchorablePane.Children.Add(newAnchorable);
                }


                var parentWindow = (Window)Parent;
                parentWindow.Close();
            }
        }
コード例 #2
0
        public void LoadSavedModulesFromFile(string fileName)
        {
            var savedModules      = GetSavedModulesFromFileJson(fileName);
            var anchorableService = new AnchorableViewService();

            foreach (var module in savedModules)
            {
                ModuleRegistry.DefaultRegistry.RegisterModule(module);

                if (module is IDashboardView)
                {
                    if (AnchorableRegistry.DefaultRegistry.IsAnchorableRegistered(module.ModuleName))
                    {
                        var anchorable = AnchorableRegistry.DefaultRegistry.GetRegisteredAnchorable(module.ModuleName);
                        var view       = module as IDashboardView;
                        anchorable.Content = view.Control;
                    }
                }
            }

            var relationships = GetConsumerRelationshipsFromFileJson(fileName);

            foreach (var relationship in relationships)
            {
                try
                {
                    var emitter  = ModuleRegistry.DefaultRegistry.GetRegisteredModule(relationship.EmitterModuleName);
                    var consumer = ModuleRegistry.DefaultRegistry.GetRegisteredModule(relationship.ConsumingModuleName);

                    ModuleRegistry.DefaultRegistry.ConsumeData(emitter, consumer);
                }
                catch (Exception)
                {
                    FarsightLogger.DefaultLogger.LogWarning($"Failed to establish consumer relationship between {relationship.EmitterModuleName} and {relationship.ConsumingModuleName}");
                }
            }
        }