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"); }
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); }
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); } }
public static void ParseActionResult(NewPayLoad RC, Act actPlugin) { // After we send it we parse the driver response if (RC.Name == "ActionResult") { // We read the ExInfo, Err and output params actPlugin.ExInfo = RC.GetValueString(); string error = RC.GetValueString(); if (!string.IsNullOrEmpty(error)) { actPlugin.Error += error; actPlugin.Status = Execution.eRunStatus.Failed; return; } List <NewPayLoad> OutpuValues = RC.GetListPayLoad(); foreach (NewPayLoad OPL in OutpuValues) { // //TODO: change to use PL AddValueByObjectType // // it is param name, type and value string PName = OPL.GetValueString(); string path = OPL.GetValueString(); string mOutputValueType = OPL.GetValueEnum(); switch (mOutputValueType) { case nameof(Amdocs.Ginger.CoreNET.RunLib.NodeActionOutputValue.OutputValueType.String): string stringValue = OPL.GetValueString(); actPlugin.AddOrUpdateReturnParamActualWithPath(PName, stringValue, path); break; case nameof(Amdocs.Ginger.CoreNET.RunLib.NodeActionOutputValue.OutputValueType.ByteArray): byte[] b = OPL.GetBytes(); //actPlugin.ReturnValues.Add(new ActReturnValue() { Param = PName, Path= path, Actual = "aaaaaaa" }); //FIXME!!! when act can have values types actPlugin.AddOrUpdateReturnParamActualWithPath(PName, "aaa", path); //FIXME!!! when act can have values types break; default: throw new Exception("Unknown param type: " + mOutputValueType); } } } else { // The RC is not OK when we faced some unexpected exception //TODO: string Err = RC.GetValueString(); actPlugin.Error += Err; } }
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); }
public static void ExecutesScreenShotActionOnAgent(Agent agent, Act act) { NewPayLoad PL = new NewPayLoad("ScreenshotAction"); List <NewPayLoad> PLParams = new List <NewPayLoad>(); NewPayLoad AIVPL = new NewPayLoad("AIV", "WindowsToCapture", act.WindowsToCapture.ToString()); PLParams.Add(AIVPL); PL.AddListPayLoad(PLParams); // Get the action payload PL.ClosePackage(); // Send the payload to the service NewPayLoad RC = agent.GingerNodeProxy.RunAction(PL); if (RC.Name == "ScreenShots") { List <NewPayLoad> FieldsandParams = RC.GetListPayLoad(); foreach (NewPayLoad Np in FieldsandParams) { string Name = Np.GetValueString(); //string base64string = Np.GetValueString(); act.AddScreenShot(Name); } } else { // The RC is not OK when we faced some unexpected exception //TODO: string Err = RC.GetValueString(); act.Error += Err; } }
private NewPayLoad RunAction(NewPayLoad pl) { if (mServiceActions == null) { ScanServiceAndCache(); } 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); } //Convert 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); NewPayLoad PLRC = CreateActionResult(nodeGingerAction.ExInfo, nodeGingerAction.Errors, nodeGingerAction.Output.OutputValues); return(PLRC); }
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 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 T GetObject <T>(string id) { NewPayLoad PL = new NewPayLoad("GetObject", id); NewPayLoad PLRC = mGingerSocketClient2.SendRequestPayLoad(PL); Guid guid = Guid.Parse(PLRC.GetValueString()); //TODO: add Guid in Payload T obj = RemoteObjectProxy <T> .Create(this, guid); return(obj); }
public void EchoRandomMessageSize() { // Arrange // Create SB size of 1M Bytes - 1,000,000 StringBuilder sb = new StringBuilder(); for (int i = 0; i < 100000; i++) { sb.Append("0123456789"); } List <string> list = new List <string>(); list.Add(sb.ToString().Substring(0, 106660)); list.Add(sb.ToString().Substring(0, 10)); list.Add(sb.ToString().Substring(0, 500)); list.Add(sb.ToString().Substring(0, 30000)); list.Add(sb.ToString().Substring(0, 10)); list.Add(sb.ToString().Substring(0, 1)); list.Add(sb.ToString().Substring(0, 20000)); list.Add(sb.ToString().Substring(0, 100)); list.Add(sb.ToString().Substring(0, 1000000)); list.Add(sb.ToString().Substring(0, 400)); list.Add(sb.ToString().Substring(0, 10000)); list.Add(sb.ToString().Substring(0, 1024)); list.Add(sb.ToString().Substring(0, 50000)); list.Add(sb.ToString().Substring(0, 1350)); list.Add(sb.ToString().Substring(0, 8921)); int count = 0; //Act foreach (string s in list) { NewPayLoad PL = new NewPayLoad("Echo", s); NewPayLoad PLRC = mMyGingerClient.Send(PL); string txt2 = PLRC.GetValueString(); if (s == txt2) { count++; } } //Assert Assert.AreEqual(list.Count, count); }
public void Echo() { // Arrange string txt = "abcABC123"; NewPayLoad PL = new NewPayLoad("Echo", txt); //Act NewPayLoad PLRC = mMyGingerClient.Send(PL); string txt2 = PLRC.GetValueString(); //Assert Assert.AreEqual(PLRC.Name, "EchoBack", "PLRC.Name = EchoBack"); Assert.AreEqual(txt, txt2, "txt = txt2"); }
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); }
public string Ping() { //TODO: create test when node is down etc. NewPayLoad PL = new NewPayLoad("Ping"); PL.ClosePackage(); Stopwatch stopwatch = Stopwatch.StartNew(); NewPayLoad RC = SendRequestPayLoad(PL); stopwatch.Stop(); string rc = RC.GetValueString() + ", ElapsedMS=" + stopwatch.ElapsedMilliseconds; return(rc); }
public void ServerSendMessagetoClient() { //FIXME get stuck!!! // Arrange string txt = "This is your server"; NewPayLoad PL = new NewPayLoad("MyServerMessage", txt); //Act NewPayLoad PLRC = mMyGingerServer.SendPayLoad(mMyGingerClient.SessionID, PL); string txt2 = PLRC.GetValueString(); //Assert Assert.AreEqual("Client Response to server", PLRC.Name, "PLRC.Name = Client Response to server"); Assert.AreEqual("OK", txt2); }
public void EchoBig10KMessage() { // Arrange string bigMessage = new string('*', 10000); NewPayLoad PL = new NewPayLoad("Echo", bigMessage); //Act NewPayLoad PLRC = mMyGingerClient.Send(PL); string txt2 = PLRC.GetValueString(); //Assert Assert.AreEqual(PLRC.Name, "EchoBack", "PLRC.Name = EchoBack"); Assert.AreEqual(bigMessage.ToString(), txt2, "sb.ToString() = txt2"); }
public bool Reserve(Guid GingerNodeSessionID) // send the GNI { //TODO: handle SessionID null NewPayLoad ReservePL = new NewPayLoad(SocketMessages.Reserve, GingerNodeSessionID); NewPayLoad rc = mGingerSocketServer.SendPayLoad(GingerNodeSessionID, ReservePL); string s = rc.GetValueString(); if (s == "OK") { return(true); } else { return(false); } }
public void Run10ClientsParallel() { // Arrange List <Task> list = new List <Task>(); for (int i = 0; i < 10; i++) { Task t = new Task(() => { Random r = new Random(); MyGingerClient client1 = new MyGingerClient(); string txt = "Hi from Client 1"; NewPayLoad PL = new NewPayLoad("Echo", txt); client1.Connect(); for (int j = 0; j < 1000; j++) { NewPayLoad PLRC = client1.Send(PL); string txt2 = PLRC.GetValueString(); if (txt != txt2) { throw new Exception("Error in Echo!!"); } int sleep = r.Next(0, 20); Thread.Sleep(sleep); } client1.Disconnect(); }); t.Start(); list.Add(t); } //Act // Wait for all clients to complete their work foreach (Task t in list) { t.Wait(); } //Assert //Assert.AreEqual(PLRC.Name, "EchoBack", "PLRC.Name = EchoBack"); //Assert.AreEqual(txt, txt2, "txt = txt2"); }
public void ClientConnectSendClose() { // Arrange MyGingerClient client1 = new MyGingerClient(); string txt = "Hi from Client 1"; NewPayLoad PL = new NewPayLoad("Echo", txt); //Act client1.Connect(); NewPayLoad PLRC = client1.Send(PL); string txt2 = PLRC.GetValueString(); client1.Disconnect(); //Assert Assert.AreEqual(PLRC.Name, "EchoBack", "PLRC.Name = EchoBack"); Assert.AreEqual(txt, txt2, "txt = txt2"); }
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); }
public void EchoBig10KMessage() { // Arrange StringBuilder sb = new StringBuilder(); for (int i = 0; i < 1000; i++) { sb.Append("0123456789"); } NewPayLoad PL = new NewPayLoad("Echo", sb.ToString()); //Act NewPayLoad PLRC = mMyGingerClient.Send(PL); string txt2 = PLRC.GetValueString(); //Assert Assert.AreEqual(PLRC.Name, "EchoBack", "PLRC.Name = EchoBack"); Assert.AreEqual(sb.ToString(), txt2, "sb.ToString() = txt2"); }
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); }
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); }
private NewPayLoad AttachDisplay(NewPayLoad pl) { string host = pl.GetValueString(); int port = pl.GetValueInt(); RemoteObjectsClient c = new RemoteObjectsClient(); c.Connect(host, port); //TODO: fix hard coded !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Assembly driverAssembly = Assembly.LoadFrom(@"C:\Yaron\TFS\Ginger\Devs\GingerNextVer_Dev\GingerWebServicesPlugin\bin\Debug\netstandard2.0\WebServices.GingerPlugin.dll"); Type t = driverAssembly.GetType("Amdocs.Ginger.WebServices.IWebServicesDriverDisplay"); // We do all using reflection, since we don't have ref to the driver dll, it will load at run time MethodInfo mi = typeof(RemoteObjectsClient).GetMethod("GetObject").MakeGenericMethod(new Type[] { t }); object driverDisplayRemoteObject = mi.Invoke(c, new object[] { "ID aas as !!!" }); mDriver.GetType().GetMethod("AttachDisplay").Invoke(mDriver, new object[] { driverDisplayRemoteObject }); return(new NewPayLoad("OK", "Done")); }
// Handle Client request private NewPayLoad HandlePayLoad(NewPayLoad PL) { switch (PL.Name) { case "Echo": string txt = PL.GetValueString(); NewPayLoad PLEcho = new NewPayLoad("EchoBack", txt); return(PLEcho); case "DummyAction": NewPayLoad PLDummy = new NewPayLoad("OK", "Done"); return(PLDummy); case "SpeedTest": NewPayLoad PLSpeedTest = new NewPayLoad("OK", "Speedy"); return(PLSpeedTest); case "SlowResponse1000": Thread.Sleep(1000); NewPayLoad PLOK1000 = new NewPayLoad("OK1000", "Done"); return(PLOK1000); case "LongAction": Thread.Sleep(10000); NewPayLoad PLOKLongAction = new NewPayLoad("LongActionDone", "Done"); return(PLOKLongAction); case "CalcSum": int num = PL.GetValueInt(); int total = 0; for (int j = 0; j < num; j++) { total += j; } NewPayLoad PLOKTotalAction = new NewPayLoad("Total", total); return(PLOKTotalAction); default: throw new Exception("Unknown PayLoad Action - " + PL.Name); } }
public void StartDriver(Amdocs.Ginger.Common.ObservableList <DriverConfigParam> driverConfiguration = null) { //TODO: get return code - based on it set status if running OK NewPayLoad PL = new NewPayLoad("StartDriver"); //!!!! Rename to StartService + use const List <NewPayLoad> DriverConfigs = new List <NewPayLoad>(); if (driverConfiguration != null) { foreach (DriverConfigParam DC in driverConfiguration) { NewPayLoad FieldPL = new NewPayLoad("Config", DC.Parameter, DC.Value == null ? " " : DC.Value); DriverConfigs.Add(FieldPL); } } PL.AddListPayLoad(DriverConfigs); PL.ClosePackage(); NewPayLoad plss = SendRequestPayLoad(PL); if (plss.IsErrorPayLoad()) { throw new Exception("Error in GingerNodeProxy.StartDriver - " + plss.GetValueString()); } }
private NewPayLoad RunAction(NewPayLoad pl) { ScanService(); Console.WriteLine(">>> Payload - Run Ginger Action"); string ActionID = pl.GetValueString(); Console.WriteLine("Received RunAction, ActionID - " + ActionID); ActionHandler AH = null; //if (mDriver != null) //{ // AH = (from x in this.mDriver.ActionHandlers where x.ID == ActionID select x).FirstOrDefault(); //} //else if (mService != null) //{ 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 NGA = new NodeGingerAction(); AH.NodeGingerAction = NGA; //AH.GingerAction.ID = ActionID; // !!!!!!!!!!!!!!!!!!!!! why do we need to keep the ID twice !! Console.WriteLine("Found Action Handler, 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(); string Value = PLP.GetValueString(); Console.WriteLine("Param " + Name + " = " + Value); ActionParam AP = actionInputParams[Name]; if (AP != null) { actionInputParams[Name].Value = Value; } else { Console.WriteLine("Cannot find input param - " + Name); } } //Console.WriteLine("Setting params done"); //TODO: print to console: Running Action: GotoURL(URL="aaa"); !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // TODO: cache !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //if (mDriver != null) //{ // mDriver.BeforeRunAction(AH.GingerAction); // mDriver.RunAction(AH.GingerAction); // mDriver.AfterRunAction(AH.GingerAction); //} //else if (mService != null) //{ // mService.BeforeRunAction(AH.GingerAction); // mService.RunAction(AH.GingerAction); // GA.Output = new ActionOutput(); RunServiceAction(AH, actionInputParams, NGA); // mService.AfterRunAction(AH.GingerAction); //} // We send back only item which can change - ExInfo and Output values NewPayLoad PLRC = new NewPayLoad("ActionResult"); //TODO: use const PLRC.AddValue(NGA.ExInfo); PLRC.AddValue(NGA.Errors); PLRC.AddListPayLoad(GetOutpuValuesPayLoad(NGA.Output.Values)); PLRC.ClosePackage(); return(PLRC); }
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); } }
public void RunAction(GingerAction GA) { // Here we decompose the GA and create Payload to transfer it to the agent NewPayLoad PL = new NewPayLoad("RunAction"); PL.AddValue(GA.ID); List <NewPayLoad> Params = new List <NewPayLoad>(); foreach (ActionParam AP in GA.InputParams.Values) { // TODO: use const NewPayLoad p = new NewPayLoad("P"); // To save network trafic we send just one letter p.AddValue(AP.Name); p.AddValue(AP.Value.ToString()); p.ClosePackage(); Params.Add(p); } PL.AddListPayLoad(Params); PL.ClosePackage(); // TODO: use function which goes to local grid or remote grid NewPayLoad RC = SendRequestPayLoad(PL); // After we send it we parse the driver response if (RC.Name == "ActionResult") { // We read the ExInfo, Err and output params GA.ExInfo = RC.GetValueString(); string Error = RC.GetValueString(); if (!string.IsNullOrEmpty(Error)) { GA.AddError("Driver", RC.GetValueString()); // We need to get Error even if Payload is OK - since it might be in } List <NewPayLoad> OutpuValues = RC.GetListPayLoad(); foreach (NewPayLoad OPL in OutpuValues) { //TODO: change to use PL AddValueByObjectType // it is param name, type and value string PName = OPL.GetValueString(); string mOutputValueType = OPL.GetValueEnum(); switch (mOutputValueType) { case nameof(OutputValueType.String): string v = OPL.GetValueString(); GA.Output.Values.Add(new ActionOutputValue() { Param = PName, ValueString = v }); break; case nameof(OutputValueType.ByteArray): byte[] b = OPL.GetBytes(); GA.Output.Values.Add(new ActionOutputValue() { Param = PName, ValueByteArray = b }); break; default: throw new Exception("Unknown param type: " + mOutputValueType); } } } else { // The RC is not OK when we faced some unexpected exception //TODO: string Err = RC.GetValueString(); GA.AddError("RunAction", Err); } }
// 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); } }