Пример #1
0
        public void ComplexStringWith2Ints()
        {
            //Arrange
            int    vala = 1237435;
            int    valb = -185;
            string vals = "Not so long String";

            NewPayLoad pl = new NewPayLoad("ComplexStringWith2Ints");

            pl.AddValue(vala);
            pl.AddValue(valb);
            pl.AddValue(vals);
            pl.ClosePackage();

            // Act
            byte[] b = pl.GetPackage();

            NewPayLoad pl2   = new NewPayLoad(b);
            int        vala2 = pl2.GetValueInt();
            int        valb2 = pl2.GetValueInt();
            string     vals2 = pl2.GetValueString();

            //Assert
            Assert.AreEqual(vala, vala2);
            Assert.AreEqual(valb, valb2);
            Assert.AreEqual(vals, vals2);
        }
        public void NoStructTest()
        {
            string first = "fffffffffffffffffffffffffff";
            string last  = "lllllllllllllllllllllllllll";
            int    age   = 25;

            //Arrange

            NewPayLoad pl = new NewPayLoad("ppl");

            pl.AddValue(first);
            pl.AddValue(last);
            pl.AddValue(age);
            pl.ClosePackage();

            // Act
            byte[]     b      = pl.GetPackage();
            NewPayLoad pl2    = new NewPayLoad(b);
            string     first2 = pl2.GetValueString();
            string     last2  = pl2.GetValueString();
            int        age2   = pl2.GetValueInt();

            //Assert
            Assert.AreEqual(first, first2, "first");
            Assert.AreEqual(last, last2, "last");
            Assert.AreEqual(age, age2, "age");
        }
Пример #3
0
        public void ComplexEnumStringsInts()
        {
            //Arrange
            int       vala  = 123;
            int       valb  = 545;
            string    valsa = "String1";
            string    valsb = "ZXCVFDSW";
            eLocateBy loc   = eLocateBy.ByName;

            NewPayLoad pl = new NewPayLoad("ComplexEnumStringsInts");

            pl.AddValue(vala);
            pl.AddValue(valb);
            pl.AddValue(valsa);
            pl.AddValue(valsb);
            pl.AddEnumValue(loc);
            pl.ClosePackage();

            // Act
            byte[] b = pl.GetPackage();

            NewPayLoad pl2    = new NewPayLoad(b);
            int        vala2  = pl2.GetValueInt();
            int        valb2  = pl2.GetValueInt();
            string     valsa2 = pl2.GetValueString();
            string     valsb2 = pl2.GetValueString();
            string     Loc2   = pl2.GetValueEnum();

            //Assert
            Assert.AreEqual(vala, vala2);
            Assert.AreEqual(valb, valb2);
            Assert.AreEqual(valsa, valsa2);
            Assert.AreEqual(valsb, valsb2);
            Assert.AreEqual(loc.ToString(), Loc2);
        }
Пример #4
0
        internal List <NewPayLoad> GetOutpuValuesPayLoad(List <NodeActionOutputValue> AOVs)
        {
            List <NewPayLoad> OutputValuesPayLoad = new List <NewPayLoad>();

            foreach (NodeActionOutputValue AOV in AOVs)
            {
                NewPayLoad PLO = new NewPayLoad(SocketMessages.ActionOutputValue);
                PLO.AddValue(AOV.Param);
                PLO.AddValue(AOV.Path);
                PLO.AddEnumValue(AOV.GetParamType());
                switch (AOV.GetParamType())
                {
                case NodeActionOutputValue.OutputValueType.String:
                    PLO.AddValue(AOV.ValueString);
                    break;

                case NodeActionOutputValue.OutputValueType.ByteArray:
                    PLO.AddBytes(AOV.ValueByteArray);
                    break;

                // TODO: add other types
                default:
                    throw new Exception("Unknown output Value Type - " + AOV.GetParamType());
                }
                PLO.ClosePackage();

                OutputValuesPayLoad.Add(PLO);
            }
            return(OutputValuesPayLoad);
        }
