Пример #1
0
 /// <summary>Undo the command</summary>
 /// <param name="CommandHistory">The command history.</param>
 public void Undo(CommandHistory CommandHistory)
 {
     // OldNodePath can be null on the very first time the GUI is opened. We
     // don't want to select a null node.
     if (oldPath != null)
         explorerView.SelectedNode = oldPath;
 }
Пример #2
0
        /// <summary>
        /// Perform the command
        /// </summary>
        public void Do(CommandHistory CommandHistory)
        {
            IsRunning = true;

            if (!DuplicatesFound())
            {
                stopwatch.Start();

                if (modelClicked is Simulations)
                {
                    simulations.SimulationToRun = null;  // signal that we want to run all simulations.
                    numSimulationsToRun = Simulations.FindAllSimulationsToRun(simulations).Length;
                }
                else
                {
                    simulations.SimulationToRun = modelClicked;
                    numSimulationsToRun = Simulations.FindAllSimulationsToRun(modelClicked).Length;
                }

                if (explorerPresenter != null)
                    explorerPresenter.ShowMessage(modelClicked.Name + " running (" + numSimulationsToRun + ")", Models.DataStore.ErrorLevel.Information);

                if (numSimulationsToRun > 1)
                {
                    timer = new Timer();
                    timer.Interval = 1000;
                    timer.Tick += OnTimerTick;
                }
                jobManager.AddJob(simulations);
                jobManager.AllJobsCompleted += OnComplete;
                jobManager.Start(waitUntilFinished: false);
                if (numSimulationsToRun > 1)
                    timer.Start();
            }
        }
Пример #3
0
 /// <summary>Undo the command</summary>
 /// <param name="commandHistory">The command history instance</param>
 public void Undo(CommandHistory commandHistory)
 {
     if (this.modelWasRemoved)
     {
         this.parent.Children.Insert(pos, this.modelToDelete as Model);
         this.explorerView.AddChild(Apsim.FullPath(this.parent), nodeDescription, pos);
         Apsim.ClearCache(this.modelToDelete);
     }
 }
Пример #4
0
 public InputProcessor(CommandProcesser commandProcesser)
 {
     this.commandProcesser = commandProcesser;
     isActive = false;
     CommandHistory = new CommandHistory();
     Out = new List<OutputLine>();
     Buffer = new OutputLine("", OutputLineType.Command);
     EventInput.CharEntered += EventInput_CharEntered; //Handles the typable characters
     EventInput.KeyDown += EventInput_KeyDown; //Handles the non-typable characters
 }
Пример #5
0
        public InputProcessor(CommandProcesser commandProcesser)
        {
            this.commandProcesser = commandProcesser;
            isActive = false;
            CommandHistory = new CommandHistory();
            Out = new List<OutputLine>();
            Buffer = new OutputLine("", OutputLineType.Command);

            var inputManager = (IInputManager)Engine.Instance.Game.Services.GetService(typeof(IInputManager));
            inputManager.KeyDown += new InputManager.KeyEventHandler(OnKeyDown);
        }
Пример #6
0
 public InputProcessor(CommandProcesser commandProcesser, GameConsoleOptions options, Action toggleInGameDebugger)
 {
     m_commandProcesser = commandProcesser;
     m_options = options;
     m_toggleInGameDebugger = toggleInGameDebugger;
     m_isActive = false;
     CommandHistory = new CommandHistory();
     Out = new List<OutputLine>();
     Buffer = new OutputLine("", OutputLineType.Command);
     m_wrappedKeyEvent = EventHelper.Wrap<KeyArgs>(OnKeyDown);
     MainEngine.GetEngineInstance().CentralDispatch.Register(EventConstants.KeyDown, GetHandlerForEvent(EventConstants.KeyDown));
 }
Пример #7
0
        public InputProcessor(CommandProcesser commandProcesser, GameWindow window)
        {
            this.commandProcesser = commandProcesser;
            isActive = false;
            CommandHistory = new CommandHistory();
            Out = new List<OutputLine>();
            Buffer = new OutputLine("", OutputLineType.Command);

            Form winGameWindow = GetGameWindow();
            winGameWindow.KeyPress += form_KeyPress;
            winGameWindow.KeyDown += EventInput_KeyDown;
        }
Пример #8
0
        /// <summary>Performs the command.</summary>
        /// <param name="CommandHistory">The command history.</param>
        public void Do(CommandHistory CommandHistory)
        {
            string originalPath = Apsim.FullPath(modelToRename);

            // Get original value of property so that we can restore it in Undo if needed.
            originalName = modelToRename.Name;

            // Set the new name.
            this.modelToRename.Name = newName;
            Apsim.EnsureNameIsUnique(this.modelToRename);
            explorerView.Rename(originalPath, this.modelToRename.Name);
        }
Пример #9
0
 /// <summary>Undo the command</summary>
 /// <param name="CommandHistory">The command history.</param>
 public void Undo(CommandHistory CommandHistory)
 {
     if (modelWasMoved)
     {
         Model parent = modelToMove.Parent as Model;
         int modelIndex = parent.Children.IndexOf(modelToMove as Model);
         if (moveUp)
             MoveModelDown(CommandHistory, parent, modelIndex);
         else
             MoveModelUp(CommandHistory, parent, modelIndex);
     }
 }
Пример #10
0
        /// <summary>User has attempted to move the current node down.</summary>
        /// <param name="sender">The sender</param>
        /// <param name="e">The args</param>
        private void OnMoveDown(object sender, EventArgs e)
        {
            Model model = Apsim.Get(this.ApsimXFile, this.view.SelectedNode) as Model;

            if (model != null && model.Parent != null)
            {
                IModel lastModel = model.Parent.Children[model.Parent.Children.Count - 1];
                if (model != lastModel)
                {
                    CommandHistory.Add(new Commands.MoveModelUpDownCommand(model, false, this.view));
                }
            }
        }
