public ProtocolInfo(ProtocolType protocolType, OperationTypeInfo operationTypeInfo, VarAddress varAddress, string typeFullName, string operation, object[] arguments)
 {
     ProtocolType      = protocolType;
     OperationTypeInfo = operationTypeInfo;
     VarAddress        = varAddress;
     TypeFullName      = typeFullName;
     Operation         = operation;
     Arguments         = arguments;
 }
Esempio n. 2
0
 internal void SetObject(VarAddress varAddress, object obj)
 {
     lock (this)
     {
         if (_handleAndObject.ContainsKey(varAddress.Core))
         {
             _handleAndObject[varAddress.Core] = new VarAndType(obj);
         }
     }
 }
Esempio n. 3
0
 internal VarAndType GetVarAndType(VarAddress varAddress)
 {
     lock (this)
     {
         VarAndType varAndType;
         if (_handleAndObject.TryGetValue(varAddress.Core, out varAndType))
         {
             return(new VarAndType(varAndType.Core, varAndType.Type));
         }
         throw new InternalException();
     }
 }
Esempio n. 4
0
 internal bool IsEmptyVar(VarAddress varAddress)
 {
     lock (this)
     {
         VarAndType varAndType;
         if (_handleAndObject.TryGetValue(varAddress.Core, out varAndType))
         {
             return(object.ReferenceEquals(varAndType.Core, null));
         }
         return(true);
     }
 }
        static ReturnInfo ExecuteField(IAsyncInvoke async, VarPool varManager, ProtocolInfo info,
                                       object obj, object[] args, FieldInfo field)
        {
            if (args.Length == 0)
            {
                VarAddress getVar = varManager.Add(null);

                KeepAlive(varManager, info.Arguments, getVar);

                async.Execute(delegate
                {
                    ReturnInfo retInfo = new ReturnInfo();
                    try
                    {
                        varManager.SetObject(getVar, field.GetValue(obj));
                    }
                    catch (Exception e)
                    {
                        retInfo = new ReturnInfo(new ExceptionInfo(e));
                    }

                    varManager.SetObject((VarAddress)info.Arguments[0], retInfo);

                    FreeKeepAlive(varManager, info.Arguments, getVar);
                });
                return(new ReturnInfo(getVar));
            }
            else if (args.Length == 1)
            {
                KeepAlive(varManager, info.Arguments, null);

                async.Execute(delegate
                {
                    ReturnInfo retInfo = new ReturnInfo();
                    try
                    {
                        field.SetValue(obj, args[0]);
                    }
                    catch (Exception e)
                    {
                        retInfo = new ReturnInfo(new ExceptionInfo(e));
                    }

                    varManager.SetObject((VarAddress)info.Arguments[0], retInfo);

                    FreeKeepAlive(varManager, info.Arguments, null);
                });
                return(new ReturnInfo());
            }
            throw new InternalException();
        }
Esempio n. 6
0
 internal void KeepAlive(VarAddress varAddress)
 {
     lock (this)
     {
         int count = 0;
         if (!_keepAlive.TryGetValue(varAddress.Core, out count))
         {
             count = 0;
         }
         count++;
         _keepAlive.Remove(varAddress.Core);
         _keepAlive.Add(varAddress.Core, count);
     }
 }
 internal static void ReflectArgsAfterInvoke(VarPool varManager, object[] argsInfo, object[] args)
 {
     if (argsInfo.Length != args.Length)
     {
         throw new InternalException();
     }
     for (int i = 0; i < argsInfo.Length; i++)
     {
         VarAddress handle = argsInfo[i] as VarAddress;
         if (handle != null)
         {
             varManager.SetObject(handle, args[i]);
         }
     }
 }
 static void FreeKeepAlive(VarPool varManager, object[] arguments, VarAddress handle)
 {
     if (handle != null)
     {
         varManager.FreeKeepAlive(handle);
     }
     for (int i = 0; i < arguments.Length; i++)
     {
         VarAddress aliveHandle = arguments[i] as VarAddress;
         if (aliveHandle != null)
         {
             varManager.FreeKeepAlive(aliveHandle);
         }
     }
 }
Esempio n. 9
0
 internal bool Remove(VarAddress varAddress)
 {
     lock (this)
     {
         if (!_handleAndObject.ContainsKey(varAddress.Core))
         {
             return(false);
         }
         _handleAndObject.Remove(varAddress.Core);
         if (!_keepAlive.ContainsKey(varAddress.Core))
         {
             _varAddressManager.FreeNo(varAddress.Core);
         }
         return(true);
     }
 }
        static ReturnInfo ExecuteMethodOrProperty(IAsyncInvoke async, VarPool varManager,
                                                  ProtocolInfo info, object obj, object[] args, MethodInfo method)
        {
            VarAddress handle = null;

            if (method.ReturnParameter.ParameterType != typeof(void))
            {
                handle = varManager.Add(null);
            }

            KeepAlive(varManager, info.Arguments, handle);

            async.Execute(delegate
            {
                ReturnInfo retInfo = new ReturnInfo();
                try
                {
                    object retObj = method.Invoke(obj, args);
                    if (method.ReturnParameter.ParameterType != typeof(void))
                    {
                        varManager.SetObject(handle, retObj);
                    }
                    List <object> retArgsTmp = new List <object>();
                    retArgsTmp.Add(null);
                    retArgsTmp.AddRange(args);
                    ReflectArgsAfterInvoke(varManager, info.Arguments, retArgsTmp.ToArray());
                }
                catch (Exception e)
                {
                    retInfo = new ReturnInfo(new ExceptionInfo(e));
                }
                varManager.SetObject((VarAddress)info.Arguments[0], retInfo);

                FreeKeepAlive(varManager, info.Arguments, handle);
            });

            return(new ReturnInfo(handle));
        }
        internal static void ResolveArgs(VarPool varManager, object[] argsInfo, out object[] args, out Type[] argTypes)
        {
            args     = new object[argsInfo.Length];
            argTypes = new Type[argsInfo.Length];
            for (int i = 0; i < argsInfo.Length; i++)
            {
                VarAddress handle = argsInfo[i] as VarAddress;

                if (handle == null)
                {
                    args[i] = argsInfo[i];
                    if (args[i] != null)
                    {
                        argTypes[i] = args[i].GetType();
                    }
                }
                else
                {
                    VarAndType varAndType = varManager.GetVarAndType(handle);
                    args[i]     = varAndType.Core;
                    argTypes[i] = varAndType.Type;
                }
            }
        }
Esempio n. 12
0
 internal void FreeKeepAlive(VarAddress varAddress)
 {
     lock (this)
     {
         int count = 0;
         if (!_keepAlive.TryGetValue(varAddress.Core, out count))
         {
             return;
         }
         count--;
         if (count <= 0)
         {
             _keepAlive.Remove(varAddress.Core);
             if (!_handleAndObject.ContainsKey(varAddress.Core))
             {
                 _varAddressManager.FreeNo(varAddress.Core);
             }
         }
         else
         {
             _keepAlive[varAddress.Core] = count;
         }
     }
 }