示例#1
0
 private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     // Closes the reader thread.
     communicator.CloseReader();
     communicator.Dispose();
     communicator = null;
 }
        private ICommunicator CreateCommunicator(CommunicatorType type, string user, string env, string application, bool isFromApplicatonProcess = false)
        {
            var           key  = string.Format(KEY_FORMAT, user, env, application, isFromApplicatonProcess ? "_App" : "");
            ICommunicator comm = null;

            switch (type)
            {
            case CommunicatorType.MappedFileType:
                comm = new MemoryMappedFileCommunicator(user, env, application, isFromApplicatonProcess);
                break;

            default:
                break;
            }
            if (comm != null)
            {
                lock (lockObj)
                {
                    commList.Add(key, comm);
                }
                comm.StartReader();
            }
            //logger.DebugFormat("CreateCommunicator, Key = {0}", key);
            return(comm);
        }
示例#3
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;
        }
示例#4
0
 internal RpcEvent(string name)
 {
     Name         = name;
     communicator = new MemoryMappedFileCommunicator(Name + ".event", 5000);
     communicator.WritePosition = 0;
     communicator.ReadPosition  = 0;
     communicator.DataReceived += Communicator_DataReceived;
 }
        void InitializeCommunicator()
        {
            Communicator = new MemoryMappedFileCommunicator($"Sakuno/HeavenlyWind({HostProcessID})", 4096);
            Communicator.ReadPosition  = 2048;
            Communicator.WritePosition = 0;

            Messages = Communicator.GetMessageObservable().Publish();
            Messages.Connect();

            Communicator.StartReader();
        }
示例#6
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            communicator = new MemoryMappedFileCommunicator("MemoryMappedShare", 4096);

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

            // 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();
        }
示例#7
0
        public RpcServer(string name, RpcSerializer serializer = null)
        {
            listener = new MemoryMappedFileCommunicator(name, 50000);

            listener.WritePosition = 0;
            listener.ReadPosition  = 2500;
            listener.DataReceived += Listener_DataReceived;

            this.Serializer = serializer;
            if (Serializer == null)
            {
                Serializer = new BinarySerializer();
            }

            Bind <IInterfaceInfo>(new InterfaceInfoImpl(this));
        }
示例#8
0
        public void Initialize(string name, long capacity, bool isOwner)
        {
            if (isOwner)
            {
                communicator = new MemoryMappedFileCommunicator(name, capacity);
                communicator.ReadPosition  = 2000;
                communicator.WritePosition = 0;
                communicator.StartReader();
            }
            else
            {
                communicator = new MemoryMappedFileCommunicator(name, capacity);
                communicator.WritePosition = 2000;
                communicator.ReadPosition  = 0;
                communicator.StartReader();
            }

            communicator.DataReceived += Communicator_DataReceived;
        }
            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);
                }
            }
示例#10
0
        public RpcClient(string name, RpcSerializer serializer = null)
        {
            sender = new MemoryMappedFileCommunicator(name, 50000);;

            sender.ReadPosition  = 0;
            sender.WritePosition = 2500;
            sender.DataReceived += Sender_DataReceived;

            events = new MemoryMappedFileCommunicator(name + ".events", 5000);
            events.ReadPosition  = 0;
            events.WritePosition = 2500;
            events.DataReceived += Events_DataReceived;

            Serializer = serializer;

            if (Serializer == null)
            {
                Serializer = new BinarySerializer();
            }
        }