コード例 #1
0
ファイル: Program.cs プロジェクト: yonglehou/Codex.IPC
 static void ReplyThreadLoop()
 {
     while (true)
     {
         if (_clientProcIds.Count > 0)
         {
             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 = getCurrentCpuUsage() };
                     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 = getAvailableRAM() };
                     response.SetBody<CounterData>(reply);
                     IPCService.Instance.SendReply(response.Header.RequestHeader.ProcessID.ToString(),response);
                 }
             }
         }
         Thread.Sleep(500);
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: yonglehou/Codex.IPC
 public void Reply(ResponseMessage response)
 {
     var data = response.GetBody<CounterData>();
     Trace.WriteLine($"{data.Type} - {data.Value}");
 }
コード例 #3
0
ファイル: IPCService.cs プロジェクト: yonglehou/Codex.IPC
 public MessageRecievedEventArgs(RequestMessage request)
 {
     Request = request;
     Response = new ResponseMessage(Request.Header);
 }
コード例 #4
0
ファイル: IPCService.cs プロジェクト: yonglehou/Codex.IPC
        /// <summary>
        /// Broadcast a message to all clients.
        /// </summary>
        /// <param name="response">Response message</param>
        public void Broadcast(ResponseMessage response)
        {
            List<string> invalidChannels = new List<string>();
            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}");
                    invalidChannels.Add(replyChannel.Key);
                }
            }

            foreach (var item in invalidChannels)
                _subscriptions.Remove(item);
        }
コード例 #5
0
ファイル: IPCService.cs プロジェクト: yonglehou/Codex.IPC
        /// <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}");
                    _subscriptions.Remove(clientID);
                }
            }
        }