Пример #1
0
        private void Events_DataReceived(object sender, MemoryMappedDataReceivedEventArgs e)
        {
            var response = Serializer.Deserialize(e.Data);

            if (response is RpcEventCallMessage ev)
            {
                InvokeHandlers(ev);
            }
        }
Пример #2
0
        private void communicator_DataReceived(object sender, MemoryMappedDataReceivedEventArgs e)
        {
            var receivedMessage = System.Text.Encoding.UTF8.GetString(e.Data);

            lstMessages.Items.Add(receivedMessage);
            lstMessages.SelectedIndex = lstMessages.Items.Count - 1;

            // Sends a message as a response.
            communicator.Write("Message from Windows App: data received at " + DateTime.Now);
        }
Пример #3
0
        private void Communicator_DataReceived(object sender, MemoryMappedDataReceivedEventArgs e)
        {
            var r = (RpcEventCallMessage)RpcServices.Deserialize(e.Data);

            if (r.Name == Name)
            {
                foreach (var h in handlers)
                {
                    h(r.Args[0], (EventArgs)r.Args[1]);
                }
            }
        }
Пример #4
0
        private void Sender_DataReceived(object sender, MemoryMappedDataReceivedEventArgs e)
        {
            var response = Serializer.Deserialize(e.Data);

            if (response is RpcMethodAwnser awnser)
            {
                ReturnValue = awnser.ReturnValue;
            }
            else if (response is RpcExceptionMessage ex)
            {
                Singleton <ExceptionStack> .Instance.Push(new RpcException(ex.Interface, ex.Name, new Exception(ex.Message)));
            }

            mre.Set();
        }
Пример #5
0
        private static void Communicator_DataReceived(object sender, MemoryMappedDataReceivedEventArgs e)
        {
            _lock.AcquireWriterLock(Timeout.Infinite);

            try
            {
                var data = ASCIIEncoding.UTF8.GetString(e.Data);
                {
                    File.WriteAllText(ContextPath, data, Encoding.GetEncoding(949));
                }

                var obj = JsonConvert.DeserializeObject <ServerInformation>(data, StorageManager.Settings);

                if (obj != null)
                {
                    WebServer.Info = obj;
                    WebServer.Info.Debug("Web Info Updated.");
                }
            }
            finally
            {
                _lock.ReleaseWriterLock();
            }
        }
Пример #6
0
 private static void communicator_DataReceived(object sender, MemoryMappedDataReceivedEventArgs e)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine(System.Text.Encoding.UTF8.GetString(e.Data));
     Console.ForegroundColor = ConsoleColor.Gray;
 }
Пример #7
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!");
            }
        }