Пример #1
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]);
        }
Пример #2
0
        /// <summary>
        /// TCP/IP Server Thread that is listening for clients.
        /// </summary>
        private void ServerThreadStart()
        {
            // Client Socket variable;
            Socket            clientSocket   = null;
            TCPSocketListener socketListener = null;

            while (!m_stopServer)
            {
                try
                {
                    // Wait for any client requests and if there is any
                    // request from any client accept it (Wait indefinitely).
                    clientSocket = m_server.AcceptSocket();

                    // Create a SocketListener object for the client.
                    IRomMessageProcessor processor = RomViewContainer.Container.GetInstance <IRomMessageProcessor>();

                    socketListener = new TCPSocketListener(clientSocket, processor);

                    // Add the socket listener to an array list in a thread
                    // safe fashon.
                    //Monitor.Enter(m_socketListenersList);
                    lock (m_socketListenersList)
                    {
                        m_socketListenersList.Add(socketListener);
                    }
                    //Monitor.Exit(m_socketListenersList);

                    // Start a communicating with the client in a different
                    // thread.
                    socketListener.StartSocketListener();
                }
                catch (SocketException se)
                {
                    m_stopServer = true;
                }
            }
        }
Пример #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();
        }
Пример #4
0
        /// <summary>
        /// Client Socket Listener Constructor.
        /// </summary>
        /// <param name="clientSocket"></param>
        public TCPSocketListener(Socket clientSocket, IRomMessageProcessor processor)
        {
            _processor = processor;

            m_clientSocket = clientSocket;
        }