/// <summary> /// Run the application. /// </summary> public override BoolMessageItem Execute() { // 1. Macro service loads classes with attribute "MacroAttribute" and of type IMacro. var macros = new MacroService(); // 2. Register Option 1: Load macro extensions from dll "CommonLibrary" macros.Load("CommonLibrary"); // 3. Register Option 2: Programmactically with macro attributes. macros.Register(new MacroAttribute() { Name = "helloworld" }, new MacroParameterAttribute[] { new MacroParameterAttribute() { Name = "language" } }, (tag) => "hello world using tag: " + tag.Name + ", " + tag.InnerContent); // 3. Register Option 3: Programmactically with simple api. macros.Register("helloworld2", "", "Simple hello world macro", (tag) => "hello world 2 : "); // 4. Now build the content by processing the macros var content = macros.BuildContent(_macroSampleText1); // 5. Render content that has a lamda based macro in it. // NOTE: Render content that has multiple macros involves the same method call. var content2 = macros.BuildContent(_macroSampleText2); return(BoolMessageItem.True); }
public void CanProcessViaAPI_Multiple_NonEmptyTag_Attributes_DifferentLocations() { var service = new MacroService('$', '[', ']'); // 1. quick api service.Register("helloworld1", "", "", (tag) => "hello world 1 " + tag.Attributes.Get <string>("saying") + ", " + tag.InnerContent); // 2. quick api service.Register("helloworld2", "", "", (tag) => "hello world 2 " + tag.Attributes.Get <string>("saying") + ", " + tag.InnerContent); // Case 1 - no external content var result = service.BuildContent("$[helloworld1 saying=\"hi\"]inner[/helloworld1] $[helloworld2 saying=\"hi\"]inner[/helloworld2]"); Assert.AreEqual(result, "hello world 1 hi, inner hello world 2 hi, inner"); // Case 2 - content after result = service.BuildContent("$[helloworld1 saying=\"hi\"]inner[/helloworld1] after 1 $[helloworld2 saying=\"hi\"]inner[/helloworld2] after 2"); Assert.AreEqual(result, "hello world 1 hi, inner after 1 hello world 2 hi, inner after 2"); // Case 3 - content before result = service.BuildContent("before 1 $[helloworld1 saying=\"hi\"]inner[/helloworld1] before 2 $[helloworld2 saying=\"hi\"]inner[/helloworld2]"); Assert.AreEqual(result, "before 1 hello world 1 hi, inner before 2 hello world 2 hi, inner"); // Case 4 - content before and after result = service.BuildContent("before 1 $[helloworld1 saying=\"hi\"]inner[/helloworld1] after 1 before 2 $[helloworld2 saying=\"hi\"]inner[/helloworld2] after 2"); Assert.AreEqual(result, "before 1 hello world 1 hi, inner after 1 before 2 hello world 2 hi, inner after 2"); }
public Channel(string channelId, TwitchService twitchService, MacroService macroService, AuthenticationService authenticationService) { Id = channelId.ToLower(); _twitchService = twitchService; _macroService = macroService; _authenticationService = authenticationService; }
public void CanProcessViaAPI_EmptyTag_No_Attributes_DifferentLocations() { var service = new MacroService('$', '[', ']'); // 1. quick api service.Register("helloworld1", "", "", (tag) => "hello world 1"); service.Register("helloworld2", "", "", (tag) => "hello world 2"); service.Register("helloworld3", "", "", (tag) => "hello world 3"); service.Register("helloworld4", "", "", (tag) => "hello world 4"); service.Register("helloworld5", "", "", (tag) => "hello world 5"); // Case 1 - no external content var result = service.BuildContent("$[helloworld1/]"); Assert.AreEqual(result, "hello world 1"); // Case 2 - content after result = service.BuildContent("$[helloworld1/] after"); Assert.AreEqual(result, "hello world 1 after"); // Case 3 - content before result = service.BuildContent("before $[helloworld1/]"); Assert.AreEqual(result, "before hello world 1"); // Case 4 - content before and after result = service.BuildContent("before $[helloworld1/] after"); Assert.AreEqual(result, "before hello world 1 after"); }
public void CanProcessViaAPI() { var service = new MacroService('$', '[', ']'); // 1. verbose api service.Register(new MacroAttribute() { Name = "helloworld1" }, new MacroParameterAttribute[] { new MacroParameterAttribute() { Name = "language" } }, (tag) => "hello world 1 : " + tag.Name + ", " + tag.InnerContent); // 2. quick api service.Register("helloworld2", "", "Simple hello world macro", (tag) => "hello world 2 : " + tag.InnerContent); var result1 = service.BuildContent(@"testing $[helloworld1 name=""kishore""]commonlibrary.net.cms[/hello]"); var result2 = service.BuildContent(@"testing $[helloworld2 name=""kishore""]commonlibrary.net.cms[/hello]"); Assert.AreEqual(result1, "testing hello world 1 : helloworld1, commonlibrary.net.cms"); Assert.AreEqual(result2, "testing hello world 2 : commonlibrary.net.cms"); }
protected override void RegisterTypes(IContainerRegistry containerRegistry) { var controller = new SerialSwitchController(); var serialPort = new SerialPortService(); var macro = new MacroService(); var cancelableTask = new CancelableTaskService(); var clock = new SwitchClock(); var work = new WorkSituation(); var gameCapture = new GameCapture(); var macroPool = new MacroPool(clock, controller, cancelableTask, gameCapture); controller.SerialPort = serialPort; macro.TaskService = cancelableTask; macro.Work = work; macro.MacroPool = macroPool; clock.Controller = controller; clock.Cancellation = cancelableTask; containerRegistry.RegisterInstance <IGameCapture>(gameCapture); containerRegistry.RegisterInstance <ISwitchController>(controller); containerRegistry.RegisterInstance <ISerialPortService>(serialPort); containerRegistry.RegisterInstance <IMacroService>(macro); containerRegistry.RegisterInstance <IMacroPool>(macroPool); containerRegistry.RegisterInstance <ITaskService>(cancelableTask); containerRegistry.RegisterInstance <ICanceler>(cancelableTask); containerRegistry.RegisterInstance <ICancellationRequest>(cancelableTask); containerRegistry.RegisterInstance <ISwitchClock>(clock); containerRegistry.RegisterInstance <IWorkSituation>(work); }
public void CanProcess() { var service = new MacroService("$", "[", "]"); service.Load("CommonLibrary.Web.Modules.Tests"); var result = service.BuildContent(@"testing $[hello name=""kishore""]commonlibrary.net.cms[/hello]"); Assert.AreEqual(result, "hello name: kishore, message: commonlibrary.net.cms"); }
public void CanProcessSimple() { var service = new MacroService(Char.MinValue, '[', ']'); service.Load(ContentLoader.TestDllName); var result = service.BuildContent("[hello]kishore[/hello]"); Assert.AreEqual(result, "hello name: kishore"); }
public void CanLoad() { var service = new MacroService(); service.Load("CommonLibrary.Web.Modules.Tests"); var macro = service.Create("hello"); Assert.IsTrue(service.Lookup.Count == 1); Assert.IsNotNull(macro); }
public void CanLoad() { var service = new MacroService(); service.Load(ContentLoader.TestDllName); var macro = service.Create("hello"); Assert.IsTrue(service.Lookup.Count == 1); Assert.IsNotNull(macro); }
public void CanProcessViaLoad() { var service = new MacroService('$', '[', ']'); service.Load(ContentLoader.TestDllName); var result = service.BuildContent(@"testing $[hello name=""kishore""]commonlibrary.net.cms[/hello]"); Assert.AreEqual(result, "testing hello name: kishore, message: commonlibrary.net.cms"); }
public ChannelService(TwitchService twitchService, AuthenticationService authenticationService, MacroService macroService) { _authenticationService = authenticationService; _twitchService = twitchService; _macroService = macroService; Channels.Add(new Channel("all", _twitchService, _macroService, _authenticationService)); AllChannel = Channels.FirstOrDefault(c => c.Id == "all"); _twitchService.OnMessageReceived += ReceiveMessageHandler; _twitchService.OnModReceived += ReceiveModHandler; _twitchService.OnWhisperReceived += WhisperRecieved; _twitchService.Connect(); }
public void WhenIExecuteTheMacroIntoResult(string reference, string ledgerReference, string resultReference) { var m = (Macro)cc.ObjectBag["macro-" + reference]; var l = (Ledger)cc.ObjectBag["ledger-" + ledgerReference]; cc.GetContext().Entry(m).Reload(); cc.GetContext().Entry(l).Reload(); var service = new MacroService(cc.GetContext()); var result = service.RunScript(m, l); cc.GetContext().SaveChanges(); cc.ObjectBag["macroResult-" + resultReference] = result; }
public MainForm() { InitializeComponent(); GlobalKeyEvents globalKeyEvents = new GlobalKeyEvents(); globalKeyEvents.SubscribeGlobal(); FormClosing += globalKeyEvents.Main_Closing; globalKeyEvents.MacroEventHandler += MacroEventListener; macroService = new MacroService(tagsService); tagsService.PrintTags(splitContainer.Panel1.Controls); macroService.PrintMacros(splitContainer.Panel2.Controls); macroService.RefreshMacrosHandler += RemoveMacrosEvent; tagsService.refreshTagsHandler += RemoveTagsEvent; }
/// <summary> /// 调用控件线程方法 /// </summary> /// <param name="args">参数</param> public void OnInvoke(object args) { CMessage message = (CMessage)args; List <Macro> macros = new List <Macro>(); MacroService.GetMacros(macros, message.m_body, message.m_bodyLength); int macrosSize = macros.Count; switch (message.m_functionID) { case MacroService.FUNCTIONID_MACRO_ADDMACROS: AddMacrosToGrid(macros); break; case MacroService.FUNCTIONID_MACRO_DELETEMACROS: { Dictionary <String, GridRow> mRowsMap = GetMacroRows(); for (int i = 0; i < macrosSize; i++) { Macro macro = macros[i]; if (mRowsMap.ContainsKey(macro.m_macroID)) { m_gridMacros.RemoveRow(mRowsMap[macro.m_macroID]); } } m_gridMacros.Update(); break; } case MacroService.FUNCTIONID_MACRO_UPDATEMACROS: { Dictionary <String, GridRow> mRowsMap = GetMacroRows(); for (int i = 0; i < macrosSize; i++) { Macro macro = macros[i]; if (mRowsMap.ContainsKey(macro.m_macroID)) { mRowsMap[macro.m_macroID].GetCell(1).Text = macro.m_name; } } break; } } m_window.Invalidate(); }
public void WhenIExecuteTheMacroOnLedgerIntoResultWithParameters(string reference, string ledgerReference, string resultReference, Table table) { var m = (Macro)cc.ObjectBag["macro-" + reference]; var l = (Ledger)cc.ObjectBag["ledger-" + ledgerReference]; cc.GetContext().Entry(m).Reload(); cc.GetContext().Entry(l).Reload(); var service = new MacroService(cc.GetContext()); var parameters = new MacroScriptParameters(); foreach (var r in table.Rows) { parameters.SetParameter(r["Name"], r["Value"]); } var result = service.RunScript(m, l, parameters); cc.GetContext().SaveChanges(); cc.ObjectBag["macroResult-" + resultReference] = result; }
public void CanProcessViaAPI_EmptyTag_Attributes_DifferentLocations() { var service = new MacroService('$', '[', ']'); // 1. quick api service.Register("helloworld1", "", "", (tag) => "hello world 1 " + tag.Attributes.Get <string>("saying")); // Case 1 - no external content var result = service.BuildContent("$[helloworld1 saying=\"hi\"/]"); Assert.AreEqual(result, "hello world 1 hi"); // Case 2 - content after result = service.BuildContent("$[helloworld1 saying=\"hi\"/] after"); Assert.AreEqual(result, "hello world 1 hi after"); // Case 3 - content before result = service.BuildContent("before $[helloworld1 saying=\"hi\"/]"); Assert.AreEqual(result, "before hello world 1 hi"); // Case 4 - content before and after result = service.BuildContent("before $[helloworld1 saying=\"hi\"/] after"); Assert.AreEqual(result, "before hello world 1 hi after"); }
public void WhenICreateAMacroWithTheProperties(string reference, Table table) { var service = new MacroService(cc.GetContext()); var m = service.CreateMacro(); foreach (var r in table.Rows) { var property = r["Property"]; var value = r["Value"]; switch (property) { case "Name": m.Name = value; break; case "Description": m.Description = value; break; case "Script": m.Script = value; break; } } cc.GetContext().SaveChanges(); cc.ObjectBag["macro-" + reference] = m; }