Ejemplo n.º 1
0
        /// <summary>
        /// register service and method to server for client call thats
        /// </summary>
        /// <typeparam name="T">type of interface for create instanse</typeparam>
        /// <returns>return instance of interface that client can call methods</returns>
        public T RegisterClientServiceInterface <T>()
        {
            var            type     = typeof(T);
            var            name     = type.GetCustomAttributes <ServiceContractAttribute>(true).FirstOrDefault().Name;
            MethodCallInfo callInfo = new MethodCallInfo()
            {
                ServiceName = name,
                MethodName  = "/RegisterService",
                Guid        = Guid.NewGuid().ToString()
            };
            var callback = this.SendData <MethodCallbackInfo>(callInfo);

            var t = CSCodeInjection.GenerateInterfaceType(type, typeof(OperationCalls), new List <Type>()
            {
                typeof(ServiceContractAttribute), this.GetType()
            }, false);

            var     objectInstance = Activator.CreateInstance(t);
            dynamic dobj           = objectInstance;

            dobj.InvokedClientMethodAction   = CSCodeInjection.InvokedClientMethodAction;
            dobj.InvokedClientMethodFunction = CSCodeInjection.InvokedClientMethodFunction;

            var duplex = objectInstance as OperationCalls;

            duplex.Connector = this;
            Services.TryAdd(name, objectInstance);
            return((T)objectInstance);
        }
