public void Test_04_ExecuteAction_ProcessContainer() { ActionExecuter executer = new ActionExecuter(null); string[] attachments = new string[] { System.IO.Path.Combine(TEST_FOLDER, "TestClean.doc"), System.IO.Path.Combine(TEST_FOLDER, "TestDoc.doc") }; IContainer container; PolicyResponseObject pro = ProHelper.GeneratePRO(attachments, PolicyType.ClientRemovableMedia, out container); Assert.AreEqual(3, pro.ContentCollection.Count); // The folder container, TestClean.doc, TestDoc.doc MockExecutableContainerAction containerAction = new MockExecutableContainerAction(); ProHelper.AddActionToContentCollection(pro, containerAction, false, true); List<string> results = new List<string>(); HasContainerBeenModified(container, results); Assert.AreEqual(0, results.Count); IUniversalRequestObject uro = executer.ExecuteActions(pro, ref container); HasContainerBeenModified(container, results); Assert.AreEqual(2, results.Count); Assert.AreEqual(2, uro.Attachments.Count); Assert.AreEqual(3, pro.ContentCollection.Count); }
protected override void InitializeCore() { // get the theme from the current application var theme = ThemeManager.DetectAppStyle(Application.Current); // now set the Green accent and dark theme ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.GetAccent(AppConfig.AccentColor), ThemeManager.GetAppTheme(AppConfig.AppTheme)); _explorerCleaner = new ExplorerCleaner(AppConfig); _explorerCleaner.Cleaned += (sender, args) => OnCleaned(args); _actionExecuter = new ActionExecuter <ExplorerWindowCleanerClientOperator>(new ExplorerWindowCleanerClientOperator(this, _explorerCleaner)); DisposableCollection.Add(_actionExecuter); ResetBackgroundWorker(AppConfig.Interval, new BackgroundAction[] { new CleanerAction(this) }); if (AppConfig.IsMouseHook) { RestoreClipboardHistories(); MonitoringClipboard(); CreateShortcutContextMenu(); CreateClipboardContextMenu(); _globalMouseHook = new GlobalMouseHook(); _globalMouseHook.MouseHooked += (sender, args) => { if (args.MouseButton == MouseButtons.Left) { _contextMenuClipboardHistories.Close(ToolStripDropDownCloseReason.AppFocusChange); _contextMenuShortcuts.Close(ToolStripDropDownCloseReason.AppFocusChange); } if (args.IsDoubleClick) { if (args.MouseButton == MouseButtons.Right) { _contextMenuClipboardHistories.Tag = GetForegroundWindow(); _contextMenuClipboardHistories.Show(args.Point); } else if (args.MouseButton == MouseButtons.Left && args.IsDesktop) { _contextMenuShortcuts.Show(args.Point); Debug.WriteLine($"Show Shortcut Menu. {args.Point}"); } Debug.WriteLine("DoubleClick Mouse."); } }; } }
private void SimpleParser(ListBox.ObjectCollection actions) { bool success = false; string command = ""; string args = ""; if (!canTimeTrigger) { return; } foreach (string action in actions) { if (action == null || action.Length == 0) { continue; } args = ""; if (action.Split(' ').Length == 1) { command = action.Split(' ')[0]; } else if (action.Split(' ').Length >= 2) { command = action.Split(' ')[0]; args = action.Split(' ')[1]; } if (command.Length == 1) { success = ActionExecuter.ExecuteAbility(command.Substring(0, 1), args, mainForm.QuickCast(), this, true); } if (command.Length > 4) { if (command.Substring(0, 5) == "item_") { success = ActionExecuter.ExecuteItem(command, args, mainForm.QuickCast(), this, true); } } if (success) { canTimeTrigger = false; return; } } }
public void AbortInFileAction() { #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set) { throw new AbortActionException("Aint going no where"); } ); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; #endregion try { // execute ActionExecuter executer = new ActionExecuter(null); IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container); } catch (PolicyActionException ex) // expecting this { Assert.AreEqual(ActionExceptionHandling.Abort, ex.ExceptionHandling, "Expecting engine to request an abort"); } }
public void ExceptionInFileAction() { #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set) { throw new InvalidDataException("This is HAL 3000"); } ); configuration.MergePropertiesMethod = delegate(ActionPropertySet[] sets) { return sets[0]; }; List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; #endregion // execute ActionExecuter executer = new ActionExecuter(null); IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container); }
private void Run() { while (true) { if (playing) { if (wardsCD == 0 && warnWards && mainForm.WardWards()) { warnWards = false; string chatStr = "▶ Wards are off cooldown!"; KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(50); KBMHelper.TypeChat(chatStr); Thread.Sleep(50); KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(200); } if (canTimeTrigger) { if (mainForm.WarnRunes() && mainForm.WarnTome() && clockTime % 600 == 0 && clockTime > 599) { string chatStr = "▶ All Runes are up and Tome of Knowledge can be purchased!"; canTimeTrigger = false; KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(50); KBMHelper.TypeChat(chatStr); Thread.Sleep(50); KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(200); } else if (!mainForm.WarnRunes() && mainForm.WarnTome() && clockTime % 600 == 0 && clockTime > 599) { string chatStr = "▶ Tome of Knowledge can be purchased!"; canTimeTrigger = false; KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(50); KBMHelper.TypeChat(chatStr); Thread.Sleep(50); KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(200); } else if (mainForm.WarnRunes() && !mainForm.WarnTome() && clockTime % 600 == 0 && clockTime > 599) { string chatStr = "▶ All Runes are up!"; canTimeTrigger = false; KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(50); KBMHelper.TypeChat(chatStr); Thread.Sleep(50); KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(200); } else if (mainForm.WarnRunes() && clockTime % 120 == 0 && clockTime % 600 != 0 && clockTime > 119) { string chatStr = "▶ Power-Up Runes are up!"; canTimeTrigger = false; KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(50); KBMHelper.TypeChat(chatStr); Thread.Sleep(50); KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(200); } else if (mainForm.WarnRunes() && clockTime % 300 == 0 && clockTime % 600 != 0 && clockTime > 299) { string chatStr = "▶ Bounty Runes are up!"; canTimeTrigger = false; KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(50); KBMHelper.TypeChat(chatStr); Thread.Sleep(50); KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(200); } } if (mainForm.WarnRoshan() && clockTime >= roshTime && roshToggle) { int limit = roshTime + 180; string chatStr = "▶ Roshan might be up! Limit is: " + TimeHelper.toHHMMSS(limit); roshToggle = false; KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(50); KBMHelper.TypeChat(chatStr); Thread.Sleep(50); KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(200); } if (mainForm.WarnAegis() && clockTime <= aegisTime && aegisToggle > 0) { string chatStr = ""; int left = aegisTime - clockTime; if (left <= 0 && aegisToggle == 1) { chatStr = "▶ Aegis expired!"; aegisToggle = 0; KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(50); KBMHelper.TypeChat(chatStr); Thread.Sleep(50); KBMHelper.PressKey(VirtualKeyCode.RETURN); } else if (left == 60 && aegisToggle == 2) { chatStr = "▶ Aegis will expire in " + left + " seconds! (" + TimeHelper.toHHMMSS(aegisTime) + ")"; KBMHelper.PressKey(VirtualKeyCode.RETURN); aegisToggle = 1; Thread.Sleep(50); KBMHelper.TypeChat(chatStr); Thread.Sleep(50); KBMHelper.PressKey(VirtualKeyCode.RETURN); } else if (left == 180 && aegisToggle == 3) { chatStr = "▶ Aegis will expire in " + left + " seconds! (" + TimeHelper.toHHMMSS(aegisTime) + ")"; KBMHelper.PressKey(VirtualKeyCode.RETURN); aegisToggle = 2; Thread.Sleep(50); KBMHelper.TypeChat(chatStr); Thread.Sleep(50); KBMHelper.PressKey(VirtualKeyCode.RETURN); } Thread.Sleep(200); } if (KBMHelper.GetAsyncKeyState(0x2D) < 0) //INSERT { string chatStr = "▶ Roshan Timer: "; int minTime = clockTime + 480; //8 MINS int maxTime = clockTime + 660; //11 MINS roshTime = minTime; roshToggle = true; chatStr = chatStr + TimeHelper.toHHMMSS(minTime) + " - " + TimeHelper.toHHMMSS(maxTime); KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(50); KBMHelper.TypeChat(chatStr); Thread.Sleep(50); KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(200); continue; } if (KBMHelper.GetAsyncKeyState(0x2E) < 0) //DELETE { string chatStr = "▶ Aegis expires on: "; int minTime = clockTime + 300; //5 MINS aegisTime = minTime; aegisToggle = 3; chatStr = chatStr + TimeHelper.toHHMMSS(minTime); KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(50); KBMHelper.TypeChat(chatStr); Thread.Sleep(50); KBMHelper.PressKey(VirtualKeyCode.RETURN); Thread.Sleep(200); continue; } if (KBMHelper.GetAsyncKeyState(0x5) < 0 && alive && !comboLock) //MOUSE4 and ALIVE { KBMHelper.keybd_event(0x5, 0, 0x2, 0); ListBox.ObjectCollection macro; macro = mainForm.Macro(); int time = 0; string command = ""; string args = ""; bool success = false; bool waited = false; bool shiftState = false; comboLock = true; foreach (string macroCMD in macro) { if (macroCMD == null || macroCMD.Length == 0) { continue; } command = ""; args = ""; waited = false; if (macroCMD.Split(' ').Length == 1) { command = macroCMD.Split(' ')[0]; } else if (macroCMD.Split(' ').Length >= 2) { command = macroCMD.Split(' ')[0]; args = macroCMD.Split(' ')[1]; } if (command == "ATTACK") { ActionExecuter.ExecuteAbility(command.Substring(0, 1), args, mainForm.QuickCast(), this, false); success = true; } else if (command == "TAB") { KBMHelper.PressKey(VirtualKeyCode.TAB); waited = true; success = true; continue; } else if (command == "STOP") { KBMHelper.PressKey(VirtualKeyCode.VK_S); shiftState = !shiftState; waited = true; success = true; continue; } else if (command == "SHIFT") { if (!shiftState) { KBMHelper.PressKey(VirtualKeyCode.VK_S); KBMHelper.ShiftDown(); } else { KBMHelper.ShiftUp(); KBMHelper.PressKey(VirtualKeyCode.VK_S); } shiftState = !shiftState; waited = true; success = true; continue; } else if (command == "WAIT" && success) { time = Int32.Parse(args); waited = true; Thread.Sleep(time); KBMHelper.PressKey(VirtualKeyCode.VK_S); continue; } success = true; if (command.Length == 1) { success = ActionExecuter.ExecuteAbility(command.Substring(0, 1), args, mainForm.QuickCast(), this, false); } if (command.Length > 4) { if (command.Substring(0, 5) == "item_") { success = ActionExecuter.ExecuteItem(command, args, mainForm.QuickCast(), this, false); } } if (!success && mainForm.Cancel()) { break; } //if (KBMHelper.GetAsyncKeyState(0x48) < 0) break; //H - HALT if (!waited && success) { Random rnd = new Random(); time = mainForm.ActionWait(); if (mainForm.WaitRandom()) { time += rnd.Next(1, mainForm.WaitRandomTime()); } if (shiftState && !mainForm.Shift()) { time = 0; } Thread.Sleep(time); } } if (shiftState) { KBMHelper.ShiftUp(); } comboLock = false; Thread.Sleep(200); } if (KBMHelper.GetAsyncKeyState(0x20) < 0) { KBMHelper.keybd_event(0x20, 0, 0x2, 0); autoShadowAmulet = !autoShadowAmulet; Thread.Sleep(200); } if (autoShadowAmulet && KBMHelper.GetAsyncKeyState(0x2) < 0) { Random rnd = new Random(); int time = 200; if (mainForm.WaitRandom()) { time += rnd.Next(1, mainForm.WaitRandomTime()); } ActionExecuter.ExecuteItem("item_shadow_amulet", "SELF", mainForm.QuickCast(), this, false); Thread.Sleep(time); } if (mainForm.Phase() && (KBMHelper.GetAsyncKeyState(0x2) < 0 || KBMHelper.GetAsyncKeyState(0x41) < 0 || KBMHelper.GetAsyncKeyState(0x4D) < 0)) { Random rnd = new Random(); int time = 200; if (mainForm.WaitRandom()) { time += rnd.Next(1, mainForm.WaitRandomTime()); } ActionExecuter.ExecuteItem("item_phase_boots", null, mainForm.QuickCast(), this, true); Thread.Sleep(time); } } Thread.Sleep(1); } }
public void AllZipContainersFilteredOutIfActionDoesntSupportZip() { int count = 0; #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = delegate(IActionData3 input, ActionPropertySet set) { count++; return input.FileName; }; configuration.MergePropertiesMethod = delegate(ActionPropertySet[] sets) { return sets[0]; }; configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*", ".zip;.fld;.email"); configuration.Capabilities = new ActionCapabilities(false, false); List<string> attachments = new List<string>(); TestHelpers.GetFilesInFolder(Path.Combine(TEST_FOLDER, "ActionExecuter\\TestZipIgnore"), attachments); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; Assert.AreEqual(7, retValue.Uro.Attachments.Count); // just verifying no one is messing with test data Assert.AreEqual(12, retValue.Pro.ContentCollection.Count); #endregion //execute ActionExecuter executer = new ActionExecuter(null); IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container); Assert.AreEqual(5, count, "Folder supported action should be called exactly 5 times"); }
public void RecursiveRequestStreamTransform() { StringBuilder sb = new StringBuilder(); #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*"); // support everything and folders except mime emails configuration.Capabilities = new ActionCapabilities(true, false); configuration.ExecuteMethod = new MockUserAction.ExecuteMethod( delegate(IActionData3 input, ActionPropertySet props) { foreach (IActionData3 nodes in input.Nested) { ReadAllContents(nodes, sb); } input.Nested.Clear(); ActionData newOne = new ActionData(); string tempFileName = System.IO.Path.GetTempFileName(); System.IO.File.WriteAllText(tempFileName, sb.ToString()); newOne.FileName = tempFileName; newOne.DisplayName = input.FileName; newOne.Underworld = new File(tempFileName, input.FileName); input.Nested.Add(newOne); return input.FileName; } ); List<string> attachments = new List<string>(); TestHelpers.GetFilesInFolder(Path.Combine(TEST_FOLDER, "ActionExecuter\\TestZipIgnore"), attachments); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; #endregion ActionExecuter executer = new ActionExecuter(null); IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container); foreach (RequestAttachment ra in outputUro.Attachments) { StreamReader reader = new StreamReader(ra.Data.AsStream()); Console.WriteLine(reader.ReadToEnd()); reader.BaseStream.Close(); } Assert.AreEqual(1, outputUro.Attachments.Count, "Expecting one result"); }
public void MimeActionExecutes() { int count = 0; bool isEmail = false; IActionProperty currentUser = null; #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = delegate(IActionData3 input, ActionPropertySet set) { count++; return input.FileName; }; configuration.ExecuteMimeMethod = delegate(IActionData3 input, ActionPropertySet props) { count++; if (props.SystemProperties.ContainsKey("FileType") && props.SystemProperties["FileType"].Value.ToString() == ".email") isEmail = true; props.SystemProperties.TryGetValue("CurrentUser", out currentUser); return input.Content; }; configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".email;.ppt", ""); configuration.Capabilities = new ActionCapabilities(false, true); IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { Path.Combine(POLICY_FOLDER, "New Policy Set.policy") }); PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null); new ConditionProcessor(policyEngineCache, null); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); attachments.Add(Path.Combine(TEST_FOLDER, "Dirty.doc")); attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.ppt")); IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments, "*****@*****.**", "*****@*****.**"); UroPolicyEngine engine = new UroPolicyEngine(); engine.PolicyCache = policyCache; PolicyResponseObject pro = engine.ProcessPolicies(RunAt.Client, uro, ProcessLevel.Actions) as PolicyResponseObject; IContainer container = engine.Container; #endregion //execute ActionExecuter executer = new ActionExecuter(null); executer.ExecuteActions(pro, ref container); Assert.AreEqual(1, count, "Mime action should be triggered 1x"); Assert.IsTrue(isEmail, "The FileType property in the system properties wasnt passed to the mime action correctly"); Assert.AreEqual(pro.UniversalRequestObject.Source.Items[0].Content, currentUser.Value, "CurrentUser not propagated to action"); }
public void FolderActionExecutedOnce() { int count = 0; #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set) { count++; return input.FileName; } ); configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*;.fld", ""); configuration.Capabilities = new ActionCapabilities(true, false); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); attachments.Add(Path.Combine(TEST_FOLDER, "Dirty.doc")); attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.ppt")); attachments.Add(Path.Combine(TEST_FOLDER, "Test folder\\Sub Folder\\TestDoc.doc")); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; #endregion //execute ActionExecuter executer = new ActionExecuter(null); IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container); Assert.AreEqual(1, count, "Folder supported action should be called only once"); }
public void EnsureContentItemDetailsArePropagatedOnActionException() { #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set) { throw new DataMisalignedException("A rather esoteric exception"); } ); configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*", ""); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; Workshare.Policy.Engine.Tests.TestUroPolicyEngine.MockProgressCallback policyEvents = new Workshare.Policy.Engine.Tests.TestUroPolicyEngine.MockProgressCallback(); ActionExecuter executer = new ActionExecuter(policyEvents); #endregion try { executer.ExecuteActions(retValue.Pro, ref container); } catch (System.Exception e) { Assert.IsInstanceOf(typeof(PolicyActionException), e); PolicyActionException paeThrown = e as PolicyActionException; Assert.IsTrue(paeThrown.Action.StartsWith("MockUser"), "Action name in exception incorrect {0}, expecting MockUser action", paeThrown.Action); Assert.AreEqual(Path.GetFileName(attachments[0]), paeThrown.ContentId, "Expected filename in exception details"); } }
public void ActionBlowsUpButAllowsUserPrompt() { #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set) { throw new DataMisalignedException("A rather esoteric exception"); } ); configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*", ""); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; Workshare.Policy.Engine.Tests.TestUroPolicyEngine.MockProgressCallback policyEvents = new Workshare.Policy.Engine.Tests.TestUroPolicyEngine.MockProgressCallback(); ActionExecuter executer = new ActionExecuter(policyEvents); // set(enforce) block on exception to false on all policies foreach (ContentItem ci in retValue.Pro.ContentCollection) { foreach (PolicySetResponse psr in ci.PolicySetCollection) { foreach (PolicyResponse p in psr.PolicyReportCollection) { if (p.Triggered) { p.BlockOnException = false; } } } } #endregion try { executer.ExecuteActions(retValue.Pro, ref container); } catch (System.Exception e) { Assert.IsInstanceOf(typeof(PolicyActionException), e); PolicyActionException paeThrown = e as PolicyActionException; Assert.IsTrue(paeThrown.Action.StartsWith("MockUser"), "Action name in exception incorrect {0}, expecting MockUser action", paeThrown.Action); Assert.AreEqual(ActionExceptionHandling.Prompt, paeThrown.ExceptionHandling, "This exception should result in a block"); } }
private void SetupRabbitConsumer() { var factory = new ConnectionFactory { HostName = Configuration["RabbitMq:HostName"].Default("localhost"), Port = Configuration["RabbitMq:Port"].ToInt(5672), UserName = Configuration["RabbitMq:UserName"].Default("guest"), Password = Configuration["RabbitMq:Password"].Default("guest") }; var connection = factory.CreateConnection(); var channel = connection.CreateModel(); channel.ExchangeDeclare(exchange: "moorea", type: "direct"); var queueName = channel.QueueDeclare().QueueName; channel.QueueBind(queue: queueName, exchange: "moorea", routingKey: "moorea-messages"); channel.QueueBind(queue: queueName, exchange: "moorea", routingKey: "moorea-actions"); var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { try { var dbOptions = new DbContextOptionsBuilder <DatabaseContext>().UseSqlServer(Configuration["Data:ConnectionString"]).Options; using (var dbContext = new DatabaseContext(dbOptions)) { var body = ea.Body; var message = Encoding.UTF8.GetString(body); if (message.StartsWith("{")) { var action = JsonConvert.DeserializeObject <IMessageQueueBaseAction>(message); Console.WriteLine("{0} received action: {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm.ss"), action.Action); var sw = new Stopwatch(); sw.Start(); if (ActionExecuter.Execute(dbContext, action)) { channel.BasicAck(ea.DeliveryTag, false); } sw.Stop(); Console.WriteLine($" tempo di esecuzione: {sw.ElapsedMilliseconds} ms"); } else { Console.WriteLine("- received message: {0}", message); channel.BasicAck(ea.DeliveryTag, false); } } } catch (Exception e) { Console.WriteLine("errore in gestione messaggio: {0}", e.Message); } }; channel.BasicConsume(queueName, false, consumer); }
private void OnNewGameState(GameState gs) { gs_dump = gs; if (gs.IsSpectator) { playing = false; } else { abilities = gs.Abilities; items = gs.Items; playing = true; clockTime = gs.Map.ClockTime; alive = gs.Hero.IsAlive; wardsCD = gs.Map.Ward_Purchase_Cooldown; if (wardsCD > 0) { warnWards = true; } if (clockTime % 2 == 1) { canTimeTrigger = true; } if (alive) { //URSA AGHS if (mainForm.StunBreakUlt() && gs.Hero.Name == "npc_dota_hero_ursa" && gs.Hero.IsStunned && items.InventoryContains("item_ultimate_scepter")) { if (items.InventoryIndexOf("item_ultimate_scepter") < 6) { ActionExecuter.ExecuteAbility("R", "", mainForm.QuickCast(), this, true); } } //ABBA ULT if (mainForm.StunBreakUlt() && gs.Hero.Name == "npc_dota_hero_abaddon" && (gs.Hero.IsStunned || gs.Hero.IsBreak)) { ActionExecuter.ExecuteAbility("R", "", mainForm.QuickCast(), this, true); } //AEON DISK /*if (main form check field && gs.Items.InventoryContains("item_aeon_disk")) * { * int index = items.InventoryIndexOf("item_aeon_disk"); * Item aeonDisk = gs.Items.GetInventoryAt(index); * if (aeonDisk.Cooldown > 0 && canAeonDiskTrigger && index < 6) * { * if (mainForm.SelectHero()) KBMHelper.SelectHero(VirtualKeyCode.F1); * ActionExecuter.ExecuteItem("item_black_king_bar", "", mainForm.QuickCast(), this, true); * canAeonDiskTrigger = false; * } * if (aeonDisk.Cooldown == 0) * { * canAeonDiskTrigger = true; * } * }*/ //DROW AURA if (mainForm.DrowAura() && gs.Hero.Name == "npc_dota_hero_drow_ranger") { ActionExecuter.ExecuteAbility("E", "", mainForm.QuickCast(), this, true); } if (mainForm.Buckler()) { ActionExecuter.ExecuteItem("item_buckler", "", mainForm.QuickCast(), this, true); } //LINKENS AND AM AGHS if (((mainForm.AmAghs() && gs.Hero.Name == "npc_dota_hero_antimage" && items.InventoryContains("item_ultimate_scepter")) || items.InventoryContains("item_sphere")) && mainForm.Linkens()) { string name; int cd = 0; int index = 6; if (items.InventoryContains("item_sphere")) { name = "item_sphere"; index = items.InventoryIndexOf(name); cd = items.GetInventoryAt(index).Cooldown; if (index > 5 && mainForm.AmAghs() && gs.Hero.Name == "npc_dota_hero_antimage") { name = "item_ultimate_scepter"; index = items.InventoryIndexOf(name); cd = abilities[2].Cooldown; } } else { name = "item_ultimate_scepter"; index = items.InventoryIndexOf(name); cd = abilities[2].Cooldown; } if (canSphereTrigger && index < 6 && cd > 0) { SimpleParser(mainForm.LinkensActions()); canSphereTrigger = false; } if (cd == 0) { canSphereTrigger = true; } } if (gs.Hero.IsSilenced && mainForm.Silenced()) { SimpleParser(mainForm.SilencedActions()); } if ((gs.Hero.IsMuted || gs.Hero.IsBreak) && mainForm.MutedBreak()) { SimpleParser(mainForm.MutedBreakActions()); } if (gs.Hero.IsDisarmed && mainForm.Disarmed()) { SimpleParser(mainForm.DisarmedActions()); } if (mainForm.HP() && (gs.Hero.Health <= mainForm.MinHP() || gs.Hero.HealthPercent <= mainForm.MinHPPercent())) { SimpleParser(mainForm.HPActions()); } if (mainForm.Mana() && (gs.Hero.Mana <= mainForm.MinMana() || gs.Hero.ManaPercent <= mainForm.MinManaPercent())) { SimpleParser(mainForm.ManaActions()); } if ((gs.Hero.IsStunned /*|| gs.Hero.IsHexed*/) && mainForm.Disabled()) { SimpleParser(mainForm.DisabledActions()); } } } }
public void Test_06_ExecuteAction_SMTP_ZipPolicy_HasZip() { IPolicyCache policyCache = TestHelpers.CreatePolicyCache( new string[] { Path.Combine(POLICY_FOLDER, "TestActionProcessor - Zip Policy Set.policy") }); Assert.IsNotNull(policyCache); Assert.AreEqual(1, policyCache.PolicySets.Count); PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null); ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); attachments.Add(Path.Combine(TEST_FOLDER, "I am a dirty zip.zip")); IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments); // PROCESS CONDITIONS IContainer container; PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container); Assert.IsNotNull(pro); // PROCESS ROUTING RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache); Assert.IsNotNull(routingProcessor.Process(pro)); Assert.AreEqual(4, pro.ContentCollection.Count); Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type); Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type); Assert.AreEqual(FileType.ZIP.ToString(), pro.ContentCollection[2].Type); Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[3].Type); Assert.AreEqual(2, pro.UniversalRequestObject.Attachments.Count); Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name)); Assert.AreEqual("I am a dirty zip.zip", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name)); // PROCESS ACTIONS ActionProcessor actionProcessor = new ActionProcessor(policyCache, policyEngineCache); actionProcessor.ProcessActions(pro); ActionUtils.PopulateResolvedActionCollection(pro); // EXECUTE ACTIONS ActionExecuter executer = new ActionExecuter(null); IUniversalRequestObject outputUro = executer.ExecuteActions(pro, ref container); Assert.AreEqual(4, pro.ContentCollection.Count); Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type); Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type); Assert.AreEqual(FileType.ZIP.ToString(), pro.ContentCollection[2].Type); Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[3].Type); Assert.AreEqual(2, outputUro.Attachments.Count); Assert.AreEqual("TestProfanity.zip", outputUro.Attachments[0].Name); Assert.AreEqual("I am a dirty zip.zip", outputUro.Attachments[1].Name); }
public void OnlySupportedFileTypesFileAction() { int count = 0; string filename = null; #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set) { count++; filename = input.Properties["FileName"]; return input.FileName; } ); configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".ppt", ""); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.ppt")); attachments.Add(Path.Combine(TEST_FOLDER, "Dirty.doc")); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; #endregion //execute ActionExecuter executer = new ActionExecuter(null); IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container); Assert.AreEqual(1, count, "Action should have been triggered just once"); Assert.AreEqual("TestDoc.ppt", Path.GetFileName(filename), "Action was given wrong file to process"); }
public void Test_10_ExecuteAction_SMTP_Default_Policy_And_ZIP_Policy() { IPolicyCache policyCache = TestHelpers.CreatePolicyCache(new string[] { Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Projects\Hygiene\Policies\p5default.policy"), Path.Combine(POLICY_FOLDER, "TestActionProcessor - Zip Policy Set.policy") }); Assert.IsNotNull(policyCache); Assert.AreEqual(2, policyCache.PolicySets.Count); PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null); ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); attachments.Add(Path.Combine(TEST_FOLDER, "Dirty.doc")); attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.ppt")); IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments); // PROCESS CONDITIONS IContainer container; PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container); Assert.IsNotNull(pro); // PROCESS ROUTING RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache); Assert.IsNotNull(routingProcessor.Process(pro)); Assert.AreEqual(4, pro.ContentCollection.Count); Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type); Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type); Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type); Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type); Assert.AreEqual(3, pro.UniversalRequestObject.Attachments.Count); Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name)); Assert.AreEqual("Dirty.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name)); Assert.AreEqual("TestDoc.ppt", Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name)); // PROCESS ACTIONS ActionProcessor actionProcessor = new ActionProcessor(policyCache, policyEngineCache); actionProcessor.ProcessActions(pro); ActionUtils.PopulateResolvedActionCollection(pro); // EXECUTE ACTIONS ActionExecuter executer = new ActionExecuter(null); IUniversalRequestObject outputUro = executer.ExecuteActions(pro, ref container); //Assert.AreEqual(4, pro.ContentCollection.Count); //Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type); //Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type); //Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type); //Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type); Assert.AreEqual(2, outputUro.Attachments.Count); Assert.AreEqual("TestDoc.ppt", outputUro.Attachments[0].Name); Assert.AreEqual("attachments.zip", outputUro.Attachments[1].Name); File outputFile = new File(outputUro.Attachments[1].Data, outputUro.Attachments[0].Name); Assert.IsNotNull(outputFile); outputFile.ExpandContainer(outputFile.Password); Assert.AreEqual(2, outputFile.Files.Count); Assert.AreEqual("TestProfanity.doc", outputFile.Files[0].DisplayName); Assert.AreEqual("Dirty.doc", outputFile.Files[1].DisplayName); }
public void DocumentInsideZipContainerFileAction() { int count = 0; #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set) { count++; return input.FileName; } ); configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*"); configuration.Capabilities = new ActionCapabilities(false, false); List<string> attachments = new List<string>(); TestHelpers.GetFilesInFolder(Path.Combine(TEST_FOLDER, "ActionExecuter\\TestZipIgnore"), attachments); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; Assert.AreEqual(7, retValue.Uro.Attachments.Count); // just verifying no one is messing with test data Assert.AreEqual(12, retValue.Pro.ContentCollection.Count); #endregion //execute ActionExecuter executer = new ActionExecuter(null); IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container); Assert.AreEqual(8, count, "Expected 8 action executions"); Assert.AreEqual(7, outputUro.Attachments.Count, "Incorrect attachment count"); }
public void ChangeFileNameFileAction() { #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set) { input.Properties["FileName"] = Path.ChangeExtension(input.Properties["FileName"], ".foobar"); return input.FileName; } ); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; #endregion //execute ActionExecuter executer = new ActionExecuter(null); IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container); //verify Assert.AreEqual(2, retValue.Pro.ContentCollection.Count); Assert.AreEqual(FileType.WordDocument.ToString(), retValue.Pro.ContentCollection[1].Type); Assert.AreEqual(1, outputUro.Attachments.Count); Assert.IsTrue(outputUro.Attachments[0].Properties["FileName"].EndsWith(".foobar"), "Filename not changed by action"); }
public void RequestTextStreamCalled() { #region setup string readContent = null; MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set) { Console.WriteLine("readable about to be called from action"); StreamReader sr = new StreamReader(input.ReadableContent); readContent = sr.ReadLine(); sr.Dispose(); return input.FileName; } ); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; ActionExecuter executer = new ActionExecuter(null); executer.GetReadableContent = new ReadableContentRequest(delegate(File source) { StreamWriter sw = new StreamWriter(new MemoryStream()); sw.WriteLine("Hello world"); sw.Flush(); sw.BaseStream.Position = 0; Console.WriteLine("readable set to Hello world"); return sw.BaseStream; }); #endregion // execute IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container); // verify Assert.AreEqual("Hello world", readContent, "Incorrect readable string provided"); }
public void RemoveFileNameFileAction() { #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set) { return null; } ); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; #endregion // execute ActionExecuter executer = new ActionExecuter(null); Assert.Throws<PolicyActionException> (delegate { executer.ExecuteActions(retValue.Pro, ref container); } ); }
public void Test_05_ExecuteAction_SMTP_ZipPolicy() { IPolicyCache policyCache = TestHelpers.CreatePolicyCache( new string[] { Path.Combine(POLICY_FOLDER, "TestActionProcessor - Zip Policy Set.policy") }); Assert.IsNotNull(policyCache); Assert.AreEqual(1, policyCache.PolicySets.Count); PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null); ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null); List<string> attachments = new List<string>(); using (LocalCopyOfFileManager lcfm = new LocalCopyOfFileManager()) { string folderName = lcfm.ManagedFolder; string fileName = Path.Combine(folderName, "TestProfanity.doc"); System.IO.File.Copy(Path.Combine(TEST_FOLDER, "TestProfanity.doc"), fileName); attachments.Add(fileName); fileName = Path.Combine(folderName, "Dirty.doc"); System.IO.File.Copy(Path.Combine(TEST_FOLDER, "Dirty.doc"), fileName); attachments.Add(fileName); fileName = Path.Combine(folderName, "TestDoc.ppt"); System.IO.File.Copy(Path.Combine(TEST_FOLDER, "TestDoc.ppt"), fileName); attachments.Add(fileName); IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments); // PROCESS CONDITIONS IContainer container; PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container); Assert.IsNotNull(pro); // PROCESS ROUTING RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache); Assert.IsNotNull(routingProcessor.Process(pro)); Assert.AreEqual(4, pro.ContentCollection.Count); Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type); Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type); Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type); Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type); Assert.AreEqual(3, pro.UniversalRequestObject.Attachments.Count); Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name)); Assert.AreEqual("Dirty.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name)); Assert.AreEqual("TestDoc.ppt", Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name)); // PROCESS ACTIONS ActionProcessor actionProcessor = new ActionProcessor(policyCache, policyEngineCache); actionProcessor.ProcessActions(pro); ActionUtils.PopulateResolvedActionCollection(pro); // EXECUTE ACTIONS ActionExecuter executer = new ActionExecuter(null); executer.ExecuteActions(pro, ref container); Assert.AreEqual(4, pro.ContentCollection.Count); Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type); Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type); Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type); Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type); Assert.AreEqual(3, pro.UniversalRequestObject.Attachments.Count); Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name)); Assert.AreEqual("Dirty.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name)); Assert.AreEqual("TestDoc.ppt", Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name)); } }
public void ChangeContentsFileAction() { string outputString = TESTDOC_RTF_CONTENT; #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set) { input.Properties["FileName"] = Path.ChangeExtension(input.Properties["FileName"], ".txtx"); return input.FileName; } ); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.rtf")); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; #endregion // execute ActionExecuter executer = new ActionExecuter(null); IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container); // verify Assert.AreEqual(1, outputUro.Attachments.Count, "Output doesnt contain any attachments"); Assert.IsTrue(outputUro.Attachments[0].Properties["FileName"].EndsWith(".txtx"), "Filename not changed"); string contents = System.IO.File.ReadAllText(outputUro.Attachments[0].FileName); Assert.AreEqual(outputString, contents, "Incorrect contents set"); }
public void ExecuteEventsRaised() { int count = 0; #region setup MockUserAction.MockActionInitializer configuration = Utilities.ThreadSafeLazyLoadSingletonT<MockUserAction.MockActionInitializer>.Instance; configuration.ExecuteMethod = new MockUserAction.ExecuteMethod(delegate(IActionData3 input, ActionPropertySet set) { count++; return input.FileName; } ); configuration.SupportedFiles = SupportedFileSet.CreateFileCollection(".*", ""); List<string> attachments = new List<string>(); attachments.Add(Path.Combine(TEST_FOLDER, "TestProfanity.doc")); attachments.Add(Path.Combine(TEST_FOLDER, "Dirty.doc")); attachments.Add(Path.Combine(TEST_FOLDER, "TestDoc.ppt")); attachments.Add(Path.Combine(TEST_FOLDER, "Test folder\\Sub Folder\\TestDoc.doc")); ReturnData retValue = SetupMockActionTest(attachments); IContainer container = retValue.Container; Workshare.Policy.Engine.Tests.TestUroPolicyEngine.MockProgressCallback policyEvents = new Workshare.Policy.Engine.Tests.TestUroPolicyEngine.MockProgressCallback(); ActionExecuter executer = new ActionExecuter(policyEvents); #endregion //execute IUniversalRequestObject outputUro = executer.ExecuteActions(retValue.Pro, ref container); Assert.AreEqual(outputUro.Attachments.Count, policyEvents.AfterExecuteEventArgs.Count, "{0} before execute events should have been fired", outputUro.Attachments.Count); Assert.AreEqual(outputUro.Attachments.Count, policyEvents.BeforeExecuteEventArgs.Count, "{0} before execute events should have been fired", outputUro.Attachments.Count); Assert.AreEqual(outputUro.Attachments.Count, count, "Expected {0} files to be processed", outputUro.Attachments.Count); }
internal void Work() { try { //prepare CurrentPosition = new GWPosition <PositionData, ActionData>(InputConverter.Convert(Input), 0, null); //CurrentPositions.AddLast(CurrentPosition); var isnewPosition = true; while (CurrentPosition != null && DateTime.Now - StartTime < ComputationTime) { NodesVisited++; //foreach (var position in CurrentPositions) { //gather options: var options = new LinkedList <GWAction <PositionData, ActionData> >(); if (CurrentPosition.HasInitActions) { //options.AddRange(CurrentPosition.UndiscoveredActions); } else { foreach (var actionFinder in ActionFinders) { var foundOptions = actionFinder.FindActions(CurrentPosition); options.AddRange(foundOptions); //TODO: filter double actions (from several actionFinders) } if (options.NullOrEmpty()) { //discovery of ending position EndPositionDiscovered(CurrentPosition); } else { foreach (var actionEvaluator in ActionEvaluators) { actionEvaluator.Weight = Program.Random.NextDouble(); } int tempNr = 0; foreach (var option in options) { option.TempNumber = tempNr; tempNr++; } //evaluateOptions int EachEvaluatorOptions = 5; //int Branches = 50; var optionsScore = new double[options.Count]; foreach (var actionEvaluator in ActionEvaluators) { var bestOptions = new LinkedList <GWAction <PositionData, ActionData> >(); foreach (var option in options) { option.Score = actionEvaluator.Evaluate(option) * actionEvaluator.Weight; bestOptions.SortedInsert(option, EachEvaluatorOptions, o => o.Score); } var bestOptionsList = bestOptions.ToList(); for (int i = 0; i < bestOptionsList.Count; i++) { optionsScore[bestOptionsList[i].TempNumber] += (EachEvaluatorOptions - i) * actionEvaluator.Weight; } } foreach (var option in options) { option.Score = optionsScore[option.TempNumber]; } //CurrentPosition.AddActions(options.MaxEntries(o => o.Score, Branches)); } } if (options.NullOrEmpty()) { //this position is fully discovered BranchingPointsControlUnit.RemoveBranchingPoint(CurrentPosition); CurrentPosition = BranchingPointsControlUnit.GetNextBranchingPoint(); isnewPosition = false; } else { if (isnewPosition) { BranchingPointsControlUnit.AddBranchingPoint(CurrentPosition); } var bestOption = options.MaxEntry(op => op.Score); //execute best Option //var bestOption = ordered_options.First(); var newPosition = ActionExecuter.CreateNewPosition(bestOption); foreach (var evaluator in PositionEvaluators) { newPosition.Score += evaluator.Evaluate(newPosition); } //newPosition.Parents.AddLast(CurrentPosition); //CurrentPosition.Children.AddLast(newPosition); //CurrentPosition.UndiscoveredActions.Remove(bestOption); //CurrentPosition.DiscoveredActions.AddLast(new AgO<GWAction<PositionData, ActionData>, GWPosition<PositionData, ActionData>>(bestOption, null)); //CurrentPosition.DiscoveredActions.AddLast(new AgO<GWAction<PositionData, ActionData>, GWPosition<PositionData, ActionData>>(bestOption, newPosition)); CurrentPosition = newPosition; isnewPosition = true; } } } } catch (Exception e) { Log.Error(e); } }