Пример #5
0
        public void SpeedTestSimpleStringX100()
        {
            //Arrange
            Stopwatch st = new Stopwatch();

            st.Start();
            string s0 = "ABCDEFGHIJ";

            // Act
            for (int i = 0; i < 100; i++)
            {
                NewPayLoad pl = new NewPayLoad("SpeedTestSimpleStringX100");
                pl.AddValue(s0);
                pl.ClosePackage();

                byte[] b = pl.GetPackage();

                NewPayLoad pl2 = new NewPayLoad(b);
                string     s1  = pl2.GetValueString();
            }

            st.Stop();

            //Assert
            Assert.IsTrue(st.ElapsedMilliseconds < 30);
        }
        public void StructTest()
        {
            string first = "fffffffffffffffffffffffffff";
            string last  = "lllllllllllllllllllllllllll";
            int    age   = 25;

            //Arrange
            ppl p1 = new ppl()
            {
                first = first, last = last, age = age
            };
            NewPayLoad pl = new NewPayLoad("ppl");

            pl.AddValue <ppl>(p1);
            pl.ClosePackage();

            // destroy the data as string is pointer to memory so we want to verify we didn't copy a pointer
            p1.first = "a";
            p1.last  = "b";
            p1.age   = 1;

            // Act
            byte[]     b   = pl.GetPackage();
            NewPayLoad pl2 = new NewPayLoad(b);
            ppl        p2  = pl2.GetValue <ppl>();

            //Assert
            Assert.AreEqual(first, p2.first, "first");
            Assert.AreEqual(last, p2.last, "last");
            Assert.AreEqual(age, p2.age, "age");
        }
Пример #7
0
        public void VeryLongString500000()
        {
            //Arrange

            string s0 = "Hello World";

            while (s0.Length < 500000)
            {
                s0 += s0;
            }

            NewPayLoad pl = new NewPayLoad("VeryLongString500000");

            pl.AddValue(s0);
            pl.ClosePackage();

            // Act
            byte[] b = pl.GetPackage();;


            NewPayLoad pl2 = new NewPayLoad(b);
            string     s1  = pl2.GetValueString();

            //Assert
            Assert.AreEqual(s0, s1);
        }
Пример #8
0
        public static NewPayLoad CreateActionResult(string exInfo, string error, List <NodeActionOutputValue> aOVs)
        {
            // TODO: use struct to return output check if faster than list of payload

            // We send back only item which can change - ExInfo and Output values
            NewPayLoad PLRC = new NewPayLoad("ActionResult"); //TODO: use const

            PLRC.AddValue(exInfo);                            // ExInfo
            PLRC.AddValue(error);                             // Error

            // add output values
            PLRC.AddListPayLoad(GingerNode.GetOutpuValuesPayLoad(aOVs));

            PLRC.ClosePackage();
            return(PLRC);
        }
        public void AttachDisplay()
        {
            //TODO: get return code - based on it set status if running OK
            NewPayLoad PL = new NewPayLoad(nameof(IDriverDisplay.AttachDisplay));

            PL.PaylodType = NewPayLoad.ePaylodType.DriverRequest;

            //tODO
            string host = SocketHelper.GetDisplayHost();
            int    port = SocketHelper.GetDisplayPort();

            PL.AddValue(host);
            PL.AddValue(port);
            PL.ClosePackage();
            SendRequestPayLoad(PL);
        }
