Beispiel #1
0
 public void FatalLog(string msg)
 {
     SendMessage("ee:fatal:" + Conversions.StringToBase64(msg));
 }
Beispiel #2
0
 public void RemoteLog(string msg)
 {
     SendMessage("ee:log:" + Conversions.StringToBase64(msg));
 }
Beispiel #3
0
 public void ReplyException(string id, string message)
 {
     SendMessage("ee:exception:" + id + ":" + Conversions.StringToBase64(message));
 }
Beispiel #4
0
 public void ReplyCommand(string id, string data)
 {
     SendMessage("ee:data:" + id + ":" + Conversions.StringToBase64(data));
 }
Beispiel #5
0
 public void ReplyPID(int pid)
 {
     SendMessage("ee:pid:" + Conversions.StringToBase64(pid.ToString(System.Globalization.CultureInfo.InvariantCulture)));
 }
Beispiel #6
0
        public void ReadCallback(IAsyncResult ar)
        {
            try
            {
                //IpcSocketClient state = (IpcSocketClient)ar.AsyncState;
                //Socket handler = state.Socket;

                int bytesRead = m_socket.EndReceive(ar);

                if (bytesRead > 0)
                {
                    m_sb.Append(Encoding.ASCII.GetString(m_buffer, 0, bytesRead));

                    string content    = m_sb.ToString();
                    int    posEndLine = content.IndexOf("\n");
                    if (posEndLine != -1)
                    {
                        m_sb.Clear();
                        string line = content.Substring(0, posEndLine);
                        if (content.Length - (posEndLine + 1) > 0)
                        {
                            m_sb.Append(content.Substring(posEndLine + 1));
                        }

                        Dictionary <string, string> parameters = new Dictionary <string, string>();
                        int pos = 0;
                        for (; ;)
                        {
                            int posKeyEnd = line.IndexOf(':', pos);
                            if (posKeyEnd == -1)
                            {
                                break;
                            }
                            string key         = line.Substring(pos, posKeyEnd - pos);
                            int    posValueEnd = line.IndexOf(';', posKeyEnd + 1);
                            if (posValueEnd == -1)
                            {
                                break;
                            }
                            string v = line.Substring(posKeyEnd + 1, posValueEnd - posKeyEnd - 1);
                            v = Conversions.Base64ToString(v);
                            parameters[key] = v;
                            pos             = posValueEnd + 1;
                        }

                        if (parameters.ContainsKey("_id") == false)
                        {
                            return;
                        }
                        if (parameters.ContainsKey("command") == false)
                        {
                            return;
                        }

                        DoCommand(parameters);
                    }
                }
                else
                {
                    throw new Exception("Read fail");
                }

                m_socket.BeginReceive(m_buffer, 0, IpcSocketClient.BufferSize, 0, new AsyncCallback(ReadCallback), m_socket);
            }
            catch (Exception ex)
            {
                Close(ex.Message);
            }
        }