Пример #11
0
        internal ConsoleInputProcessor(ConsoleOptions consoleOptions)
        {
            _options = consoleOptions;

            ScriptParser = new LuaParser();
            ScriptParser.Initialize();

            History = new CommandHistory();
            Out = new List<OutputLine>();
            Buffer = new InputBuffer();

            Engine.Input.Keyboard.KeyClicked += EventInput_KeyClicked;
        }
Пример #12
0
        /// <summary>Perform the command</summary>
        /// <param name="commandHistory">The command history.</param>
        public void Do(CommandHistory commandHistory)
        {
            int suppNo = SupplementLibrary.DefaultSuppConsts.IndexOf(this.supplementName);

            if (suppNo >= 0)
            {
                this.supplementToAdd = SupplementLibrary.DefaultSuppConsts[suppNo];
                this.prevSuppIdx     = this.parent.CurIndex;
                this.parent.CurIndex = this.parent.Add(this.supplementName);
                this.supplementAdded = true;
                commandHistory.InvokeModelChanged(this.parent);
            }
        }
Пример #13
0
        /// <summary>Undo the command.</summary>
        public void Undo(CommandHistory commandHistory)
        {
            if (modelMoved)
            {
                presenter.Move(this.fromModel.FullPath, fromParent, nodeDescription);
                Structure.Move(fromModel, fromParent);
                fromModel.Name       = originalName;
                nodeDescription.Name = originalName;

                commandHistory.InvokeModelStructureChanged(fromParent);
                commandHistory.InvokeModelStructureChanged(toParent);
            }
        }
Пример #14
0
        /// <summary>User has attempted to move the current node up.</summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">Event arguments</param>
        private void OnMoveUp(object sender, EventArgs e)
        {
            Model model = Apsim.Get(this.ApsimXFile, this.view.SelectedNode) as Model;

            if (model != null && model.Parent != null)
            {
                IModel firstModel = model.Parent.Children[0];
                if (model != firstModel)
                {
                    CommandHistory.Add(new Commands.MoveModelUpDownCommand(model, true, this.view));
                }
            }
        }
Пример #15
0
        /// <summary>
        /// Perform the command
        /// </summary>
        public void Do(CommandHistory CommandHistory)
        {
            Simulation clonedSimulation = null;

            try
            {
                List <Simulation> sims = new List <Models.Core.Simulation>();
                clonedSimulation = Apsim.Clone(simulation) as Simulation;
                sims.Add(clonedSimulation);
                Simulations.MakeSubstitutions(explorerPresenter.ApsimXFile, sims);

                clonedSimulation.ConnectLinksAndEvents();

                List <ModelDoc> models = new List <ModelDoc>();
                foreach (IModel model in Apsim.ChildrenRecursively(clonedSimulation))
                {
                    ModelDoc newModelDoc = DocumentModel(model);
                    newModelDoc.Name = Apsim.FullPath(model);
                    models.Add(newModelDoc);
                }

                StringWriter  rawXML     = new StringWriter();
                XmlSerializer serialiser = new XmlSerializer(typeof(List <ModelDoc>));
                serialiser.Serialize(rawXML, models);
                rawXML.Close();

                // Load the XSL transform from the resource
                Stream s         = Assembly.GetExecutingAssembly().GetManifestResourceStream("ApsimNG.Resources.DebugDoc.xsl");
                var    transform = new XslCompiledTransform();
                using (XmlReader reader = XmlReader.Create(s))
                {
                    transform.Load(reader);
                }

                // Apply the transform to the reader and write it to a temporary file.
                string htmlFileName = Path.GetTempFileName() + ".html";
                using (XmlReader reader = XmlReader.Create(new StringReader(rawXML.ToString())))
                    using (XmlWriter htmlWriter = XmlWriter.Create(htmlFileName))
                    {
                        transform.Transform(reader, htmlWriter);
                    }
                Process.Start(htmlFileName);
            }
            finally
            {
                if (clonedSimulation != null)
                {
                    clonedSimulation.DisconnectLinksAndEvents();
                }
            }
        }
Пример #16
0
        /// <summary>Perform the command</summary>
        public void Do(CommandHistory commandHistory)
        {
            IsRunning = true;
            jobRunner.Run();

            if (IsRunning)
            {
                timer           = new Timer();
                timer.Interval  = 1000;
                timer.AutoReset = true;
                timer.Elapsed  += OnTimerTick;
                timer.Start();
            }
        }
Пример #17
0
        public void MoveUpDown()
        {
            CommandHistory commandHistory = new CommandHistory();
            Model          modelToMove    = Apsim.Get(simulations, "APS14.Factors.Permutation.NRate") as Model;

            MoveModelUpDownCommand moveCommand = new MoveModelUpDownCommand(modelToMove, true, null);

            moveCommand.Do(commandHistory);

            Model modelToMove2 = Apsim.Get(simulations, "APS14.Factors.NRate") as Model;

            Assert.AreEqual(simulations.Children[2].Children[0].Children[0].Children[0].Name, "NRate");
            Assert.AreEqual(simulations.Children[2].Children[0].Children[0].Children[0].Children.Count, 4);
        }
Пример #18
0
        /// <summary>Perform the command</summary>
        public void Do(CommandHistory CommandHistory)
        {
            IsRunning = true;

            stopwatch.Start();

            jobRunner.Run(jobManager, wait: false);

            timer           = new Timer();
            timer.Interval  = 1000;
            timer.AutoReset = true;
            timer.Elapsed  += OnTimerTick;
            timer.Start();
        }