Пример #10
0
        public void StartGingerNode(string Name, string HubIP, int HubPort)
        {
            Console.WriteLine("Starting Ginger Node");
            Console.WriteLine("ServiceID: " + mServiceID);

            string Domain      = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
            string IP          = SocketHelper.GetLocalHostIP();
            string MachineName = System.Environment.MachineName;
            string OSVersion   = System.Environment.OSVersion.ToString();

            //TODO: first register at the hub
            mHubClient = new GingerSocketClient2();
            mHubClient.MessageHandler = HubClientMessageHandler;

            Console.WriteLine("Connecting to Ginger Grid Hub: " + HubIP + ":" + HubPort);
            mHubClient.Connect(HubIP, HubPort);
            if (!mHubClient.IsConnected)
            {
                return;
            }
            Console.WriteLine("Connected!");
            Console.WriteLine("Registering Ginger node");
            //Register the service in GG
            NewPayLoad PLRegister = new NewPayLoad(SocketMessages.Register);

            PLRegister.AddValue(Name);
            PLRegister.AddValue(mServiceID);
            PLRegister.AddValue(OSVersion);
            PLRegister.AddValue(MachineName);
            PLRegister.AddValue(IP);
            PLRegister.ClosePackage();
            NewPayLoad RC = mHubClient.SendRequestPayLoad(PLRegister);

            if (RC.Name == "SessionID")
            {
                mSessionID = RC.GetGuid();
                Console.WriteLine("Ginger Node started SessionID - " + mSessionID);
                if (GingerNodeMessage != null)
                {
                    GingerNodeMessage.Invoke(this, eGingerNodeEventType.Started);
                }
            }
            else
            {
                throw new Exception("Unable to find Ginger Grid at: " + HubIP + ":" + HubPort);
            }
        }
Пример #11
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;
            }

            default:
                throw new Exception("GingerSocketServerMessageHandler: Unknown Message type: " + p.Name);
            }
        }
Пример #12
0
        internal object Invoke <T>(RemoteObjectProxy <T> remoteObjectProxy, MethodInfo targetMethod, object[] args)
        {
            NewPayLoad pl = new NewPayLoad("Invoke");

            pl.AddValue(remoteObjectProxy.RemoteObjectGuid.ToString());
            pl.AddValue(targetMethod.Name);
            pl.AddValue(args.Length); // count of params
            foreach (object o in args)
            {
                pl.AddValueByObjectType(o);
            }
            pl.ClosePackage();
            NewPayLoad PLRC = mGingerSocketClient2.SendRequestPayLoad(pl);

            object rc = PLRC.GetValueByObjectType();

            return(rc);
        }
Пример #13
0
        private NewPayLoad Ping()
        {
            Console.WriteLine("Payload - Ping");
            NewPayLoad PLRC = new NewPayLoad("OK");

            PLRC.AddValue(DateTime.Now.ToString());
            PLRC.ClosePackage();
            return(PLRC);
        }
        public void Shutdown()
        {
            NewPayLoad PL = new NewPayLoad("Shutdown");

            PL.AddValue(mGingerNodeInfo.SessionID);
            PL.ClosePackage();
            NewPayLoad RC = SendRequestPayLoad(PL);

            mIsConnected = false;
        }
Пример #15
0
        public NewPayLoad GetActionPayload()
        {
            // Need work to cover all options per platfrom !!!!!!!!!!!!!!!!!!!!
            //TODO:     // Make it generic function in Act.cs to be used by other actions

            NewPayLoad PL = new NewPayLoad("RunPlatformAction");

            PL.AddValue("UIElementAction");
            List <NewPayLoad> PLParams = new List <NewPayLoad>();

            foreach (FieldInfo FI in typeof(ActUIElement.Fields).GetFields())
            {
                string Name  = FI.Name;
                string Value = GetOrCreateInputParam(Name).ValueForDriver;

                if (string.IsNullOrEmpty(Value))
                {
                    object Output = this.GetType().GetProperty(Name) != null?this.GetType().GetProperty(Name).GetValue(this, null) : string.Empty;

                    if (Output != null)
                    {
                        Value = Output.ToString();
                    }
                }

                if (!string.IsNullOrEmpty(Value))
                {
                    NewPayLoad FieldPL = new NewPayLoad("Field", Name, Value);
                    PLParams.Add(FieldPL);
                }
            }

            /*
             * PL.AddValue(this.ElementLocateBy.ToString());
             * PL.AddValue(GetOrCreateInputParam(Fields.ElementLocateValue).ValueForDriver); // Need Value for driver
             * PL.AddValue(this.ElementType.ToString());
             * PL.AddValue(this.ElementAction.ToString());
             */

            foreach (ActInputValue AIV in this.InputValues)
            {
                if (!string.IsNullOrEmpty(AIV.Value))
                {
                    NewPayLoad AIVPL = new NewPayLoad("AIV", AIV.Param, AIV.ValueForDriver);
                    PLParams.Add(AIVPL);
                }
            }
            PL.AddListPayLoad(PLParams);
            PL.ClosePackage();

            return(PL);
        }