Ejemplo n.º 2
0
        public void OnEnable()
        {
            var methods =
                target.GetType()
                .GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public |
                            BindingFlags.NonPublic);

            foreach (var method in methods)
            {
                if (method.GetCustomAttributes(typeof(DebugButtonAttribute), false).Any())
                {
                    if (_methodCallInfo == null)
                    {
                        _methodCallInfo = new List <MethodCallInfo>();
                    }

                    var mci = new MethodCallInfo
                    {
                        MethodInfo = method,
                        Parameters = new List <ParamTuple>()
                    };

                    foreach (var p in method.GetParameters().ToList())
                    {
                        mci.Parameters.Add(new ParamTuple {
                            Obj = p.DefaultValue, ParamInfo = p
                        });
                    }

                    _methodCallInfo.Add(mci);
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     This returns true if we have set (changed) values during a transaction
 /// </summary>
 /// <param name="methodCallInfo">MethodCallInfo</param>
 private void IsTransactionDirty(MethodCallInfo methodCallInfo)
 {
     lock (_transactionProperties)
     {
         methodCallInfo.ReturnValue = _inTransaction && _transactionProperties.Count > 0;
     }
 }
Ejemplo n.º 4
0
        internal static async Task RunMethod(ServerBase serverBase, ClientInfo client)
        {
            MethodCallbackInfo callback = null;

            try
            {
                byte[] bytes = await client.StreamHelper.ReadBlockToEndAsync(client.ClientStream, CompressMode.None, serverBase.ProviderSetting.MaximumReceiveStreamHeaderBlock);

                string         json     = Encoding.UTF8.GetString(bytes);
                MethodCallInfo callInfo = ServerSerializationHelper.Deserialize <MethodCallInfo>(json, serverBase);
                //MethodsCallHandler.BeginStreamCallAction?.Invoke(client, guid, serviceName, methodName, values);
                CallMethodResultInfo <OperationContext> result = await CallMethod(callInfo.ServiceName, callInfo.Guid, callInfo.MethodName, callInfo.Parameters, null, client, null, serverBase, null, null);

                callback = result.CallbackInfo;
            }
            catch (Exception ex)
            {
                callback = new MethodCallbackInfo
                {
                    IsException = true,
                    Data        = ServerSerializationHelper.SerializeObject(ex)
                };
            }
            finally
            {
                //MethodsCallHandler.EndStreamCallAction?.Invoke(client, guid, serviceName, methodName, values, jsonResult, exception);
            }
            await SendCallbackData(callback, client, serverBase);
        }
Ejemplo n.º 5
0
        private string OnCallMqlMethod(string methodName, IEnumerable <string> parameters)
        {
            string returnValue = "";

            try
            {
                try
                {
                    this.ClientMethod = new MethodCallInfo(methodName, parameters);
                    this.ClientCallSemaphore.Set();
                    this.ServerCallSemaphore.WaitOne();
                    returnValue = this.ClientMethod.ReturnValue;
                    if (!string.IsNullOrEmpty(this.ClientMethod.ErrorMessage) && this._mqlHandler.MqlError != null)
                    {
                        MqlErrorException mqlErrorException = new MqlErrorException(this.ExpertInfo, this.ClientMethod);
                        this._mqlHandler.MqlError(mqlErrorException);
                        Trace.Write(new TraceInfo(BridgeTraceErrorType.MqlError, mqlErrorException, ""));
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    Trace.Write(new TraceInfo(BridgeTraceErrorType.Execption, exception, ""));
                }
            }
            finally
            {
                this.ClientMethod = null;
            }
            return(returnValue);
        }
Ejemplo n.º 6
0
 /// <summary>
 ///     Logic to start the transaction, any setter used after this will be in the transaction
 /// </summary>
 /// <param name="methodCallInfo">MethodCallInfo</param>
 private void StartTransaction(MethodCallInfo methodCallInfo)
 {
     lock (_transactionProperties)
     {
         _inTransaction = true;
     }
 }
Ejemplo n.º 7
0
        private string OnCallMqlMethod(string methodName, IEnumerable <string> parameters)
        {
            string str = "";

            try
            {
                this.ClientMethod = new MethodCallInfo(methodName, parameters);
                this.ClientCallSemaphore.Set();
                this.ServerCallSemaphore.WaitOne();
                str = this.ClientMethod.ReturnValue;
                if (!string.IsNullOrEmpty(this.ClientMethod.ErrorMessage))
                {
                    if (this._mqlHandler.MqlError != null)
                    {
                        MqlErrorException mqlErrorException = new MqlErrorException(this.ExpertInfo, this.ClientMethod);
                        this._mqlHandler.MqlError(mqlErrorException);
                        Trace.Write((object)new LogInfo(LogType.MqlError, (Exception)mqlErrorException, ""));
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.Write((object)new LogInfo(LogType.Execption, ex, ""));
            }
            finally
            {
                this.ClientMethod = (MethodCallInfo)null;
            }
            return(str);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// send data to server
        /// </summary>
        /// <param name="client">client is sended</param>
        /// <param name="callerName">methos name</param>
        /// <param name="attibName">service name</param>
        /// <param name="args">method parameters</param>
        /// <returns></returns>
        internal static object SendData(this OperationCalls client, string callerName, string attibName, params object[] args)
        {
            MethodCallInfo callInfo = new MethodCallInfo();

            if (string.IsNullOrEmpty(attibName))
            {
                callInfo.ServiceName = client.GetType().GetCustomAttributes <ServiceContractAttribute>(true).FirstOrDefault().Name;
            }
            else
            {
                callInfo.ServiceName = attibName;
            }

            callInfo.MethodName = callerName;
            foreach (var item in args)
            {
                callInfo.Parameters.Add(new Shared.Models.ParameterInfo()
                {
                    Value = JsonConvert.SerializeObject(item), Type = item?.GetType().FullName
                });
            }
            var guid = Guid.NewGuid().ToString();

            callInfo.Guid = guid;
            return(SendData(client.Connector, callInfo, args.Length == 1 && args[0] != null && args[0].GetType() == typeof(StreamInfo) ? (StreamInfo)args[0] : null));
        }
        /// <summary>
        /// return types of method parameter
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="callInfo"></param>
        /// <returns></returns>
        public static List <Type> GetMethodTypes(Type serviceType, MethodCallInfo callInfo)
        {
            List <Type> methodParameterTypes = new List <Type>();

#if (NETSTANDARD1_6)
            var methods = serviceType.GetTypeInfo().GetMethods();
#else
            var methods = serviceType.GetMethods();
#endif
            foreach (var item in methods)
            {
                if (item.Name == callInfo.MethodName)
                {
                    if (item.GetParameters().Length != callInfo.Parameters.Count)
                    {
                        continue;
                    }
                    foreach (var p in item.GetParameters())
                    {
                        methodParameterTypes.Add(p.ParameterType);
                    }
                    break;
                }
            }
            return(methodParameterTypes);
        }
Ejemplo n.º 10
0
        private void FindMethods(Type targetType)
        {
            var methods = targetType.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

            foreach (var method in methods)
            {
                if (method.GetCustomAttributes(typeof(DebugButtonAttribute), false).Any())
                {
                    var mci = new MethodCallInfo
                    {
                        methodInfo = method,
                        parameters = new List <ParamTuple>()
                    };

                    foreach (var p in method.GetParameters())
                    {
                        mci.parameters.Add(new ParamTuple {
                            obj = p.DefaultValue, paramInfo = p
                        });
                    }

                    _methodCallInfo.Add(mci);
                }
            }

            if (_methodCallInfo.Count == 0 && targetType.BaseType != null)
            {
                // Could not find methods, look in parent class (as long as it is not simply 'object')
                FindMethods(targetType.BaseType);
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageInfo"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="target">The target.</param>
 /// <param name="methodCallName">Name of the method call.</param>
 /// <param name="methodCallInfo">The method call info.</param>
 internal MessageInfo(ObjectInfo source, ObjectInfo target, string methodCallName, MethodCallInfo methodCallInfo)
 {
   this.Source = source;
   this.Target = target;
   this.MethodCallName = methodCallName;
   this.MethodCallInfo = methodCallInfo;
 }
Ejemplo n.º 12
0
        internal static object SendCustomCallbackToClient(ClientInfo client, MethodCallInfo callInfo)
        {
            var guid = Guid.NewGuid().ToString();

            callInfo.Guid = guid;
            var waitedMethodsForResponse = client.ServerBase.WaitedMethodsForResponse[client];

            waitedMethodsForResponse.TryAdd(guid, new KeyValue <AutoResetEvent, MethodCallbackInfo>(new AutoResetEvent(false), null));
            client.ServerBase.CallClientMethod(client, callInfo);
            var seted = waitedMethodsForResponse[guid].Key.WaitOne(client.ServerBase.ProviderSetting.ReceiveDataTimeout);

            if (!seted)
            {
                client.ServerBase.CheckClient(client);
                waitedMethodsForResponse.Remove(guid);
                throw new TimeoutException();
            }
            if (waitedMethodsForResponse[guid].Value.IsException)
            {
                var data = waitedMethodsForResponse[guid].Value.Data;
                waitedMethodsForResponse.Remove(guid);
                throw new Exception("call method return exception: " + data);
            }
            var result = waitedMethodsForResponse[guid].Value.Data;

            waitedMethodsForResponse.Remove(guid);
            return(result);
        }
Ejemplo n.º 13
0
        //public object SendData(this ClientDuplex client, string className, string callerName, params object[] args)
        //{
        //    MethodCallInfo callInfo = new MethodCallInfo();
        //    callInfo.FullClassName = className;
        //    callInfo.MethodName = callerName;
        //    foreach (var item in args)
        //    {
        //        callInfo.Parameters.Add(new Shared.Models.ParameterInfo() { Type = item.GetType().FullName, Value = JsonConvert.SerializeObject(item) });
        //    }
        //    SendData(callInfo);
        //    return null;
        //}

        /// <summary>
        /// send data to call server method
        /// </summary>
        /// <param name="Data"></param>
        internal void SendData(MethodCallInfo Data)
        {
            AsyncActions.Run(() =>
            {
                try
                {
                    var json          = JsonConvert.SerializeObject(Data);
                    List <byte> bytes = new List <byte>
                    {
                        (byte)DataType.CallMethod,
                        (byte)CompressMode.None
                    };
                    var jsonBytes = Encoding.UTF8.GetBytes(json);
                    if (SecuritySettings != null)
                    {
                        jsonBytes = EncryptBytes(jsonBytes);
                    }
                    byte[] dataLen = BitConverter.GetBytes(jsonBytes.Length);
                    bytes.AddRange(dataLen);
                    bytes.AddRange(jsonBytes);
                    if (bytes.Count > ProviderSetting.MaximumSendDataBlock)
                    {
                        throw new Exception("SendData data length is upper than MaximumSendDataBlock");
                    }
                    GoStreamWriter.WriteToStream(_client.GetStream(), bytes.ToArray(), IsWebSocket);
                }
                catch (Exception ex)
                {
                    AutoLogger.LogError(ex, "ConnectorBase SendData");
                }
            });
        }
        /// <summary>
        /// this method call when client want to upload file or stream to your server
        /// </summary>
        /// <param name="stream">client stream</param>
        /// <param name="client">client</param>
        private static async Task DownloadStreamFromClient(ClientInfo client, ServerBase serverBase)
        {
            MethodCallbackInfo callback = null;
            string             guid     = Guid.NewGuid().ToString();

            try
            {
                byte[] bytes = await client.StreamHelper.ReadBlockToEndAsync(client.ClientStream, CompressMode.None, serverBase.ProviderSetting.MaximumReceiveStreamHeaderBlock);

                string         json     = Encoding.UTF8.GetString(bytes);
                MethodCallInfo callInfo = ServerSerializationHelper.Deserialize <MethodCallInfo>(json, serverBase);

                CallMethodResultInfo <OperationContext> result = await CallMethod(callInfo.ServiceName, callInfo.Guid, callInfo.MethodName,
                                                                                  callInfo.Parameters, null, client, null, serverBase, null, null);

                callback = result.CallbackInfo;
            }
            catch (IOException ex)
            {
                callback             = new MethodCallbackInfo();
                callback.IsException = true;
                callback.Data        = ServerSerializationHelper.SerializeObject(ex);
                //return;
            }
            catch (Exception ex)
            {
                callback             = new MethodCallbackInfo();
                callback.IsException = true;
                callback.Data        = ServerSerializationHelper.SerializeObject(ex);
            }
            finally
            {
            }
            await SendCallbackData(callback, client, serverBase);
        }
Ejemplo n.º 15
0
 /// <summary>
 ///     Check if a property is tagged with a certain tag
 /// </summary>
 /// <param name="methodCallInfo">IMethodCallMessage</param>
 private void IsTaggedWith(MethodCallInfo methodCallInfo)
 {
     methodCallInfo.ReturnValue = false;
     if (_taggedProperties.TryGetValue(methodCallInfo.PropertyNameOf(0), out var tags))
     {
         methodCallInfo.ReturnValue = tags.ContainsKey(methodCallInfo.Arguments[1]);
     }
 }
Ejemplo n.º 16
0
        public void Equals_OtherNull_ReturnsFalse()
        {
            MethodCallInfo subject = CreateSubject(() => Console.WriteLine());

            bool result = subject.Equals(default(MethodCallInfo));

            Assert.IsFalse(result);
        }
Ejemplo n.º 17
0
        public void Equals_OtherSameInstance_ReturnsTrue()
        {
            MethodCallInfo subject = CreateSubject(() => Console.WriteLine());

            bool result = subject.Equals(subject);

            Assert.IsTrue(result);
        }
Ejemplo n.º 18
0
        public static ValueSet ToValueSet(this MethodCallInfo methodCall)
        {
            var set = new ValueSet
            {
                { FuncMethodBase64Key, methodCall.ToBase64BinaryString() },
            };

            return(set);
        }
Ejemplo n.º 19
0
        public void Test_Two_Objects_With_The_Same_Arguments_Returns_The_Same_HashCode()
        {
            // Arrange
            var callInfo1 = new MethodCallInfo("Foo", new object[] { 1, "foo", 2.0 });
            var callInfo2 = new MethodCallInfo("Foo", new object[] { 1, "foo", 2.0 });

            // Assert
            Assert.AreEqual(callInfo1.GetHashCode(), callInfo2.GetHashCode());
        }
Ejemplo n.º 20
0
        public void Test_Two_Objects_With_The_Same_Arguments_Are_Equal()
        {
            // Arrange
            var callInfo1 = new MethodCallInfo("Foo", new object[] { 1, "foo", 2.0 });
            var callInfo2 = new MethodCallInfo("Foo", new object[] { 1, "foo", 2.0 });

            // Assert
            Assert.AreEqual(callInfo1, callInfo2);
        }
Ejemplo n.º 21
0
        public void EqualsObject_OtherSameMethod_ReturnsTrue()
        {
            MethodCallInfo subject = CreateSubject(() => Console.WriteLine());
            MethodCallInfo other   = CreateSubject(() => Console.WriteLine());

            bool result = subject.Equals((object)other);

            Assert.IsTrue(result);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Bind a subscription to an event name, and prepare it for disposal.
        /// </summary>
        private void BindInnerHandler(MethodCallInfo eventToBind, Action <IList <JToken> > innerHandler)
        {
            var subscription = _proxy.Subscribe(eventToBind.MethodName);

            subscription.Received += innerHandler;
            DisposalActions.Add(() => {
                subscription.Received -= innerHandler;
            });
        }
Ejemplo n.º 23
0
        public void EqualsObject_OtherDifferentType_ReturnsFalse()
        {
            MethodCallInfo subject = CreateSubject(() => Console.WriteLine());
            object         other   = new StringBuilder();

            bool result = subject.Equals(other);

            Assert.IsFalse(result);
        }
Ejemplo n.º 24
0
        public void EqualsObject_OtherDifferentMethod_ReturnsFalse()
        {
            MethodCallInfo subject = CreateSubject(() => Console.WriteLine());
            MethodCallInfo other   = CreateSubject(() => Console.ReadLine());

            bool result = subject.Equals((object)other);

            Assert.IsFalse(result);
        }
Ejemplo n.º 25
0
        internal static async Task <T> SendWebSocketDataWithCallClientServiceMethod <T>(ServerBase serverBase, ClientInfo client, Type returnType, string serviceName, string methodName, params Shared.Models.ParameterInfo[] args)
        {
            if (returnType == null || returnType == typeof(void))
            {
                returnType = typeof(object);
            }
            else if (returnType.GetBaseType() == typeof(Task))
            {
                returnType = returnType.GetGenericArguments()[0];
            }

            if (methodName.LastIndexOf("Async", StringComparison.OrdinalIgnoreCase) == methodName.Length - 5)
            {
                methodName = methodName.Substring(0, methodName.Length - 5);
            }
#if (NET35 || NET40)
            return(null);// Task<object>.Factory.StartNew(run);
#else
            Type           type = typeof(TaskCompletionSource <>).MakeGenericType(returnType);
            object         taskCompletionSource = Activator.CreateInstance(type);
            MethodCallInfo callInfo             = new MethodCallInfo();
            callInfo.ServiceName = serviceName;
            callInfo.MethodName  = methodName;
            callInfo.Parameters  = args;
            string guid = Guid.NewGuid().ToString();
            callInfo.Guid = guid;
            serverBase.ClientServiceCallMethodsResult.TryAdd(guid, new KeyValue <Type, object>(returnType, taskCompletionSource));

            string json = ServerSerializationHelper.SerializeObject(callInfo, serverBase);
            ///when length is large we need to send data by parts
            if (json.Length > 30000)
            {
                List <string> listOfParts = WebSocketProvider.GeneratePartsOfData(json);
                int           i           = 1;
                foreach (string item in listOfParts)
                {
                    MethodCallInfo cb = callInfo.Clone();
                    cb.PartNumber = i == listOfParts.Count ? (short)-1 : (short)i;
                    json          = (int)DataType.CallMethod + "," + (int)CompressMode.None + "/" + ServerSerializationHelper.SerializeObject(cb, serverBase);
                    byte[] bytes = Encoding.UTF8.GetBytes(json);
                    await client.StreamHelper.WriteToStreamAsync(client.ClientStream, bytes);

                    i++;
                }
            }
            else
            {
                json = (int)DataType.CallMethod + "," + (int)CompressMode.None + "/" + json;
                byte[] bytes = Encoding.UTF8.GetBytes(json);
                await client.StreamHelper.WriteToStreamAsync(client.ClientStream, bytes);
            }
            object value  = taskCompletionSource.GetType().GetProperty("Task").GetValue(taskCompletionSource, null);
            T      result = await(Task <T>) value;
            return(result);
#endif
        }
Ejemplo n.º 26
0
        /// <summary>
        ///     Return the default value for a property
        /// </summary>
        private static void GetDefaultValue(MethodCallInfo methodCallInfo)
        {
            var propertyInfo = typeof(T).GetProperty(methodCallInfo.PropertyNameOf(0));

            // Prevent ArgumentNullExceptions
            if (propertyInfo != null)
            {
                methodCallInfo.ReturnValue = GetConvertedDefaultValue(propertyInfo);
            }
        }
Ejemplo n.º 27
0
 public void RegisterClientServiceInterface(string serviceName)
 {
     MethodCallInfo callInfo = new MethodCallInfo()
     {
         ServiceName = serviceName,
         MethodName  = "/RegisterService",
         Guid        = Guid.NewGuid().ToString()
     };
     var callback = this.SendData <MethodCallbackInfo>(callInfo);
 }
Ejemplo n.º 28
0
        /// <summary>
        /// send data to connector
        /// </summary>
        /// <typeparam name="T">return type data</typeparam>
        /// <param name="connector">connetor for send data</param>
        /// <param name="callInfo">method for send</param>
        /// <returns></returns>
        internal static T SendData <T>(this ConnectorBase connector, MethodCallInfo callInfo)
        {
            var data = SendData(connector, callInfo, null);

            if (data == null || data.ToString() == "")
            {
                return(default(T));
            }
            return(JsonConvert.DeserializeObject <T>(data.ToString()));
        }
        public void RegisterStaticCall(MethodDescriptor callee, IList <PropGraphNodeDescriptor> arguments,
                                       VariableNode lhs, AnalysisCallNode callNode)
        {
            Contract.Requires(callee != null);
            Contract.Requires(callNode != null);
            Contract.Requires(arguments != null);

            var callExp = new MethodCallInfo(this.Method, callNode, callee, arguments, lhs, false);

            RegisterInvocation(arguments, callNode, callExp);
        }
Ejemplo n.º 30
0
        /// <summary>
        ///     Return the default value for a property
        /// </summary>
        private void RestoreToDefault(MethodCallInfo methodCallInfo)
        {
            var propertyInfo = typeof(T).GetProperty(methodCallInfo.PropertyNameOf(0));

            // Prevent ArgumentNullExceptions
            if (propertyInfo == null)
            {
                return;
            }
            RestoreToDefault(methodCallInfo.Interceptor, propertyInfo, out var _);
        }
Ejemplo n.º 31
0
        internal static async Task <T> SendData <T>(this ConnectorBase connector, MethodCallInfo callInfo)
        {
            string data = await SendDataAsync(connector, callInfo);
#endif

            if (string.IsNullOrEmpty(data))
            {
                return(default(T));
            }
            return(ClientSerializationHelper.DeserializeObject <T>(data.ToString()));
        }
Ejemplo n.º 32
0
        private void DecompileAndEnqueueCallees(CodeDescriptor cd, object instance, object[] arguments, MethodCallInfo mymci = null)
        {
            IPackageOrComponentDescriptor owner = cd.Owner as IPackageOrComponentDescriptor;

            var rmd = cd.Method.GetCustomOrInjectedAttribute<RewriteMethodDefinition>();

            IDecompilationResult result;

            var md = cd as MethodDescriptor;
            var pd = cd as ProcessDescriptor;
            if (pd != null)
                _context.CurrentProcess = pd.Instance;
            else
                _context.CurrentProcess = md.CallingProcess.Instance;

            EVariability[] argVar;
            if (md == null)
                argVar = new EVariability[0];
            else
                argVar = md.ArgVariabilities;
            if (rmd != null)
            {
                result = rmd.Rewrite(_context, cd, instance, arguments);
            }
            else if (cd.Method.IsMoveNext())
            {
                var decomp = new AsyncMethodDecompiler(_context, cd, instance, arguments);
                result = decomp.Decompile();
                cd.Implementation = result.Decompiled;
                cd.GenuineImplementation = result.Decompiled;
            }
            else
            {
                var decomp = new MSILDecompiler(cd, instance, arguments, argVar);
                if (cd is ProcessDescriptor)
                {
                    decomp.Template.DisallowReturnStatements = true;
                }
                decomp.Template.DisallowConditionals = true;
                if (mymci != null)
                    mymci.Inherit(decomp.Template);
                result = decomp.Decompile();
                cd.Implementation = result.Decompiled;
                cd.GenuineImplementation = result.Decompiled;
            }

            foreach (var mci in result.CalledMethods)
            {
                _methodQ.Enqueue(mci);
            }
            foreach (var fri in result.ReferencedFields)
            {
                AnalyzeFieldRef(fri, cd);
            }

            _allMethods.Add(cd);
        }
Ejemplo n.º 33
0
        private MethodDescriptor ConstructMethodDescriptor(MethodCallInfo mci, bool special)
        {
            MethodBase method = mci.GetStrongestOverride();
            MethodDescriptor md = new MethodDescriptor(
                method,
                mci.EvaluatedArgumentsWithoutThis,
                special ? mci.ArgumentVariabilities : VariabilityPattern.CreateDefault(method).Pattern);
            var caller = mci.CallerTemplate.Decompilee;
            var callerPd = caller as ProcessDescriptor;
            var callerMd = caller as MethodDescriptor;
            if (callerPd != null)
                md.CallingProcess = callerPd;
            else
                md.CallingProcess = callerMd.CallingProcess;

            return md;
        }
Ejemplo n.º 34
0
 public ExpertInfo(string discriminator, string handlerName, MethodCallInfo methodCallInfo)
 {
     this.Discriminator = discriminator;
       this.HandlerName = handlerName;
       this.MethodCallInfo = methodCallInfo;
 }
Ejemplo n.º 35
0
 internal Setup(MethodCallInfo methodCall)
     : base(methodCall)
 {
 }
Ejemplo n.º 36
0
 string GenerateProperty(IPropertySymbol property, MethodCallInfo changed, MethodCallInfo changing)
 {
     var setterModifier = property.SetMethod.DeclaredAccessibility.ToAccessibilityModifier(property.DeclaredAccessibility);
     var oldValueStorage = changed.NeedParameter ? $"var oldValue = base.{property.Name};".AddTabs(2) : null;
     return
     $@"public override {property.TypeDisplayString(model)} {property.Name} {{
     get {{ return base.{property.Name}; }}
     {setterModifier}set {{
     if(base.{property.Name} == value)
     return;
     {changing.MethodCall}
     {oldValueStorage}
     base.{property.Name} = value;
     RaisePropertyChanged(""{property.Name}"");
     {changed.MethodCall}
     }}
     }}";
 }
Ejemplo n.º 37
0
        private void Resolve(MethodCallInfo mci)
        {
            Function genericImpl;
            var md = ConstructMethodDescriptor(mci, false);
            if (md == null)
                return;
            object instance = mci.Instance;
            bool hasThis = md.Method.CallingConvention.HasFlag(CallingConventions.HasThis);
            if (hasThis)
            {
                if (instance != null)
                {
                    var owner = instance as Component;
                    if (owner == null)
                    {
                        ReportError("Method " + md.Method.Name + " is not declared inside a component.");
                    }
                    else
                    {
                        md.Owner = owner.Descriptor;
                    }
                }
                else
                {
                    ReportError("Method " + md.Method.Name + ": unable to resolve declaring component instance.");
                }
            }
            else
            {
                md.Owner = GetPackageDescriptor(md.Method.DeclaringType);
            }
            var key = new MethodKey(md);
            if (_methodMap.TryGetValue(key, out genericImpl))
            {
                md.Implementation = genericImpl;
            }
            else
            {
                DecompileAndEnqueueCallees(md, instance, md.ArgValueSamples, mci);
                System.Diagnostics.Debug.Assert(md.Implementation != null);
                _methodMap[key] = md.Implementation;
            }

            System.Diagnostics.Debug.Assert(md.Implementation != null);
            if (md.Owner != null)
                md = md.Owner.Canonicalize(md);

            var mds = ConstructMethodDescriptor(mci, true);
            mds.Owner = md.Owner;
            DecompileAndEnqueueCallees(mds, instance, mds.ArgValueSamples, mci);
            System.Diagnostics.Debug.Assert(mds.Implementation != null);
            mci.Resolve(md, mds);
        }