예제 #1
0
        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);
        }
예제 #2
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 = 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);
        }