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 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 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 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); }
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 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); }
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 = (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); }
// 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); }
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); }
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); } }