コード例 #1
0
        public static string Format(object target, MethodInfo method, IList <Type> genericArguments, IList <object> parameterValues)
        {
            var unwrappedTarget = InvocationTarget.UnwrapDelegateTargetAndProxyBaseObject(target);

            if (InvocationTarget.IsDelegate(target))
            {
                return(FormatDelegate(unwrappedTarget, parameterValues));
            }

            if (method == null)
            {
                return(FormatWildcardInvocation(unwrappedTarget));
            }

            var property = method.GetDeclaringProperty();

            if (property != null)
            {
                return(FormatProperty(unwrappedTarget, method, property, parameterValues));
            }

            var @event = method.GetDeclaringEvent();

            if (@event != null)
            {
                return(FormatEvent(unwrappedTarget, method, @event, parameterValues));
            }

            return(FormatMethod(unwrappedTarget, genericArguments, method, parameterValues));
        }
コード例 #2
0
        public object Memoize(object dataSource, MethodInfo method, object[] args, CacheItemPolicyEx policy)
        {
            if (dataSource == null)
            {
                throw new ArgumentNullException(nameof(dataSource));
            }
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            var taskResultType = MetadataProvider.GetMethodTaskResultType(method);

            if (taskResultType == null)
            {
                throw new ArgumentException("The specified method doesn't return Task<T> and therefore cannot be memoized", nameof(method));
            }

            var    target   = new InvocationTarget(method);
            string cacheKey = $"{target}#{GetArgumentHash(args)}";

            return(Cache.GetOrAdd(cacheKey, () => (Task)method.Invoke(dataSource, args), taskResultType, policy, target.TypeName, target.MethodName));
        }
コード例 #3
0
        public void ExceptionInHandler(bool targetHasLogger)
        {
            // Arrange
            var target = new InvocationTarget();
            var logger = (DummyLogger)(targetHasLogger ? target.Logger : _parallelOperations.Logger);

            if (targetHasLogger)
            {
                SimpleEventSource += _parallelOperations.DecoupleListener(target.FaultyListener);
            }
            else
            {
                SimpleEventSource += _parallelOperations.DecoupleListener(FaultyListener);
            }
            // Act
            SimpleEventSource(this, EventArgs.Empty);
            while (!logger.Messages.Any())
            {
                Thread.Sleep(1);
            }

            // Assert
            if (targetHasLogger)
            {
                Assert.AreEqual(0, ((DummyLogger)_parallelOperations.Logger).Messages.Count, "ParallelOperations should not use its own logger for logging components");
            }
            Assert.AreEqual(logger.Messages[0].Exception.Message, "Test", "Did not log the correct exception");
        }
コード例 #4
0
        public Invocation(InvocationTarget target, object param, long delayTimeMs)
        {
            this.Target      = target;
            this.Parameter   = param;
            this.DelayTimeMs = delayTimeMs;

            elapsed  = 0;
            lastTime = Network.Util.Clock.GetTimeMilliseconds();
        }
コード例 #5
0
        public Invocation(InvocationTarget target, object param, long delayTimeMs)
        {
            this.Target = target;
            this.Parameter = param;
            this.DelayTimeMs = delayTimeMs;

            elapsed = 0;
            lastTime = Network.Util.Clock.GetTimeMilliseconds();
        }
コード例 #6
0
        public void ShouldBeAbleToChangeInputs()
        {
            MethodBase        methodBase = typeof(InvocationTarget).GetMethod("FirstTarget");
            InvocationTarget  target     = new InvocationTarget();
            IMethodInvocation invocation = new MethodInvocation(target, methodBase, new object[] { 1, "two" });

            Assert.Equal <object>(1, invocation.Inputs["one"]);
            invocation.Inputs["one"] = 42;
            Assert.Equal <object>(42, invocation.Inputs["one"]);
        }
コード例 #7
0
        static public bool MustBeNotNull(this InvocationTarget inTarget)
        {
            switch (inTarget)
            {
            case InvocationTarget.Null:
                return(false);

            default:
                return(true);
            }
        }
