예제 #1
0
        internal static void GetAsyncResult(BinaryReader res, TaskCompletionSource <object> result,
                                            TcpConnector connector)
        {
            object asynchronous = null;

            if (!GetResult(res, ref asynchronous, connector))
            {
                result.SetException(new Exception(connector.LastError));
            }
        }
예제 #2
0
        public static object GetObject(BinaryReader stream, TcpConnector connector)
        {
            // Считываем тип объекта
            EnumVar type = (EnumVar)stream.ReadByte();

            // В зависмости от типа считываем и преобразуем данные
            switch (type)
            {
            case EnumVar.VtypeEmpty:
            case EnumVar.VtypeNull: return(null);

            case EnumVar.VtypeI2: return(stream.ReadInt16());

            case EnumVar.VtypeI4: return(stream.ReadInt32());

            case EnumVar.VtypeR4: return(stream.ReadSingle());

            case EnumVar.VtypeR8: return(stream.ReadDouble());

            case EnumVar.VtypeDecimal: return(stream.ReadDecimal());

            case EnumVar.VtypeBool: return(stream.ReadBoolean());

            case EnumVar.VtypeI1: return(stream.ReadSByte());

            case EnumVar.VtypeUi1: return(stream.ReadByte());

            case EnumVar.VtypeUi2: return(stream.ReadUInt16());

            case EnumVar.VtypeUi4: return(stream.ReadUInt32());

            case EnumVar.VtypeI8: return(stream.ReadInt64());

            case EnumVar.VtypeUi8: return(stream.ReadUInt64());

            case EnumVar.VtypeChar: return(stream.ReadChar());

            case EnumVar.VtypePwstr: return(stream.ReadString());

            case EnumVar.VtypeBlob: return(ReadByteArray(stream));

            case EnumVar.VtypeDate: return(ReadDateTime(stream));

            case EnumVar.VtypeGuid: return(new Guid(stream.ReadBytes(16)));

            case EnumVar.VtypeAutoWrap: return(new AutoWrapClient(stream.ReadInt32(), connector));
            }
            return(null);
        }
예제 #3
0
        public AutoWapEnumerator(AutoWrapClient target, TcpConnector connector)
        {
            _connector = connector;

            if (!AutoWrapClient.TryInvokeMember(
                    0,
                    "GetIterator",
                    new object[] { target },
                    out var result,
                    _connector
                    ))
            {
                throw new Exception(_connector.LastError);
            }

            _enumerator = (AutoWrapClient)result;
        }
예제 #4
0
        internal static bool GetResult(BinaryReader res, ref object result, TcpConnector connector)
        {
            var resRun      = res.ReadBoolean();
            var returnValue = WorkVariants.GetObject(res, connector);

            if (!resRun)
            {
                if (returnValue != null && returnValue is string stringValue)
                {
                    connector.LastError = stringValue;
                }
                return(false);
            }

            result = returnValue;
            return(true);
        }
예제 #5
0
        internal static bool TryInvokeMember(int target, string methodName, object[] args, out object result,
                                             TcpConnector connector)
        {
            result = null;

            var ms = new MemoryStream();
            var bw = new BinaryWriter(ms);

            bw.Write((byte)CallMethod.CallFunc);
            bw.Write(target);
            bw.Write(methodName);
            bw.Write(args.Length);

            foreach (var arg in args)
            {
                WorkVariants.WriteObject(arg, bw);
            }

            bw.Flush();

            return(GetResultWithChangeParams(connector.SendMessage(ms), ref result, connector, args));
        }
예제 #6
0
 public static dynamic GetProxy(TcpConnector connector)
 {
     return(new AutoWrapClient(0, connector));
 }
예제 #7
0
 public AutoWrapClient(int target, TcpConnector connector)
 {
     Target    = target;
     Connector = connector;
 }
예제 #8
0
 public AsyncAutoWrapClient(int target, TcpConnector connector) : base(target, connector)
     => GC.SuppressFinalize(this);
예제 #9
0
        internal static bool GetResultWithChangeParams(BinaryReader res, ref object result, TcpConnector connector,
                                                       object[] args, int offset = 0)
        {
            if (!GetResult(res, ref result, connector))
            {
                return(false);
            }
            var count = res.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                var    index = res.ReadInt32();                        // Получим индекс измененного параметра
                object value = WorkVariants.GetObject(res, connector); // Получим значение измененного параметра

                // args[index + offset]= value;// Установим нужный параметр, для Generic методов с 0 индексом идет тип аргументов

                // Вариант с  RefParam
                object param = args[index + offset];
                if (param != null && param is RefParam refParam)
                {
                    refParam.Value = value;
                }
            }

            return(true);
        }
예제 #10
0
        internal static bool TryInvokeGenericMethod(int target, string methodName, object[] args, out object result, TcpConnector connector)
        {
            var ms = new MemoryStream();
            var bw = new BinaryWriter(ms);

            bw.Write((byte)CallMethod.CallGenericFunc);
            bw.Write(target);
            bw.Write(methodName);

            var arguments = (object[])args[0];

            bw.Write(arguments.Length);

            foreach (var arg in arguments)
            {
                WorkVariants.WriteObject(arg, bw);
            }

            bw.Write(args.Length - 1);

            for (var i = 1; i < args.Length; i++)
            {
                WorkVariants.WriteObject(args[i], bw);
            }

            bw.Flush();

            var res = connector.SendMessage(ms);

            result = null;
            return(GetResultWithChangeParams(res, ref result, connector, args, 1));
        }