Пример #16
0
        public void PayLoadList()
        {
            //Arrange
            NewPayLoad pl = new NewPayLoad("Package wth list of Payloads");

            List <NewPayLoad> list = new List <NewPayLoad>();

            NewPayLoad pl1 = new NewPayLoad("PL1");

            pl1.AddValue("ABC");
            pl1.AddValue("DEF");
            pl1.ClosePackage();
            list.Add(pl1);

            NewPayLoad pl2 = new NewPayLoad("PL2");

            pl2.AddValue("GHI");
            pl2.AddValue("JKL");
            pl2.ClosePackage();
            list.Add(pl2);

            pl.AddListPayLoad(list);
            pl.ClosePackage();


            // Act
            byte[]            b     = pl.GetPackage();
            NewPayLoad        plc   = new NewPayLoad(b);
            List <NewPayLoad> list2 = plc.GetListPayLoad();

            //Assert
            Assert.AreEqual(2, list2.Count, "list2.Count=2");

            Assert.AreEqual("PL1", list2[0].Name, "list2[0].Name =PL1");
            Assert.AreEqual("PL2", list2[1].Name, "list2[1].Name =PL2");

            //Assert.AreEqual(pl1.Name, pl2.Name);
        }
Пример #17
0
        // Being used in plugin - DO NOT Remove will show 0 ref
        public void NotifyNodeClosing()
        {
            Console.WriteLine("GingerNode is closing");
            //Unregister the service in GG
            NewPayLoad PLUnregister = new NewPayLoad(SocketMessages.Unregister);

            PLUnregister.AddValue(mSessionID);
            PLUnregister.ClosePackage();
            NewPayLoad RC = mHubClient.SendRequestPayLoad(PLUnregister);

            if (RC.Name == "OK")
            {
                Console.WriteLine("GingerNode removed successsfully from Grid");
            }
        }
Пример #18
0
        public void PayloadOnSameSide()
        {
            //Arrange
            string s0 = "Hello World";

            NewPayLoad pl = new NewPayLoad("SimpleString");

            pl.AddValue(s0);
            pl.ClosePackage();


            NewPayLoad pl2 = pl;
            string     s1  = pl2.GetValueString();

            //Assert
            Assert.AreEqual(s0, s1);
            Assert.AreEqual(pl.Name, pl2.Name);
        }
Пример #19
0
        public void IntMaxValue()
        {
            //Arrange
            int val = Int16.MaxValue;

            NewPayLoad pl = new NewPayLoad("IntMaxValue");

            pl.AddValue(val);
            pl.ClosePackage();

            // Act
            byte[] b = pl.GetPackage();

            NewPayLoad pl2  = new NewPayLoad(b);
            int        val2 = pl2.GetValueInt();

            //Assert
            Assert.AreEqual(val, val2);
        }
Пример #20
0
        public void NegativeInt()
        {
            //Arrange
            int val = -123;

            NewPayLoad pl = new NewPayLoad("NegativeInt");

            pl.AddValue(val);
            pl.ClosePackage();

            // Act
            byte[] b = pl.GetPackage();

            NewPayLoad pl2  = new NewPayLoad(b);
            int        val2 = pl2.GetValueInt();

            //Assert
            Assert.AreEqual(val, val2);
        }
Пример #21
0
        public void NullTest()
        {
            //Arrange
            string s0 = null;

            NewPayLoad pl = new NewPayLoad("NullString");

            pl.AddValue(s0);
            pl.ClosePackage();

            // Act
            byte[] b = pl.GetPackage();

            NewPayLoad pl2 = new NewPayLoad(b);
            string     s1  = pl2.GetValueString();

            //Assert
            Assert.AreEqual(s0, s1);
            Assert.AreEqual(pl.Name, pl2.Name);
        }