Пример #19
0
        /// <summary>
        /// Perform the command
        /// </summary>
        public void Do(CommandHistory commandHistory)
        {
            string bibFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "APSIM.bib");

            bibTeX    = new BibTeX(bibFile);
            citations = new List <BibTeX.Citation>();

            // Get the model we are to export.
            string modelName = Path.GetFileNameWithoutExtension(explorerPresenter.ApsimXFile.FileName.Replace("Validation", string.Empty));

            modelName = modelName.Replace("validation", string.Empty);
            DoExportPDF(modelName);
            citations.Clear();
        }
Пример #20
0
 /// <summary>Undo the command</summary>
 /// <param name="CommandHistory">The command history.</param>
 public void Undo(CommandHistory commandHistory)
 {
     if (supplementsReset)
     {
         for (int i = 0; i < this.prevList.Count; i++)
         {
             suppList[i].Assign(prevList[i]);
         }
     }
     if (this.parent.CurIndex > 0)
     {
         commandHistory.InvokeModelChanged(this.parent[this.parent.CurIndex]);
     }
 }
Пример #21
0
        /// <summary>Perform the command</summary>
        public void Do(CommandHistory CommandHistory)
        {
            IsRunning = true;

            stopwatch.Start();

            jobManager.AddJob(job);
            jobManager.Start(waitUntilFinished: false);

            timer = new Timer();
            timer.Interval = 1000;
            timer.AutoReset = true;
            timer.Elapsed += OnTimerTick;
            timer.Start();
        }
Пример #22
0
        /// <summary>Perform the command</summary>
        public void Do(CommandHistory CommandHistory)
        {
            IsRunning = true;

            stopwatch.Start();

            jobs.ForEach(job => jobManager.AddJob(job));
            jobManager.Start(waitUntilFinished: false);

            timer           = new Timer();
            timer.Interval  = 1000;
            timer.AutoReset = true;
            timer.Elapsed  += OnTimerTick;
            timer.Start();
        }
Пример #23
0
        /// <summary>
        /// Undo the command
        /// </summary>
        public void Undo(CommandHistory CommandHistory)
        {
            if (ModelMoved)
            {
                Model FromParent = FromModel.Parent as Model;

                ToParent.Children.Remove(FromModel);
                FromModel.Name = OriginalName;
                FromParent.Children.Add(FromModel);
                FromModel.Parent = FromParent;

                CommandHistory.InvokeModelStructureChanged(FromParent);
                CommandHistory.InvokeModelStructureChanged(ToParent);
            }
        }
Пример #24
0
        protected virtual void AddCommandHistory(DbCommand command)
        {
            string commandText = command.CommandText;

            foreach (DbParameter p in command.Parameters)
            {
                commandText = commandText.Replace('@' + p.ParameterName, string.Format("'{0}'", p.Value?.ToString() ?? ""));
            }

#if DEBUG
            System.Diagnostics.Debug.Print("SQL Command Len: " + commandText.Length.ToString("N0"));
#endif

            CommandHistory.Add(commandText);
        }
Пример #25
0
        public void MoveUpDown()
        {
            var            tree           = new MockTreeView();
            CommandHistory commandHistory = new CommandHistory(tree);
            Model          modelToMove    = simulations.FindByPath("APS14.Factors.Permutation.NRate")?.Value as Model;

            MoveModelUpDownCommand moveCommand = new MoveModelUpDownCommand(modelToMove, true);

            moveCommand.Do(tree, _ => {});

            Model modelToMove2 = simulations.FindByPath("APS14.Factors.NRate")?.Value as Model;

            Assert.AreEqual(simulations.Children[2].Children[0].Children[0].Children[0].Name, "NRate");
            Assert.AreEqual(simulations.Children[2].Children[0].Children[0].Children[0].Children.Count, 4);
        }
Пример #26
0
        public ApplicationBridge(MenuStrip menuStrip, ToolStripContainer toolStripContainer, MapPanel mapPanel, MapTreeView mapTreeView) : base(false)
        {
            m_commandHistory = CommandHistory.Instance;

            m_menuStripBridge = new MenuStripBridge(menuStrip);

            m_toolStripContainer = toolStripContainer;
            m_toolBars           = new List <ToolBarBridge>();
            PopulateToolBars(toolStripContainer.TopToolStripPanel, mapPanel);
            PopulateToolBars(toolStripContainer.BottomToolStripPanel, mapPanel);
            PopulateToolBars(toolStripContainer.LeftToolStripPanel, mapPanel);
            PopulateToolBars(toolStripContainer.RightToolStripPanel, mapPanel);

            m_editorBridge = new EditorBridge(mapPanel, mapTreeView);
        }
Пример #27
0
        /// <summary>
        /// Undo the command
        /// </summary>
        public void Undo(CommandHistory CommandHistory)
        {
            if (ModelMoved)
            {
                Model FromParent = FromModel.Parent as Model;

                ToParent.Children.Remove(FromModel);
                FromModel.Name = OriginalName;
                FromParent.Children.Add(FromModel);
                FromModel.Parent = FromParent;

                CommandHistory.InvokeModelStructureChanged(FromParent);
                CommandHistory.InvokeModelStructureChanged(ToParent);
            }
        }
Пример #28
0
        /// <summary>
        /// Perform the command
        /// </summary>
        public void Do(CommandHistory commandHistory)
        {
            // Get a list of tags for each type.
            var tags = new List <AutoDocumentation.ITag>();

            for (int i = 0; i < typesToDocument.Count; i++)
            {
                tags.AddRange(DocumentType(typesToDocument[i]));
            }

            // Convert the list of models into a list of tags.
            var pdfWriter = new PDFWriter(explorerPresenter, portraitOrientation: false);

            pdfWriter.CreatePDF(tags, FileNameWritten);
        }
