protected override void BeforeAwake() { BtnCommand = new ButtonCommand(BtnCommand_CanExecute, BtnCommand_Execute); TglCommand = new BoolCommand(TglCommand_CanExecute, TglCommand_Execute); SliderCommand = new FloatCommand(SliderCommand_CanExecute, SliderCommand_Execute); DropdownCommand = new IntCommand(DropdownCommand_CanExecute, DropdownCommand_Execute); InputCommand = new StringCommand(InputCommand_CanExecute, InputCommand_Execute); }
public void GetHashcode_Test() { // Arrange var command = new StringCommand("a", "Test Command A", () => { }); // Act var hashCode = new CommandComparer().GetHashCode(command); // Assert Assert.Equal(command.Id.GetHashCode(), hashCode); }
protected override void _PreRender(CancellationTokenSource tokenSource = null) { _elementData = new EffectIntents(); if (_data == null) { return; } ICommand command = null; switch (ValueType) { case CustomValueType._8Bit: command = new _8BitCommand(Value8Bit); break; case CustomValueType._16Bit: command = new _16BitCommand(Value16Bit); break; case CustomValueType._32Bit: command = new _32BitCommand(Value32Bit); break; case CustomValueType._64Bit: command = new _64BitCommand(Value64Bit); break; case CustomValueType.Color: command = new ColorCommand(ColorValue); break; case CustomValueType.String: command = new StringCommand(StringValue); break; } CommandValue value = new CommandValue(command); foreach (ElementNode node in TargetNodes) { foreach (var leafNode in node.GetLeafEnumerator()) { if (tokenSource != null && tokenSource.IsCancellationRequested) { return; } IIntent intent = new CommandIntent(value, TimeSpan); _elementData.AddIntentForElement(leafNode.Element.Id, intent, TimeSpan.Zero); } } }
public void Command_IsNotNummeric_Test() { // Arrange var command = new StringCommand("A", "Test Command A", () => { }); // Act var isNumeric = command.IsNumericCommand(); // Assert Assert.False(isNumeric); }
public void Initialize_StringCommand_Test() { // Arrange var commandId = "One"; var description = "TestCommand One"; // Act var command = new StringCommand(commandId, description, () => { }); // Assert Assert.NotNull(command); }
public void Initialize_Test() { // Arrange var id = "ID"; var description = "DESCRIPTION"; // Act var command = new StringCommand(id, description, () => { }); // Assert Assert.Equal(id, command.Id); Assert.Equal(description, command.Description); }
//========= HOST EVENTS ========== #region Host Events private void OnHostMessageReceived(Server server, ServerConnection connection, byte[] data, int size) { switch (Command.GetCommandType(data, data.Length)) { case Commands.Login: { var cmd = new StringCommand(data, data.Length); connection.User.IPAddress = connection.IPAddress; connection.User.Port = connection.Port; if (cmd.Text != Config.Syncing.HostPassword) { server.SendToConnection(new Command(Commands.InvalidPassword, Server.ServerName), connection); } else if (userMap.ContainsKey(cmd.Name)) { server.SendToConnection(new Command(Commands.NameTaken, Server.ServerName), connection); } else { connection.User.Name = cmd.Name; connection.IsLoggedIn = true; AddUser(connection.User); server.SendTo(new Command(Commands.AcceptedUser, Server.ServerName), cmd.Name); } break; } case Commands.Ready: { connection.User.Ready = ReadyStates.Ready; int index = userList.IndexOf(connection.User); if (index != -1) { Dispatcher.Invoke(() => { ((HostClientListViewItem)listViewClients.Items[index]).Ready = ReadyStates.Ready; }); } break; } case Commands.NotReady: { connection.User.Ready = ReadyStates.NotReady; int index = userList.IndexOf(connection.User); if (index != -1) { Dispatcher.Invoke(() => { ((HostClientListViewItem)listViewClients.Items[index]).Ready = ReadyStates.NotReady; }); } break; } } }
public void CanPushString() { ParserParameter param = new ParserNamedParameter("Name", false); ParseResult result = new ParseResult(); result.AddCommandValue(param, "value"); var pusher = new CommandPusher(result); var command = new StringCommand(); pusher.Push(command); command.Name.ShouldBe("value"); }
void init() { c = new controller(); v = new view(); render = new RendertoViewcommand(); add = new AddGoodscommand(); once = new Oncesessioncommand(); task = new AddTaskcommand(); rtask = new RenderTaskcommand(); input = new InputFieldcommand(); boolCommend = new BoolCommend(); stringCommand = new StringCommand(); lightImageCommand = new LightImageCommand(); studentCommand = new Studentcommand(); playerCommand = new PlayerCommand(); // Packageview packageview = //THIS IS MORE VIEW BE WRITTER AdjustView(new Packageview()); AdjustView(new dialogview()); AdjustView(new taskview()); AdjustView(new Studentview()); AdjustCommand("once", once); AdjustCommand("RendertoViewcommand", render); AdjustCommand(Cmd.addItem, add); // later will be add delete task AdjustCommand("addtask", task); AdjustCommand("rtask", rtask); //Tip的操作 tip = new TipTaskcommand(); AdjustCommand(Cmd.showTip, tip); colorcommand = new Colorcommand(); AdjustCommand(Cmd.showColor, colorcommand); AdjustCommand(Cmd.ShowImageAndText, input); AdjustCommand(Cmd.changeColor, input); AdjustCommand(Cmd.ChangeBool, boolCommend); AdjustCommand(Cmd.ChangeString, stringCommand); AdjustCommand(Cmd.ChangeColorInImage, lightImageCommand); AdjustCommand(Cmd.DeleteMinScore, studentCommand); AdjustCommand(Cmd.ShowStudentInformtion, studentCommand); AdjustCommand(Cmd.ShowMajorColor, studentCommand); AdjustCommand(Cmd.GetStudentModel, studentCommand); AdjustCommand(Cmd.ImproveAttack, playerCommand); //List<PlayerRoleInfo> playerInfo = ArchiveManager.Instance.GetSamplelist<PlayerRoleInfo>(); //Log(playerInfo[0].Attack); //PlayerRoleInfo player1 = ArchiveManager.Instance.GetSampleInIndex<PlayerRoleInfo>(0); //Debug.Log(player1.BreathingRate); }
public void CommandsContainer_AddStringCommand_Test() { // Arrange var container = new CommandsContainer(); var command = new StringCommand("One", "TestCommand One", () => { }); // Act container.Add(command); // Assert Assert.Contains(command, container.AllCommands); Assert.Contains(command, container.StringCommands); Assert.DoesNotContain(command as Command, container.NumericCommands); Assert.DoesNotContain(command as Command, container.SystemCommands); }
public void Cast_safely_to_context_in_CanExecute_and_Execute() { var sut = new StringCommand(); sut.CanExecute("hello").Should().BeTrue(); sut.CanExecute(string.Empty).Should().BeFalse(); sut.CanExecute(null).Should().BeFalse(); sut.CanExecute(42).Should().BeFalse(); sut.CanExecute(new Uri("http://some/server")).Should().BeFalse(); sut.CanExecute(DateTime.UtcNow).Should().BeFalse(); sut.Execute("hello"); sut.Execute(null); }
public void CommandsContainer_CanNotRegister_Test() { // Arrange var container = new CommandsContainer(); var command = new StringCommand("One", "Test Command 1", () => { }); // Act var canRegister1 = container.CanRegister(command); container.Add(command); var canRegister2 = container.CanRegister(command); // Assert Assert.True(canRegister1); Assert.False(canRegister2); }
public static Command Create(string argname, TypeEnum type, string value) { switch (type) { case TypeEnum.String: return(StringCommand.Create(argname, value)); case TypeEnum.Int: return(IntCommand.Create(argname, value)); case TypeEnum.Bool: return(BooleanCommand.Create(argname, value)); default: // TODO: Handle not supported types throw new NotImplementedException(); } }
void init() { c = new controller(); v = new view(); render = new RendertoViewcommand(); add = new AddGoodscommand(); once = new Oncesessioncommand(); task = new AddTaskcommand(); rtask = new RenderTaskcommand(); input = new InputFieldcommand(); boolCommend = new BoolCommend(); stringCommand = new StringCommand(); lightImageCommand = new LightImageCommand(); studentCommand = new Studentcommand(); // Packageview packageview = //THIS IS MORE VIEW BE WRITTER AdjustView(new Packageview()); AdjustView(new dialogview()); AdjustView(new taskview()); AdjustView(new Studentview()); AdjustCommand("once", once); AdjustCommand("RendertoViewcommand", render); AdjustCommand(Cmd.addItem, add); // later will be add delete task AdjustCommand("addtask", task); AdjustCommand("rtask", rtask); //Tip的操作 tip = new TipTaskcommand(); AdjustCommand(Cmd.showTip, tip); colorcommand = new Colorcommand(); AdjustCommand(Cmd.showColor, colorcommand); AdjustCommand(Cmd.ShowImageAndText, input); AdjustCommand(Cmd.changeColor, input); AdjustCommand(Cmd.ChangeBool, boolCommend); AdjustCommand(Cmd.ChangeString, stringCommand); AdjustCommand(Cmd.ChangeColorInImage, lightImageCommand); AdjustCommand(Cmd.DeleteMinScore, studentCommand); AdjustCommand(Cmd.ShowStudentInformtion, studentCommand); AdjustCommand(Cmd.ShowMajorColor, studentCommand); AdjustCommand(Cmd.GetStudentModel, studentCommand); }
private void RestartMatchers() { logger.Info("Matchers are done. Restarting..."); var ac = new ActionCommand('r', "Restart matchers with the same options.", () => this.matcherRegistry.StartMatchers((MatchMode)this.lastMode)); var cc = new ContinuationCommand('s', "Restart matcher with with new job."); var binaryPath = new StringCommand("Path of the matcher job binary:"); cc.Then(binaryPath).Done(() => { this.JobBinaryPath = binaryPath.Answer; this.matcherRegistry.RestartMatchers(); }); var ch = new ConsoleHandler(new CommandBase[] { ac, cc }); ch.Execute(); }
private ICommand GetCommand(XElement element, object channel) { ICommand command = null; string commandType = GetAttribute(element, "Type"); string commandName = GetAttribute(element, "Name"); if (commandType == "ByteArrayCommand") { if (!string.IsNullOrEmpty(element.Value.Trim())) { command = new ByteArrayCommand(commandName, (IChannel <byte[]>)channel, HexStringToByteArray(element.Value.Trim().Replace(" ", ""))); } else { throw new ElementValueNotFoundException("Command value not found."); } } else if (commandType == "StringCommand") { if (!string.IsNullOrEmpty(element.Value.Trim())) { command = new StringCommand(commandName, (IChannel <string>)channel, element.Value.Trim()); } else { throw new ElementValueNotFoundException("Command value not found."); } } else { throw new UnknownElementException("Unknown command type:" + commandType); } _adapterObjects[_currentAdapterName].Add(command.Name, command); return(command); }
private ICommand GetCommand(XElement element, object channel) { ICommand command = null; string commandType = GetAttribute(element, "Type"); string commandName = GetAttribute(element, "Name"); if (commandType == "ByteArrayCommand") { if (!string.IsNullOrEmpty(element.Value.Trim())) { command = new ByteArrayCommand(commandName, (IChannel<byte[]>)channel, HexStringToByteArray(element.Value.Trim().Replace(" ", ""))); } else { throw new ElementValueNotFoundException("Command value not found."); } } else if (commandType == "StringCommand") { if (!string.IsNullOrEmpty(element.Value.Trim())) { command = new StringCommand(commandName, (IChannel<string>)channel, element.Value.Trim()); } else { throw new ElementValueNotFoundException("Command value not found."); } } else { throw new UnknownElementException("Unknown command type:" + commandType); } _adapterObjects[_currentAdapterName].Add(command.Name, command); return command; }
public override void Handle(StringCommand obj) { Value = obj; }
public void InputCommand(string commandName) { StringCommand command = StringCommands.FirstOrDefault(i => i.CommandName == commandName); command.Command.Invoke(commandName); }
public void AddCommand(StringCommand command) { command.SetVariableDictionary(m_variableDictionary); Add(command); }
public StringConnector(StringCommand command, TextBox control, Label label, CommandCategory category) : base(command, control, label, category) { }
public static ICommand GenerateCommandWithLuaTable(LuaTable vmTable, LuaTable cmdLua) { XLuaCommandCanExecuteHandler commandCanExecute = cmdLua.Get <XLuaCommandCanExecuteHandler>("can_execute"); Func <object, bool> canExecuteDelegate = delegate(object parameter) { if (commandCanExecute == null) { return(true); } else { return(commandCanExecute.Invoke(vmTable, parameter)); } }; ICommand command = null; XLuaCommandType commandType = cmdLua.Get <XLuaCommandType>("type"); switch (commandType) { case XLuaCommandType.Void: XLuaCommandExecuteHandler commandExecute = cmdLua.Get <XLuaCommandExecuteHandler>("execute"); command = new VoidCommand( canExecuteDelegate, delegate(object parameter) { if (commandExecute != null) { commandExecute.Invoke(vmTable, parameter); } } ); break; case XLuaCommandType.Bool: XLuaCommandExecuteHandler <bool> boolCommandExecute = cmdLua.Get <XLuaCommandExecuteHandler <bool> >("execute"); command = new BoolCommand( canExecuteDelegate, delegate(bool v, object parameter) { if (boolCommandExecute != null) { boolCommandExecute.Invoke(vmTable, v, parameter); } } ); break; case XLuaCommandType.Float: XLuaCommandExecuteHandler <float> floatCommandExecute = cmdLua.Get <XLuaCommandExecuteHandler <float> >("execute"); command = new FloatCommand( canExecuteDelegate, delegate(float v, object parameter) { if (floatCommandExecute != null) { floatCommandExecute.Invoke(vmTable, v, parameter); } } ); break; case XLuaCommandType.Int: XLuaCommandExecuteHandler <int> intCommandExecute = cmdLua.Get <XLuaCommandExecuteHandler <int> >("execute"); command = new IntCommand( canExecuteDelegate, delegate(int v, object parameter) { if (intCommandExecute != null) { intCommandExecute.Invoke(vmTable, v, parameter); } } ); break; case XLuaCommandType.String: XLuaCommandExecuteHandler <string> stringCommandExecute = cmdLua.Get <XLuaCommandExecuteHandler <string> >("execute"); command = new StringCommand( canExecuteDelegate, delegate(string v, object parameter) { if (stringCommandExecute != null) { stringCommandExecute.Invoke(vmTable, v, parameter); } } ); break; case XLuaCommandType.Vector2: XLuaCommandExecuteHandler <Vector2> vector2CommandExecute = cmdLua.Get <XLuaCommandExecuteHandler <Vector2> >("execute"); command = new Vector2Command( canExecuteDelegate, delegate(Vector2 v, object parameter) { if (vector2CommandExecute != null) { vector2CommandExecute.Invoke(vmTable, v, parameter); } } ); break; } return(command); }
private StringConnector ConnectStringControl(StringCommand command, TextBox control, Label label, CommandCategory category) { return(new StringConnector(command, control, label, category)); }
protected override void _PreRender(CancellationTokenSource tokenSource = null) { _elementData = new EffectIntents(); if (_data == null) return; ICommand command = null; switch (ValueType) { case CustomValueType._8Bit: command = new _8BitCommand(Value8Bit); break; case CustomValueType._16Bit: command = new _16BitCommand(Value16Bit); break; case CustomValueType._32Bit: command = new _32BitCommand(Value32Bit); break; case CustomValueType._64Bit: command = new _64BitCommand(Value64Bit); break; case CustomValueType.Color: command = new ColorCommand(ColorValue); break; case CustomValueType.String: command = new StringCommand(StringValue); break; } CommandValue value = new CommandValue(command); foreach (ElementNode node in TargetNodes) { foreach (var leafNode in node.GetLeafEnumerator()) { if (tokenSource != null && tokenSource.IsCancellationRequested) return; IIntent intent = new CommandIntent(value, TimeSpan); _elementData.AddIntentForElement(leafNode.Element.Id, intent, TimeSpan.Zero); } } }
public virtual void Handle(StringCommand obj) { }
private void OnClientMessageReceived(ClientConnection client, byte[] data, int size) { switch (Command.GetCommandType(data, data.Length)) { case Commands.InvalidPassword: if (!clientAccepted) { ClientDisconnect(); Dispatcher.Invoke(() => { if (textBoxClientPassword.Text.Length == 0) { TriggerMessageBox.Show(this, MessageIcon.Warning, "A password is required.", "Password Required"); } else { TriggerMessageBox.Show(this, MessageIcon.Warning, "The chosen password is incorrect.", "Invalid Password"); } }); } break; case Commands.NameTaken: if (!clientAccepted) { ClientDisconnect(); Dispatcher.Invoke(() => { if (reconnectWatch.ElapsedMilliseconds < 1200) { TriggerMessageBox.Show(this, MessageIcon.Warning, "You are trying to reconnect to the server too quickly.\nWait at least one second before reconnecting.", "Name Taken"); } else { TriggerMessageBox.Show(this, MessageIcon.Warning, "The chosen username is already in use.", "Name Taken"); } }); } break; case Commands.AcceptedUser: if (!clientAccepted) { // Finish logging in clientAccepted = true; clientTimeout.Stop(); // Update the control states Dispatcher.Invoke(() => { textBoxClientNextSong.IsEnabled = true; numericClientTimeOffset.IsEnabled = true; buttonClientReady.IsEnabled = true; buttonClientConnect.IsEnabled = true; buttonClientConnect.Content = "Disconnect"; }); } break; case Commands.AssingSong: if (clientAccepted) { var cmd = new StringCommand(data, data.Length); clientReady = false; Dispatcher.Invoke(() => { textBoxClientNextSong.Text = cmd.Text; buttonClientReady.Content = "Ready"; }); } break; case Commands.PlaySong: if (clientAccepted && clientReady && !client.IsPlaying) { if (clientPlayThread.ThreadState == System.Threading.ThreadState.Unstarted) { clientPlayTime = new TimeCommand(data, size).DateTime; clientPlayThread.Start(); } else if (clientPlayThread.ThreadState == System.Threading.ThreadState.Stopped) { clientPlayTime = new TimeCommand(data, size).DateTime; clientPlayThread = new Thread(ClientPlay); clientPlayThread.Start(); } } break; case Commands.StopSong: if (clientAccepted && clientReady) { ClientStop(); } break; } }