예제 #1
0
        public bool CommandExecSinter(Sinter sinter)
        {
            string     requested_service, invoking_method_name;
            MethodInfo invoking_method;

            log.InfoFormat("[Sinter recv] service code/sub_code = {0}/{1} ", sinter.HeaderNode.ServiceCode, sinter.HeaderNode.SubCode);
            if (serviceCodesRev.TryGetValue(sinter.HeaderNode.ServiceCode, out requested_service))
            {
                invoking_method_name = "execute_" + requested_service.Trim();
                if (actuator.bPasscodeVerified == true ||
                    requested_service.Equals(@"verify_passcode"))
                {
                    invoking_method = type.GetMethod(invoking_method_name);
                    if (invoking_method != null)
                    {
                        invoking_method.Invoke(actuator, new Sinter[] { sinter });
                        return(true);
                    }
                    else
                    {
                        log.Error("invoke error: " + invoking_method_name + " doesn't exist");
                    }
                }
                else
                {
                    log.Warn("passcode not verified yet, ignore the msg!");
                }
            }
            else
            {
                log.Error("invoke error: " + sinter.HeaderNode.ServiceCode + " doesn't exist");
            }
            invoking_method = null;
            return(false);
        }
예제 #2
0
 private void AddToMessageQueue(string xml)
 {
     using (XmlReader reader = XmlReader.Create(new StringReader(xml))) {
         Sinter sinter = (Sinter)serializer.Deserialize(reader);
         messageQueue.Add(sinter);
     }
 }
예제 #3
0
        public override void SendMessage(Sinter sinter)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (XmlWriter writer = XmlWriter.Create(ms, settings))
                {
                    // add timestamp
                    sinter.HeaderNode.Timestamp = DateTime.Now.ToShortTimeString();

                    // add process id
                    sinter.HeaderNode.Process = RequestedProcessId.ToString();

                    // serialize
                    serializer.Serialize(writer, sinter, ns);
                }

                byte[] bytesToFile = ms.ToArray();
                string filestring  = Encoding.ASCII.GetString(bytesToFile);

                File.WriteAllText(filepath, filestring);

                // Debug statement
                Console.WriteLine("[Sinter sent] service code/sub_code = {0}/{1}", sinter.HeaderNode.ServiceCode, sinter.HeaderNode.SubCode);
            }
        }
예제 #4
0
 public void SaveMessageInTextFile(Sinter sinter)
 {
     using (TextWriter WriteFileStream = new StreamWriter("messages.xml", true))
     {
         serializer.Serialize(WriteFileStream, sinter);
     }
 }
예제 #5
0
        private void CommandExecutor()
        {
            string     requested_service, invoking_method_name;
            MethodInfo invoking_method;

            while (!_shouldStop)
            {
                try {
                    Sinter sinter = messageQueue.Take();
                    if (serviceCodesRev.TryGetValue(sinter.HeaderNode.ServiceCode, out requested_service))
                    {
                        invoking_method_name = "execute_" + requested_service.Trim();
                        invoking_method      = type.GetMethod(invoking_method_name);
                        if (invoking_method != null)
                        {
                            invoking_method.Invoke(actuator, new Sinter [] { sinter });
                        }
                        else
                        {
                            Console.WriteLine("invoke error: " + invoking_method_name + " doesn't exist");
                        }
                    }
                    else
                    {
                        Console.WriteLine("invoke error: " + sinter.HeaderNode.ServiceCode + " doesn't exist");
                    }
                    invoking_method = null;
                }
                catch (Exception ex) {
                    Console.WriteLine(ex.Message);
                }
            }
        }
예제 #6
0
        public virtual void SendMessage(Sinter sinter)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (XmlWriter writer = XmlWriter.Create(ms, settings))
                {
                    if (_shouldStop)
                    {
                        return;
                    }

                    // add timestamp
                    sinter.HeaderNode.Timestamp = DateTime.Now.ToShortTimeString();

                    // add process id
                    sinter.HeaderNode.Process = RequestedProcessId.ToString();

                    // serialize
                    serializer.Serialize(writer, sinter, ns);
                }

                byte[] bytesToFile = ms.ToArray();
                string filestring  = Encoding.ASCII.GetString(bytesToFile);
                xmlLogger.Debug(filestring);

                if (networkStream != null)
                {
                    try
                    {
                        networkStream.Write(ms.GetBuffer(), 0, (int)ms.Length);
                    }
                    catch (Exception e)
                    {
#if DEBUG
                        log.ErrorFormat("Exception: {0}", e);
#endif
                        this.StopConnectionHandling();
                        return;
                    }
                    networkStream.Flush();
                }

                /*
                 * else
                 * {   //this is Unit-Test;
                 *  File.WriteAllText(unittest_filename, filestring);
                 * }
                 */

                // Debug statement
                log.Debug("sent: " + (int)ms.Length + " bytes");
                log.InfoFormat("[Sinter sent] service code/sub_code = {0}/{1}", sinter.HeaderNode.ServiceCode, sinter.HeaderNode.SubCode);
            }

            // Debug statement
            //SaveMessageInTextFile(sinter);
        }
예제 #7
0
파일: Form1.cs 프로젝트: oscarlab/sinter
        private void button2_Click(object sender, EventArgs e)
        {
            Sinter sinter = new Sinter {
                HeaderNode = new Header {
                    ServiceCode = 1,
                }
            };

            //if (clientHandler != null)
            //  clientHandler.sendMessage(sinter);
        }
예제 #8
0
 private void CommandExecutor()
 {
     while (!_shouldStop)
     {
         try
         {
             Sinter sinter = messageQueue.Take();
             CommandExecSinter(sinter);
         }
         catch (Exception ex)
         {
             log.Error(ex.Message);
         }
     }
 }
예제 #9
0
        public void SendMessage(Sinter sinter)
        {
            using (MemoryStream ms = new MemoryStream()) {
                using (XmlWriter writer = XmlWriter.Create(ms, settings)) {
                    // add timestamp
                    sinter.HeaderNode.Timestamp = DateTime.Now.ToShortTimeString();

                    // add process id
                    sinter.HeaderNode.Process = RequestedProcessId.ToString();

                    // serialize
                    serializer.Serialize(writer, sinter, ns);
                }
                networkStream.Write(ms.GetBuffer(), 0, (int)ms.Length);
                networkStream.Flush();
                // Debug statement
                Console.WriteLine("sent: " + (int)ms.Length + " bytes");
            }

            // Debug statement
            //SaveMessageInTextFile(sinter);
        }
예제 #10
0
 public void SendMessage(Sinter sinter)
 {
     connectionHandler.SendMessage(sinter);
 }