Пример #29
0
        public void AddCommandHistory(IUser user, string command, bool state)
        {
            var User = userRepository.GetUser(user.ToString());

            CommandHistory commandHistory = new CommandHistory();

            commandHistory.CommandName = command;
            commandHistory.UserId      = User.Id;
            commandHistory.TimeStamp   = DateTime.Now;
            commandHistory.Success     = state;

            commandsRepository.Insert(commandHistory);

            Log.Information($"{user.ToString()} called !{command}");
        }
Пример #30
0
        public async void CommandSuccessTests()
        {
            var history = new CommandHistory("ChangeDeviceState");
            var command = new DeserializableCommand(history, "LockToken");

            //null pararameters
            history.Parameters             = new ExpandoObject();
            history.Parameters.DeviceState = "newState";
            _coolerDevice.SetupAllProperties();
            _coolerDevice.Object.DeviceProperties = new DeviceProperties();

            var r = await _changeDeviceStateCommandProcessor.HandleCommandAsync(command);

            Assert.Equal(r, CommandProcessingResult.Success);
        }
Пример #31
0
        /// <summary>
        /// Perform the command
        /// </summary>
        public void Do(CommandHistory CommandHistory)
        {
            Simulation clonedSimulation = null;
            try
            {
                List<Simulation> sims = new List<Models.Core.Simulation>();
                clonedSimulation = Apsim.Clone(simulation) as Simulation;
                sims.Add(clonedSimulation);
                Simulations.MakeSubstitutions(explorerPresenter.ApsimXFile, sims);

                clonedSimulation.ConnectLinksAndEvents();

                List<ModelDoc> models = new List<ModelDoc>();
                foreach (IModel model in Apsim.ChildrenRecursively(clonedSimulation))
                {
                    ModelDoc newModelDoc = DocumentModel(model);
                    newModelDoc.Name = Apsim.FullPath(model);
                    models.Add(newModelDoc);
                }

                StringWriter rawXML = new StringWriter();
                XmlSerializer serialiser = new XmlSerializer(typeof(List<ModelDoc>));
                serialiser.Serialize(rawXML, models);
                rawXML.Close();

                // Load the XSL transform from the resource
                Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("UserInterface.Resources.DebugDoc.xsl");
                var transform = new XslCompiledTransform();
                using (XmlReader reader = XmlReader.Create(s))
                {
                    transform.Load(reader);
                }

                // Apply the transform to the reader and write it to a temporary file.
                string htmlFileName = Path.GetTempFileName() + ".html";
                using (XmlReader reader = XmlReader.Create(new StringReader(rawXML.ToString())))
                using (XmlWriter htmlWriter = XmlWriter.Create(htmlFileName))
                {
                    transform.Transform(reader, htmlWriter);
                }
                Process.Start(htmlFileName);
            }
            finally
            {
                if (clonedSimulation != null)
                    clonedSimulation.DisconnectLinksAndEvents();
            }
        }
Пример #32
0
 /// <summary>
 /// Changes the state of the undo and redo buttons to be enabled or not.
 /// </summary>
 private void ChangeStateOfUndoRedoButtons()
 {
     foreach (CommandHistory.StackTypes stackType in Enum.GetValues(typeof(CommandHistory.StackTypes)))
     {
         string stackButtonName = $"btn{ConvertWordToTitleCase(stackType.ToString())}";
         Button stackButton     = FormHelper.FindControlByName <Button, Panel>(stackButtonName, titleBar);
         if (CommandHistory.PeekInStack(stackType) == null)
         {
             stackButton.Enabled = false;
         }
         else
         {
             stackButton.Enabled = true;
         }
     }
 }
Пример #33
0
        /// <summary>
        /// Undo the command
        /// </summary>
        public void Undo(CommandHistory CommandHistory)
        {
            if (ModelMoved)
            {
                ToParent.Children.Remove(FromModel);
                this.explorerView.Tree.Delete(Apsim.FullPath(this.FromModel));
                FromModel.Name       = OriginalName;
                nodeDescription.Name = OriginalName;
                FromParent.Children.Add(FromModel);
                FromModel.Parent = FromParent;
                this.explorerView.Tree.AddChild(Apsim.FullPath(FromParent), nodeDescription);

                CommandHistory.InvokeModelStructureChanged(FromParent);
                CommandHistory.InvokeModelStructureChanged(ToParent);
            }
        }
Пример #34
0
        public void Moves_to_last_command_when_new_command_entered_regardless_prior_position_in_history()
        {
            var history = new CommandHistory();

            history.EnterCommand("command1");
            history.EnterCommand("command2");
            history.EnterCommand("command3");

            history.GetOlder();
            history.GetOlder();

            history.EnterCommand("command4");

            history.GetOlder().Should().Be("command4");
            history.GetOlder().Should().Be("command3");
        }
Пример #35
0
        public void Doesnt_duplicate_last_command()
        {
            var history = new CommandHistory();

            history.EnterCommand("command1");
            history.EnterCommand("command2");
            history.EnterCommand("command1");

            history.GetOlder();
            history.GetOlder();
            history.EnterCommand(history.GetOlder());

            history.GetOlder().Should().Be("command1");
            history.GetOlder().Should().Be("command2");
            history.GetOlder().Should().Be("command1");
        }
Пример #36
0
 /// <summary>Undo the command</summary>
 /// <param name="CommandHistory">The command history.</param>
 public void Undo(CommandHistory CommandHistory)
 {
     if (modelWasMoved)
     {
         Model parent     = modelToMove.Parent as Model;
         int   modelIndex = parent.Children.IndexOf(modelToMove as Model);
         if (moveUp)
         {
             MoveModelDown(CommandHistory, parent, modelIndex);
         }
         else
         {
             MoveModelUp(CommandHistory, parent, modelIndex);
         }
     }
 }
