Beispiel #1
0
            public override void Execute(object parameter)
            {
                ITrainer trainer = Control.Trainer;

                trainer.Operator.WaitForStateChanged();

                Control.Running = false;
                trainer.Reset();
                trainer.Initialise(trainer.Operator.Handler);                 // because we're manually resetting we have to initialise manually as well
                // TODO maybe find a nicer way to reset and reinitialise - maybe separate command?
            }
Beispiel #2
0
        /// <summary>
        /// The default item generation that will be called if no other title bar item is specified (i.e. <see cref="TitleBarFuncs"/> is empty).
        /// </summary>
        public virtual void InitialiseDefaultItems()
        {
            _log.Info("Creating default title bar items because no others have been specified.");

            AddSigmaFunction((app, window) =>
                             new TitleBarItem(Properties.Resources.ButtonEnvironment,
                                              Properties.Resources.MenuButtonLoad, (Action)(() =>
            {
                SigmaEnvironment sigma = window.Monitor.Sigma;
                ITrainer activeTrainer = sigma.RunningOperatorsByTrainer.Keys.FirstOrDefault();

                if (activeTrainer != null)
                {
                    OpenFileDialog fileDialog = new OpenFileDialog();
                    fileDialog.Title = "Open Network";
                    fileDialog.Multiselect = false;
                    fileDialog.Filter = "Sigma Network Files (*.sgnet)|*.sgnet";
                    fileDialog.InitialDirectory = new FileInfo(SigmaEnvironment.Globals.Get <string>("storage_path")).FullName;

                    if (fileDialog.ShowDialog() == true)
                    {
                        try
                        {
                            INetwork network = Serialisation.Read <INetwork>(Target.FileByPath(fileDialog.FileName), Serialisers.BinarySerialiser, false);

                            if (!Network.AreNetworkExternalsCompatible(network, activeTrainer.Network))
                            {
                                throw new InvalidOperationException($"Unable to switch to network \"{network.Name}\" with incompatible internals (from {fileDialog.FileName}).");
                            }

                            activeTrainer.Reset();

                            bool forceInitialisationBefore = activeTrainer.ForceInitialisation;
                            activeTrainer.ForceInitialisation = false;
                            activeTrainer.Network = network;
                            activeTrainer.Initialise(activeTrainer.Operator.Handler);

                            activeTrainer.ForceInitialisation = forceInitialisationBefore;

                            Task.Factory.StartNew(() => window.SnackbarMessageQueue.Enqueue(
                                                      $"Switched network \"{network.Name}\", reset training (now using \"{fileDialog.FileName}\")", "Got it", null));
                        }
                        catch (Exception e)
                        {
                            _log.Error($"Error while switching to network \"{fileDialog.FileName}\": {e.GetType()} ({e.Message})", e);
                        }
                    }
                }
                else
                {
                    _log.Warn($"Unable to load new network because no trainer is active.");
                }
            }),
                                              Properties.Resources.MenuButtonSave, new TitleBarItem("Extras", "Extra1", "Extra2", new TitleBarItem("More", "Extra 3"))));

#if DEBUG
            AddSigmaFunction((app, window) => new TitleBarItem(Properties.Resources.ButtonDebug,
                                                               "5 second indeterminate task",
                                                               (Action)(() =>
            {
                new Thread(() =>
                {
                    ITaskObserver task = null;
                    try
                    {
                        task = SigmaEnvironment.TaskManager.BeginTask(TaskType.Preprocess, "Indeterminate task");
                        Thread.Sleep(5000);
                    }
                    catch (Exception)
                    {
                        // ignore
                    }
                    finally
                    {
                        SigmaEnvironment.TaskManager.EndTask(task);
                    }
                }).Start();
            }), "Flood", (Action)(() =>
            {
                ILog log = LogManager.GetLogger(typeof(TitleBarFactory));
                new Thread(() =>
                {
                    for (int i = 1; i <= 1; i++)
                    {
                        log.Debug($"Flood {i}: debug");
                        log.Info($"Flood {i}: info");
                        log.Warn($"Flood {i}: warn");
                        log.Error($"Flood {i}: error");
                        log.Fatal($"Flood {i}: fatal");
                    }
                }).Start();
            }), "Print Hierarchy", (Action)(() =>
            {
                SigmaWindow root = window;
                while (!root.IsRoot)
                {
                    root = root.ParentWindow;
                }

                PrintWindow(root);
            })
                                                               ));
#endif

            AddSigmaFunction((app, window) => new TitleBarItem(Properties.Resources.ButtonSettings, new TitleBarItem(Properties.Resources.MenuButtonStyle, Properties.Resources.MenuButtonToggleDark,
                                                                                                                     (Action)(() => window.Monitor.ColourManager.Dark = !window.Monitor.ColourManager.Dark),
                                                                                                                     Properties.Resources.MenuButtonToggleAlternate, (Action)(() => window.Monitor.ColourManager.Alternate = !window.Monitor.ColourManager.Alternate) /*,
                                                                                                                                                                                                                                                                       * Properties.Resources.MenuButtonLanguage, (Action< Application, Window, TitleBarItem>) ((application, genericWindow, item) =>
                                                                                                                                                                                                                                                                       * {
                                                                                                                                                                                                                                                                       * WPFMonitor monitor = window.Monitor;
                                                                                                                                                                                                                                                                       * monitor.UiCultureInfo = CultureInfo.GetCultureInfo("de-DE");
                                                                                                                                                                                                                                                                       * monitor.Reload();
                                                                                                                                                                                                                                                                       * })*/)));

            AddSigmaFunction((app, window) =>
            {
                IUIFactory <UIElement> aboutFactory = (IUIFactory <UIElement>)Registry.TryGetValue(AboutFactoryIdentifier, () => new AboutFactory(window.DialogHost));
                object aboutContent = aboutFactory.CreateElement(app, window);

                TitleBarItem about = new TitleBarItem(Properties.Resources.ButtonHelp, new TitleBarItem(Properties.Resources.MenuButtonAbout, (Action)(async() =>
                {
                    window.DialogHost.IsOpen = false;
                    await DialogHost.Show(aboutContent, window.DialogHostIdentifier);
                })));

                return(about);
            });
        }