Ejemplo n.º 1
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (!IsEvent(binder.Name))
            {
                result = Call(() => rpcClient.GetProperty <Interface>(binder.Name));
            }

            var e = RpcEventRepository.Get(binder.Name);

            e.Start();

            result = e;

            return(true);
        }
Ejemplo n.º 2
0
        internal void InvokeHandlers(RpcEventCallMessage ev)
        {
            var e = RpcEventRepository.Get(ev.Name);

            e.Invoke(ev.Args[0], (EventArgs)ev.Args[1]);
        }
Ejemplo n.º 3
0
        private void Listener_DataReceived(object sender, MemoryMappedDataReceivedEventArgs e)
        {
            var msg = Serializer.Deserialize(e.Data);

            object r = null;

            if (msg == null)
            {
                return;
            }

            if (_binds.ContainsKey(msg.Interface))
            {
                var type = _binds[msg.Interface].GetType();

                if (msg is RpcIndexMethod ri)
                {
                    if (ri.Name == "get_Index")
                    {
                        var p = GetIndexProperties(_binds[msg.Interface]).First();

                        r = InvokeMethod(p, ri, ri.Indizes);
                    }
                    else
                    {
                        var p    = SetIndexProperties(_binds[msg.Interface]).First();
                        var args = new List <object>();
                        args.AddRange(ri.Indizes);
                        args.Add(ri.Value);

                        InvokeMethod(p, ri, args.ToArray());
                    }
                }
                else if (msg is RpcMethod rm)
                {
                    var name = rm.Name.Replace("get_", "");

                    if (name.StartsWith("On"))
                    {
                        r = RpcEventRepository.Get(name);
                        return;
                    }

                    var m = type.GetMethod(msg.Name);

                    if (m?.ReturnType == typeof(void))
                    {
                        r = null;

                        InvokeMethod(m, rm, rm.Args.ToArray());
                    }
                    else
                    {
                        r = InvokeMethod(m, rm, rm.Args.ToArray());
                    }
                }

                var returner = new RpcMethodAwnser()
                {
                    Interface   = msg.Interface,
                    Name        = msg.Name,
                    ReturnValue = r
                };
                returner.Headers = msg.Headers;
                //ToDo: fix headers

                var exSt = Singleton <ExceptionStack> .Instance;
                if (exSt.Any())
                {
                    var errMsg = new RpcExceptionMessage(msg.Interface, msg.Name, exSt.Pop().ToString());
                    listener.Write(Serializer.Serialize(errMsg));

                    return;
                }

                listener.Write(Serializer.Serialize(returner));
            }
            else
            {
                throw new Exception($"Interface '{msg.Interface}' is not bound!");
            }
        }