Пример #37
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Shell"/> class.
        /// </summary>
        public Shell()
        {
            CommandBindings.Add(new CommandBinding(ShellCommands.Clear, HandleClearCommand));
            CommandBindings.Add(new CommandBinding(ShellCommands.Execute, HandleExecuteCommand));
            CommandBindings.Add(new CommandBinding(ShellCommands.CommandHistoryUp, HandleHistoryUpCommand));
            CommandBindings.Add(new CommandBinding(ShellCommands.CommandHistoryDown, HandleHistoryDownCommand));

            OutputDocument = new FlowDocument(_outputParagraph = new Paragraph());
            History = new CommandHistory();
            OutputFormatter = new ShellOutputFormatter {DelayNewlines = true};

            _writer = new CallbackScriptOutputWriter(
                OutputWriter_OutputWritten,
                OutputWriter_Clear
                );
        }
Пример #38
0
        /// <summary>
        /// Handles the "preview key down" event for the command line edit control.
        /// </summary>
        /// <param name="sender">The object that triggered this event.</param>
        /// <param name="e">Arguments associated with this event.</param>
        private void txtCommand_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            // If shell input is not being redirected, handle special keys in the UI.
            if (!UIManager.DefaultShellSession.UiRedirectionActive)
            {
                switch (e.Key)
                {
                // If the Enter key was pressed, attempt to parse and execute the command specified in the command line edit control.
                case Key.Enter:
                    var command = txtCommand.Text;
                    CommandHistory.Add(command);
                    UIManager.DefaultShellSession.ProcessCommand(command);
                    UIManager.PresentCommandPrompt();
                    e.Handled = true;
                    break;

                // If the Esc key was pressed, discard the contents of the command line edit control and wait for a new command.
                case Key.Escape:
                    UIManager.PresentCommandPrompt();
                    e.Handled = true;
                    break;

                // If the Up arrow was pressed, replace the contents of the command line edit control with the previous entry in the command history.
                case Key.Up:
                    ShowCommandFromHistory(-1);
                    e.Handled = true;
                    break;

                // If the Down arrow was pressed, replace the contents of the command line edit control with the next entry in the command history.
                case Key.Down:
                    ShowCommandFromHistory(1);
                    e.Handled = true;
                    break;
                }
            }
            else
            {
                // Else forward the key to the associated standard output stream.
                var kc    = new KeyConverter();
                var chars = GetKeyString(e.Key, e.KeyboardDevice.Modifiers);
                if (chars.Length > 0)
                {
                    UIManager.DefaultShellSession.UiTargetStandardIOStream.Write(chars[0]);
                }
                e.Handled = true;
            }
        }
Пример #39
0
 void LabelEditor_AfterLabelEdit(object sender, VVVV.Core.Viewer.LabelEditEventArgs args)
 {
     if (args.Model.Equals(Renameable))
     {
         var label = args.Label;
         if (Renameable.CanRenameTo(label))
         {
             var command = Command.Rename(Renameable, label);
             CommandHistory.Insert(command);
             LabelEditor.AfterLabelEdit -= LabelEditor_AfterLabelEdit;
         }
         else
         {
             args.CancelEdit = true;
         }
     }
 }
Пример #40
0
        public void Push_and_PrevNext_Test()
        {
            var commandHistory = new CommandHistory();

            commandHistory.Push("foo -a");
            commandHistory.Push("foo -b");
            commandHistory.Push("bar");

            commandHistory.TryGetPrevious(out var c1).Is(true);
            c1.Is("bar");
            commandHistory.TryGetPrevious(out var c2).Is(true);
            c2.Is("foo -b");
            commandHistory.TryGetNext(out var c3).Is(true);
            c3.Is("bar");
            commandHistory.TryGetNext(out var _).Is(false);

            commandHistory.TryGetPrevious(out var c4).Is(true);
            c4.Is("foo -b");
            commandHistory.TryGetPrevious(out var c5).Is(true);
            c5.Is("foo -a");
            commandHistory.TryGetPrevious(out var _).Is(false);

            commandHistory.Push("foo -a");

            commandHistory.TryGetPrevious(out var c6).Is(true);
            c6.Is("foo -a");
            commandHistory.TryGetPrevious(out var _).Is(false);
            commandHistory.TryGetNext(out var c7).Is(true);
            c7.Is("foo -b");

            commandHistory.Push("foo -b");

            commandHistory.TryGetNext(out var c8).Is(true);
            c8.Is("bar");
            commandHistory.TryGetPrevious(out var c9).Is(true);
            c9.Is("foo -b");

            commandHistory.Push("fizz");

            commandHistory.TryGetPrevious(out var c10).Is(true);
            c10.Is("fizz");
            commandHistory.TryGetPrevious(out var c11).Is(true);
            c11.Is("bar");
            commandHistory.TryGetPrevious(out var c12).Is(true);
            c12.Is("foo -b");
        }
Пример #41
0
            public override void Click()
            {
                var dialog = new ReferenceDialog();

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var command = new CompoundCommand();
                    foreach (var reference in dialog.References)
                    {
                        if (!FReferences.Contains(reference))
                        {
                            command.Append(Command.Add(FReferences, reference));
                        }
                    }
                    CommandHistory.Insert(command);
                }
            }
        public DeserializableCommand(Client.Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            Debug.Assert(
                !string.IsNullOrEmpty(message.LockToken),
                "message.LockToken is a null reference or empty string.");
            _lockToken = message.LockToken;

            byte[] messageBytes = message.GetBytes(); // this needs to be saved if needed later, because it can only be read once from the original Message

            string jsonData = Encoding.UTF8.GetString(messageBytes);
            _commandHistory = JsonConvert.DeserializeObject<CommandHistory>(jsonData);
        }
