Esempio n. 1
0
        public IValue CallMethod(IRuntimeContextInstance target, string methodName, ArrayImpl arguments = null)
        {
            var methodIdx = target.FindMethod(methodName);
            var methInfo  = target.GetMethodInfo(methodIdx);

            var argsToPass = GetArgsToPass(arguments, methInfo);

            IValue retValue = ValueFactory.Create();

            if (methInfo.IsFunction)
            {
                target.CallAsFunction(methodIdx, argsToPass, out retValue);
            }
            else
            {
                target.CallAsProcedure(methodIdx, argsToPass);
            }

            if (arguments != null)
            {
                for (int i = 0; i < argsToPass.Length; i++)
                {
                    if (i < arguments.Count())
                    {
                        arguments.Set(i, argsToPass[i]?.GetRawValue());
                    }
                }
            }

            return(retValue);
        }
Esempio n. 2
0
        public IValue CallMethod(IRuntimeContextInstance target, string methodName, IRuntimeContextInstance arguments = null)
        {
            ArrayImpl argArray;

            if (arguments != null)
            {
                argArray = arguments as ArrayImpl;
                if (argArray == null)
                {
                    throw RuntimeException.InvalidArgumentType();
                }
            }
            else
            {
                argArray = new ArrayImpl();
            }

            var methodIdx = target.FindMethod(methodName);

            var    methInfo = target.GetMethodInfo(methodIdx);
            IValue retValue = ValueFactory.Create();

            if (methInfo.IsFunction)
            {
                target.CallAsFunction(methodIdx, argArray.ToArray(), out retValue);
            }
            else
            {
                target.CallAsProcedure(methodIdx, argArray.ToArray());
            }

            return(retValue);
        }
        public void CallCommonModuleProcedure(string moduleName, string methodName, IValue[] parameters)
        {
            IRuntimeContextInstance commonModule = (IRuntimeContextInstance)_hostedScript.EngineInstance.Environment.GetGlobalProperty(moduleName);
            int methodId = commonModule.FindMethod(methodName);

            commonModule.CallAsProcedure(methodId, parameters);
        }
Esempio n. 4
0
        public IValue CallMethod(IRuntimeContextInstance target, string methodName, ArrayImpl arguments = null)
        {
            if (arguments == null)
            {
                arguments = new ArrayImpl();
            }

            var methodIdx = target.FindMethod(methodName);

            var methInfo = target.GetMethodInfo(methodIdx);

            if (methInfo.ArgCount < arguments.Count())
            {
                throw RuntimeException.TooManyArgumentsPassed();
            }

            if (methInfo.ArgCount > arguments.Count())
            {
                throw RuntimeException.TooLittleArgumentsPassed();
            }

            IValue retValue = ValueFactory.Create();

            if (methInfo.IsFunction)
            {
                target.CallAsFunction(methodIdx, arguments.ToArray(), out retValue);
            }
            else
            {
                target.CallAsProcedure(methodIdx, arguments.ToArray());
            }

            return(retValue);
        }
Esempio n. 5
0
        private static void ProduceResponse(HttpContext context, IRuntimeContextInstance runner)
        {
            int    methodIndex = runner.FindMethod("ОбработкаВызоваHTTPСервиса");
            IValue result;

            IValue[] args = new IValue[1];
            args[0] = new OneScript.HTTPService.HTTPServiceRequestImpl(context);
            runner.CallAsFunction(methodIndex, args, out result);

            // Обрабатываем результаты
            var response = (OneScript.HTTPService.HTTPServiceResponseImpl)result;

            context.Response.StatusCode = response.StatusCode;

            if (response.Headers != null)
            {
                foreach (var ch in response.Headers)
                {
                    context.Response.AddHeader(ch.Key.AsString(), ch.Value.AsString());
                }
            }

            if (response.Reason != "")
            {
                context.Response.Status = response.Reason;
            }

            if (response.BodyStream != null)
            {
                response.BodyStream.Seek(0, SeekOrigin.Begin);
                response.BodyStream.CopyTo(context.Response.OutputStream);
            }

            context.Response.Charset = response.ContentCharset;
        }
Esempio n. 6
0
        public void PublishMethod(string name, string alias)
        {
            var thisIndex = _thisMethIndexes.RegisterName(name, alias);
            var thatIndex = _inst.FindMethod(name);

            Debug.Assert(thatIndex >= 0);

            _methRedirects.Add(thisIndex, thatIndex);
        }
        public IValue CallCommonModuleFunction(string moduleName, string methodName, IValue[] parameters)
        {
            IRuntimeContextInstance commonModule = (IRuntimeContextInstance)_hostedScript.EngineInstance.Environment.GetGlobalProperty(moduleName);
            int    methodId = commonModule.FindMethod(methodName);
            IValue result   = ValueFactory.Create();

            commonModule.CallAsFunction(methodId, parameters, out result);
            return(result);
        }
        private int GetDispatchIndex(IRuntimeContextInstance obj)
        {
            if (_dispId != -1)
            {
                return(obj.FindMethod(Name));
            }

            return(_dispId);
        }
Esempio n. 9
0
 private static bool MethodExistsForObject(IRuntimeContextInstance target, string methodName)
 {
     try
     {
         var idx = target.FindMethod(methodName);
         return(idx >= 0);
     }
     catch (RuntimeException)
     {
         return(false);
     }
 }
Esempio n. 10
0
        public static DelegateAction Create(IRuntimeContextInstance target, string methodName)
        {
            var method = target.FindMethod(methodName);

            Func <IValue[], IValue> action = (parameters) =>
            {
                IValue retVal;
                target.CallAsFunction(method, parameters, out retVal);
                return(retVal);
            };

            return(new DelegateAction(action));
        }
Esempio n. 11
0
        public BackgroundTask(IRuntimeContextInstance target, string methodName, ArrayImpl parameters = default)
        {
            Target     = target;
            MethodName = methodName;
            if (parameters != default)
            {
                Parameters = new ArrayImpl(parameters);
            }

            Identifier = new GuidWrapper();

            _methIndex = Target.FindMethod(MethodName);
            _method    = Target.GetMethodInfo(_methIndex);
        }
Esempio n. 12
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            int methIdx;

            try
            {
                methIdx = _context.FindMethod(binder.Name);
            }
            catch (MethodAccessException)
            {
                result = null;
                return(false);
            }

            var    valueArgs = args.Select(x => CustomMarshaller.ConvertReturnValue(x, x.GetType())).ToArray();
            IValue methResult;

            _context.CallAsFunction(methIdx, valueArgs, out methResult);
            result = CustomMarshaller.ConvertToDynamicCLRObject(methResult);

            return(true);
        }
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            int methIdx;

            try
            {
                methIdx = _context.FindMethod(binder.Name);
            }
            catch (MethodAccessException)
            {
                result = null;
                return(false);
            }

            var methInfo   = _context.GetMethodInfo(methIdx);
            var valueArgs  = new IValue[methInfo.Params.Length];
            var passedArgs = args.Select(x => CustomMarshaller.ConvertReturnValue(x, x.GetType())).ToArray();

            for (int i = 0; i < valueArgs.Length; i++)
            {
                if (i < passedArgs.Length)
                {
                    valueArgs[i] = passedArgs[i];
                }
                else
                {
                    valueArgs[i] = ValueFactory.CreateInvalidValueMarker();
                }
            }

            IValue methResult;

            _context.CallAsFunction(methIdx, valueArgs, out methResult);
            result = methResult == null? null : CustomMarshaller.ConvertToDynamicCLRObject(methResult);

            return(true);
        }