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)); }
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); }
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); }
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)); }
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)); }
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); }
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)); }
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)); }
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)); }