Пример #43
0
        public void TestCommandHistory()
        {
            PositiveInt    x    = new PositiveInt();
            CommandHistory test = new CommandHistory();

            // test initial state
            Assert.IsTrue(!test.CanUndo);
            Assert.IsTrue(!test.CanRedo);
            Assert.IsTrue(!test.Dirty);

            // test adding command
            Command cmd = new IncCommand(x);

            test.Add(cmd);
            cmd.Do();
            Assert.IsTrue(x.Value == 1);
            Assert.IsTrue(test.CanUndo);
            Assert.IsTrue(!test.CanRedo);
            Assert.IsTrue(test.Dirty);

            test.Undo();
            Assert.IsTrue(x.Value == 0);
            Assert.IsTrue(!test.CanUndo);
            Assert.IsTrue(test.CanRedo);
            Assert.IsTrue(!test.Dirty);

            test.Redo();
            Assert.IsTrue(x.Value == 1);
            Assert.IsTrue(test.CanUndo);
            Assert.IsTrue(!test.CanRedo);
            Assert.IsTrue(test.Dirty);

            test.Dirty = false;
            Assert.IsTrue(!test.Dirty);

            cmd = new IncCommand(x);
            test.Add(cmd);
            cmd.Do();
            Assert.IsTrue(test.Dirty);
            test.Undo();
            Assert.IsTrue(!test.Dirty);

            test.Dirty = true;
            Assert.IsTrue(test.Dirty);
        }
Пример #44
0
 /// <summary>
 /// Updates the message displayed for each undo/redo button.
 /// </summary>
 private void UpdateUndoRedoToolTip()
 {
     foreach (CommandHistory.StackTypes stackType in Enum.GetValues(typeof(CommandHistory.StackTypes)))
     {
         string   stackTypeName       = ConvertWordToTitleCase(stackType.ToString());
         string   stackButtonName     = $"btn{stackTypeName}";
         Button   stackButton         = FormHelper.FindControlByName <Button, Panel>(stackButtonName, titleBar);
         ICommand commandAtTopOfStack = CommandHistory.PeekInStack(stackType);
         if (commandAtTopOfStack == null)
         {
             toolTip.SetToolTip(stackButton, $"Nothing to {stackTypeName}");
         }
         else
         {
             toolTip.SetToolTip(stackButton, $"{stackTypeName} {commandAtTopOfStack.CommandName}");
         }
     }
 }
Пример #45
0
        /// <summary>Perform the command</summary>
        /// <param name="CommandHistory">The command history.</param>
        public void Do(CommandHistory CommandHistory)
        {
            IModel parent = modelToMove.Parent as IModel;

            int modelIndex = parent.Children.IndexOf(modelToMove as Model);

            modelWasMoved = false;
            if (moveUp)
            {
                if (modelIndex != 0)
                    MoveModelUp(CommandHistory, parent, modelIndex);
            }
            else
            {
                if (modelIndex != parent.Children.Count - 1)
                    MoveModelDown(CommandHistory, parent, modelIndex);
            }
        }
Пример #46
0
        /// <summary>
        /// Perform the command
        /// </summary>
        public void Do(CommandHistory CommandHistory)
        {
            Model FromParent = FromModel.Parent as Model;

            // Remove old model.
            ModelMoved = FromParent.Children.Remove(FromModel);

            // Add model to new parent.
            if (ModelMoved)
            {
                // The AddModel method may rename the FromModel. Go get the original name in case of
                // Undo later.
                OriginalName = FromModel.Name;

                ToParent.Children.Add(FromModel);
                FromModel.Parent = ToParent;
                Apsim.EnsureNameIsUnique(FromModel);
                CommandHistory.InvokeModelStructureChanged(FromParent);
                CommandHistory.InvokeModelStructureChanged(ToParent);
            }
        }
Пример #47
0
        /// <summary>
        /// Perform the change.
        /// </summary>
        /// <param name="commandHistory">The parent command history object</param>
        public void Do(CommandHistory commandHistory)
        {
            // Maintain a list of objects that have been changed.
            List<object> objectsChanged = new List<object>();

            // Change all properties.
            foreach (Property property in this.properties)
            {
                if (property.Do())
                {
                    if (!objectsChanged.Contains(property.Obj))
                    {
                        objectsChanged.Add(property.Obj);
                    }
                }
            }

            // Loop through all changed objects and invoke a model changed event for each.
            foreach (object obj in objectsChanged)
            {
                commandHistory.InvokeModelChanged(obj);
            }
        }
Пример #48
0
        /// <summary>
        /// Perform the command
        /// </summary>
        public void Do(CommandHistory CommandHistory)
        {
            IsRunning = true;

            if (!DuplicatesFound())
            {
                stopwatch.Start();

                JobManager.IRunnable job = Runner.ForSimulations(simulations, modelClicked);

                jobManager.AddJob(job);
                jobManager.AllJobsCompleted += OnComplete;
                jobManager.Start(waitUntilFinished: false);

                showNumberRunning = true;

                timer = new Timer();
                timer.Interval = 1000;
                timer.AutoReset = true;
                timer.Elapsed += OnTimerTick;
                timer.Start();
            }
        }
