Exemple #1
0
        internal static bool GetResultWithChangeParams(BinaryReader res, ref object result, TCPClientConnector 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);
        }
Exemple #2
0
        public bool MoveNext()
        {
            var ms = new MemoryStream();
            var bw = new BinaryWriter(ms);

            bw.Write((byte)CallMethod.IteratorNext);
            bw.Write(_enumerator.Target);
            bw.Flush();

            var res     = _connector.SendMessage(ms);
            var resCall = res.ReadBoolean();

            if (!resCall)
            {
                throw new Exception(res.ReadString());
            }

            var resNext = res.ReadBoolean();

            if (!resNext)
            {
                GC.SuppressFinalize(_enumerator);
                return(false);
            }

            Current = WorkVariants.GetObject(res, _connector);
            return(true);
        }
Exemple #3
0
        public override bool TryGetIndex(
            GetIndexBinder binder, object[] indexes, out object result)
        {
            result = null;
            if (Connector.ServerIsClosed)
            {
                return(false);
            }

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

            bw.Write((byte)CallMethod.GetIndex);
            bw.Write(Target);
            bw.Write(indexes.Length);
            foreach (var arg in indexes)
            {
                WorkVariants.WriteObject(arg, bw);
            }

            bw.Flush();

            var res = Connector.SendMessage(ms);

            return(GetResult(res, ref result, Connector));
        }
Exemple #4
0
        public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
        {
            result = null;
            if (Connector.ServerIsClosed)
            {
                return(false);
            }

            if (args.Length == 1 && ReferenceEquals(args[0], FlagDeleteObject))
            {
                Dispose(true);
                return(true);
            }

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

            bw.Write((byte)CallMethod.CallDelegate);
            bw.Write(Target);

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

            bw.Flush();

            var res = Connector.SendMessage(ms);

            return(GetResult(res, ref result, Connector));
        }
Exemple #5
0
        internal static bool TryInvokeGenericMethod(int target, string methodName, object[] args, out object result, TCPClientConnector 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));
        }
        private void SetEvent(BinaryReader br)
        {
            Guid key = new Guid(br.ReadBytes(16));
            var  res = WorkVariants.GetObject(br, this);
            WrapperObjectWithEvents value;

            if (EventDictionary.TryGetValue(key, out value))
            {
                value.RaiseEvent(key, res);
            }
        }
Exemple #7
0
        internal static bool GetResult(BinaryReader res, ref object result, TCPClientConnector 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);
        }
Exemple #8
0
        public override bool TryBinaryOperation(
            BinaryOperationBinder binder, object arg, out object result)
        {
            result = null;

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

            bw.Write((byte)CallMethod.CallBinaryOperation);
            bw.Write(Target);
            bw.Write((byte)binder.Operation);
            WorkVariants.WriteObject(arg, bw);

            bw.Flush();
            var res = Connector.SendMessage(ms);

            return(GetResult(res, ref result, Connector));
        }
        private void SetAsyncResult(BinaryReader br)
        {
            Guid key    = new Guid(br.ReadBytes(16));
            var  res    = br.ReadBoolean();
            var  resObj = WorkVariants.GetObject(br, this);
            TaskCompletionSource <object> value;

            if (AsyncDictionary.TryGetValue(key, out value))
            {
                if (res)
                {
                    value.SetResult(resObj);
                }
                else
                {
                    value.TrySetException(new Exception((string)resObj));
                }
            }
        }
Exemple #10
0
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            if (Connector.ServerIsClosed)
            {
                return(false);
            }

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

            bw.Write((byte)CallMethod.SetMember);
            bw.Write(Target);
            bw.Write(binder.Name);
            WorkVariants.WriteObject(value, bw);

            var    res    = Connector.SendMessage(ms);
            object result = null;

            return(GetResult(res, ref result, Connector));
        }
Exemple #11
0
        internal static bool TryInvokeMember(int target, string methodName, object[] args, out object result,
                                             TCPClientConnector 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));
        }