private async Task <CommunicationMessage> GenerateMessageForAggregateMessagesAsync(AggregateCommunicationRequest request, IEnumerable <CommunicationMessage> messages) { var templateMessage = GetTemplateMessageFromMessagesToBeAggregated(messages); var aggregatedMessage = new CommunicationMessage { Id = request.RequestId, RequestDateTime = request.RequestDateTime, ParticipantsResolverName = templateMessage.ParticipantsResolverName, OriginatingServiceName = templateMessage.OriginatingServiceName, Recipient = new CommunicationUser(templateMessage.Recipient.UserId, templateMessage.Recipient.Email, templateMessage.Recipient.Name, templateMessage.Recipient.UserType, UserParticipation.PrimaryUser), RequestType = request.RequestType, Channel = templateMessage.Channel, Frequency = DeliveryFrequency.Immediate, TemplateId = templateMessage.TemplateId }; var compositeDataItemProvider = _compositeDataItemProviders[templateMessage.RequestType]; var consolidatedMessageData = await compositeDataItemProvider.GetConsolidatedMessageDataItemsAsync(aggregatedMessage, messages); if (consolidatedMessageData != null && consolidatedMessageData.Any()) { aggregatedMessage.DataItems = consolidatedMessageData.ToList(); } return(aggregatedMessage); }
internal async Task <TReturn> Request <TReturn>(string @event, params object[] args) { var message = new CommunicationMessage(@event, this); var tcs = new TaskCompletionSource <TReturn>(); try { On($"{message.Id}:{@event}", new Action <ICommunicationMessage, TReturn>((e, data) => { tcs.SetResult(data); })); this._logger.Trace(args.Length > 0 ? $"Request Emit: \"{@event}\" with {args.Length} payload(s): {string.Join(", ", args.Select(a => a?.ToString() ?? "NULL"))}" : $"Fire: \"{@event}\" without payload"); lock (this._subscriptions) { var payload = new List <object> { message }; payload.AddRange(args); this._subscriptions.Single(s => s.Key == @event).Value.Single().DynamicInvoke(payload.ToArray()); } return(await tcs.Task); } finally { lock (this._subscriptions) { this._subscriptions.Remove($"{message.Id}:{@event}"); } } }
private void SendMessageList(string teamId, bool useMulticast) { object[] messages; lock (_messageQueue.SyncRoot) { messages = _messageQueue.ToArray(); } List <CommunicationMessage> messagesToSend = new List <CommunicationMessage>(); int numberSend = 0; for (int i = messages.Length - 1; i >= 0; i--) { CommunicationMessage message = (CommunicationMessage)messages[i]; if (string.IsNullOrEmpty(message.GetTeamId()) || message.GetTeamId().Equals(teamId, StringComparison.OrdinalIgnoreCase)) { CommunicationMessage newMessage = new CommunicationMessage(message.Data); newMessage.SetTeamId(teamId); newMessage.IsMulticast = useMulticast; newMessage.SetSynchronizedFlag(); messagesToSend.Add(newMessage); numberSend++; if (numberSend >= 50) { break; } } } for (int i = messagesToSend.Count - 1; i >= 0; i--) { _server.Enqueue(messagesToSend[i]); } }
///<summary> Reads this CommunicationMessage from the specified stream.</summary> ///<param name="reader"> the input stream to read from</param> ///<returns> the object</returns> ///<exception cref="System.IO.IOException"> if an error occurs</exception> public override object Deserialize(HlaEncodingReader reader, ref object msg) { CommunicationMessage decodedValue; if (!(msg is CommunicationMessage)) { decodedValue = new CommunicationMessage(); BaseInteractionMessage baseMsg = msg as BaseInteractionMessage; decodedValue.InteractionClassHandle = baseMsg.InteractionClassHandle; decodedValue.FederationExecutionHandle = baseMsg.FederationExecutionHandle; decodedValue.UserSuppliedTag = baseMsg.UserSuppliedTag; } else { decodedValue = msg as CommunicationMessage; } //object tmp = decodedValue; //decodedValue = base.Deserialize(reader, ref tmp) as CommunicationMessage; try { decodedValue.Message = reader.ReadHLAunicodeString(); } catch (System.IO.IOException ioe) { throw new RTIinternalError(ioe.ToString()); } return decodedValue; }
public void TestCommunicationMessage() { lock (syncObject) { long ticks = System.DateTime.Now.Ticks; CommunicationMessage msg = new CommunicationMessage(); msg.FederationExecutionHandle = 10; msg.UserSuppliedTag = BitConverter.GetBytes(ticks); msg.Message = "Say Hello"; channel.OutputStream.Position = 0; helper.SendInteraction(msg); channel.InputStream.Position = 0; myListener.LastMessage = null; reliableChannel.ReliableRead(); System.Threading.Monitor.Wait(syncObject, milliSeconds); if (!(myListener.LastMessage is CommunicationMessage)) { throw new RTIexception("Error reading CommunicationMessage"); } else { CommunicationMessage lastMsg = myListener.LastMessage as CommunicationMessage; Assert.AreEqual(msg.FederationExecutionHandle, lastMsg.FederationExecutionHandle); Assert.AreEqual(msg.InteractionClassHandle, lastMsg.InteractionClassHandle); Assert.AreEqual(msg.UserSuppliedTag, lastMsg.UserSuppliedTag); Assert.AreEqual(msg.Message, lastMsg.Message); } } }
private JoinResponseCommMessage SendMessagesJoin(int userId, IEnumerator <ActionResultInfo> iterator, CommunicationMessage originalMsg) { JoinResponseCommMessage response = null; GameDataCommMessage gameData = null; bool found = false; while (iterator.MoveNext()) { var curr = iterator.Current; if (curr != null && curr.Id != userId) { gameData = curr.GameData; _commHandler.AddMsgToSend(_parser.SerializeMsg(curr.GameData, ShouldUseDelim), curr.Id); } else if (curr != null) { found = true; gameData = curr.GameData; response = new JoinResponseCommMessage(_sessionIdHandler.GetSessionIdByUserId(userId), userId, curr.GameData.IsSucceed, originalMsg, curr.GameData); response.SetGameData(curr.GameData); } } if (!found && gameData != null) { response = new JoinResponseCommMessage(_sessionIdHandler.GetSessionIdByUserId(userId), userId, gameData.IsSucceed, originalMsg, gameData); response.SetGameData(gameData); } return(response); }
static async Task Main(string[] args) { if (args.Length < 2) { Console.WriteLine("PlcName IP Port"); Console.WriteLine("Example: PlcName 192.168.100.10 20256"); } else { try { var plc = new PcomTcpClient(new CancellationTokenSource(), null); await plc.TcpClient.ConnectAsync(args[1], int.Parse(args[2])); var message = new CommunicationMessage(); var plcName = plc.SendAndReceive(message.GetPlcName()); Console.WriteLine("PlcName: " + plcName); Console.ReadLine(); } catch (Exception e) { Console.WriteLine("Något gick fel!, Kontrollera IP och Port"); Console.WriteLine("Example: PlcName 192.168.100.10 20256"); Console.ReadLine(); } } }
public void OnReceiveCommunication(CommunicationMessage msg) { message = msg; if (log.IsDebugEnabled) log.Debug("Received LastMessage = " + msg.ToString()); PulseMonitor(); }
public void SendMessage(CommunicationMessage message) { IClientProxy proxy = null; switch (message.CommunicationType) { case RecipientType.Broadcast: proxy = Clients.All; break; case RecipientType.Organization: proxy = Clients.Group(GetGroupName()); break; case RecipientType.User: proxy = Clients.Client(GetConnectionid(message.UserId)); break; } proxy?.Invoke(_clientReceiveMessageMethodName, message); if (message.IsPersist) { var repository = new MessageRepository(); repository.InsertMessage(message); } }
public void Emit(string @event, params object[] args) { lock (this._subscriptions) { if (!this._subscriptions.ContainsKey(@event)) { return; } var message = new CommunicationMessage(@event, this); this._logger.Trace(args.Length > 0 ? $"Emit: \"{@event}\" with {args.Length} payload(s): {string.Join(", ", args.Select(a => a?.ToString() ?? "NULL"))}" : $"Emit: \"{@event}\" without payload"); foreach (var subscription in this._subscriptions[@event]) { var payload = new List <object> { message }; payload.AddRange(args); subscription.DynamicInvoke(payload.ToArray()); } } }
public void Process(CommunicationMessage msg) { lock (lockObj) { communicationMessageCount++; } }
public async Task CreateAndSendReciveMessage() { var cMessage = new CommunicationMessage(); var MI10 = new MIReadOperation(10, 1); cMessage.AddOperation(MI10); cMessage.AddOperation(new MIWriteOperation(12, 1)); var client = new PcomTcpClient(new CancellationTokenSource(), new FileLogger(new FileLoggerSettings { BytesPerLine = 16, FileName = string.Empty, //Use this file to hexdump messages sent ShowAscii = false, ShowHeader = true, ShowOffset = true })); await client.TcpClient.ConnectAsync("192.168.100.101", 20258); if (client.TcpClient.Connected) { var response = await client.SendAndReceive(cMessage.GetMessage()); cMessage.ParseMessage(response); Assert.AreNotEqual(0, MI10.GetValue(0)); } else { throw new Exception("Not Connected"); } }
public Task InsertAsync(CommunicationMessage msg) { var collection = GetCollection <CommunicationMessage>(); return(RetryPolicy.Execute(_ => collection.InsertOneAsync(msg), new Context(nameof(InsertAsync)))); }
private void HandleClientAuthenticated(object sender, CommunicationMessage e) { Infragistics.Win.UltraWinTree.UltraTreeNode UnauthenticatedClientNode = trvConnectedClients.GetNodeByKey(e.UserID + " on " + e.SenderID); UnauthenticatedClientNode.Remove(); Infragistics.Win.UltraWinTree.UltraTreeNode authenticatedClientNodeParent = trvConnectedClients.Nodes[1]; Infragistics.Win.UltraWinTree.UltraTreeNode authenticatedClientNode = new Infragistics.Win.UltraWinTree.UltraTreeNode(e.UserID + " on " + e.SenderID); authenticatedClientNodeParent.Nodes.Add(authenticatedClientNode); }
public void OnReceiveCommunication(CommunicationMessage msg) { message = msg; if (log.IsDebugEnabled) { log.Debug("Received LastMessage = " + msg.ToString()); } PulseMonitor(); }
//public override void Notify(IResponseNotifier notifier, ResponeCommMessage response) //{ // notifier.Notify(response.OriginalMsg, response); //} public override bool Equals(CommunicationMessage other) { if (other != null && other.GetType() == typeof(ReturnToGameAsPlayerCommMsg)) { var afterCasting = (ReturnToGameAsPlayerCommMsg)other; return(RoomId == afterCasting.RoomId && UserId == afterCasting.UserId); } return(false); }
//public override void Notify(IResponseNotifier notifier, ResponeCommMessage response) //{ // notifier.Notify(response.OriginalMsg, response); //} public override bool Equals(CommunicationMessage other) { if (other != null && other.GetType() == typeof(ActionCommMessage)) { var afterCasting = (ActionCommMessage)other; return(Amount == afterCasting.Amount && RoomId == afterCasting.RoomId && UserId == afterCasting.UserId); } return(false); }
//public override void Notify(IResponseNotifier notifier, ResponeCommMessage response) //{ // notifier.Notify(response.OriginalMsg, response); //} public override bool Equals(CommunicationMessage other) { if (other != null && other.GetType() == typeof(SearchCommMessage)) { var afterCasting = (SearchCommMessage)other; return searchType == afterCasting.searchType && SearchByString.Equals(afterCasting.SearchByString) && UserId == afterCasting.UserId && SearchByInt == afterCasting.SearchByInt; } return false; }
//public override void Notify(IResponseNotifier notifier, ResponeCommMessage msg) //{ // notifier.Notify(OriginalMsg, this); //} public override bool Equals(CommunicationMessage other) { if (other != null && other.GetType() == typeof(CreateNewGameResponse)) { var afterCasting = (CreateNewGameResponse)other; return(Success == afterCasting.Success && OriginalMsg.Equals(afterCasting.OriginalMsg) && UserId == afterCasting.UserId && GameData.Equals(afterCasting.GameData)); } return(false); }
public void InsertMessage(CommunicationMessage message) { string insertQuery = "INSERT INTO dbo.Messages (UserId, OrganizationId, Title, Message, CommunicationType, IsPersist, IsRead) Values (@UserId, @OrganizationId, @Title, @Message, @CommunicationType, @IsPersist, @IsRead);"; using (var connection = new SqlConnection(_connectionString)) { connection.Open(); connection.ExecuteAsync(insertQuery, message); } }
//another visitor //public override void Notify(IResponseNotifier notifier, ResponeCommMessage msg) //{ // notifier.Notify(OriginalMsg, this); //} public override bool Equals(CommunicationMessage other) { if (other != null && other.GetType() == typeof(ResponeCommMessage)) { var afterCasting = (ResponeCommMessage)other; return(Success == afterCasting.Success && OriginalMsg.Equals(afterCasting.OriginalMsg) && UserId == afterCasting.UserId); } return(false); }
//public override void Notify(IResponseNotifier notifier, ResponeCommMessage msg) //{ // notifier.Notify(OriginalMsg, this); //} public override bool Equals(CommunicationMessage other) { if (other != null && other.GetType() == typeof(ReplaySearchResponseCommMessage)) { var afterCasting = (ReplaySearchResponseCommMessage)other; bool same = afterCasting.RoomId == RoomId && afterCasting.UserId == UserId; return(same); } return(false); }
/// <summary> /// Sends a message to all clients. /// </summary> public void BroadcastMessage(T data, Action <CallbackArgs> responseHandler = null) { var msg = new CommunicationMessage { From = _coordinator.ClientDevice.Identity }; msg.SetValue(data); _coordinator.SendMessage(msg, responseHandler); }
//public override void Notify(IResponseNotifier notifier, ResponeCommMessage response) //{ // notifier.Notify(response.OriginalMsg, response); //} public override bool Equals(CommunicationMessage other) { if (other != null && other.GetType() == typeof(EditCommMessage)) { var afterCasting = (EditCommMessage)other; return(FieldToEdit == afterCasting.FieldToEdit && NewValue == afterCasting.NewValue && UserId == afterCasting.UserId); } return(false); }
//public override void Notify(IResponseNotifier notifier, ResponeCommMessage response) //{ // notifier.Notify(response.OriginalMsg, response); //} public override bool Equals(CommunicationMessage other) { if (other != null && other.GetType() == typeof(ChatCommMessage)) { var afterCasting = (ChatCommMessage)other; return(IdSender == afterCasting.IdSender && RoomId == afterCasting.RoomId && UserId == afterCasting.UserId && ChatType == afterCasting.ChatType && MsgToSend.Equals(afterCasting.MsgToSend)); } return(false); }
public Task UpdateAsync(CommunicationMessage commMsg) { var filter = Builders <CommunicationMessage> .Filter.Eq(cm => cm.Id, commMsg.Id); var collection = GetCollection <CommunicationMessage>(); return(RetryPolicy.Execute(_ => collection.ReplaceOneAsync(filter, commMsg), new Context(nameof(UpdateAsync)))); }
//public override void Notify(IResponseNotifier notifier, ResponeCommMessage response) //{ // notifier.Notify(response.OriginalMsg, response); //} public override bool Equals(CommunicationMessage other) { if (other != null && other.GetType() == typeof(LoginCommMessage)) { var afterCasting = (LoginCommMessage)other; return(IsLogin == afterCasting.IsLogin && UserName.Equals(afterCasting.UserName) && UserId == afterCasting.UserId && Password.Equals(afterCasting.Password)); } return(false); }
} //for parsing public ChatResponceCommMessage(int _roomId, int _idReciver, long sid, string _senderngUsername, ActionType _chatType, string _msgToSend, int id, bool success, CommunicationMessage originalMsg) : base(id, sid, success, originalMsg) { idReciver = _idReciver; senderngUsername = _senderngUsername; chatType = _chatType; msgToSend = _msgToSend; roomId = _roomId; }
//public override void Notify(IResponseNotifier notifier, ResponeCommMessage response) //{ // notifier.Notify(response.OriginalMsg, response); //} public override bool Equals(CommunicationMessage other) { bool ans = false; if (other.GetType() == typeof(LeaderboardCommMessage)) { var afterCast = (LeaderboardCommMessage)other; ans = UserId == afterCast.UserId && SortedBy.Equals(afterCast.SortedBy); } return(ans); }
//public override void Notify(IResponseNotifier notifier, ResponeCommMessage response) //{ // notifier.Notify(response.OriginalMsg, response); //} public override bool Equals(CommunicationMessage other) { if (other != null && other.GetType() == typeof(RegisterCommMessage)) { var afterCasting = (RegisterCommMessage)other; return(Money == afterCasting.Money && Name.Equals(afterCasting.Name) && MemberName.Equals(afterCasting.MemberName) && UserId == afterCasting.UserId && Password.Equals(afterCasting.Password)); } return(false); }
public Task <string> GetTemplateIdAsync(CommunicationMessage message) { var templateId = string.Empty; switch (message.RequestType) { case CommunicationConstants.RequestType.VacancySubmittedForReview: templateId = CommunicationConstants.TemplateIds.VacancySubmittedForReview; break; case CommunicationConstants.RequestType.VacancyRejected: templateId = CommunicationConstants.TemplateIds.VacancyRejected; break; case CommunicationConstants.RequestType.VacancyRejectedByEmployer: templateId = CommunicationConstants.TemplateIds.VacancyRejectedByEmployer; break; case CommunicationConstants.RequestType.ApplicationSubmitted: if (_digestDeliveryFrequencies.Contains(message.Frequency)) { templateId = CommunicationConstants.TemplateIds.ApplicationsSubmittedDigest; } else { templateId = CommunicationConstants.TemplateIds.ApplicationSubmittedImmediate; } break; case CommunicationConstants.RequestType.VacancyWithdrawnByQa: templateId = CommunicationConstants.TemplateIds.VacancyWithdrawnByQa; break; case CommunicationConstants.RequestType.ProviderBlockedProviderNotification: templateId = CommunicationConstants.TemplateIds.ProviderBlockedProviderNotification; break; case CommunicationConstants.RequestType.ProviderBlockedEmployerNotificationForTransferredVacancies: templateId = CommunicationConstants.TemplateIds.ProviderBlockedEmployerNotificationForTransferredVacancies; break; case CommunicationConstants.RequestType.ProviderBlockedEmployerNotificationForLiveVacancies: templateId = CommunicationConstants.TemplateIds.ProviderBlockedEmployerNotificationForLiveVacancies; break; case CommunicationConstants.RequestType.ProviderBlockedEmployerNotificationForPermissionOnly: templateId = CommunicationConstants.TemplateIds.ProviderBlockedEmployerNotificationForPermissionsOnly; break; default: throw new NotImplementedException($"Template for request type {message.RequestType} is not defined."); } return(Task.FromResult(templateId)); }
//public override void Notify(IResponseNotifier notifier, ResponeCommMessage msg) //{ // notifier.Notify(OriginalMsg, this); //} public override bool Equals(CommunicationMessage other) { if (other != null && other.GetType() == typeof(SearchResponseCommMessage)) { var afterCasting = (SearchResponseCommMessage)other; return(Success == afterCasting.Success && OriginalMsg.Equals(afterCasting.OriginalMsg) && UserId == afterCasting.UserId && Games.TrueForAll(g => afterCasting.Games.Contains(g))); } return(false); }