Пример #49
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RichTextConsole"/> class.
        /// </summary>
        public RichTextConsole()
            : base()
        {
            //this.myHistory = new List<string>();
            _expansion = new TabExpansion();
            _cmdHistory = new CommandHistory();

            // add a do-nothing delegate so we don't have to test for it
            ProcessCommand += new CommandHandler(delegate(string cmd) { });

            DataObject.AddPastingHandler(this, OnDataObjectPasting);

            // Set the FontFamily from the settings by hand ... kinda weird, but it seems to work.
            FontFamily = new FontFamily(new Uri("pack://application:,,,/PoshConsole;component/poshconsole.xaml"), Properties.Settings.Default.FontFamily.Source + ",/FontLibrary;Component/#Bitstream Vera Sans Mono, Global Monospace");

            Properties.Colors.Default.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(ColorsPropertyChanged);
            Properties.Settings.Default.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(SettingsPropertyChanged);

            _popup = new PopupMenu(this);
            // Add the popup to the logical branch of the console so keystrokes can be
            // processed from the popup by the console for the tab-complete scenario.
            // E.G.: $Host.Pri[tab].  => "$Host.PrivateData." instead of swallowing the period.
            AddLogicalChild(_popup);
        }
Пример #50
0
        public Shell(string[] args)
        {
            _input = string.Empty;
            _history = new CommandHistory(10);
            KeyEventActionMap = new Dictionary<string, Action<ConsoleKeyInfo>>();
            CommandActionMap = new Dictionary<string, Action>();
            KeyEventActionMap.Add("default", OnEventDefault);
            KeyEventActionMap.Add("RightArrow", OnEventRightArrow);
            KeyEventActionMap.Add("LeftArrow", OnEventLeftArrow);
            KeyEventActionMap.Add("UpArrow", OnEventUpArrow);
            KeyEventActionMap.Add("DownArrow", OnEventDownArrow);
            KeyEventActionMap.Add("Enter", OnEventEnter);
            KeyEventActionMap.Add("Backspace", OnEventBackspace);

            CommandActionMap.Add("history", OnCommandHistory);
            CommandActionMap.Add("default", OnCommandDefault);
            CommandActionMap.Add("clear", OnCommandClear);
            CommandActionMap.Add("exit", OnCommandExit);
            CommandActionMap.Add("tata", OnCommandExit);
            CommandActionMap.Add("bye", OnCommandExit);
            CommandActionMap.Add("quit", OnCommandExit);

            // set flags
        }
Пример #51
0
 /// <summary>
 /// Undo the command
 /// </summary>
 public void Undo(CommandHistory CommandHistory)
 {
 }
Пример #52
0
        private static void Command()
        {
            CommandHistory commandHistory = new CommandHistory();
            bool interactiveMode = true;
            string input = string.Empty;

            Console.WriteLine("");

            while (interactiveMode)
            {
                Console.Write("cmd> ");
                input = Console.ReadLine();

                switch (input.ToLower())
                {
                    case "exit":
                        interactiveMode = false;
                        Console.WriteLine("cmd> Exiting cmd program... Thanks for playing!");
                        Console.WriteLine("");
                        Console.WriteLine("");
                        Console.WriteLine("");
                        break;

                    case "help":
                        Console.WriteLine("cmd> Commands:");
                        Console.WriteLine("cmd> exit   - exit the cmd program");
                        Console.WriteLine("cmd> help   - display this help text");
                        Console.WriteLine("cmd> type   - add type command with specified argument to the command history at the next prompt");
                        Console.WriteLine("cmd> delete - add delete command with specified argument to the command history at the next prompt");
                        Console.WriteLine("cmd> undo   - undo the last input from the command history");
                        Console.WriteLine("cmd> redo   - redo the last input from the command history");
                        break;

                    case "type":
                        Console.WriteLine("cmd> Enter character to type:");
                        Console.Write("cmd> ");

                        input = Console.ReadLine();
                        Console.WriteLine("cmd> Typing character [{0}]...", input.First<char>());
                        List<object> args1 = new List<object>();
                        args1.Add(input.First<char>());
                        commandHistory.AddItemToHistory(new Command() { Arguments = args1, CommandType = CommandType.TypeCharacter, UndoCommandType = CommandType.DeleteCharacter });
                        break;

                    case "delete":
                        Console.WriteLine("cmd> Enter character to delete:");
                        Console.Write("cmd> ");

                        input = Console.ReadLine();
                        Console.WriteLine("cmd> Deleting character [{0}]...", input.First<char>());
                        List<object> args2 = new List<object>();
                        args2.Add(input.First<char>());
                        commandHistory.AddItemToHistory(new Command() { Arguments = args2, CommandType = CommandType.DeleteCharacter, UndoCommandType = CommandType.TypeCharacter });
                        break;

                    case "undo":
                        Command undo = commandHistory.Undo();

                        if (undo != null)
                        {
                            Console.WriteLine("cmd> Undoing command [{0}] by executing command [{1}] with parameters [{2}]...", CommandTypeHelper.ToString(undo.CommandType), CommandTypeHelper.ToString(undo.UndoCommandType), string.Join(",", undo.Arguments.Select(a => a.ToString()).ToArray()));
                        }
                        else
                        {
                            Console.WriteLine("cmd> Nothing to undo...");
                        }
                        break;

                    case "redo":
                        Command redo = commandHistory.Redo();

                        if (redo != null)
                        {
                            Console.WriteLine("cmd> Redoing command [{0}] by executing command [{1}] with parameters [{2}]...", CommandTypeHelper.ToString(redo.CommandType), CommandTypeHelper.ToString(redo.UndoCommandType), string.Join(",", redo.Arguments.Select(a => a.ToString()).ToArray()));
                        }
                        else
                        {
                            Console.WriteLine("cmd> Nothing to redo...");
                        }
                        break;

                    default:
                        Console.Beep();
                        Console.WriteLine("cmd> Command not recognized...  Please try again.");
                        break;
                }
            }
        }
Пример #53
0
 /// <summary>Perform the command</summary>
 /// <param name="commandHistory">The command history instance</param>
 public void Do(CommandHistory commandHistory)
 {
     this.explorerView.Delete(Apsim.FullPath(this.modelToDelete));
     pos = this.parent.Children.IndexOf(this.modelToDelete as Model);
     modelWasRemoved = Apsim.Delete(this.modelToDelete as Model);
 }