Пример #22
0
        public void StringWithSpecialCharsUTF8()
        {
            //Arrange
            string s0 = @"ABC!@#$%^&*(){}[]~|\/<>,.~`XYZ";

            NewPayLoad pl = new NewPayLoad("StringWithSpecialChars");

            pl.AddValue(s0);
            pl.ClosePackage();

            // Act
            byte[] b = pl.GetPackage();


            NewPayLoad pl2 = new NewPayLoad(b);
            string     s1  = pl2.GetValueString();

            //Assert
            Assert.AreEqual(s0, s1);
        }
Пример #23
0
        public void GuidTest()
        {
            //Arrange
            Guid guid = System.Guid.NewGuid();


            NewPayLoad pl = new NewPayLoad("SimpleGuid");

            pl.AddValue(guid);
            pl.ClosePackage();

            // Act
            byte[] b = pl.GetPackage();

            NewPayLoad pl2 = new NewPayLoad(b);
            Guid       g1  = pl2.GetGuid();

            //Assert
            Assert.AreEqual(guid.ToString(), g1.ToString());
            Assert.AreEqual(pl.Name, pl2.Name);
        }
Пример #24
0
        NewPayLoad GetPL()
        {
            //TODO: reuse from GingerRunner
            NewPayLoad PL = new NewPayLoad("RunAction");

            PL.AddValue("Sum");

            List <NewPayLoad> Params = new List <NewPayLoad>();

            NewPayLoad p1 = new NewPayLoad("P", "a", "1");

            Params.Add(p1);

            NewPayLoad p2 = new NewPayLoad("P", "b", "2");

            Params.Add(p2);

            PL.AddListPayLoad(Params);
            PL.ClosePackage();
            return(PL);
        }
        public void NumsStructTest()
        {
            //Arrange
            nums p1 = new nums()
            {
                num1 = 7, num2 = 5.123F, num3 = 7.344F
            };
            NewPayLoad pl = new NewPayLoad("ppl");

            pl.AddValue <nums>(p1);
            pl.ClosePackage();

            string s134 = pl.BufferInfo;

            // Act
            byte[]     b   = pl.GetPackage();
            NewPayLoad pl2 = new NewPayLoad(b);
            nums       p2  = pl2.GetValue <nums>();

            //Assert
            Assert.AreEqual(p1.num1, p2.num1);
            Assert.AreEqual(p1.num2, p2.num2);
            Assert.AreEqual(p1.num3, p2.num3);
        }
Пример #26
0
        public NewPayLoad GetActionPayload()
        {
            NewPayLoad PL = new NewPayLoad("RunPlatformAction");

            PL.AddValue("BrowserAction");
            List <NewPayLoad> PLParams = new List <NewPayLoad>();

            foreach (FieldInfo FI in typeof(ActBrowserElement.Fields).GetFields())
            {
                string Name  = FI.Name;
                string Value = GetOrCreateInputParam(Name).ValueForDriver;

                if (string.IsNullOrEmpty(Value))
                {
                    object Output = this.GetType().GetProperty(Name) != null?this.GetType().GetProperty(Name).GetValue(this, null) : string.Empty;

                    if (Output != null)
                    {
                        Value = Output.ToString();
                    }
                }

                if (!string.IsNullOrEmpty(Value))
                {
                    NewPayLoad FieldPL = new NewPayLoad("Field", Name, Value);
                    PLParams.Add(FieldPL);
                }
            }

            foreach (FieldInfo FI in typeof(Act.Fields).GetFields())
            {
                string Name  = FI.Name;
                string Value = GetOrCreateInputParam(Name).ValueForDriver;

                if (string.IsNullOrEmpty(Value))
                {
                    object Output = this.GetType().GetProperty(Name) != null?this.GetType().GetProperty(Name).GetValue(this, null) : string.Empty;

                    if (Output != null)
                    {
                        Value = Output.ToString();
                    }
                }

                if (!string.IsNullOrEmpty(Value))
                {
                    NewPayLoad FieldPL = new NewPayLoad("Field", Name, Value);
                    PLParams.Add(FieldPL);
                }
            }


            foreach (ActInputValue AIV in this.InputValues)
            {
                if (!string.IsNullOrEmpty(AIV.ValueForDriver))
                {
                    NewPayLoad AIVPL = new NewPayLoad("AIV", AIV.Param, AIV.ValueForDriver);
                    PLParams.Add(AIVPL);
                }
            }



            PL.AddListPayLoad(PLParams);
            PL.ClosePackage();

            return(PL);
        }
