Esempio n. 1
0
        internal void Add <TBehavior> (string path, Func <TBehavior> initializer)
            where TBehavior : WebSocketBehavior
        {
            lock (_sync) {
                path = HttpUtility.UrlDecode(path).TrimEndSlash();

                WebSocketServiceHost host;
                if (_hosts.TryGetValue(path, out host))
                {
                    _logger.Error(
                        "A WebSocket service with the specified path already exists:\n  path: " + path);

                    return;
                }

                host = new WebSocketServiceHost <TBehavior> (path, initializer, _logger);
                if (!_clean)
                {
                    host.KeepClean = false;
                }

                if (_waitTime != host.WaitTime)
                {
                    host.WaitTime = _waitTime;
                }

                if (_state == ServerState.Start)
                {
                    host.Start();
                }

                _hosts.Add(path, host);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Tries to get the WebSocket service host with the specified <paramref name="path"/>.
        /// </summary>
        /// <returns>
        /// <c>true</c> if the service is successfully found; otherwise, <c>false</c>.
        /// </returns>
        /// <param name="path">
        /// A <see cref="string"/> that represents the absolute path to the service to find.
        /// </param>
        /// <param name="host">
        /// When this method returns, a <see cref="WebSocketServiceHost"/> instance that
        /// provides the access to the information in the service, or <see langword="null"/>
        /// if it's not found. This parameter is passed uninitialized.
        /// </param>
        public bool TryGetServiceHost(string path, out WebSocketServiceHost host)
        {
            var msg = _state.CheckIfStart() ?? path.CheckIfValidServicePath();

            if (msg != null)
            {
                _logger.Error(msg);
                host = null;

                return(false);
            }

            return(InternalTryGetServiceHost(path, out host));
        }
Esempio n. 3
0
        internal bool InternalTryGetServiceHost(string path, out WebSocketServiceHost host)
        {
            bool ret;

            lock (_sync) {
                path = HttpUtility.UrlDecode(path).TrimEndSlash();
                ret  = _hosts.TryGetValue(path, out host);
            }

            if (!ret)
            {
                _logger.Error(
                    "A WebSocket service with the specified path isn't found:\n  path: " + path);
            }

            return(ret);
        }