示例#1
0
        public Result Invoke(InvokeParameter param)
        {
            using (var ps = PowerShell.Create())
            {
                ps.InvocationStateChanged += param.invocationStateChanged;
                ps.RunspacePool            = param.rsp;

                ps.AddScript(script);
                ps.AddParameters(param.parameters);

                var ret = new Result();
                try
                {
                    using (param.cancelToken.Register(() => { ps.Stop(); ret.canceled = true; }))
                    {
                        ret.objs = ps.Invoke();
                    }
                    ret.errors = ps.Streams.Error.ToList();
                }
                catch (Exception e)
                {
                    ret.errors = (new[] { new ErrorRecord(e, "", ErrorCategory.InvalidData, null) }).ToList();
                }

                return(ret);
            }
        }
示例#2
0
 public InvokeParameter(InvokeParameter other)
 {
     rsp                    = other.rsp;
     parameters             = other.parameters;
     cancelToken            = other.cancelToken;
     invocationStateChanged = other.invocationStateChanged;
 }
        /**
         * Last in series of element callbacks. For more information refer to /DotNet/Action/ZenAction.cs.
         * Here goes main element logic.
         */
        public void ExecuteAction(Hashtable elements, IPlugin element, IPlugin iAmStartedYou)
        {
            // Get current element results that are then passed as arguments to neo smart contract function
            object[] args = GetSmartContractArgs();

            List <InvokeParameter> neoParameters = new List <InvokeParameter>();

            for (int i = 0; i < args.Length; i++)
            {
                InvokeParameter neoParameter = new InvokeParameter();
                //TO DO : read type from property
                //http://docs.neo.org/en-us/sc/tutorial/Parameter.html
                neoParameter.Type  = "02";
                neoParameter.Value = args[i].ToString();
                neoParameters.Add(neoParameter);
            }

            var client = new RpcClient(new Uri(_rpcClientUri));

            var result = await new RPC.NeoApiService(client).Contracts.
                         InvokeContract.SendRequestAsync(_scriptHash, neoParameters);

            Hashtable htResult = new Hashtable();

            htResult.Add("TYPE", result.Stack[0].Type);
            htResult.Add("VALUE", result.Stack[0].Value);
            element.LastResultBoxed = htResult;
            element.IsConditionMet  = true;
        }
示例#4
0
 private void Init()
 {
     foreach (PropertyInfo pi in View.GetProperties(BindingFlags.Public | BindingFlags.Instance))
     {
         InvokeParameter parameter = new InvokeParameter(pi);
         BindAttribute[] ba        = Functions.GetPropertyAttributes <BindAttribute>(pi, false);
         if (ba.Length > 0)
         {
             parameter.Binder = ba[0];
         }
         Parameters.Add(parameter);
     }
 }
示例#5
0
 private void Init()
 {
     foreach (PropertyInfo pi in View.GetProperties(BindingFlags.Public | BindingFlags.Instance))
     {
         InvokeParameter parameter = new InvokeParameter(pi);
         BindAttribute[] ba = Functions.GetPropertyAttributes<BindAttribute>(pi, false);
         if (ba.Length > 0)
             parameter.Binder = ba[0];
         Parameters.Add(parameter);
     }
 }