Exemple #1
0
        public bool UnregisterGlobalEvent(VgcApis.Interfaces.Lua.ILuaMailBox mailbox, string handle)
        {
            if (postOffice.ValidateMailBox(mailbox) &&
                globalEvHooks.TryRemove(handle, out var evhook))
            {
                try
                {
                    var handler = evhook.evHandler;
                    switch (evhook.evType)
                    {
                    case CoreEvTypes.CoreStart:
                        vgcServerService.OnCoreStart -= handler;
                        break;

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

                    default:
                        return(false);
                    }
                    return(true);
                }
                catch { }
            }
            return(false);
        }
Exemple #2
0
 public GlobalEvHook(
     CoreEvTypes evType,
     VgcApis.Interfaces.Lua.ILuaMailBox mailBox,
     EventHandler evHandler)
 {
     this.evType    = evType;
     this.mailBox   = mailBox;
     this.evHandler = evHandler;
 }
Exemple #3
0
 public bool RemoveMailBox(VgcApis.Interfaces.Lua.ILuaMailBox mailbox)
 {
     if (mailboxes.TryRemove(mailbox.GetAddress(), out var box))
     {
         box.Close();
         return(true);
     }
     return(false);
 }
Exemple #4
0
 public HttpServer(
     string url,
     VgcApis.Interfaces.Lua.ILuaMailBox inbox,
     VgcApis.Interfaces.Lua.ILuaMailBox outbox)
 {
     this.inbox  = inbox;
     this.outbox = outbox;
     serv        = new HttpListener();
     serv.Prefixes.Add(url);
 }
Exemple #5
0
 public bool UnregisterHotKey(VgcApis.Interfaces.Lua.ILuaMailBox mailbox, string handle)
 {
     if (postOffice.ValidateMailBox(mailbox) &&
         hotkeys.TryGetValue(handle, out var mb) &&
         ReferenceEquals(mb, mailbox) &&
         hotkeys.TryRemove(handle, out _))
     {
         return(luaApis.UnregisterHotKey(handle));
     }
     return(false);
 }
Exemple #6
0
 public CoreEvHook(
     CoreEvTypes evType,
     VgcApis.Interfaces.ICoreServCtrl coreServCtrl,
     VgcApis.Interfaces.Lua.ILuaMailBox mailBox,
     EventHandler evHandler)
 {
     this.evType       = evType;
     this.coreServCtrl = coreServCtrl;
     this.mailBox      = mailBox;
     this.evHandler    = evHandler;
 }
Exemple #7
0
        public bool RemoveMailBox(VgcApis.Interfaces.Lua.ILuaMailBox mailbox)
        {
            if (!postOffice.ValidateMailBox(mailbox))
            {
                return(false);
            }

            lock (procLocker)
            {
                if (mailboxs.Contains(mailbox))
                {
                    mailboxs.Remove(mailbox);
                }
            }

            return(postOffice.RemoveMailBox(mailbox));
        }
Exemple #8
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);
        }
Exemple #9
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);
        }
Exemple #10
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);
        }
Exemple #11
0
 public VgcApis.Interfaces.Lua.IRunnable CreateHttpServer(
     string url,
     VgcApis.Interfaces.Lua.ILuaMailBox inbox,
     VgcApis.Interfaces.Lua.ILuaMailBox outbox)
 {
     try
     {
         var serv = new SysCmpos.HttpServer(url, inbox, outbox);
         lock (httpServs)
         {
             httpServs.Add(serv);
         }
         return(serv);
     }
     catch (Exception ex)
     {
         luaApis.SendLog(ex.ToString());
         throw;
     }
 }
Exemple #12
0
        public bool UnregisterCoreEvent(VgcApis.Interfaces.Lua.ILuaMailBox mailbox, string handle)
        {
            if (!postOffice.ValidateMailBox(mailbox))
            {
                return(false);
            }

            if (coreEvHooks.TryRemove(handle, out var evhook))
            {
                try
                {
                    var coreServ = evhook.coreServCtrl;
                    var handler  = evhook.evHandler;
                    switch (evhook.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(false);
                    }
                    return(true);
                }
                catch { }
            }
            return(false);
        }
Exemple #13
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);
        }
Exemple #14
0
 public bool ValidateMailBox(VgcApis.Interfaces.Lua.ILuaMailBox mailbox) =>
 postOffice.ValidateMailBox(mailbox);