private void ReceiveMessage() { while (true) { if (m_TcpClient == null || m_TcpClient.Connected == false) { return; } int length = m_TcpClient.Receive(m_ReceiveData); if (length > 0) { //获取长度 int size = BitConverter.ToInt32(m_ReceiveData, 2); //Debug.Log("接收到的数据长度为:" + size); MessageCommand messageCommand = new MessageCommand(m_ReceiveData[0], m_ReceiveData[1], size); byte[] messageBytes = new byte[size]; length = m_TcpClient.Receive(messageBytes); if (length > 0) { //通过UTF8进行操作 messageCommand.Message = messageBytes; //开始对接收到的数据进行处理 MessageModelHandle(messageCommand); } } else { Debug.Log("和服务器断开连接"); } } }
void ISerializable.Deserialize(BinaryReader reader) { Flags = (MessageFlags)reader.ReadByte(); Command = (MessageCommand)reader.ReadByte(); _payload_compressed = reader.ReadVarBytes(PayloadMaxSize); DecompressPayload(); }
private void Consume_Message(MessageCommand command) { var cat = TestData.Cats.FirstOrDefault(); var message = new Message <Cat>(command, cat); MessageConsumer.Consume(message); }
public MainWindow() { this.DataContext = this; MessageCommand = new MessageCommand(Display); SendCommand = new SendCommand(Send); InitializeComponent(); }
public static Message Create(MessageCommand command, ISerializable payload = null) { Message message = new Message { Flags = MessageFlags.None, Command = command, Payload = payload, _payload_compressed = payload?.ToArray() ?? Array.Empty <byte>() }; bool tryCompression = command == MessageCommand.Block || command == MessageCommand.Consensus || command == MessageCommand.Extensible || command == MessageCommand.Transaction || command == MessageCommand.Headers || command == MessageCommand.Addr || command == MessageCommand.MerkleBlock || command == MessageCommand.FilterLoad || command == MessageCommand.FilterAdd; // Try compression if (tryCompression && message._payload_compressed.Length > CompressionMinSize) { var compressed = message._payload_compressed.CompressLz4(); if (compressed.Length < message._payload_compressed.Length - CompressionThreshold) { message._payload_compressed = compressed; message.Flags |= MessageFlags.Compressed; } } return(message); }
/// <summary> /// /// </summary> /// <param name="conversation"></param> /// <param name="avMessage"></param> /// <returns></returns> public Task <AVIMMessage> SendMessageAsync(AVIMConversation conversation, AVIMMessage avMessage) { var cmd = new MessageCommand() .Message(avMessage.EncodeJsonString()) .ConvId(conversation.ConversationId) .Receipt(avMessage.Receipt) .Transient(avMessage.Transient) .AppId(AVClient.ApplicationId) .PeerId(this.clientId); return(AVIMClient.AVCommandRunner.RunCommandAsync(cmd).ContinueWith <AVIMMessage>(t => { if (t.IsFaulted) { throw t.Exception; } else { var response = t.Result.Item2; avMessage.Id = response["uid"].ToString(); avMessage.ServerTimestamp = long.Parse(response["t"].ToString()); return avMessage; } })); }
public async Task <IActionResult> SendMessageCommand(MessageModel model) { var method = new BaseCommands { Method = "Message" }; var messageVariables = new MessageVariables { Msg = model.Msg, Closed = model.Closed }; var messageCommand = new MessageCommand { newMessageVariables = messageVariables, newBaseCommand = method, }; var bots = new GetBotsByStatusQuery { status = model.Force }; var botlist = await _mediator.Send(bots); var response = CommandExecute.TcpConnects(botlist, JsonConvert.SerializeObject(messageCommand).Replace(@"\", "")); return(Json(response)); }
public void ProtocolMessages() { //"T:1:0"(Drink maker makes 1 tea with 1 sugar and a stick) //"H::"(Drink maker makes 1 chocolate with no sugar - and therefore no stick) //"C:2:0"(Drink maker makes 1 coffee with 2 sugars and a stick) //"M:message-content"(Drink maker forwards any message received // onto the coffee machine interface for the customer to see) var cm = new CoffeeMachine(); var coffee = new CoffeeCommand(); var tea = new TeaCommand(3); var hotChocolate = new ExtraHotChocolateCommand(1); var orangeJuice = new OrangeJuiceCommand(); var message = new MessageCommand("HelloWorld!"); var c = cm.Order(coffee, 1); var t = cm.Order(tea, 1); var h = cm.Order(hotChocolate, 1); var o = cm.Order(orangeJuice, 1); var msg = cm.Order(message); var fail = cm.Order(null, 1); Assert.AreEqual(c, "C::"); Assert.AreEqual(t, "T:2:0"); Assert.AreEqual(h, "Hh:1:0"); Assert.AreEqual(o, "O::"); Assert.AreEqual(msg, "M:HelloWorld!"); Assert.That(fail, Is.Null); }
public void UpdateMessageCommand(MessageCommand messageCommand, int pageIndex, int commandIndex, string rules, string comment) { messageCommand.PageIndex = pageIndex; messageCommand.CommandIndex = commandIndex; messageCommand.messageDialogInfo.Rules = rules; messageCommand.messageDialogInfo.Comment = comment; }
internal override MessageCommand BeforeSend(MessageCommand cmd) { var result = base.BeforeSend(cmd); result = result.Binary(this.BinaryData); return(result); }
public void Parse_GoodGetNewCommandText_CorrectGetNewMessagesCommand() { string commandText = GetNewCommandPrefix; MessageCommand result = CommandParser.Parse(commandText); Assert.IsType(typeof(GetNewMessagesCommand), result); }
public ShellViewModel() { base.DisplayName = "Sample App"; Message = new MessageCommand(); this.WhenPropertyChanged(nameof(Item)).ExecuteCommand(Message); }
public Task SendMessageCommand(MessageCommand command, CancellationToken cancellationToken) { return(SendCommand(new WebSocketMessage <MessageCommand> { MessageType = "MessageCommand", Data = command }, cancellationToken)); }
protected virtual void RaiseCanExecuteEvents() { MessageCommand.RaiseCanExecuteChanged(); DeleteCommand.RaiseCanExecuteChanged(); ReadCommand.RaiseCanExecuteChanged(); ChangeCategoryCommand.RaiseCanExecuteChanged(); FollowUpCommand.RaiseCanExecuteChanged(); }
public void SendDragPos(Vector2 pos) { MessageCommand message = new MessageCommand(1, 1, 8); message.WriteFloat(pos.x); message.WriteFloat(pos.y); socketClient.SendMessage(message); }
/// <summary> /// Sends the remove dir. /// </summary> /// <param name="dir">The dir.</param> public void SendRemoveDir(string dir) { MessageCommand mc = new MessageCommand(); mc.CommandID = (int)CommandEnum.CloseCommand; mc.CommandMsg = dir; communicationHandler.Client.Send(mc.ToJSON()); }
/// <summary> /// The function sending to the tcp the command of closed handler to notify all clients /// </summary> /// <param name="dirPath"> dirPath of folder to remove </param> private void RemoveHandlerFromClients(string dirPath) { MessageCommand mc = new MessageCommand(); mc.CommandID = (int)CommandEnum.CloseCommand; mc.CommandMsg = dirPath; m_tcpServer.SendAll(mc.ToJSON()); }
public void Execute(object parameter) { Message outgoingMessage = new MessageCommand(MsgType.Command, SubType.JoinRoom, ((string)parameter), Parent.Username, ""); TCPConnection.Send(outgoingMessage); outgoingMessage = new MessageCommand(MsgType.Command, SubType.Userlist, ((string)parameter), Parent.Username, ""); TCPConnection.Send(outgoingMessage); }
public void Handle <T>(MessageCommand <T> messageCommand) where T : IMessage { if (messageCommand.Content.Type == MessageType.Text) { var c = messageCommand.Content as TextMessage; _clientFront.ShowMsg($"{messageCommand.UserName}:{c.Content}"); } }
public static Message Create(MessageCommand command) { Message message = new Message { Command = command }; return(message); }
private void AppendEntry(MessageCommand command, byte[] data) { FlushTextBuilder(); _entries.Add(new MessageCommandModel { Command = command, Data = data }); }
public NotifyUserMessageEventArgs(string messageKey, MessageIcon icon, MessageCommand command = MessageCommand.DoNothing, object commandParameter = null, MessageFlags flags = MessageFlags.Ignorable, params object[] messageArgs) { MessageKey = messageKey; Icon = icon; Command = command; CommandParameter = commandParameter; Flags = flags; MessageArgs = messageArgs; }
private static void SetControllerData(TController controller, Update update, MessageCommand command, TContext context, TelegramChat chat, ITelegramBotData botData) { controller.Update = update; controller.MessageCommand = command; controller.TelegramContext = context; controller.TelegramChat = chat; controller.BotData = botData; }
public Task SendMessageCommand(MessageCommand command, CancellationToken cancellationToken) { var socket = GetActiveSocket(); return(socket.SendAsync(new WebSocketMessage <MessageCommand> { MessageType = "MessageCommand", Data = command }, cancellationToken)); }
/// <summary> /// Ejecuta un comando /// </summary> private void ExecuteCommand(MessageCommand messageCommand) { if (messageCommand != null && messageCommand.TargetPlugin.EqualsIgnoreCase(FtpManagerViewModel.Instance.ModuleName)) { if (messageCommand.Action.EqualsIgnoreCase("Upload")) { ExecuteUpload(messageCommand.Parameters); } } }
public void Parse_GoodSendCommandText_SendMessageCommand() { string messageText = "message"; string commandText = string.Format("{0} {1}", SendCommandPrefix, messageText); MessageCommand result = CommandParser.Parse(commandText); Assert.Equal(messageText, result.MessageText); Assert.IsType(typeof(SendMessageCommand), result); }
private void SocketClientSendMessage() { if (m_SocketClient == null) { return; } MessageCommand messageCommand = new MessageCommand(0, 0, Encoding.UTF8.GetBytes("客户端给服务器发消息")); m_SocketClient.SendMessage(messageCommand); }
public ActionResult DeleteHandler() { MessageCommand mc = new MessageCommand(); mc.CommandID = (int)CommandEnum.CloseCommand; mc.CommandMsg = m_directory; m_communication.Client.Send(mc.ToJSON()); m_settingsModel.SettingsRequest(); return(RedirectToAction("Settings")); }
/// <summary> /// Posts the specified request. /// </summary> /// <param name="request">The request.</param> public Task Post(SendMessageCommand request) { var command = new MessageCommand { Header = string.IsNullOrEmpty(request.Header) ? "Message from Server" : request.Header, TimeoutMs = request.TimeoutMs, Text = request.Text }; return(_sessionManager.SendMessageCommand(GetSession(_sessionContext).Id, request.Id, command, CancellationToken.None)); }
/// <summary> /// Gets the command. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="DataReceivedEventArgs"/> instance containing the event data.</param> private void GetCommand(object sender, DataReceivedEventArgs e) { Application.Current.Dispatcher.Invoke(new Action(() => { MessageCommand mc = MessageCommand.FromJSON(e.Message); if (m_commands.ContainsKey(mc.CommandID)) { m_commands[mc.CommandID](mc.CommandMsg); } })); }
public virtual MessageCommand CreateMessage(string subject, string text, IInformation senderInformation) { var message = new MessageCommand() { SenderInformation = senderInformation, Subject = subject, Text = text }; return message; }
void HandleMessages(MessageCommand messageCommand, IConnection connection) { Message message = new Message(messageCommand.Payload); OnMessageReceived(new MessageEventArgs(messageCommand.Sender, messageCommand.SenderNickname, message, false)); }
/// <summary> /// Create a command message. /// </summary> /// <param name="controller">Contextual node of the message.</param> /// <param name="command">Command to process.</param> /// <param name="zId">Node identifier to send in message. 0x00 if no node is concerned.</param> /// <returns>Message.</returns> private static MessageToDto CreateCommandMessage(MessageCommand command, DeviceDto controller, int zId = 0) { var result = new MessageToDto { Command = command, IsValid = true, Node = controller, ZIdentifier = (byte)zId, Type = MessageType.Request, }; return result; }
public UserMessageCommandParameter(UserMessageViewModel viewModel, MessageCommand command, object parameter) { ViewModel = viewModel; Command = command; Parameter = parameter; }