コード例 #8
0
ファイル: MethodBinding.cs プロジェクト: BeauPrime/RuleScript
 static private bool TryAssignContext(Type inType, ref InvocationTarget ioTarget)
 {
     if (typeof(IScriptContext).IsAssignableFrom(inType))
     {
         ioTarget = InvocationTarget.Context;
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #9
0
 public InvocationStatement(
     Location location,
     InvocationTarget invocationTarget,
     IDictionary <ParameterIndex, Reference> passedParameters,
     IDictionary <ParameterIndex, Reference> returnedValues,
     bool isConstructor = false)
     : base(location)
 {
     InvocationTarget = invocationTarget;
     PassedParameters = new Dictionary <ParameterIndex, Reference>(passedParameters);
     ReturnedValues   = new Dictionary <ParameterIndex, Reference>(returnedValues);
     IsConstructor    = isConstructor;
 }
コード例 #10
0
        public ServiceMethod Resolve(InvocationTarget target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target), "An invocation target must be specified.");
            }

            if (target.IsWeaklyTyped)
            {
                ServiceMethod[] methods;
                if (string.IsNullOrEmpty(target.TypeName))
                {
                    SimpleMethodCache.TryGetValue(target.MethodName, out methods);
                }
                else
                {
                    TypedMethodCache.TryGetValue(GetTypedMethodKey(target.TypeName, target.MethodName), out methods);
                }

                if (methods == null)
                {
                    throw new MissingMethodException("The specified request contains an unrecognized interface name, method name.");
                }

                if (methods.Length > 1)
                {
                    throw new ProgrammaticException("Weakly-typed requests cannot be used for methods with more than one overload (including methods that are only differentiated by letter case)",
                                                    unencrypted: new Tags {
                        { "method", target.MethodName }, { "type", target.TypeName }
                    });
                }

                return(methods.Single());
            }
            else
            {
                if (string.IsNullOrEmpty(target.TypeName) || string.IsNullOrEmpty(target.MethodName) || target.ParameterTypes == null)
                {
                    throw new ArgumentException("The specified invocation target is invalid.", nameof(target));
                }

                MethodCache.TryGetValue(target, out ServiceMethod method);

                if (method == null)
                {
                    throw new MissingMethodException("The specified request contains an unrecognized interface name, method name or method overload.");
                }

                return(method);
            }
        }
コード例 #11
0
ファイル: MethodBinding.cs プロジェクト: BeauPrime/RuleScript
        private void Bind(InvocationTarget inTarget, IRSRuntimeEntity inEntity, IScriptContext inContext, ref object ioValue)
        {
            switch (inTarget)
            {
            case InvocationTarget.Entity:
                ioValue = inEntity;
                break;

            case InvocationTarget.Component:
                ioValue = inEntity?.GetRSComponent(ComponentType);
                break;

            case InvocationTarget.Context:
                ioValue = inContext;
                break;
            }
        }