Пример #27
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);
            }
        }
Пример #28
0
        // Move code to the ActPlugIn and make it impl IACtPlug...
        public static NewPayLoad CreateActionPayload(ActPlugIn ActPlugIn)
        {
            // Here we decompose the GA and create Payload to transfer it to the agent
            NewPayLoad PL = new NewPayLoad("RunAction");

            PL.AddValue(ActPlugIn.ActionId);
            //Add Params
            List <NewPayLoad> Params = new List <NewPayLoad>();

            // if this is the first time the action run it will not have param type
            // so read it from plugin action info
            if (ActPlugIn.InputValues.Count > 0)
            {
                if (ActPlugIn.InputValues[0].ParamType == null)
                {
                    UpdateParamsType(ActPlugIn);
                }
            }

            foreach (ActInputValue AP in ActPlugIn.InputValues)
            {
                // Why we need GA?
                if (AP.Param == "GA")
                {
                    continue;
                }
                // TODO: use const
                NewPayLoad p = new NewPayLoad("P");   // To save network traffic we send just one letter
                p.AddValue(AP.Param);
                if (AP.ParamType == typeof(string))
                {
                    p.AddValue(AP.ValueForDriver.ToString());
                }
                else if (AP.ParamType == typeof(int))
                {
                    p.AddValue(AP.IntValue);
                }
                else if (AP.ParamType == typeof(bool))
                {
                    p.AddValue(AP.BoolValue);
                }
                else if (AP.ParamType == typeof(DynamicListWrapper))
                {
                    p.AddValue(AP.ValueForDriver.ToString());
                }
                else if (AP.ParamType == typeof(EnumParamWrapper))
                {
                    p.AddValue(AP.ValueForDriver.ToString());
                }

                else
                {
                    throw new Exception("Unknown param type to pack: " + AP.ParamType.FullName);
                }
                p.ClosePackage();
                Params.Add(p);
            }
            PL.AddListPayLoad(Params);

            PL.ClosePackage();
            return(PL);
        }
