Example #1
0
 static void ReplyThreadLoop()
 {
    while (true)
    {
       if (_clientProcIds.Count > 0)
       {
          lock (_syncLock)
          {
             var cpu = getCurrentCpuUsage();
             var ram = getAvailableRAM();
             foreach (var client in _clientProcIds)
             {
                var response = new ResponseMessage(client.Value.Item1);
                if ((CounterType.CPU & client.Value.Item2) == CounterType.CPU)
                {
                   var reply = new CounterData() { Type = CounterType.CPU, Value = cpu };
                   response.SetBody<CounterData>(reply);
                   IPCService.Instance.SendReply(response.Header.RequestHeader.ProcessID.ToString(), response);
                }
                if ((CounterType.MEMORY & client.Value.Item2) == CounterType.MEMORY)
                {
                   var reply = new CounterData() { Type = CounterType.MEMORY, Value = ram };
                   response.SetBody<CounterData>(reply);
                   IPCService.Instance.SendReply(response.Header.RequestHeader.ProcessID.ToString(), response);
                }
             }
          }
       }
       Thread.Sleep(1000);
    }
 }
Example #2
0
 public void Reply(ResponseMessage response)
 {
     var data = response.GetBody<CounterData>();
     Console.WriteLine($"{data.Type} - {data.Value}");
 }
Example #3
0
 public MessageRecievedEventArgs(RequestMessage request)
 {
    Request = request;
    Response = new ResponseMessage(Request.Header);
 }
Example #4
0
      /// <summary>
      /// Broadcast a message to all clients.
      /// </summary>
      /// <param name="response">Response message</param>
      /// <remarks>Only works with duplex clients</remarks>
      public void Broadcast(ResponseMessage response)
      {
         IIPCDuplexCallback notUsed = null;
         foreach (var replyChannel in _subscriptions)
         {
            try
            {
               replyChannel.Value.Reply(response);
            }
            catch (Exception ex)
            {
               Trace.WriteLine($"Reply to {response.Header.RequestHeader.ProcessID} failed with error: {ex.Message}");
               _subscriptions.TryRemove(replyChannel.Key, out notUsed);
            }
         }

      }
Example #5
0
      /// <summary>
      /// Reply from the server to the client.
      /// </summary>
      /// <param name="clientID">Unique ID for the clients response channel.</param>
      /// <param name="response">Response</param>
      public void SendReply(string clientID, ResponseMessage response)
      {
         if (_subscriptions.ContainsKey(clientID))
         {
            var replyChannel = _subscriptions[clientID];

            try
            {
               replyChannel.Reply(response);
            }
            catch (Exception ex)
            {
               Trace.WriteLine($"Reply to {response.Header.RequestHeader.ProcessID} failed with error: {ex.Message}");
               IIPCDuplexCallback notUsed = null;
               _subscriptions.TryRemove(clientID, out notUsed);
            }
         }
      }