コード例 #12
0
ファイル: MethodBinding.cs プロジェクト: BeauPrime/RuleScript
 static private bool TryAssignTarget(Type inType, ref InvocationTarget ioTarget, ref Type ioComponentType)
 {
     if (typeof(IRSEntity).IsAssignableFrom(inType))
     {
         ioTarget = InvocationTarget.Entity;
         return(true);
     }
     else if (typeof(IRSComponent).IsAssignableFrom(inType))
     {
         ioTarget        = InvocationTarget.Component;
         ioComponentType = inType;
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #13
0
        public void HttpServiceRequestShouldContainAdditionaPropertiesRecursively()
        {
            TracingData tData = new TracingData
            {
                ParentSpanID = "ParentSpanID1",
                SpanID       = "SpanID1"
            };
            RequestOverrides requestOverrides = new RequestOverrides
            {
                Hosts = new[] { new HostOverride {
                                    ServiceName = "Service1", Host = "HostNameOverride"
                                } }.ToList(),
                             SuppressCaching = CacheSuppress.RecursiveAllDownstreamServices
            };
            InvocationTarget invocationTarget = new InvocationTarget {
                MethodName = "MethodName1"
            };

            HttpServiceRequest serviceRequest = new HttpServiceRequest
            {
                TracingData = tData,
                Overrides   = requestOverrides,
                Target      = invocationTarget
            };

            dynamic            jObject = JObject.FromObject(serviceRequest);
            HttpServiceRequest serviceRequestResult = DeserializeObject <HttpServiceRequest>(jObject);

            AssertShouldBeNull(serviceRequestResult);

            jObject.Add("ServiceRequestData", "ServiceRequestData1");
            jObject["TracingData"].Add("TracingData", "TracingData1");
            jObject["Overrides"].Add("OverridesData", "OverridesData1");
            jObject["Overrides"]["Hosts"][0].Add("HostOverrideData", "HostOverrideData1");
            jObject["Target"].Add("TargetData", "TargetData1");

            serviceRequestResult = DeserializeObject <HttpServiceRequest>(jObject);
            AssertShouldNotBeNull(serviceRequestResult);
        }
コード例 #14
0
 public Invocation(InvocationTarget target, object param)
     : this(target, param, 0)
 {
 }
コード例 #15
0
 public Invocation(InvocationTarget target, object param)
     : this(target, param, 0)
 {
 }
コード例 #16
0
 public Invocation(InvocationTarget target)
     : this(target, null)
 {
 }
コード例 #17
0
 public ServiceMethod Resolve(InvocationTarget target)
 {
     return(_serviceMethodResolver.Resolve(target));
 }
コード例 #18
0
ファイル: Invocation.cs プロジェクト: bburhans/vtank
 public Invocation(InvocationTarget target)
     : this(target, null)
 {
 }
コード例 #19
0
ファイル: Invocation.cs プロジェクト: bburhans/vtank
 public Invocation(InvocationTarget target, object param)
 {
     this.Target    = target;
     this.Parameter = param;
 }
コード例 #20
0
 public Invocation(InvocationTarget target, object param)
 {
     this.Target = target;
     this.Parameter = param;
 }
コード例 #21
0
ファイル: MethodBinding.cs プロジェクト: BeauPrime/RuleScript
        public void Configure(MethodInfo inMethod, ParameterInfo[] inParameters, bool inbAllowUnboundParams)
        {
            EditorArgsStartIndex = 0;

            if (inMethod.IsStatic)
            {
                ThisParam = InvocationTarget.Null;
                bool bIsExtension = inParameters.Length > 0 && inMethod.IsDefined(typeof(ExtensionAttribute));
                if (bIsExtension)
                {
                    IsExtension = true;
                    BoundType   = inParameters[0].ParameterType;

                    if (!TryAssignTarget(inParameters[0].ParameterType, ref FirstParam, ref ComponentType))
                    {
                        throw InvalidBindException("Cannot bind extension method target", inParameters[0].ParameterType, inMethod);
                    }

                    ++EditorArgsStartIndex;
                    if (inParameters.Length > 1)
                    {
                        if (!TryAssignContext(inParameters[1].ParameterType, ref SecondParam))
                        {
                            if (!inbAllowUnboundParams)
                            {
                                throw InvalidBindException("Cannot bind extension method context", inParameters[1].ParameterType, inMethod);
                            }
                            return;
                        }

                        ++EditorArgsStartIndex;
                        if (!inbAllowUnboundParams && inParameters.Length > 2)
                        {
                            throw InvalidArgumentCountException("Invalid parameter count for query extension method", inParameters.Length, 2, inMethod);
                        }
                    }
                }
                else
                {
                    BoundType = null;

                    if (inParameters.Length > 0)
                    {
                        if (!TryAssignContext(inParameters[0].ParameterType, ref FirstParam))
                        {
                            if (!inbAllowUnboundParams)
                            {
                                throw InvalidBindException("Cannot bind static method context", inParameters[0].ParameterType, inMethod);
                            }
                            return;
                        }

                        ++EditorArgsStartIndex;
                        if (!inbAllowUnboundParams && inParameters.Length > 1)
                        {
                            throw InvalidArgumentCountException("Invalid parameter count for static method", inParameters.Length, 1, inMethod);
                        }
                    }
                }
            }
            else
            {
                IsInstance = true;
                BoundType  = inMethod.DeclaringType;

                if (!TryAssignTarget(inMethod.DeclaringType, ref ThisParam, ref ComponentType))
                {
                    throw InvalidBindException("Cannot bind instance method target", inMethod.DeclaringType, inMethod);
                }

                if (inParameters.Length > 0)
                {
                    if (TryAssignContext(inParameters[0].ParameterType, ref FirstParam))
                    {
                        ++EditorArgsStartIndex;
                    }
                    else
                    {
                        if (!inbAllowUnboundParams)
                        {
                            throw InvalidBindException("Cannot bind instance method context", inParameters[0].ParameterType, inMethod);
                        }
                    }
                }
            }
        }
コード例 #22
0
 public void Dispose()
 {
     Target = null;
     Parameter = null;
 }
コード例 #23
0
 public void Dispose()
 {
     Target    = null;
     Parameter = null;
 }
コード例 #24
0
 public override bool Equals(object obj)
 {
     return(base.Equals(InvocationTarget.UnwrapProxyBaseObject(obj)));
 }