Пример #29
0
        // Handle Client request
        private NewPayLoad HandlePayLoad(NewPayLoad PL)
        {
            switch (PL.Name)
            {
            case "GetObject":
                string             id  = PL.GetValueString();
                object             obj = GetObjectHandler(id);
                RemoteObjectHandle remoteObjectHandle = new RemoteObjectHandle();
                Guid guid = Guid.NewGuid();
                remoteObjectHandle.GUID   = guid;
                remoteObjectHandle.Object = obj;

                //check if the object have Dispatcher - means GUI element so STA thread then run it on the STA, so we keep the Dispatcher for the invoke part later
                PropertyInfo PI = obj.GetType().GetProperty("Dispatcher");
                if (PI != null)
                {
                    object  DispObj = obj;
                    dynamic d       = DispObj;
                    // It means it is UI control - so invoke on the UI control Dispatcher, this way we avoid code on the page to change the UI on the Dispatcher every time
                    // temp comment for build
                    // !!!!!!!!! d. requires Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo
                    // remoteObjectHandle.Dispatcher = d.Dispatcher;
                }

                mObjects.Add(guid, remoteObjectHandle);
                NewPayLoad PLEcho = new NewPayLoad("Object", guid.ToString());
                return(PLEcho);

            case "SendObject":
                string     txt2    = "a=1;b=2";
                NewPayLoad PLEcho2 = new NewPayLoad("Object", txt2);
                return(PLEcho2);

            case "Invoke":
                Guid               objguid    = Guid.Parse(PL.GetValueString());
                string             methodName = PL.GetValueString();
                RemoteObjectHandle ROH;
                // Get the object by guid
                bool   bFound = mObjects.TryGetValue(objguid, out ROH);
                object obj1   = ROH.Object;
                //TODO: if not found...
                MethodInfo mi = obj1.GetType().GetMethod(methodName);

                int ParamCounter = PL.GetValueInt();

                object[] param = new object[ParamCounter];
                for (int i = 0; i < ParamCounter; i++)
                {
                    param[i] = PL.GetValueByObjectType();
                }

                // invoke
                object rc = null;

                // temp comment for build
                // !!!!!!!!! d. requires Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo
                //if (ROH.Dispatcher == null)
                //{

                //    // Non UI object safe to call from another thread
                //    rc = mi.Invoke(obj1, param);
                //}
                //else
                //{
                //    // It means the obj is UI control like driver Page- so invoke on the UI control Dispatcher,
                //    // this way we avoid code on the page to change the UI on the Dispatcher every time we do UI changes and avoid getting exception
                //    ROH.Dispatcher.BeginInvoke(
                //                    (Action)(() => {
                //                        rc = mi.Invoke(obj1, param);
                //                    }
                //                ));
                //}

                // return result
                NewPayLoad PLRC = new NewPayLoad("OK");
                if (rc != null)
                {
                    PLRC.AddValueByObjectType(rc);
                }
                else
                {
                    PLRC.AddValue("NULL");
                    PLRC.AddValue("NULL");
                }
                PLRC.ClosePackage();
                return(PLRC);

            default:
                throw new InvalidOperationException("Unknown PayLoad Action - " + PL.Name);
            }
        }
Пример #30
0
        private NewPayLoad RunAction(NewPayLoad pl)
        {
            ScanService();

            Console.WriteLine(">>> Payload - Run Ginger Action");
            string ActionID = pl.GetValueString();

            Console.WriteLine("Received RunAction, ActionID - " + ActionID);

            ActionHandler AH = (from x in mServiceActions where x.ServiceActionId == ActionID select x).FirstOrDefault();

            if (AH == null)
            {
                Console.WriteLine("Unknown ActionID to handle - " + ActionID);
                throw new Exception("Unknown ActionID to handle - " + ActionID);
            }

            //Conver the Payload to GingerAction
            NodeGingerAction nodeGingerAction = new NodeGingerAction();

            AH.NodeGingerAction = nodeGingerAction;
            Console.WriteLine("Found Action Handler, setting parameters");

            // setting parameters
            List <NewPayLoad> Params = pl.GetListPayLoad();

            Console.WriteLine("Found " + Params.Count + " parameters");
            ActionInputParams actionInputParams = new ActionInputParams();

            foreach (NewPayLoad PLP in Params)
            {
                // we get Param name and value
                string Name  = PLP.GetValueString();
                object Value = PLP.GetValueByObjectType();
                Console.WriteLine("Param " + Name + " = " + Value);
                ActionParam AP = actionInputParams[Name];
                if (AP != null)
                {
                    actionInputParams[Name].Value = Value;
                }
                else
                {
                    Console.WriteLine("Cannot find input param - " + Name);
                }
            }

            // TODO: add hookd for before and after using interface
            //if (IBeforeAfterAction != null)
            //    mService.BeforeRunAction(AH.GingerAction);
            // mService.RunAction(AH.GingerAction);

            ExecuteMethod(AH, actionInputParams, nodeGingerAction);

            // We send back only item which can change - ExInfo and Output values
            NewPayLoad PLRC = new NewPayLoad("ActionResult");   //TODO: use const

            PLRC.AddValue(nodeGingerAction.ExInfo);
            PLRC.AddValue(nodeGingerAction.Errors);
            PLRC.AddListPayLoad(GetOutpuValuesPayLoad(nodeGingerAction.Output.OutputValues));
            PLRC.ClosePackage();
            return(PLRC);
        }