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 ListsStructTestJSON() { //Arrange complexStructwithStrings s1 = new complexStructwithStrings() { a = "aaa", strings = new List <string>() { "aaa", "bbb", "ccc" }, b = "ggg" }; // Act NewPayLoad pl = new NewPayLoad("ll"); pl.AddJSONValue(s1); pl.ClosePackage(); string s123 = pl.BufferInfo; byte[] b = pl.GetPackage(); NewPayLoad pl2 = new NewPayLoad(b); complexStructwithStrings s2 = pl2.GetJSONValue <complexStructwithStrings>(); //Assert Assert.AreEqual(s1.a, s2.a); Assert.AreEqual(s2.strings.Count, s2.strings.Count); Assert.AreEqual(s2.strings[0], s2.strings[0]); Assert.AreEqual(s2.strings[1], s2.strings[1]); Assert.AreEqual(s2.strings[2], s2.strings[2]); Assert.AreEqual(s1.b, s2.b); }
private void SendButton_Click(object sender, RoutedEventArgs e) { NewPayLoad PL = new NewPayLoad(PayLoadNameTextBox.Text); PL.ClosePackage(); mGingerNodeProxy.SendRequestPayLoad(PL); }
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"); }
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 CloseDriver() { NewPayLoad PL = new NewPayLoad("CloseDriver"); //!!!! Rename to StopService + use const PL.ClosePackage(); NewPayLoad RC = SendRequestPayLoad(PL); }
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); }
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 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); }
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; } }
public void CloseDriver() { NewPayLoad PL = new NewPayLoad("CloseDriver"); PL.ClosePackage(); NewPayLoad RC = SendRequestPayLoad(PL); }
private NewPayLoad StartDriver(NewPayLoad pl) { try { List <NewPayLoad> FieldsandParams = pl.GetListPayLoad(); Dictionary <string, string> InputParams = new Dictionary <string, string>(); foreach (NewPayLoad Np in FieldsandParams) { string Name = Np.GetValueString(); string Value = Np.GetValueString(); if (!InputParams.ContainsKey(Name)) { InputParams.Add(Name, Value); } } ConfigureServiceParams(mService, InputParams); Console.WriteLine("Payload - Start Session"); ((IServiceSession)mService).StartSession(); NewPayLoad PLRC = new NewPayLoad("OK"); PLRC.ClosePackage(); return(PLRC); } catch (Exception ex) { return(NewPayLoad.Error(ex.Message)); } }
public void StartDriver() { //TODO: get return code - based on it set status if running OK NewPayLoad PL = new NewPayLoad("StartDriver"); PL.ClosePackage(); SendRequestPayLoad(PL); }
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); } }
private NewPayLoad TakeScreenot(NewPayLoad ActionPayload) { if (mService is IScreenShotService ScreenshotService) { Dictionary <string, string> InputParams = new Dictionary <string, string>(); List <NewPayLoad> FieldsandParams = ActionPayload.GetListPayLoad(); foreach (NewPayLoad Np in FieldsandParams) { string Name = Np.GetValueString(); string Value = Np.GetValueString(); if (!InputParams.ContainsKey(Name)) { InputParams.Add(Name, Value); } } NewPayLoad ResponsePL = new NewPayLoad("ScreenShots"); string WindowsToCapture = InputParams["WindowsToCapture"]; List <NewPayLoad> ScreenShots = new List <NewPayLoad>(); switch (WindowsToCapture) { case "OnlyActiveWindow": ScreenShots.Add(BitmapToPayload(ScreenshotService.GetActiveScreenImage())); break; case "AllAvailableWindows": foreach (Bitmap bmp in ScreenshotService.GetAllScreensImages()) { ScreenShots.Add(BitmapToPayload(bmp)); } break; default: return(NewPayLoad.Error("Service is not supporting IScreenShotService cannot delegate to take screen shot")); } Bitmap img = ScreenshotService.GetActiveScreenImage(); ResponsePL.AddListPayLoad(ScreenShots); ResponsePL.ClosePackage(); return(ResponsePL); } NewPayLoad err2 = NewPayLoad.Error("Service is not supporting IScreenShotService cannot delegate to take screen shot"); return(err2); }
private NewPayLoad StartDriver() { Console.WriteLine("Payload - Start Driver"); mDriver.StartDriver(); NewPayLoad PLRC = new NewPayLoad("OK"); PLRC.ClosePackage(); return(PLRC); }
private NewPayLoad ShutdownNode() { Console.WriteLine("Payload - Shutdown, start closing"); GingerNodeMessage.Invoke(this, eGingerNodeEventType.Shutdown); NewPayLoad PLRC = new NewPayLoad("OK"); PLRC.ClosePackage(); return(PLRC); }
private NewPayLoad StartDriver() { Console.WriteLine("Payload - Start Session"); ((IServiceSession)mService).StartSession(); NewPayLoad PLRC = new NewPayLoad("OK"); PLRC.ClosePackage(); return(PLRC); }
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; }
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); }
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); }
// 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"); } }
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); }
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 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); } }
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); }
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 UTF16String() { //Arrange string s0 = "Hello World גךעחךגכ ■N╜ !@#$!@#$% ÜÑ├µΦ"; NewPayLoad pl = new NewPayLoad("UTF16String"); pl.AddStringUTF16(s0); pl.ClosePackage(); // Act byte[] b = pl.GetPackage(); NewPayLoad pl2 = new NewPayLoad(b); string s1 = pl2.GetStringUTF16(); //Assert Assert.AreEqual(s0, s1); }