示例#1
0
 public bool RemoveMailBox(VgcApis.Interfaces.Lua.ILuaMailBox mailbox)
 {
     if (mailboxes.TryRemove(mailbox.GetAddress(), out var box))
     {
         box.Close();
         return(true);
     }
     return(false);
 }
示例#2
0
        public bool ValidateMailBox(VgcApis.Interfaces.Lua.ILuaMailBox mailbox)
        {
            if (mailbox == null)
            {
                return(false);
            }

            var addr = mailbox.GetAddress();

            if (string.IsNullOrEmpty(addr) ||
                !mailboxes.TryGetValue(addr, out var mb) ||
                !ReferenceEquals(mb, mailbox))
            {
                return(false);
            }
            return(true);
        }
示例#3
0
        void HandleOneConnection(HttpListenerContext ctx)
        {
            var req  = ctx.Request;
            var code = HttpMethodToCode(req.HttpMethod);

            string text;

            using (var reader = new StreamReader(req.InputStream, req.ContentEncoding))
            {
                text = reader.ReadToEnd();
            }

            var id = Guid.NewGuid().ToString();

            contexts.TryAdd(id, ctx);
            inbox.Send(inbox.GetAddress(), code, id, true, text ?? "");
        }
示例#4
0
        public string RegisterCoreEvent(
            VgcApis.Interfaces.ICoreServCtrl coreServ,
            VgcApis.Interfaces.Lua.ILuaMailBox mailbox,
            int evType,
            int evCode)
        {
            // 无权访问
            if (!postOffice.ValidateMailBox(mailbox))
            {
                return(null);
            }

            try
            {
                var          handle  = Guid.NewGuid().ToString();
                var          addr    = mailbox.GetAddress();
                EventHandler handler = (s, a) => mailbox.SendCode(addr, evCode);
                switch ((CoreEvTypes)evType)
                {
                case CoreEvTypes.CoreStart:
                    coreServ.OnCoreStart += handler;
                    break;

                case CoreEvTypes.CoreStop:
                    coreServ.OnCoreStop += handler;
                    break;

                case CoreEvTypes.CoreClosing:
                    coreServ.OnCoreStop += handler;
                    break;

                case CoreEvTypes.PropertyChanged:
                    coreServ.OnPropertyChanged += handler;
                    break;

                default:
                    return(null);
                }
                var item = new CoreEvHook((CoreEvTypes)evType, coreServ, mailbox, handler);
                coreEvHooks.TryAdd(handle, item);
                return(handle);
            }
            catch { }
            return(null);
        }
示例#5
0
        public string RegisterGlobalEvent(
            VgcApis.Interfaces.Lua.ILuaMailBox mailbox,
            int evType, int evCode)
        {
            if (!postOffice.ValidateMailBox(mailbox))
            {
                return(null);
            }

            try
            {
                var          handle  = Guid.NewGuid().ToString();
                var          addr    = mailbox.GetAddress();
                EventHandler handler = (s, a) =>
                {
                    var coreServ = s as VgcApis.Interfaces.ICoreServCtrl;
                    if (coreServ == null)
                    {
                        return;
                    }
                    var uid = coreServ.GetCoreStates().GetUid();
                    mailbox.SendCode(addr, evCode, uid);
                };
                switch ((CoreEvTypes)evType)
                {
                case CoreEvTypes.CoreStart:
                    vgcServerService.OnCoreStart += handler;
                    break;

                case CoreEvTypes.CoreStop:
                    vgcServerService.OnCoreStop += handler;
                    break;

                default:
                    return(null);
                }
                var item = new GlobalEvHook((CoreEvTypes)evType, mailbox, handler);
                globalEvHooks.TryAdd(handle, item);
                return(handle);
            }
            catch { }
            return(null);
        }
示例#6
0
        public string RegisterHotKey(
            VgcApis.Interfaces.Lua.ILuaMailBox mailbox, int evCode,
            string keyName, bool hasAlt, bool hasCtrl, bool hasShift)
        {
            // 无权访问
            if (!postOffice.ValidateMailBox(mailbox))
            {
                return(null);
            }

            var    addr    = mailbox.GetAddress();
            Action handler = () => mailbox.SendCode(addr, evCode);

            var hkHandle = luaApis.RegisterHotKey(handler, keyName, hasAlt, hasCtrl, hasShift);

            if (!string.IsNullOrEmpty(hkHandle))
            {
                hotkeys.TryAdd(hkHandle, mailbox);
                return(hkHandle);
            }

            return(null);
        }