Пример #54
0
		public void ForceFIFO()
		{
			int maxSize = 3;
			CommandHistory history = new CommandHistory(maxSize);

			// Add 3 commands
			TestCommand1 cmd1 = new TestCommand1();
			TestCommand2 cmd2 = new TestCommand2();
			TestCommand3 cmd3 = new TestCommand3();

			history.AddCommand(cmd1);
			history.AddCommand(cmd2);
			history.AddCommand(cmd3);
			Assert.AreEqual(3, history.NumCommands);

			// Force history to drop oldest item (FIFO)
			TestCommand4 cmd4 = new TestCommand4();
			history.AddCommand(cmd4);
			Assert.AreEqual(3, history.NumCommands);

			// Undo all commands
			history.Undo();
			Assert.AreEqual("Unexecuted TestCommand4", _message);
			history.Undo();
			Assert.AreEqual("Unexecuted TestCommand3", _message);
			history.Undo();
			Assert.AreEqual("Unexecuted TestCommand2", _message);

			// We've undone all the commands; test the boundary
			// by adding a new one
			TestCommand5 cmd5 = new TestCommand5();
			history.AddCommand(cmd5);
			Assert.AreEqual(1, history.NumCommands);
		}
Пример #55
0
		public void AddUndoRedo()
		{
			int maxSize = 10;
			CommandHistory history = new CommandHistory(maxSize);

			// Add 4 commands
			TestCommand1 cmd1 = new TestCommand1();
			TestCommand2 cmd2 = new TestCommand2();
			TestCommand3 cmd3 = new TestCommand3();
			TestCommand4 cmd4 = new TestCommand4();

			history.AddCommand(cmd1);
			history.AddCommand(cmd2);
			history.AddCommand(cmd3);
			history.AddCommand(cmd4);

			Assert.AreEqual(4, history.NumCommands);

			// Undo all commands we've added 
			history.Undo();
			Assert.AreEqual("Unexecuted TestCommand4", _message);
			history.Undo();
			Assert.AreEqual("Unexecuted TestCommand3", _message);
			history.Undo();
			Assert.AreEqual("Unexecuted TestCommand2", _message);
			history.Undo();
			Assert.AreEqual("Unexecuted TestCommand1", _message);

			// Try to undo two extra times, even though we should be at the beginning
			_message = String.Empty;
			history.Undo();
			Assert.AreEqual(String.Empty, _message);
			history.Undo();
			Assert.AreEqual(String.Empty, _message);

			// Redo all commands we've added
			history.Redo();
			Assert.AreEqual("Executed TestCommand1", _message);
			history.Redo();
			Assert.AreEqual("Executed TestCommand2", _message);
			history.Redo();
			Assert.AreEqual("Executed TestCommand3", _message);
			history.Redo();
			Assert.AreEqual("Executed TestCommand4", _message);

			// Try to redo two extra times, even though we should be at the end
			_message = String.Empty;
			history.Redo();
			Assert.AreEqual(String.Empty, _message);
			history.Redo();
			Assert.AreEqual(String.Empty, _message);

			// Add another command
			TestCommand5 cmd5 = new TestCommand5();
			history.AddCommand(cmd5);

			Assert.AreEqual(5, history.NumCommands);

			// Undo a couple times
			history.Undo();
			Assert.AreEqual("Unexecuted TestCommand5", _message);
			history.Undo();
			Assert.AreEqual("Unexecuted TestCommand4", _message);
			history.Undo();
			Assert.AreEqual("Unexecuted TestCommand3", _message);

			// Now add a new command
			TestCommand6 cmd6 = new TestCommand6();
			history.AddCommand(cmd6);

			Assert.AreEqual(3, history.NumCommands);
			
			// Try to redo again
			_message = String.Empty;
			history.Redo();
			Assert.AreEqual(String.Empty, _message);

			// Undo again
			history.Undo();
			Assert.AreEqual("Unexecuted TestCommand6", _message);
			history.Undo();
			Assert.AreEqual("Unexecuted TestCommand2", _message);
		}
Пример #56
0
        /// <summary>
        /// Perform the command
        /// </summary>
        public void Do(CommandHistory CommandHistory)
        {
            string bibFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "APSIM.bib");
            bibTeX = new BibTeX(bibFile);
            citations = new List<BibTeX.Citation>();

            // Get the model we are to export.
            string modelName = Path.GetFileNameWithoutExtension(ExplorerPresenter.ApsimXFile.FileName.Replace("Validation", ""));
            DoExportPDF(modelName);
        }
Пример #57
0
 /// <summary>Undoes the command.</summary>
 /// <param name="CommandHistory">The command history.</param>
 public void Undo(CommandHistory CommandHistory)
 {
     explorerView.Rename(Apsim.FullPath(modelToRename), originalName);
     modelToRename.Name = originalName;
 }
Пример #58
0
 /// <summary>Perform the command</summary>
 /// <param name="CommandHistory">The command history.</param>
 public void Do(CommandHistory CommandHistory)
 {
     explorerView.SelectedNode = newPath;
 }
Пример #59
0
 /// <summary>Moves the model down.</summary>
 /// <param name="CommandHistory">The command history.</param>
 /// <param name="parent">The parent.</param>
 /// <param name="modelIndex">Index of the model.</param>
 private void MoveModelDown(CommandHistory CommandHistory, IModel parent, int modelIndex)
 {
     explorerView.MoveDown(Apsim.FullPath(modelToMove));
     parent.Children.Remove(modelToMove as Model);
     parent.Children.Insert(modelIndex + 1, modelToMove as Model);
     modelWasMoved = true;
 }