Exemplo n.º 1
0
        public void PayloadinPayload()
        {
            //Arrange
            NewPayLoad plin = new NewPayLoad("plin", "AAA", "BBB", "CCC");

            // Act
            NewPayLoad pl = new NewPayLoad("master", "123", plin);

            byte[]     b   = pl.GetPackage();
            NewPayLoad pl2 = new NewPayLoad(b);

            // Extract
            string     v123  = pl2.GetValueString();
            NewPayLoad plin2 = pl2.ReadPayload();

            string aaa = plin2.GetValueString();
            string bbb = plin2.GetValueString();
            string ccc = plin2.GetValueString();

            //Assert
            Assert.AreEqual("plin", plin2.Name);
            Assert.AreEqual("AAA", aaa);
        }
Exemplo n.º 2
0
        private void GingerSocketServerMessageHandler(GingerSocketInfo gingerSocketInfo)
        {
            NewPayLoad p = gingerSocketInfo.DataAsPayload;

            switch (p.Name)
            {
            case "List":      //TODO: use const
            {
                NewPayLoad RC = new NewPayLoad("RC");
                RC.AddValue("OK");

                //TODO: return the list of GingerNodeInfo

                RC.ClosePackage();
                gingerSocketInfo.Response = RC;
                break;
            }

            case SocketMessages.Register:
            {
                string NodeName      = p.GetValueString();
                string NodeServiceID = p.GetValueString();
                string NodeOS        = p.GetValueString();
                string NodeHost      = p.GetValueString();
                string NodeIP        = p.GetValueString();

                NewPayLoad RC = new NewPayLoad("SessionID", gingerSocketInfo.SessionID);
                gingerSocketInfo.Response = RC;

                // add the info of the new node to the grid list
                mGingerNodeInfo.Add(new GingerNodeInfo()
                    {
                        Name = NodeName, ServiceId = NodeServiceID, OS = NodeOS, Host = NodeHost, IP = NodeIP, SessionID = gingerSocketInfo.SessionID, Status = GingerNodeInfo.eStatus.Ready
                    });
                break;
            }

            case SocketMessages.Unregister:
            {
                Guid           SessionID = p.GetGuid();
                GingerNodeInfo GNI       = (from x in mGingerNodeInfo where x.SessionID == SessionID select x).FirstOrDefault();
                if (GNI == null)
                {
                    gingerSocketInfo.Response = new NewPayLoad("Error", "Ginger node info not found for session id " + SessionID.ToString());
                }

                mGingerNodeInfo.Remove(GNI);

                NewPayLoad RC = new NewPayLoad("OK");
                RC.ClosePackage();
                gingerSocketInfo.Response = RC;
                break;
            }


            // Combine find and send to one - send session id or how to find
            // Change to reserve node
            case SocketMessages.FindNode:      // Find node which match criteria, used for remote grid
                string ServiceID = p.GetValueString();

                // !!! find first or use better algorithm
                GingerNodeInfo gingerNodeInfo1 = (from x in NodeList where x.ServiceId == ServiceID select x).FirstOrDefault();

                // Reserve
                // TODO: lock !!!!!!!!!!!!!!!!!!!!
                gingerNodeInfo1.Status = GingerNodeInfo.eStatus.Reserved;     // TODO: release !!!!!!!!!!!!!!!!
                NewPayLoad RC2 = new NewPayLoad("NodeInfo", gingerNodeInfo1.SessionID);
                gingerSocketInfo.Response = RC2;
                break;

            case SocketMessages.SendToNode:      // Send action to Node, used when Grid is remote
                Guid           SessionID2               = p.GetGuid();
                GingerNodeInfo gingerNodeInfo           = (from x in NodeList where x.SessionID == SessionID2 select x).SingleOrDefault();
                NewPayLoad     actionPayload            = p.ReadPayload();
                NewPayLoad     remoteNodeActionResponce = SendRequestPayLoad(gingerNodeInfo.SessionID, actionPayload);
                remoteNodeActionResponce.Truncate();
                gingerSocketInfo.Response = remoteNodeActionResponce;
                gingerNodeInfo.Status     = GingerNodeInfo.eStatus.Ready;  //TODO: in case of session to do not release
                break;

            default:
                throw new Exception("GingerSocketServerMessageHandler: Unknown Message type: " + p.Name);
            }
        }