public HttpActionViewModel(ITranslationUpdater translationUpdater, ICurrentSettings <Conversion.Settings.Accounts> accountsProvider, ICurrentSettingsProvider currentSettingsProvider, ICommandLocator commandLocator, IDispatcher dispatcher, IGpoSettings gpoSettings) : base(translationUpdater, currentSettingsProvider, dispatcher) { _gpoSettings = gpoSettings; _httpAccounts = accountsProvider?.Settings.HttpAccounts; if (_httpAccounts != null) { HttpAccountsView = new ListCollectionView(_httpAccounts); HttpAccountsView.SortDescriptions.Add(new SortDescription(nameof(HttpAccount.AccountInfo), ListSortDirection.Ascending)); } AddAccountCommand = commandLocator.CreateMacroCommand() .AddCommand <HttpAccountAddCommand>() .AddCommand(new DelegateCommand(o => SelectNewAccountInView())) .Build(); EditAccountCommand = commandLocator.CreateMacroCommand() .AddCommand <HttpAccountEditCommand>() .AddCommand(new DelegateCommand(o => RefreshAccountsView())) .Build(); }
protected override IEnumerable <int> GetInterestingElementIds(IContainerElement element) { IMacroCommand c = element.InnerElement as IMacroCommand; yield return(c.Id); if (c.Condition != null) { yield return(c.Condition.ConditionalId); } IWaitConditionCommand wc = c as IWaitConditionCommand; if (wc != null && wc.AwaitedCondition != null) { yield return(wc.AwaitedCondition.ConditionalId); } IStartCommand sc = c as IStartCommand; if (sc != null) { yield return(sc.StartedElementId); } IStopCommand sc2 = c as IStopCommand; if (sc2 != null) { yield return(sc2.StoppedElementId); } }
public AddMacroCommandAction(IMacro macro, IMacroCommand command) { m_Macro = macro; m_MacroElement = macro.AddElement(command); m_Index = macro.GetElements().Count - 1; macro.RemoveElement(m_MacroElement.Id); }
private void addCommandButton_Click(object sender, EventArgs e) { IMacroCommand command = selectCommandComboBox.SelectedValue as IMacroCommand; if (command == null) { // Show error message return; } List <object> argumentValues = new List <object>(); foreach (CommandArgumentControl argControl in commandArgumentControls) { argumentValues.Add(argControl.ArgumentValue); } noInterpretOnTextChange = true; RichTextBox rtfBox = commandsEditorTextBox.TextBox; if ((rtfBox.Text.Length > 0) && (rtfBox.Text[rtfBox.Text.Length - 1] != '\n')) { commandsEditorTextBox.TextBox.AppendText("\n"); } commandsEditorTextBox.TextBox.AppendText(command.GetCode(argumentValues.ToArray()) + "\n"); interpretCurrentLine(-1); noInterpretOnTextChange = false; }
private void selectCommandComboBox_SelectedIndexChanged(object sender, EventArgs e) { IMacroCommand selectedCommand = selectCommandComboBox.SelectedValue as IMacroCommand; commandDescriptionTextBox.Text = ""; commandArgumentsPanel.Controls.Clear(); foreach (CommandArgumentControl argControl in commandArgumentControls) { argControl.ArgumentValueChanged -= CommandArgumentControl_ArgumentValueChanged; } commandArgumentControls.Clear(); addCommandButton.Enabled = (selectedCommand != null); if (selectedCommand != null) { commandDescriptionTextBox.Text = selectedCommand.Description; int i = 0; int argCount = selectedCommand.Arguments.Length; foreach (IMacroCommandArgument arg in selectedCommand.Arguments) { var argumentControl = new CommandArgumentControl(arg, i, (i == (argCount - 1))); argumentControl.ArgumentValueChanged += CommandArgumentControl_ArgumentValueChanged; commandArgumentControls.Add(argumentControl); i++; } } for (int i = commandArgumentControls.Count - 1; i >= 0; i--) { CommandArgumentControl control = commandArgumentControls[i]; commandArgumentsPanel.Controls.Add(control); control.Dock = DockStyle.Top; } }
protected override void Context() { base.Context(); _macroCommand = A.Fake <IMacroCommand>(); _macroCommand.Description = "_macroCommand"; _macroCommand.Visible = true; _subCommand1 = A.Fake <IMacroCommand>(); _subCommand1.Description = "_subCommand1"; _subCommand2 = A.Fake <ICommand>(); _subCommand2.Description = "_subCommand2"; _subCommand3 = A.Fake <ICommand>(); _subCommand3.Description = "_subCommand3"; _subCommand1.Visible = true; _subCommand2.Visible = false; _subCommand3.Visible = false; _subCommand11 = A.Fake <ICommand>(); _subCommand11.Description = "_subCommand11"; _subCommand11.Visible = false; _subCommand12 = A.Fake <IMacroCommand>(); _subCommand12.Description = "_subCommand12"; _subCommand12.Visible = true; _subCommand121 = A.Fake <ICommand>(); _subCommand121.Description = "_subCommand121"; _subCommand121.Visible = false; _subCommand122 = A.Fake <ICommand>(); _subCommand122.Description = "_subCommand122"; _subCommand122.Visible = true; _historyItem = A.Fake <IHistoryItem>(); A.CallTo(() => _historyItem.Command).Returns(_macroCommand); A.CallTo(() => _macroCommand.All()).Returns(new[] { _subCommand1, _subCommand2, _subCommand3 }); A.CallTo(() => _subCommand1.All()).Returns(new[] { _subCommand11, _subCommand12 }); A.CallTo(() => _subCommand12.All()).Returns(new[] { _subCommand121, _subCommand122 }); }
//1 2 3 4 // C1 C2 C31 C32 roll back to 1 protected override void Context() { _context = new MyContext(); _historyItems = new List <IHistoryItem>(); _command0 = new MyReversibleCommand { InternalId = "_command0" }; _command1 = new MyReversibleCommand { InternalId = "_command1" }; _command2 = new MyReversibleCommand { InternalId = "_command2" }; _command31 = new MyReversibleCommand { InternalId = "_command31" }; _command32 = new MyReversibleCommand { InternalId = "_command32" }; _inverseCommand32 = _command32.InverseCommand(_context); _inverseCommand31 = _command31.InverseCommand(_context); _inverseCommand2 = _command2.InverseCommand(_context); _exceptionManager = A.Fake <IExceptionManager>(); _eventPublisher = A.Fake <IEventPublisher>(); sut = new HistoryManager <MyContext>(_context, _eventPublisher, _exceptionManager, new HistoryItemFactory(), new RollBackCommandFactory(), _historyItems); sut.AddToHistory(_command0); sut.AddToHistory(_command1); sut.AddToHistory(_command2); _command3 = new MacroCommand <MyContext>(); _command3.Add(_command31); _command3.Add(_command32); sut.AddToHistory(_command3); }
public object DeserializeItem(XmlNode serializedItem) { if (serializedItem.LocalName != TAG_NAME) { return(null); } string commandCode = serializedItem.Attributes[ATTRIBUTE_CODE]?.Value; List <string> argumentKeys = new List <string>(); foreach (XmlNode childNode in serializedItem.ChildNodes) { if (childNode.LocalName == TAG_NAME_ARGUMENT) { string argumentKey = childNode.Attributes[ATTRIBUTE_ARGUMENT_KEY]?.Value; argumentKeys.Add(argumentKey); } } IMacroCommand command = MacroCommandRegister.Instance.GetCommand(commandCode); if (command == null) { return(null); } return(command.GetWithArgumentsByKeys(argumentKeys.ToArray())); }
protected override void ChangeElementDataInGrid(int elementID, int row) { IMacroCommand c = (IMacroCommand)m_Container.GetElements()[row].InnerElement; elementsGrid.Rows[row].Cells[0].Value = c.DisplayDescription(m_Project); elementsGrid.Rows[row].Cells[1].Value = c.Condition.DisplayDescription(m_Project); }
private CommandMetaData metaDataCommandFrom(IMacroCommand macroCommand) { var commandMetaData = new CommandMetaData { Discriminator = Constants.Serialization.MACRO_COMMAND }; macroCommand.All().Each(childCommand => commandMetaData.AddCommand(MapFrom(childCommand))); return(commandMetaData); }
/// <summary> /// Executes all commands stored after the BeginMacro call /// </summary> public void CommitMacro() { IMacroCommand tmp = CreatedMacro; CreatedMacro = null; if (tmp.Commands.Count > 0) { tmp.Execute(); } }
public void VisitMacro(IMacroCommandVisitor commandVisitor) { foreach (IMacroElement element in m_Elements) { IMacroCommand command = element != null ? element.InnerElement as IMacroCommand : null; if (command != null) { command.VisitMacroCommand(commandVisitor); } } }
public void AddCommand(IMacroCommand command) { lock (commands.SyncRoot) { int index = -1; if (command.CommandType == MacroCommandType.PrecedingActive) { index = FindLastActiveCommand(); } InsertCommand(index, command); } }
private CallbackResult PacketHandler(byte[] data, CallbackResult prevResult) { lock (syncRoot) { IMacroCommand cmd = PacketTranslator.Translate(data); if (cmd != null) { AddCommand(cmd); } } return(CallbackResult.Normal); }
public void Setup() { var commandLocator = Substitute.For <ICommandLocator>(); _navigateMainTabCommand = Substitute.For <IMacroCommand>(); commandLocator.GetMacroCommand().Returns(_navigateMainTabCommand); _navigateMainTabCommand.AddCommand <ICommand>().Returns(_navigateMainTabCommand); _eventAggregator = new EventAggregator(); _updateAssistant = Substitute.For <IUpdateAssistant>(); ViewModel = new MainShellViewModel(new DragAndDropEventHandler(Substitute.For <IFileConversionHandler>()), new TranslationUpdater(new TranslationFactory(), new ThreadManager()), new ApplicationNameProvider("Free"), new InteractionRequest(), new EventAggregator(), commandLocator, null, null, null, null, _updateAssistant, _eventAggregator); }
protected override void Context() { base.Context(); _historyItem = A.Fake <IHistoryItem>(); _macroCommand = A.Fake <IMacroCommand>(); _macroCommand.Visible = true; _subCommand1 = A.Fake <ICommand>(); _subCommand2 = A.Fake <ICommand>(); _subCommand3 = A.Fake <ICommand>(); _subCommand1.Visible = true; _subCommand2.Visible = false; _subCommand3.Visible = true; A.CallTo(() => _historyItem.Command).Returns(_macroCommand); A.CallTo(() => _macroCommand.All()).Returns(new[] { _subCommand1, _subCommand2, _subCommand3 }); }
protected override MacroElement ReadContainerElement(System.Xml.XmlReader reader) { IMacroCommand command = DataModule.TheMacroFactory.CreateMacroCommand(reader); if (command != null) { MacroElement element = new MacroElement(); element.InnerElement = command; return(element); } else { return(null); } }
private void CheckCondition(IMacroCommand command) { switch (command.Condition.ConditionType) { case MacroConditionType.ElementNotRunning: case MacroConditionType.ElementRunning: if (command.Condition.Conditional == null || Data.DataModule.ElementRepository.GetElement(command.Condition.Conditional.Id) == null) { AddError(m_ModelErrors, ModelError.ErrorSeverity.Error, StringResources.ConditionElementNotFound, command); } break; default: break; } }
public ReplaceMacroCommandAction(IMacro macro, int oldCommandId, IMacroCommand newCommand) { m_Macro = macro; m_OldElement = macro.GetElement(oldCommandId); IList <IMacroElement> elements = m_Macro.GetElements(); for (int i = 0; i < elements.Count; ++i) { if (elements[i] == m_OldElement) { m_Index = i; break; } } m_NewElement = macro.AddElement(newCommand); macro.RemoveElement(m_NewElement.Id); }
public IAsyncCommand BuildCommand(Action <Job> changeJobAction, IMacroCommand preSaveCommand = null) { if (_getJob == null || _callFinishInteraction == null || _getLatestConfirmedPath == null || _setLatestConfirmedPath == null) { throw new InvalidOperationException($"Call {nameof(ProceedWithChangedJobCommand)}.Init first!"); } return(new ProceedWithChangedJobCommand( _interactiveProfileChecker, _interactiveFileExistsChecker, _getJob, _callFinishInteraction, _getLatestConfirmedPath, _setLatestConfirmedPath, changeJobAction, preSaveCommand)); }
public HttpActionViewModel(ITranslationUpdater translationUpdater, ICurrentSettingsProvider currentSettingsProvider, ICommandLocator commandLocator) : base(translationUpdater, currentSettingsProvider) { if (currentSettingsProvider?.Settings != null) { _httpAccounts = currentSettingsProvider.Settings.ApplicationSettings.Accounts.HttpAccounts; HttpAccountsView = new ListCollectionView(_httpAccounts); HttpAccountsView.SortDescriptions.Add(new SortDescription(nameof(HttpAccount.AccountInfo), ListSortDirection.Ascending)); } AddAccountCommand = commandLocator.GetMacroCommand() .AddCommand <HttpAccountAddCommand>() .AddCommand(new DelegateCommand(o => SelectNewAccountInView())); EditAccountCommand = commandLocator.GetMacroCommand() .AddCommand <HttpAccountEditCommand>() .AddCommand(new DelegateCommand(o => RefreshAccountsView())); }
public MacroCommandRow(IMacroCommand macro) { if (macro == null) { throw new ArgumentNullException("macro"); } this.macro = macro; Editable = false; Enabled = true; Cell cell = new Cell(macro.ToString()); Cells.Add(cell); macro.CommandChanged += new EventHandler(macro_CommandChanged); }
public static String DisplayDescription(this IMacroCommand command, IProject project) { switch (command.CommandType) { case MacroCommandType.StartElement: return(String.Format(StringResources.StartCommand, GetElementDisplayName(((IStartCommand)command).StartedElement, project))); case MacroCommandType.StopElement: return(String.Format(StringResources.StopCommand, GetElementDisplayName(((IStopCommand)command).StoppedElement, project))); case MacroCommandType.WaitTime: return(String.Format(StringResources.WaitTimeCommand, ((IWaitTimeCommand)command).TimeInMillis.ToString(System.Globalization.CultureInfo.CurrentUICulture))); case MacroCommandType.WaitCondition: { IWaitConditionCommand wcc = (IWaitConditionCommand)command; switch (wcc.AwaitedCondition.ConditionType) { case MacroConditionType.ElementNotRunning: return(String.Format(StringResources.WaitElementNotRunningCommand, GetElementDisplayName(wcc.AwaitedCondition.Conditional, project))); case MacroConditionType.ElementRunning: return(String.Format(StringResources.WaitElementRunningCommand, GetElementDisplayName(wcc.AwaitedCondition.Conditional, project))); default: return(StringResources.NoCondition); } } case MacroCommandType.AddTag: return(String.Format(StringResources.AddTagCommand, GetTagName(((ITagCommand)command).TagId, project))); case MacroCommandType.RemoveTag: return(String.Format(StringResources.RemoveTagCommand, GetTagName(((ITagCommand)command).TagId, project))); case MacroCommandType.RemoveAllTags: return(StringResources.RemoveAllTagsCommand); default: return(String.Empty); } }
public ProceedWithChangedJobCommand( IInteractiveProfileChecker interactiveProfileChecker, IInteractiveFileExistsChecker interactiveFileExistsChecker, Func <Job> getJob, Action callFinishInteraction, Func <string> getLatestConfirmedPath, Action <string> setLatestConfirmedPath, Action <Job> changeJobAction, IMacroCommand preProcessingCommand = null) { _interactiveProfileChecker = interactiveProfileChecker; _interactiveFileExistsChecker = interactiveFileExistsChecker; _getJob = getJob; _changeJobAction = changeJobAction; _callFinishInteraction = callFinishInteraction; _getLatestConfirmedPath = getLatestConfirmedPath; _setLatestConfirmedPath = setLatestConfirmedPath; _preProcessingCommand = preProcessingCommand; }
public void InsertCommand(int index, IMacroCommand command) { lock (commands.SyncRoot) { if (index >= 0) { // Insert item commands.Insert(index++, command); if (pause > 0 && command.CommandType == MacroCommandType.Active) { IMacroCommand waitCmd = new WaitMacroCommand(pause); if (index >= 0) { commands.Insert(index, waitCmd); } else { commands.Add(waitCmd); } } } else { // Add item if (pendingPause && pause > 0) { IMacroCommand waitCmd = new WaitMacroCommand(pause); commands.Add(waitCmd); pendingPause = false; } commands.Add(command); if (command.CommandType == MacroCommandType.Active) { pendingPause = true; } } } }
public static string GetCode(this IMacroCommand command, IEnumerable <object> argumentValues) { StringBuilder code = new StringBuilder(); code.Append(command.Code); code.Append("("); string[] argKeys = command.GetArgumentKeys(argumentValues.ToArray()); int argCount = command.Arguments.Length; for (int i = 0; i < argCount; i++) { bool isString = (command.Arguments[i].KeyType == MacroArgumentKeyType.String); string argKey = string.Format("{1}{0}{1}", argKeys[i], isString ? "\"" : ""); code.Append(argKey); if (i < (argCount - 1)) { code.Append(", "); } } code.Append(")"); return(code.ToString()); }
public void Setup() { _versionHelper = Substitute.For <IVersionHelper>(); _navigateMainTabCommand = Substitute.For <IMacroCommand>(); var macroBuilder = Substitute.For <IMacroCommandBuilder>(); macroBuilder.AddCommand <ICommand>().Returns(macroBuilder); macroBuilder.Build().Returns(_navigateMainTabCommand); var commandLocator = Substitute.For <ICommandLocator>(); commandLocator.CreateMacroCommand().Returns(macroBuilder); _eventAggregator = new EventAggregator(); _updateAssistant = Substitute.For <IUpdateAssistant>(); _usageStatisticsProvider = Substitute.For <ICurrentSettings <UsageStatistics> >(); ViewModel = new MainShellViewModel(new DragAndDropEventHandler(Substitute.For <IFileConversionAssistant>()), new TranslationUpdater(new TranslationFactory(), new ThreadManager()), new ApplicationNameProvider("Free"), new InteractionRequest(), new EventAggregator(), commandLocator, null, null, null, _updateAssistant, _eventAggregator, Substitute.For <IStartupActionHandler>(), _usageStatisticsProvider, _versionHelper); }
public void InsertCommand(int index, IMacroCommand command) { lock (commands.SyncRoot) { if (index >= 0) { // Insert item commands.Insert(index++, command); if (pause > 0 && command.CommandType == MacroCommandType.Active) { IMacroCommand waitCmd = new WaitMacroCommand(pause); if (index >= 0) commands.Insert(index, waitCmd); else commands.Add(waitCmd); } } else { // Add item if (pendingPause && pause > 0) { IMacroCommand waitCmd = new WaitMacroCommand(pause); commands.Add(waitCmd); pendingPause = false; } commands.Add(command); if (command.CommandType == MacroCommandType.Active) pendingPause = true; } } }
public MacroCommandRow(IMacroCommand macro) { if (macro == null) throw new ArgumentNullException("macro"); this.macro = macro; Editable = false; Enabled = true; Cell cell = new Cell(macro.ToString()); Cells.Add(cell); macro.CommandChanged += new EventHandler(macro_CommandChanged); }
private void showPointForLine(int lineIndex, MacroCodeInterpreter interpreter) { RichTextBox rtfBox = commandsEditorTextBox.TextBox; if (interpreter.HasSyntaxError) { string tooltip = string.Format("Syntax error at position {0}.", interpreter.SyntaxErrorPosition); commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_SYNTAX_ERROR, tooltip); return; } if (interpreter.IsEmpty) { commandsEditorTextBox.RemovePoint(lineIndex); return; } if (!interpreter.IsComplete) { commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_INCOMPLETE, "Line incomplete."); return; } if (!interpreter.CommandExists) { commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_NOTEXISTS, "Command does not exist."); return; } IMacroCommand command = interpreter.GetCommand(); if (interpreter.ArgumentCountMismatch) { string tooltip = string.Format("Command should have {0} arguments.", command.Arguments.Length); commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_ARGUMENT_COUNT_MISMATCH, tooltip); return; } List <bool> argumentTypeMatches = new List <bool>(interpreter.ArgumentTypeMatches); if (!argumentTypeMatches.TrueForAll(atm => atm)) { string tooltip = ""; for (int i = 0; i < argumentTypeMatches.Count; i++) { if (!argumentTypeMatches[i]) { tooltip += string.Format("Argument #{0} should be a {1}.\n", i + 1, command.Arguments[i].KeyType.ToString().ToLower()); } } tooltip = tooltip.Substring(0, tooltip.Length - 1); commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_ARGUMENT_TYPE_MISMATCH, tooltip); return; } if (interpreter.IsComplete) { commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_OK, "OK."); return; } commandsEditorTextBox.SetPointColor(lineIndex, POINTCOLOR_UNKNOWN, "???"); }
public void VisitMacroCommand(IMacroCommand macroCommand) { }
public void VisitMacroCommand(IMacroCommand macroCommand) { macroCommand.VisitMacroCommand(this); }