示例#1
0
        /// <summary>
        /// This method parses data that is sent by a client using TCP/IP.
        /// As per the "Protocol" between client and this Listener, client
        /// sends each line of information by appending "#0" (
        /// ). But since the data is transmitted from client to
        /// here by TCP/IP protocol, it is not guarenteed that each line that
        /// arrives ends with a "CRLF". So the job of this method is to make a
        /// complete line of information that ends with "CRLF" from the data
        /// that comes from the client and get it processed.
        /// </summary>
        /// <param name="byteBuffer"></param>
        /// <param name="size"></param>
        private void ParseReceiveBuffer(Byte [] byteBuffer, int size)
        {
            string data         = Encoding.ASCII.GetString(byteBuffer, 0, size);
            int    lineEndIndex = 0;

            // Check whether data from client has more than one line of
            // information, where each line of information ends with "CRLF"
            // ("\r\n"). If so break data into different lines and process
            // separately.
            do
            {
                lineEndIndex = data.IndexOf((char)0);
                if (lineEndIndex != -1)
                {
                    m_oneLineBuf = m_oneLineBuf.Append(data, 0, lineEndIndex);
                    if (_processor != null)
                    {
                        string response = _processor.HandleMessage(m_oneLineBuf.ToString());

                        if (response != null)
                        {
                            m_clientSocket.Send(Encoding.ASCII.GetBytes(response));
                        }
                    }
                    m_oneLineBuf.Remove(0, m_oneLineBuf.Length);
                    data = data.Substring(lineEndIndex + 1,
                                          data.Length - lineEndIndex - 1);
                }
                else
                {
                    // Just append to the existing buffer.
                    m_oneLineBuf = m_oneLineBuf.Append(data);
                }
            }while((lineEndIndex != -1) && (!string.IsNullOrEmpty(data)));
        }
示例#2
0
        public void TestCanRequestItem()
        {
            ISessionFactory fac     = RomViewContainer.Container.GetInstance <ISessionFactory>();
            ISession        session = fac.OpenSession();
            //LazySessionContext.Bind(new Lazy<ISession>(() => session), fac);

            IRomMessageProcessor p = RomViewContainer.Container.GetInstance <IRomMessageProcessor>();

            //romItem id = 228216
            int    itemId   = 228216;
            string source   = string.Format("ITEM{0}GET{0}{1}", (char)1, itemId);
            string response = p.HandleMessage(source);

            string[] result = response.Split((char)1);
            Assert.AreEqual(itemId.ToString(), result[0]);
        }
示例#3
0
        public void TestCanAddAndCanDeleteItem()
        {
            ISessionFactory fac     = RomViewContainer.Container.GetInstance <ISessionFactory>();
            ISession        session = fac.OpenSession();
            ITransaction    tx      = session.BeginTransaction();

            LazySessionContext.Bind(new Lazy <ISession>(() => session), fac);

            IRomMessageProcessor p          = RomViewContainer.Container.GetInstance <IRomMessageProcessor>();
            IItemRepository      repository = RomViewContainer.Container.GetInstance <IItemRepository>();

            ItemDefinition expected = new ItemDefinition()
            {
                RomId          = 999999,
                Name           = "TestItem",
                ItemType       = "ItemType",
                ItemSubType    = "ItemSubType",
                ItemSubSubType = "ItemSubSubType",
                Value          = 999
            };



            //romItem id = 228216
            string source   = string.Format("ITEM{0}SAVE{0}{1}", (char)1, expected.ToDelimitedString(2));
            string response = p.HandleMessage(source);

            Assert.IsNull(response);

            ItemDefinition result = repository.GetByRomId(expected.RomId);

            Assert.IsNotNull(result);

            Assert.AreEqual(expected.ToDelimitedString(1), result.ToDelimitedString(1));
            tx.Rollback();
        }