protected override void OnKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { base.OnKeyPress(sender, e); if (e.KeyChar == ' ') { if (MyTextBox.CaretPosition == MyTextBox.Text.Length) { Block next = this.Next; if (next != null && next is SpaceBlock) { next.SetFocus(true); } } else if (MyTextBox.CaretPosition > 0) { string TextBeforeCaret = MyTextBox.TextBeforeCaret; string TextAfterCaret = MyTextBox.TextAfterCaret; using (ActionBuilder a = new ActionBuilder(this.Root)) { a.RenameItem(MyTextBox, TextBeforeCaret); a.AppendBlocks( this, new TokenSeparatorBlock(), new TokenBlock(TextAfterCaret) ); a.Run(); } } } }
public Task ExecuteAsync(IDictionary <string, string> arguments) { if (!arguments.TryGetValue(ActionParameters.ADDRESS, out string address) || string.IsNullOrWhiteSpace(address)) { return(Task.CompletedTask); } Uri uri = TryToBuildUri(address); if (uri == null) { return(Task.CompletedTask); } if (string.Equals(uri.Scheme, Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase)) { actionService.ExecuteAsync(ActionBuilder.PathUri(uri.LocalPath)); } else if (string.Equals(uri.Scheme, ActionConstants.ACTION_SCHEMA, StringComparison.OrdinalIgnoreCase)) { actionService.ExecuteAsync(uri.OriginalString); } else { return(UriOpenAction.ExecuteAsync(uri.OriginalString)); } return(Task.CompletedTask); }
public async Task Process_Should_NotCallGatewayToUpdateHeader_IfNoAuthTokenProvided() { // Arrange var action = new ActionBuilder() .WithActionType(EActionType.RetrieveExternalData) .WithPageActionSlug(new PageActionSlug { URL = "www.test.com", AuthToken = string.Empty, Environment = "local" }) .WithTargetQuestionId("targetId") .Build(); var actions = new List <IAction> { action }; // Act await _service.Process(actions, new FormSchema(), "test"); // Assert _mockGateway.Verify(_ => _.ChangeAuthenticationHeader(It.IsAny <string>()), Times.Never); }
public void ExecuteWhenAs_ChainingPreviousResults_ShouldReturnCorrectValue( ActionBuilder sut, IAction <object> action1, IAction <object> action2, IAction <string> action3, Mock <IFunc> funcs, object result1, object result2, string expected, IActor actor) { //arrange Mock.Get(actor).SetupExecuteWhen <object>(); Mock.Get(actor).SetupExecuteWhen <string>(); funcs.Setup(f => f.Func <ActionResult <IAction <object>, object>, IAction <object> >(It.Is <ActionResult <IAction <object>, object> >(r => r.Action == action1 && r.Result == result1))) .Returns(action2); funcs.Setup(f => f.Func <ActionResult <IAction <object>, object>, IAction <string> >(It.Is <ActionResult <IAction <object>, object> >(r => r.Action == action2 && r.Result == result2))) .Returns(action3); Mock.Get(action1).Setup(a => a.ExecuteWhenAs(actor)).Returns(result1); Mock.Get(action2).Setup(a => a.ExecuteWhenAs(actor)).Returns(result2); Mock.Get(action3).Setup(a => a.ExecuteWhenAs(actor)).Returns(expected); //act var action = sut.Then <IAction <object>, object>(action1) .Then <IAction <object>, object>(funcs.Object.Func <ActionResult <IAction <object>, object>, IAction <object> >) .Then <IAction <string>, string>(funcs.Object.Func <ActionResult <IAction <object>, object>, IAction <string> >); var actual = action.ExecuteWhenAs(actor); //assert actual.Should().Be(expected); }
private void ImportGroupAction(Core.Action.Models.ActionModel action, int parentID = 0) { //创建头 var builder = ActionBuilder.BuilderByAction(action); var actionModel = builder.GetActionItemModel(); var a = action.Parameter as BaseGroupActionParamsModel; var parameter = ObjectConvert.Get <BaseGroupActionParamsModel>(action.Parameter); actionModel.ParentID = parentID; AddItem(actionModel, builder); //创建action子级 if (parameter.Actions.Count > 0) { foreach (var item in parameter.Actions) { ImportAction(item, actionModel.ID); } } //创建end action var endActionModel = ActionData.GetCreateActionItemModel(UI.Types.ActionType.LoopsEnd); endActionModel.ID = GetCreateActionID(); endActionModel.ParentID = actionModel.ID; AddItem(endActionModel); }
private static IBlock BuildOptionInfo(Option option) { Section result = new Section( new Header(option.Documentation?.Title ?? option.GetMainRepresentation())); ISpanBuilder content = new SpanBuilder(); foreach (string representation in option.Representations) { using (content.StartStrongContext()) { string optionInput = representation.Length > 2 ? $"--{representation}" : $"-{representation}"; content.Link(optionInput, ActionBuilder.InputAddUri(optionInput)); } content.WriteLine(); } result = result.AddChild(new Paragraph(content.Span)); if (!string.IsNullOrEmpty(option.Documentation?.Description)) { result = result.AddChild(new Paragraph(option.Documentation.Description)); } if (option.Parameters.Count > 0) { result = result.AddChild(BuildParametersSection(option)); } return(result); }
private static void CreateCommandForSetupAction(CommandLineApplication app) { Log.Verbose("Start creating command [setup]."); app.Command("setup", (command) => { command.Description = "Performs the SETUP step which initializes the embedded database"; command.HelpOption("-?|-h|--help"); var overwriteOption = command.Option("-o|--overwrite <true/false>", "Overwrite an existing database.", CommandOptionType.SingleValue); command.OnExecute(() => { var overwrite = overwriteOption.HasValue() && Convert.ToBoolean(overwriteOption.Value()); ActionBuilder.Execute <ActionSetupDb>(new ActionSetupDbOptions() { Overwrite = overwrite }); return(0); }); }); Log.Verbose("Finished creating command [setup]."); }
public override void WriteToMarkdown(MarkdownBuilder builder, int intent) { builder.Bullet(intent); builder.Write("**"); builder.Link(Name, ActionBuilder.PathOpenUri(file.FilePath)); builder.Write("** *(file)*"); }
public void Then_ChainingPreviousResultsThenDiscardingResult_ShouldReturnCorrectName( ActionBuilder sut, IAction <object> action1, IAction <object> action2, IAction <string> action3, IAction <object> action4, string name1, string name4) { //arrange Mock.Get(action1).Setup(a => a.Name).Returns(name1); Mock.Get(action4).Setup(a => a.Name).Returns(name4); //act var action = sut.Then <IAction <object>, object>(action1) .Then <IAction <object>, object>(_ => action2) .Then <IAction <string>, string>(_ => action3) .Then <IAction <object>, object>(action4); var actual = action.Name; //assert var name2 = typeof(IAction <object>).Name; var name3 = typeof(IAction <object>).Name; var expected = $"{name1}, Then {name2}, Then {name3}, Then {name4}"; actual.Should().Be(expected); }
CheckRetrieveExternalDataAction_ShouldThrowException_WhenActionDoesNotContain_URL_or_TargetQuestionId(string url, string questionId, string env, string message) { // Arrange var action = new ActionBuilder() .WithActionType(EActionType.RetrieveExternalData) .WithPageActionSlug(new PageActionSlug { URL = url, Environment = env }) .WithTargetQuestionId(questionId) .Build(); var schema = new FormSchemaBuilder() .WithFormActions(action) .Build(); var check = new RetrieveExternalActionsCheck(_mockHostingEnv.Object); // Act & Assert var result = check.Validate(schema); Assert.False(result.IsValid); Assert.Contains(message, result.Messages); }
public Task BuildAsync(IEntityBuilder builder) { var endpointDescriptor = this._endpointDescriptorProvider.GetEndpointDescriptor(this._captureExpression, this._claimsPrincipal); if (endpointDescriptor == null) { return(Task.CompletedTask); } var method = endpointDescriptor.Method; var href = this._hrefFactory.MakeHref(endpointDescriptor); var fields = this._fieldsFactory.MakeFields(new ActionArgument(endpointDescriptor.BodyArgument.Descriptor, endpointDescriptor.BodyArgument.Value)); var action = new Actions.Action(this._name, href, method, fields); if (this._configureActionBuilder != null) { var actionBuilder = new ActionBuilder <TBody>(action); this._configureActionBuilder(actionBuilder); } builder.WithAction(action); return(Task.CompletedTask); }
public void ExecuteWhenAs_AfterCallingThenMultipleTimes_ShouldReturnCorrectValue( ActionBuilder sut, Mock <IAction <object> > nextAction1, Mock <IAction <object> > nextAction2, Mock <IAction <object> > nextAction3, IActor actor) { //arrange Mock.Get(actor).SetupExecuteWhen <object>(); var callResult = new List <string>(); nextAction1.Setup(a => a.ExecuteWhenAs(actor)).Callback <IActor>(a => callResult.Add("action1")); nextAction2.Setup(a => a.ExecuteWhenAs(actor)).Callback <IActor>(a => callResult.Add("action2")); nextAction3.Setup(a => a.ExecuteWhenAs(actor)).Callback <IActor>(a => callResult.Add("action3")); var action = sut.Then <IAction <object>, object>(nextAction1.Object) .Then <IAction <object>, object>(nextAction2.Object) .Then <IAction <object>, object>(nextAction3.Object); //act action.ExecuteWhenAs(actor); //assert var expected = new[] { "action1", "action2", "action3" }; callResult.ShouldAllBeEquivalentTo(expected, o => o.WithStrictOrdering()); }
public void ExecuteGivenAs_DiscardingResultsTwiceThenChainingPreviousResult_ShouldReturnCorrectValue( ActionBuilder sut, IAction <object> action1, IAction <object> action2, IAction <string> action3, Mock <IFunc> funcs, object result2, string expected, IActor actor) { //arrange Mock.Get(actor).SetupExecuteGiven <object>(); Mock.Get(actor).SetupExecuteGiven <string>(); funcs.Setup(f => f.Func <ActionResult <IAction <object>, object>, IAction <string> >(It.Is <ActionResult <IAction <object>, object> >(r => r.Action == action2 && r.Result == result2))) .Returns(action3); Mock.Get(action2).Setup(a => a.ExecuteGivenAs(actor)).Returns(result2); Mock.Get(action3).Setup(a => a.ExecuteGivenAs(actor)).Returns(expected); //act var action = sut.Then <IAction <object>, object>(action1) .Then <IAction <object>, object>(action2) .Then <IAction <string>, string>(funcs.Object.Func <ActionResult <IAction <object>, object>, IAction <string> >); var actual = action.ExecuteGivenAs(actor); //assert actual.Should().Be(expected); Mock.Get(action1).Verify(a => a.ExecuteGivenAs(actor), "First action has not been called"); Mock.Get(action2).Verify(a => a.ExecuteGivenAs(actor), "Second action has not been called"); }
private static string BuildOutput(CopyContext context) { MarkdownBuilder builder = new MarkdownBuilder(); builder.Header("Copy"); builder.Link(context.Destination, ActionBuilder.PathOpenUri(context.Destination)); bool empty = true; if (context.CopiedFiles.Count > 0) { builder.Header("Copied", 2); builder.WritePathList(context.CopiedFiles, context.Destination); empty = false; } if (context.OverwritenFiles.Count > 0) { builder.Header("Overwriten"); builder.WritePathList(context.OverwritenFiles, context.Destination); empty = false; } if (empty) { builder.WriteLine(); builder.WriteLine(); builder.Italic("Nothing copied."); } return(builder.ToString()); }
private static LinksModel BuildLinks(IEnumerable <string> paths, string relatedTo) { LinksModel result = new LinksModel(); foreach (string path in paths) { PathTypeEnum type = path.GetPathType(); switch (type) { case PathTypeEnum.Directory: result.Directories.Add(new Link(path.GetFriendlyPath(relatedTo), ActionBuilder.PathOpenUri(path))); break; case PathTypeEnum.File: result.Files.Add(new Link(path.GetFriendlyPath(relatedTo), ActionBuilder.PathOpenUri(path))); break; case PathTypeEnum.NonExistent: result.NonExists.Add(new Link(path.GetFriendlyPath(relatedTo), ActionBuilder.PathUri(path))); break; } } return(result); }
public override void WriteToMarkdown(MarkdownBuilder builder, int intent) { builder.Bullet(intent); builder.Write("*"); builder.Link(Name, ActionBuilder.PathOpenUri(project.FilePath)); builder.Write("* "); builder.Italic($"(project)"); }
private string ReplaceBranchName(Match match) { AnsiStringBuilder builder = new AnsiStringBuilder(); string helpCommand = $"git checkout {match.Value}"; builder.AppendLink(match.Value, ActionBuilder.InputSetUri(helpCommand)); return(builder.ToString()); }
public void Sut_VerifyGuardClause_ActionBuilder2(ActionBuilder <TestAction, Unit> sut) { var sutAsInterface = (IActionBuilder <TestAction, Unit>)sut; new Action(() => sutAsInterface.Then <IAction <Unit>, Unit>(default(IAction <Unit>))).Should().ThrowExactly <ArgumentNullException>("Then"); new Action(() => sutAsInterface.Named(string.Empty)).Should().ThrowExactly <ArgumentNullException>("string.Empty"); new Action(() => sutAsInterface.Named(null)).Should().ThrowExactly <ArgumentNullException>("null"); }
public ActionBuilderTest() { this.resultFactory = new Mock<IResultFactory>(); this.applicatorPipeline = new Mock<IDecoratorApplicatorPipeline>(); this.scopeDecoratorApplicator = new Mock<IScopeDecoratorApplicator>(); this.testee = new ActionBuilder(this.resultFactory.Object, this.applicatorPipeline.Object, this.scopeDecoratorApplicator.Object); }
private string ReplaceHelpCommand(Match match) { string help = match.Value.TrimEnd(); AnsiStringBuilder builder = new AnsiStringBuilder(); builder.AppendLink(help, ActionBuilder.InputSetUri(help)); return(builder.ToString()); }
public async Task AcaoIntent(IDialogContext context, LuisResult result) { var subscription = ObterSubscription(context); if (string.IsNullOrEmpty(subscription)) { return; } var applicationId = ObterApplicationId(context); if (string.IsNullOrEmpty(applicationId)) { return; } var secretKey = ObterSecretKey(context); if (string.IsNullOrEmpty(secretKey)) { return; } var activity = context.Activity; var stateClient = activity.GetStateClient(); var userData = stateClient.BotState.GetUserData(activity.ChannelId, activity.From.Id); ProcessadorResult processadorResult = null; if (result.Intents.Any(i => i.Intent.ToUpper() == "ACAO")) { if (result.Entities.Any(v => v.Type.ToUpper() == "LISTAR")) { processadorResult = await ProcessarListagem(result, userData); } if (result.Entities.Any(i => i.Type.ToUpper() == "OPERACOES" && i.Entity.ToUpper() != "CRIAR")) { processadorResult = await ProcessarAcao(result, userData); } if (result.Entities.Any(i => i.Type.ToUpper() == "OPERACOES" && i.Entity.ToUpper() == "CRIAR")) { var resourceGroups = await ActionBuilder.ListResourceGroups(subscription, applicationId, secretKey); var dialog = new PromptDialog.PromptChoice <string>(resourceGroups.Select(r => r.Name), "Em qual resource group deseja criar?", "Desculpa opção inválida", 3); context.Call(dialog, ResourceGroupPromptResultAsync); return; } } await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); await context.PostAsync(processadorResult?.Mensagem); context.Wait(MessageReceived); }
public Action GetActionTestScore() { Action MOTHER_ACTION = new ActionBuilder("Test IR") .Add(new ActionBuilder("Afficher score homol").BuildActionDelegate(() => Robot.robot.IHM.AfficherInformation("Score : 0", false))) .Add(new ActionBuilder("Start robot countdown").BuildActionDelegate(() => Robot.robot.StartCountdown())) .BuildActionEnSerie(); return(MOTHER_ACTION); }
public Action GetActionTestJack() { Action MOTHER_ACTION = new ActionBuilder("Test jack") .Add(new ActionJack()) .Add(new ActionBuilder("Deplacement bidon").BuildActionBaseRoulante_DRIVE(1000, 100)) .BuildActionEnSerie(); return(MOTHER_ACTION); }
public static Actions Add(this Actions self, Action <IActionBuilder> build) { var builder = new ActionBuilder(); build(builder); var action = builder.Build(); self.Add(action); return(self); }
public Action GetActionTestIR() { Action MOTHER_ACTION = new ActionBuilder("Test IR") .Add(new ActionBuilder("Regler vitese drive").BuildActionDelegate(() => Robot.robot.BASE_ROULANTE.speedDrive = 200)) .Add(new ActionBuilder("Activer IR").BuildActionSetDetecteurObstacle(true)) .Add(new ActionBuilder("Deplacement").BuildActionBaseRoulante_GOTO_ONLY(new PointOriente(1000, 0), OBSTACLE_DIRECTION.AVANT)) .BuildActionEnSerieRepeated(1); return(MOTHER_ACTION); }
public static async Task <IActionResult> AsActionResultAsync(this Task <OperationResult> operationTask, bool?internalFlag = null) { var actionBuilder = new ActionBuilder(operationTask); if (internalFlag.HasValue) { actionBuilder.WithInternalFlag(internalFlag.Value); } return(await new ActionBuilder(operationTask).ExecuteAsync()); }
public static IActionResult AsActionResult(this OperationResult operation, bool?internalFlag = null) { var actionBuilder = new ActionBuilder(operation); if (internalFlag.HasValue) { actionBuilder.WithInternalFlag(internalFlag.Value); } return(actionBuilder.Execute()); }
public ActionBuilderTest() { _fixture = new Fixture(); _schemaValidation = Substitute.For <IJsonSchemaValidationFactory>(); _jsonConvertibleFactory = Substitute.For <IJsonConvertibleFactory>(); _convertibleFactory = Substitute.For <IConvertibleFactory>(); _builder = new ActionBuilder(_schemaValidation, _jsonConvertibleFactory, _convertibleFactory); }
private string ReplaceHelpWithAction(Match match) { AnsiStringBuilder builder = new AnsiStringBuilder(); builder.Append("\""); string helpCommand = match.Groups["help"].Value; builder.AppendLink(helpCommand, ActionBuilder.InputSetUri(helpCommand)); builder.Append("\""); return(builder.ToString()); }
public Action TestRecallage() { Action MOTHER_ACTION = new ActionBuilder("Test recallage") .Add(new ActionBuilder("Afficher score homol").BuildActionBaseRoulante_DRIVE(500, 50)) .Add(new ActionDelegate("Reinit kangaroo", () => { Thread.Sleep(50); Robot.robot.SWITCH_GLOBAL.Activate(); Thread.Sleep(50); Robot.robot.SWITCH_GLOBAL.Desactivate(); Thread.Sleep(1500); })) .Add(new ActionBuilder("Afficher score homol").BuildActionBaseRoulante_DRIVE(-500, 50)) .Add(new ActionBuilder("Afficher score homol").BuildActionBaseRoulante_DRIVE(300, 50)) .BuildActionEnSerie(); return(MOTHER_ACTION); }
public Action GetActionTestTimerExtinctionPR() { Action MOTHER_ACTION = new ActionBuilder("Test timer switch global PR") .Add(new ActionDelegate("Rotate forever", () => Robot.robot.PR_SERVO_AIGUILLAGE.RotateForever(400))) .Add(new ActionWait("Wait a bit...", 5000)) .Add(new ActionDelegate("Switch off", () => Robot.robot.SWITCH_GLOBAL.Activate())) .Add(new ActionBuilder("Deplacement bidon").BuildActionBaseRoulante_DRIVE(1000, 100)) .BuildActionEnSerie(); return(MOTHER_ACTION); }
public static void TestPerf() { //这次测试中文1234 Stopwatch sw = new Stopwatch(); int MaxTimes = 100; TT t = new TT(); MethodInfo mi = t.GetType().GetMethod("Test"); MethodWrapper invoker = new MethodWrapper(t.GetType().GetCustomAttributes(false), true, () => { return new TT(); }, t, mi, mi.GetCustomAttributes(false)); ActionBuilder builder = new ActionBuilder(); builder.RegistType<TT>(); IAction action = builder.FindAction("TT.Test"); ActionContext context = new ActionContext() { Arguments = new object[] { "1", "2" }, oInstance = t }; Test(5, MaxTimes, (i, w) => { string s = string.Empty; switch (i) { case 0: s = "方法直接调用"; break; case 1: s = "动态代理方法调用"; break; case 2: s = "Zata封装方法调用"; break; case 3: s = "反射调用"; break; } Console.WriteLine("{0}: {1}毫秒",s, w.ElapsedMilliseconds); }, i => { t.Test("1", "2"); }, i => invoker.Execute(context), i => { action.Execute(context); }, i => mi.Invoke(t, new object[] { "1", "2"}) ); }