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 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); }
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); }
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 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); }
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); }
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); } }