예제 #1
0
        /// <summary>
        /// Get one server
        /// </summary>
        /// <param name="serverId"></param>
        /// <param name="cache"></param>
        /// <returns>throws KeyNotFoundException if server not found</returns>
        public IVirtualServer GetServer(int serverId, bool cache = false)
        {
            if (!cache || !_servers.ContainsKey(serverId))
            {
                var server = _meta.getServer(serverId);
                if (server == null)
                {
                    throw new KeyNotFoundException();
                }

                var vs = new VirtualServer(server, this);

                // add to cache
                if (!_servers.ContainsKey(serverId))
                {
                    _servers.Add(serverId, vs);
                }
                else
                {
                    _servers[serverId] = vs;
                }
            }

            return(_servers[serverId]);
        }
예제 #2
0
        /// <summary>
        /// Create new server
        /// </summary>
        /// <param name="slots"></param>
        /// <param name="port">if port == 0 then random port will be used</param>
        /// <returns></returns>
        public IVirtualServer CreateServer(int slots = 10, int port = 0)
        {
            // add server on remote side
            var server = _meta.newServer();

            var vs = new VirtualServer(server, this);

            // setup server
            vs.Port  = (port == 0) ? GetNextAvailablePort() : port;
            vs.Slots = slots;

            // add to cache
            _servers.Add(vs.Id, vs);

            return(vs);
        }
예제 #3
0
        /// <summary>
        /// Return all servers
        /// </summary>
        /// <param name="cache"></param>
        /// <returns></returns>
        public SerializableDictionary <int, IVirtualServer> GetAllServers(bool cache = false)
        {
            // clear
            //  (it's needed to update one time to cache)
            if (_isNewAllServers || !cache)
            {
                _isNewAllServers = false;

                // add to cache
                foreach (var s in _meta.getAllServers())
                {
                    var vs = new VirtualServer(s, this);
                    if (!_servers.ContainsKey(vs.Id))
                    {
                        _servers.Add(vs.Id, vs);
                    }
                }
            }

            return(_servers);
        }
 public override void userTextMessage(User state, TextMessage message, Current current__)
 {
     // UNDONE: create wrapper for TextMessage, it has more context than just a message text
     callbackHandler.UserTextMessage(VirtualServer.getOnlineUser(state), message.text, server);
 }
 public override void userStateChanged(User state, Current current__)
 {
     callbackHandler.UserStateChanged(VirtualServer.getOnlineUser(state), server);
 }
 public override void channelStateChanged(Channel state, Current current__)
 {
     callbackHandler.ChannelStateChanged(VirtualServer.getChannel(state), server);
 }
 public VirtualServerCallbackWrapper(VirtualServer vs, IVirtualServerCallbackHandler callbackHandler)
 {
     this.server          = vs;
     this.callbackHandler = callbackHandler;
 }
예제 #8
0
        internal KeyValuePair <string, ServerContextCallbackPrx> AddVirtualServerContextCallback(int session, string action, string title, IVirtualServerContextCallbackHandler callback, int ctx, VirtualServer vs)
        {
            var callbackWrapper = new VirtualServerContextCallbackWrapper(vs, callback);

            // Create identity and callback for Virtual server
            var key = Guid.NewGuid().ToString();
            var server_context_callback = ServerContextCallbackPrxHelper.checkedCast(_adapter.add(callbackWrapper, new Ice.Identity(key, "")));

            vs.Server.addContextCallback(session, action, title, server_context_callback, ctx);
            return(new KeyValuePair <string, ServerContextCallbackPrx>(key, server_context_callback));
        }
예제 #9
0
 public override void contextAction(string action, User usr, int session, int channelid, Current current__)
 {
     callbackHandler.ContextAction(action, VirtualServer.getOnlineUser(usr), session, channelid, server);
 }