Exemplo n.º 1
0
        public static void IteratorNext(BinaryReader br, BinaryWriter bw)
        {
            if (!GetAW(br, bw, out var autoWrap))
            {
                return;
            }

            try
            {
                var enumerator = (System.Collections.IEnumerator)autoWrap.Object;
                var res        = enumerator.MoveNext();
                bw.Write(true);
                if (!res)
                {
                    AutoWrap.ObjectsList.RemoveKey(autoWrap.IndexInStorage);
                    bw.Write(false);
                    return;
                }

                bw.Write(true);
                WorkWithVariant.WriteObject(AutoWrap.WrapObject(enumerator.Current), bw);
            }
            catch (Exception e)
            {
                SetError(AutoWrap.GetExceptionString("Ошибка итератора", "", e), bw);
            }
        }
Exemplo n.º 2
0
        public static void CallAsDelegate(BinaryReader br, BinaryWriter bw)
        {
            object result;

            if (!GetAW(br, bw, out var autoWrap))
            {
                return;
            }

            var args = GetArrayParams(br);

            try
            {
                var del = (Delegate)autoWrap.Object;
                result = del.DynamicInvoke(args);
            }
            catch (Exception e)
            {
                SetError(AutoWrap.GetExceptionString($"Ошибка вызова делегата Target = ", "", e), bw);
                return;
            }

            bw.Write(true);
            WorkWithVariant.WriteObject(AutoWrap.WrapObject(result), bw);
        }
Exemplo n.º 3
0
 public static void DeleteObjects(BinaryReader br, BinaryWriter bw)
 {
     try
     {
         int count = br.ReadInt32();
         for (int i = 0; i < count; i++)
         {
             int target = br.ReadInt32();
             AutoWrap.ObjectsList.RemoveKey(target);
         }
         bw.Write(true);
         WorkWithVariant.WriteObject(null, bw);
     }
     catch (Exception e)
     {
         SetError(AutoWrap.GetExceptionString("Ошибка удаления объектов", "", e), bw);
     }
 }
Exemplo n.º 4
0
        public static void CallAsyncFunc(BinaryReader br, BinaryWriter bw, IPAddress address)
        {
            if (!CallAsFuncAll(br, bw, out var result, false))
            {
                return;
            }
            try
            {
                var taskId   = new Guid(br.ReadBytes(16));
                var port     = br.ReadInt32();
                var typeInfo = result.GetType().GetTypeInfo();

                var asyncCallBack = new TcpAsyncCallBack(taskId, address, port);
                var callBack      = new Action <bool, object>(asyncCallBack.SendAsyncMessage);
                if (!typeInfo.IsGenericType)
                {
                    AsyncRunner.TaskExecute((Task)result, callBack);
                    return;
                }

                var args   = new[] { result, callBack };
                var method = InformationOnTheTypes.FindMethod(typeof(AsyncRunner), true, "Execute", args);

                if (method == null)
                {
                    SetError("Неверный результат", bw);
                    return;
                }

                method.ExecuteMethod(null, args);
            }
            catch (Exception e)
            {
                SetError(AutoWrap.GetExceptionString("Ошибка вызова делегата", "", e), bw);
                return;
            }

            bw.Write(true);
            WorkWithVariant.WriteObject(null, bw);
        }
Exemplo n.º 5
0
        private static void CallStaticMethod(BinaryWriter bw, Type T, string methodName, object[] args)
        {
            try
            {
                var method = InformationOnTheTypes.FindMethod(T, true, methodName, args);

                if (method == null)
                {
                    SetError($"Нет найден метод  {method} для типа {T}", bw);
                    return;
                }

                var obj = method.ExecuteMethod(null, args);

                bw.Write(true);
                WorkWithVariant.WriteObject(AutoWrap.WrapObject(obj), bw);
                bw.Write((int)0);
            }
            catch (Exception e)
            {
                SetError(AutoWrap.GetExceptionString("Ошибка бинарной операции ", "", e), bw);
            }
        }
Exemplo n.º 6
0
        public static bool CallAsGenericFuncAll(BinaryReader br, BinaryWriter bw, out object result, bool writeResult)
        {
            result = null;;
            if (!GetAW(br, bw, out var autoWrap))
            {
                return(false);
            }

            string methodName = br.ReadString();
            var    arguments  = GetArrayParams(br);
            var    Params     = GetArrayParams(br);

            // Можно параметры передавать ввиде типов и строк
            var genericArguments = new Type[arguments.Length];

            for (int i = 0; i < genericArguments.Length; i++)
            {
                genericArguments[i] = NetObjectToNative.FindTypeForCreateObject(arguments[i]);
            }

            result = null;
            var typesOfParameters = AllMethodsForName.GetTypesParameters(Params);
            var res = InformationOnTheTypes.FindGenericMethodsWithGenericArguments(
                autoWrap.Type,
                autoWrap.IsType,
                methodName,
                genericArguments,
                typesOfParameters);

            if (res == null)
            {
                SetError("Не найден дженерик метод " + methodName, bw);
                return(false);
            }

            try
            {
                var copyParams = new object[Params.Length];
                Params.CopyTo(copyParams, 0);

                var obj = autoWrap.IsType ? null : autoWrap.Object;
                result = res.ExecuteMethod(obj, copyParams);

                var returnType = res.Method.ReturnType;

                if (result != null && returnType.GetTypeInfo().IsInterface)
                {
                    result = new AutoWrap(result, returnType);
                }

                if (writeResult)
                {
                    bw.Write(true);
                    WorkWithVariant.WriteObject(AutoWrap.WrapObject(result), bw);
                    WriteChangeParams(bw, copyParams, AutoWrap.GetChangeParams(Params, copyParams));
                }
            }
            catch (Exception e)
            {
                SetError(AutoWrap.GetExceptionString($"Ошибка вызова Дженерик метода {methodName}", "", e), bw);
                return(false);
            }

            return(true);
        }