private static void Wait(ICommandAdapter adapter, int interval) { var sleepCommand = new SleepCommand(); sleepCommand.Parameters.MainParameter = new MainParameter(interval.ToString(CultureInfo.InvariantCulture)); sleepCommand.Execute(adapter); }
protected override void InternalExecute(ICommandAdapter adapter) { var focusWindowCommand = new FocusWindowCommand(); focusWindowCommand.Execute(adapter); var sleepCommand = new SleepCommand(); sleepCommand.Parameters.MainParameter = new MainParameter("300"); sleepCommand.Execute(adapter); var simulator = new InputSimulator(); if (!string.IsNullOrEmpty(Parameters.MainParameter.Value)) { simulator.Keyboard.TextEntry(Parameters.MainParameter.Value); } var keysParameter = Parameters["Keys"]; if (keysParameter != null) { foreach (var key in keysParameter.Value.Split(';')) { var keyCode = (VirtualKeyCode)Enum.Parse(typeof(VirtualKeyCode), key); simulator.Keyboard.KeyPress(keyCode); } } }
public void SetUp() { wakeup = new WakeUpCommand(); engine = new ActiveObjectEngine(); sleep = new SleepCommand(1000, engine, wakeup); engine.AddCommand(sleep); }
public void TestCancelSleep() { var sc = new SleepCommand(TimeSpan.FromMilliseconds(10000)); var script = new Script(); script.AddCommand(sc); OperationCanceledException exception = null; Thread scriptThread = new Thread(() => { try { script.Execute(); } catch (OperationCanceledException e) { exception = e; } }); scriptThread.Start(); script.Cancel(); scriptThread.Join(); Assert.IsNotNull(exception); }
public void Dispose() { SwitchUserCommand?.Dispose(); LockCommand?.Dispose(); SleepCommand?.Dispose(); HibernateCommand?.Dispose(); _subscriptions?.Dispose(); }
public void TestSimple() { SleepCommand sc = new SleepCommand(TimeSpan.FromMilliseconds(10000)); var start = DateTime.Now; sc.Execute(); TimeSpan span = DateTime.Now - start; Assert.That((int)span.TotalMilliseconds, Is.GreaterThanOrEqualTo(10000)); }
private List <string> SensorCommands(int sensorId) { var commands = new List <string>(); commands.Add(StreamReadingsCommand.Create(15000)); commands.Add(SleepCommand.Create(1000)); commands.Add(StatusCommand.Create()); return(commands); }
/// <summary> /// Unityによって呼び出される. /// </summary> private async void Start() { UnityEngine.Debug.Log("start"); SleepCommand sleedCmd = new SleepCommand("5"); { await process.StartCommandAsync(sleedCmd.Invoke()); } UnityEngine.Debug.Log("end"); }
protected override void InternalExecute(ICommandAdapter adapter) { var actionCommand = new ActionCommand(); actionCommand.Parameters.MainParameter = new MainParameter("Log Off"); actionCommand.Parameters.ExtraParameter = new MainParameter(); actionCommand.Execute(adapter); var sleepCommand = new SleepCommand(); sleepCommand.Parameters.MainParameter = new MainParameter("2000"); sleepCommand.Execute(adapter); }
//睡眠 protected virtual CommandReplyType CheckSleep(SleepCommand cmd) { if (CannotControlSelf()) { return(CommandReplyType.NO); } if (GetActorState(ActorStateType.IsDivine)) { return(CommandReplyType.NO); } m_ActorSkill.Clear(); ChangeState <ActorSleepFsm>(cmd); return(CommandReplyType.YES); }
public void TestSleep() { WakeUpCommand wakeUp=new WakeUpCommand(); ActionObjectEngine action=new ActionObjectEngine(); SleepCommand sleep=new SleepCommand(1000,action,wakeUp); action.AddCommand(sleep); DateTime start=DateTime.Now; action.Run(); DateTime stop=DateTime.Now; double sleepTime = (stop - start).TotalMilliseconds; Assert.IsTrue(sleepTime>=1000,"SleetTime "+sleepTime+" expected>1000"); //Assert.IsTrue(sleepTime <= 1000, "SleetTime " + sleepTime + " expected<1000"); Assert.IsTrue(wakeUp.Executed,"Commend Executed"); }
protected override void InternalExecute(ICommandAdapter adapter){ var focusWindowCommand=new FocusWindowCommand(); focusWindowCommand.Execute(adapter); var sleepCommand = new SleepCommand(); sleepCommand.Parameters.MainParameter = new MainParameter("300"); sleepCommand.Execute(adapter); var simulator=new InputSimulator(); if (!string.IsNullOrEmpty(Parameters.MainParameter.Value)) simulator.Keyboard.TextEntry(Parameters.MainParameter.Value); var keysParameter = Parameters["Keys"]; if (keysParameter != null){ foreach (var key in keysParameter.Value.Split(';')){ var keyCode = (VirtualKeyCode) Enum.Parse(typeof (VirtualKeyCode), key); simulator.Keyboard.KeyPress(keyCode); } } }
public void TestSleep() { WakeUpCommand wakeUp = new WakeUpCommand(); ActiveObjectEngine objectEngine = new ActiveObjectEngine(); SleepCommand sleep = new SleepCommand(1000, objectEngine, wakeUp); objectEngine.AddCommand(sleep); DateTime start = DateTime.Now; objectEngine.Run(); DateTime stop = DateTime.Now; double sleepTime = (stop - start).TotalMilliseconds; Assert.IsTrue(sleepTime >= 1000, "SleepTime " + sleepTime + " exepcted > 1000"); Assert.IsTrue(sleepTime <= 1100, "SleepTime " + sleepTime + " exepcted < 1100"); Assert.IsTrue(wakeUp.executed, "Command Executed"); }
public void TestSleep() { WakeUpCommand wakeUp = new WakeUpCommand(); ActiveObjectEngine e = new ActiveObjectEngine(); SleepCommand c = new SleepCommand(1000, e, wakeUp); e.AddCommand(c); DateTime start = DateTime.Now; e.Run(); DateTime stop = DateTime.Now; double sleepTime = (stop - start).TotalMilliseconds; Assert.IsTrue(sleepTime >= 1000, $"SleepTime {sleepTime} expected > 1000"); Assert.IsTrue(sleepTime <= 1000, $"SleepTime {sleepTime} expected < 1000"); Assert.IsTrue(wakeUp.executed, "Command executed"); }
protected override void InternalExecute(ICommandAdapter adapter) { base.InternalExecute(adapter); var sleepCommand = new SleepCommand(); sleepCommand.Parameters.MainParameter = new MainParameter("1000"); sleepCommand.Execute(adapter); var actionCommand = new ActionCommand(); actionCommand.Parameters.MainParameter = new MainParameter("Delete"); actionCommand.Parameters.ExtraParameter = new MainParameter(); actionCommand.Execute(adapter); var handleDialogCommand = new XpandHandleDialogCommand(); handleDialogCommand.Parameters.Add(new Parameter("Respond", "Yes", true, EndPosition)); handleDialogCommand.Execute(adapter); }
protected override void InternalExecute(ICommandAdapter adapter) { var deleteFileCommand = new XpandDeleteFileCommand(); deleteFileCommand.Parameters.MainParameter = Parameters.MainParameter; deleteFileCommand.Parameters.Add(new Parameter(XpandDeleteFileCommand.InBin, "True", true, EndPosition)); deleteFileCommand.Execute(adapter); var binPath = this.GetBinPath(); var fillFormCommand = new XpandFillFormCommand(); fillFormCommand.Parameters.Add(new Parameter("File name:", Path.Combine(binPath, Parameters.MainParameter.Value), true, EndPosition)); fillFormCommand.Execute(adapter); var handleDialogCommand = new XpandHandleDialogCommand(); handleDialogCommand.Parameters.Add(new Parameter("Respond", ButtonLocalizations.GetLocalizedButtonCaption("Save"), true, EndPosition)); handleDialogCommand.Execute(adapter); var sleepCommand = new SleepCommand(); sleepCommand.Parameters.MainParameter = new MainParameter("1000"); sleepCommand.Execute(adapter); }
/// <summary> /// This method checks if the command line has a valid insert command at the valid position. /// </summary> /// <param name="commandLine">The command line the user has written.</param> /// <exception cref="ArgumentNullException"> /// If the commandLine is null. /// </exception> /// <returns>An instanced insert command if the command is valid or null if the command is not valid.</returns> public static IEditorCommand Parse(string commandLine) { if (commandLine == null) { throw new ArgumentNullException(); } string[] possibleCommands = commandLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (possibleCommands.Length < 3) { return(null); } string value = possibleCommands[1]; int editorValue; try { editorValue = int.Parse(value); } catch { return(null); } string[] newpossibleCommands = new string[possibleCommands.Length - 1]; newpossibleCommands[0] = possibleCommands[0]; if (newpossibleCommands.Length == 2) { newpossibleCommands[1] = possibleCommands[2]; } else if (newpossibleCommands.Length == 3) { newpossibleCommands[1] = possibleCommands[2]; newpossibleCommands[2] = possibleCommands[3]; } commandLine = string.Join(" ", newpossibleCommands); string command = newpossibleCommands[1].ToLower(); ITurtleCommand turtleCommand = null; switch (command) { case "move": turtleCommand = MoveCommand.Parse(commandLine); break; case "rotate": turtleCommand = RotateCommand.Parse(commandLine); break; case "sleep": turtleCommand = SleepCommand.Parse(commandLine); break; case "penup": turtleCommand = PenUpCommand.Parse(commandLine); break; case "pendown": turtleCommand = PenDownCommand.Parse(commandLine); break; case "changecolor": turtleCommand = ChangeColorCommand.Parse(commandLine); break; case "changetracksymbol": turtleCommand = ChangeTrackSymbolCommand.Parse(commandLine); break; case "changeturtlesymbol": turtleCommand = ChangeTurtleSymbolCommand.Parse(commandLine); break; } if (turtleCommand != null && editorValue > 0) { turtleValue = turtleCommand.GetValue(); return(new InsertCommand(editorValue, turtleCommand)); } else { return(null); } }
/// <summary> /// This method checks if the command line has a valid add command at the valid position. /// </summary> /// <param name="commandLine">The command line the user has written.</param> /// <exception cref="ArgumentNullException"> /// If the commandLine is null. /// </exception> /// <returns>An instanced add command if the command is valid or null if the command is not valid.</returns> public static IEditorCommand Parse(string commandLine) { if (commandLine == null) { throw new ArgumentNullException(); } string[] possibleCommands = commandLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (possibleCommands.Length <= 1 || possibleCommands.Length >= 4) { return(null); } string command = possibleCommands[1].ToLower(); ITurtleCommand turtleCommand = null; switch (command) { case "move": turtleCommand = MoveCommand.Parse(commandLine); break; case "rotate": turtleCommand = RotateCommand.Parse(commandLine); break; case "sleep": turtleCommand = SleepCommand.Parse(commandLine); break; case "penup": turtleCommand = PenUpCommand.Parse(commandLine); break; case "pendown": turtleCommand = PenDownCommand.Parse(commandLine); break; case "changecolor": turtleCommand = ChangeColorCommand.Parse(commandLine); break; case "changetracksymbol": turtleCommand = ChangeTrackSymbolCommand.Parse(commandLine); break; case "changeturtlesymbol": turtleCommand = ChangeTurtleSymbolCommand.Parse(commandLine); break; } if (turtleCommand != null) { return(new AddCommand(turtleCommand)); } else { return(null); } }
bool HandleCommand(Plugin plugin, Sequence sequence, XmlNode commandNode, ref string errorString) { string sCommandName = commandNode.Name; string sCommandDestination; XmlNode commandSource1; string sCommandSource1; bool bIsCommandSource1Variable; XmlNode commandSource2; string sCommandSource2; bool bIsCommandSource2Variable; switch (sCommandName) { case "CatenateString": sCommandDestination = commandNode.SelectSingleNode("Destination").InnerText; if (plugin.GetVariable(sCommandDestination) == null) { errorString = "Invalid Catenate String Destination"; return(false); } commandSource1 = commandNode.SelectSingleNode("Source1"); if (commandSource1.HasChildNodes && commandSource1.ChildNodes[0].NodeType != XmlNodeType.Text) { sCommandSource1 = commandSource1.ChildNodes[0].InnerText; bIsCommandSource1Variable = true; if (plugin.GetVariable(sCommandSource1) == null) { errorString = "Invalid Catenate String Source1"; return(false); } } else { sCommandSource1 = commandSource1.InnerText; bIsCommandSource1Variable = false; } commandSource2 = commandNode.SelectSingleNode("Source2"); if (commandSource2.HasChildNodes && commandSource2.ChildNodes[0].NodeType != XmlNodeType.Text) { sCommandSource2 = commandSource2.ChildNodes[0].InnerText; bIsCommandSource2Variable = true; if (plugin.GetVariable(sCommandSource2) == null) { errorString = "Invalid Catenate String Source2"; return(false); } } else { sCommandSource2 = commandSource2.InnerText; bIsCommandSource2Variable = false; } CatenateStringCommand catenateCommand = new CatenateStringCommand(sCommandDestination, sCommandSource1, bIsCommandSource1Variable, sCommandSource2, bIsCommandSource2Variable); sequence.AddCommand(catenateCommand); break; case "Click": sCommandDestination = commandNode.SelectSingleNode("Destination").InnerText; ClickElementWebDriverCommand clickCommand = new ClickElementWebDriverCommand(sCommandDestination); sequence.AddCommand(clickCommand); break; case "GetItem": string sGetItemName = commandNode.Attributes["name"].Value.ToLower(); string sGetItemParentElement = commandNode.SelectSingleNode("ParentElement").InnerText.ToLower(); string sGetItemSearchType = commandNode.SelectSingleNode("SearchType").InnerText.ToLower(); string sGetItemSearchValue = commandNode.SelectSingleNode("SearchValue").InnerText; if (sGetItemName == "" || sGetItemSearchType == "" || sGetItemSearchValue == "") { errorString = "Invalid Get Item name \"" + sGetItemName; return(false); } if (sGetItemParentElement != "" && plugin.GetWebElement(sGetItemParentElement) == null) { errorString = "Invalid Get Item parent element"; return(false); } if (sGetItemSearchType == "id") { GetElementByIdWebDriverCommand getItemByID = new GetElementByIdWebDriverCommand(sGetItemParentElement, sGetItemName, sGetItemSearchValue); sequence.AddCommand(getItemByID); } else if (sGetItemSearchType == "xpath") { GetElementByXPathWebDriverCommand getItemByXPath = new GetElementByXPathWebDriverCommand(sGetItemParentElement, sGetItemName, sGetItemSearchValue); sequence.AddCommand(getItemByXPath); } break; case "GoBack": GoBackWebDriverCommand goBackCommand = new GoBackWebDriverCommand(); sequence.AddCommand(goBackCommand); break; case "GoTo": string sGoToDestination; bool bGoToDestIsVariable; if (commandNode.HasChildNodes && commandNode.ChildNodes[0].NodeType != XmlNodeType.Text) { sGoToDestination = commandNode.ChildNodes[0].InnerText.ToLower(); bGoToDestIsVariable = true; if (plugin.GetVariable(sGoToDestination) == null) { errorString = "Invalid GoTo Destination"; return(false); } } else { sGoToDestination = commandNode.InnerText; bGoToDestIsVariable = false; } GoToWebDriverCommand goToCommand = new GoToWebDriverCommand(sGoToDestination, bGoToDestIsVariable); sequence.AddCommand(goToCommand); break; case "Refresh": RefreshWebDriverCommand refreshCommand = new RefreshWebDriverCommand(); sequence.AddCommand(refreshCommand); break; case "Type": sCommandDestination = commandNode.SelectSingleNode("Destination").InnerText.ToLower(); string sTypeValue; bool bTypeIsVariable; if (commandNode.HasChildNodes && commandNode.ChildNodes[0].NodeType != XmlNodeType.Text) { sTypeValue = commandNode.SelectSingleNode("String").ChildNodes[0].InnerText.ToLower(); bTypeIsVariable = true; if (plugin.GetVariable(sTypeValue) == null) { errorString = "Invalid Type Command Variable"; return(false); } } else { sTypeValue = commandNode.InnerText; bTypeIsVariable = false; } TypeElementWebDriverCommand typeCommand = new TypeElementWebDriverCommand(sCommandDestination, sTypeValue, bTypeIsVariable); sequence.AddCommand(typeCommand); break; case "Sleep": int dwSleepTime = Int32.Parse(commandNode.InnerText); SleepCommand sleepCommand = new SleepCommand(dwSleepTime); sequence.AddCommand(sleepCommand); break; case "SetVariable": string sSetVariableName = commandNode.SelectSingleNode("Destination").InnerText; string sSetVariableValue = commandNode.SelectSingleNode("String").InnerText; SetVariableCommand setVariableCommand = new SetVariableCommand(sSetVariableName, sSetVariableValue); sequence.AddCommand(setVariableCommand); break; case "IncreaseVariable": string sIncreaseVariableName = commandNode.SelectSingleNode("Destination").InnerText; int dwIncreaseVariableValue = Int32.Parse(commandNode.SelectSingleNode("String").InnerText); IncreaseVariableCommand increaseVariableCommand = new IncreaseVariableCommand(sIncreaseVariableName, dwIncreaseVariableValue); sequence.AddCommand(increaseVariableCommand); break; default: errorString = "Invalid command " + sCommandName + " in sequence " + sequenceName; return(false); } }