예제 #1
0
        static void Main(string[] args)
        {
            MemoryMappedFileCommunicator communicator = new MemoryMappedFileCommunicator("MemoryMappedShare", 4096);

            // This process reads data that begins in the position 2000 and writes starting from the position 0.
            communicator.ReadPosition  = 2000;
            communicator.WritePosition = 0;

            // Creates an handler for the event that is raised when data are available in the
            // MemoryMappedFile.
            communicator.DataReceived += new EventHandler <MemoryMappedDataReceivedEventArgs>(communicator_DataReceived);
            communicator.StartReader();

            bool quit = false;

            Console.WriteLine("Write messages and press ENTER to send (empty to terminate): ");
            while (!quit)
            {
                string message = Console.ReadLine();
                if (!string.IsNullOrEmpty(message))
                {
                    var data = System.Text.Encoding.UTF8.GetBytes(message);
                    communicator.Write(data);
                }
                else
                {
                    quit = true;
                }
            }

            communicator.Dispose();
            communicator = null;
        }
예제 #2
0
        public void Publish <T>(T obj)
        {
            var msg = new QueueMessage();

            msg.Typename = typeof(T).Name;
            msg.Argument = Signal.Serializer.Serialize(obj);

            _com.Write(Signal.Serializer.Serialize(msg));
        }
예제 #3
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);
        }
예제 #4
0
        public void Invoke(object sender, EventArgs e)
        {
            var msg = new RpcEventCallMessage
            {
                Name = Name,
                Args = new List <object> {
                    sender, e
                }
            };

            communicator.Write(RpcServices.Serialize(msg));
        }
            private void SendServerInfo(MemoryMappedFileCommunicator communicator)
            {
                if (Info == null)
                {
                    Info = new ServerInformation
                    {
                        ServerConfig     = Config,
                        MonsterTemplates = new List <MonsterTemplate>(GlobalMonsterTemplateCache),
                        ItemTemplates    = new List <ItemTemplate>(GlobalItemTemplateCache.Select(i => i.Value)),
                        SkillTemplates   = new List <SkillTemplate>(GlobalSkillTemplateCache.Select(i => i.Value)),
                        SpellTemplates   = new List <SpellTemplate>(GlobalSpellTemplateCache.Select(i => i.Value)),
                        MundaneTemplates = new List <MundaneTemplate>(GlobalMundaneTemplateCache.Select(i => i.Value)),
                        WarpTemplates    = new List <WarpTemplate>(GlobalWarpTemplateCache),
                        Areas            = new List <Area>(GlobalMapCache.Select(i => i.Value)),
                        Buffs            = new List <Buff>(GlobalBuffCache.Select(i => i.Value)),
                        Debuffs          = new List <Debuff>(GlobalDeBuffCache.Select(i => i.Value)),
                    };
                }

                Info.GameServerOnline  = true;
                Info.LoginServerOnline = true;

                var players_online = Game?.Clients.Where(i => i != null && i.Aisling != null && i.Aisling.LoggedIn);

                if (players_online != null)
                {
                    Info.PlayersOnline    = new List <Aisling>(players_online.Select(i => i.Aisling));
                    Info.GameServerStatus = $"Up time {Math.Round(Uptime.TotalDays, 2)}:{Math.Round(Uptime.TotalHours, 2)} | Online Users ({ players_online.Count() }) | Total Characters ({ StorageManager.AislingBucket.Count })";
                    Info.GameServerOnline = true;
                }
                else
                {
                    Info.PlayersOnline    = new List <Aisling>();
                    Info.GameServerOnline = false;
                    Info.GameServerStatus = "Offline.";
                }

                lock (communicator)
                {
                    var jsonWrap = JsonConvert.SerializeObject(Info, StorageManager.Settings);
                    communicator.Write(jsonWrap);
                }
            }
예제 #6
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!");
            }
        }