/// <summary> /// Please see <seealso cref="IEncodeMessageService{T}.Encode" /> for documentation. /// </summary> /// <param name="sendMessageParameters">-</param> /// <returns>-</returns> public EncodedMessage Encode(SendMessageParameters sendMessageParameters) { var messageHeaderParameters = new MessageHeaderParameters { ApplicationMessageId = sendMessageParameters.ApplicationMessageId, TeamSetContextId = sendMessageParameters.TeamsetContextId ?? "", TechnicalMessageType = sendMessageParameters.TechnicalMessageType, Mode = Mode, Recipients = sendMessageParameters.Recipients }; var messagePayloadParameters = new MessagePayloadParameters { TypeUrl = sendMessageParameters.TypeUrl ?? TechnicalMessageTypes.Empty, Value = ByteString.FromBase64(sendMessageParameters.Base64MessageContent) }; var encodedMessage = new EncodedMessage { Id = Guid.NewGuid().ToString(), Content = EncodeMessageService.Encode(messageHeaderParameters, messagePayloadParameters) }; return(encodedMessage); }
/// <summary> /// The actions for the sender are the following: /// 1. Send the message containing the image file. /// 2. Let the AR process the message for some seconds to be sure (this depends on the use case and is just an example /// time limit) /// 3. Fetch the message response and validate it. /// </summary> private static void ActionsForSender() { var sendMessageService = new SendDirectMessageService(new HttpMessagingService(HttpClientForSender)); var sendMessageParameters = new SendMessageParameters { OnboardResponse = Sender, ApplicationMessageId = MessageIdService.ApplicationMessageId(), TechnicalMessageType = TechnicalMessageTypes.ImgPng, Recipients = new List <string> { Recipient.SensorAlternateId }, Base64MessageContent = DataProvider.ReadBase64EncodedImage() }; sendMessageService.Send(sendMessageParameters); Thread.Sleep(TimeSpan.FromSeconds(2)); var fetchMessageService = new FetchMessageService(HttpClientForSender); var fetch = fetchMessageService.Fetch(Sender); Assert.Single(fetch); var decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message); Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode); }
public void GivenValidMessageContentWhenSendingMessageToSingleRecipientThenTheMessageShouldBeDelivered() { PrepareTestEnvironment(Sender, HttpClientForSender); PrepareTestEnvironment(Recipient, HttpClientForRecipient); var sendMessageService = new SendDirectMessageService(new HttpMessagingService(HttpClientForSender)); var sendMessageParameters = new SendMessageParameters { OnboardResponse = Sender, ApplicationMessageId = MessageIdService.ApplicationMessageId(), TechnicalMessageType = TechnicalMessageTypes.ImgPng, Recipients = new List <string> { Recipient.SensorAlternateId }, Base64MessageContent = DataProvider.ReadBase64EncodedLargeBmp() }; sendMessageService.Send(sendMessageParameters); Thread.Sleep(TimeSpan.FromSeconds(5)); var fetchMessageService = new FetchMessageService(HttpClientForSender); var fetch = fetchMessageService.Fetch(Sender); Assert.Equal(6, fetch.Count); foreach (var messageResponse in fetch) { var decodedMessage = DecodeMessageService.Decode(messageResponse.Command.Message); Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode); } }
public void GivenSmallMessageContentWhenCheckingIfTheMessageHasToBeChunkedThenTheMethodShouldReturnFalse() { var sendMessageParameters = new SendMessageParameters { Base64MessageContent = DataProvider.ReadBase64EncodedSmallShape() }; Assert.False(SendDirectMessageService.MessageHasToBeChunked(sendMessageParameters.Base64MessageContent)); }
/// <summary> /// Checks whether a message has to be chunked or not. /// </summary> /// <param name="sendMessageParameters"></param> /// <returns></returns> public void CheckWetherMessageShouldHaveBeenChunked(SendMessageParameters sendMessageParameters) { var base64MessageContent = sendMessageParameters.Base64MessageContent; var byteCount = Encoding.Unicode.GetByteCount(base64MessageContent); if (byteCount / ChunkSizeDefinition.MaximumSupported > 1) { throw new MessageShouldHaveBeenChunkedException(); } }
public String sendMessage([FromBody] SendMessageParameters sendMessageParameters) { using (OurDBContext db = new OurDBContext()) { var usr = db.userAccount.Single(u => u.UserID == db.session.ToList()[0].UserID); var receiver = db.userAccount.Single(u => u.Username.Equals(sendMessageParameters.Username)); usr.sentMessages.Add(sendMessageParameters.Message, receiver); receiver.personalMessages.Add(sendMessageParameters.Message, usr); } return(sendMessageParameters.Message); }
GivenValidMessageContentWhenPublishingAndSendingMessageToSingleRecipientThenTheMessageShouldBeDelivered() { // Description of the messaging process. // 1. Set all capabilities for each endpoint - this is done once, not each time. SetCapabilitiesForSender(); SetCapabilitiesForRecipient(); // 2. Recipient has to create his subscriptions in order to get the messages. If they are not set correctly the AR will return a HTTP 400. // Done once before the test. // 3. Set routes within the UI - this is done once, not each time. // Done manually, not API interaction necessary. // 4. Publish message from sender to recipient. var publishAndSendMessageService = new PublishAndSendMessageService(new HttpMessagingService(HttpClientForSender)); var sendMessageParameters = new SendMessageParameters { OnboardResponse = Sender, ApplicationMessageId = MessageIdService.ApplicationMessageId(), TechnicalMessageType = TechnicalMessageTypes.ImgPng, Recipients = new List <string> { Recipient.SensorAlternateId }, Base64MessageContent = DataProvider.ReadBase64EncodedImage() }; publishAndSendMessageService.Send(sendMessageParameters); // 5. Let the AR handle the message - this can take up to multiple seconds before receiving the ACK. Thread.Sleep(TimeSpan.FromSeconds(5)); // 6. Fetch and analyze the ACK from the AR. var fetchMessageService = new FetchMessageService(HttpClientForSender); var fetch = fetchMessageService.Fetch(Sender); Assert.Single(fetch); var decodedMessage = DecodeMessageService.Decode(fetch[0].Command.Message); Assert.Equal(201, decodedMessage.ResponseEnvelope.ResponseCode); }
/// <summary> /// Function called to clear all the button's parameters /// </summary> public void Clear() { name = "Button"; buttonStyle = new GUIStyle(); OnClickMessage = new SendMessageParameters(); OnReleaseMessage = new SendMessageParameters(); }
/// <summary> /// Please see base class declaration for documentation. /// </summary> /// <param name="sendMessageParameters">-</param> /// <returns>-</returns> public MessagingResult Send(SendMessageParameters sendMessageParameters) { var encodedMessages = new List <string>(); if (string.IsNullOrWhiteSpace(sendMessageParameters.Base64MessageContent)) { throw new CouldNotSendEmptyMessageException("Sending empty messages does not make any sense."); } if (MessageCanBeChunked(sendMessageParameters.TechnicalMessageType)) { if (MessageHasToBeChunked(sendMessageParameters.Base64MessageContent)) { var chunkContextId = Guid.NewGuid().ToString(); var totalSize = Encoding.Unicode.GetByteCount(sendMessageParameters.Base64MessageContent); var chunkedMessages = ChunkMessageContent(sendMessageParameters.Base64MessageContent, sendMessageParameters.ChunkSize > 0 ? sendMessageParameters.ChunkSize : ChunkSizeDefinition.MaximumSupported); var current = 0; foreach (var chunkedMessage in chunkedMessages) { var sendMessageParametersDuplicate = new SendChunkedMessageParameters { Recipients = sendMessageParameters.Recipients, TypeUrl = sendMessageParameters.TypeUrl, TechnicalMessageType = sendMessageParameters.TechnicalMessageType, ApplicationMessageId = MessageIdService.ApplicationMessageId() }; var chunkComponent = new ChunkComponent { Current = current++, Total = chunkedMessage.Length, ContextId = chunkContextId, TotalSize = totalSize }; sendMessageParametersDuplicate.ChunkInfo = chunkComponent; sendMessageParametersDuplicate.Base64MessageContent = chunkedMessage; encodedMessages.Add(Encode(sendMessageParametersDuplicate).Content); } } else { encodedMessages = new List <string> { Encode(sendMessageParameters).Content }; } } else { encodedMessages = new List <string> { Encode(sendMessageParameters).Content }; } var messagingParameters = sendMessageParameters.BuildMessagingParameter(encodedMessages); return(_messagingService.Send(messagingParameters)); }
private void ShowCircularButtonSendMessageItem(SendMessageParameters _sendMessage) { bool allowSceneObjects = !EditorUtility.IsPersistent(target); _sendMessage.elementToCall = (GameObject)EditorGUILayout.ObjectField("Element to call", _sendMessage.elementToCall, typeof(GameObject), allowSceneObjects); if (_sendMessage.elementToCall != null) { _sendMessage.functionToCall = EditorGUILayout.TextField("Function to call", _sendMessage.functionToCall); _sendMessage.paramType = (SendMessageParameters.UsableParameterType)EditorGUILayout.EnumPopup("Parameter Type", _sendMessage.paramType); switch (_sendMessage.paramType) { case SendMessageParameters.UsableParameterType.Bool: _sendMessage.paramBool = EditorGUILayout.Toggle("Parameter", (bool)_sendMessage.paramBool); break; case SendMessageParameters.UsableParameterType.Float: _sendMessage.paramFloat = EditorGUILayout.FloatField("Parameter", (float)_sendMessage.paramFloat); break; case SendMessageParameters.UsableParameterType.Int: _sendMessage.paramInt = EditorGUILayout.IntField("Parameter", (int)_sendMessage.paramInt); break; case SendMessageParameters.UsableParameterType.String: _sendMessage.paramString = EditorGUILayout.TextField("Parameter", (string)_sendMessage.paramString); break; default: _sendMessage.paramString = EditorGUILayout.TextField("Parameter", (string)_sendMessage.paramString); break; } } }