Ejemplo n.º 1
0
        private PSHttpHandlerInfo RegisterPSHttpHandler(PSCmdlet hostCmdlet, string name, Func <PSHttpHandler> createHandler)
        {
            PSHttpHandlerInfo info;

            Monitor.Enter(_syncRoot);
            try
            {
                if (Status == PSHttpListenerStatus.Closed)
                {
                    throw new InvalidOperationException("HTTP listener is closed");
                }
                if (Status != PSHttpListenerStatus.Stopped)
                {
                    throw new InvalidOperationException("HTTP listener is not stopped");
                }
                if (_handlers.Any(h => h.Matches(name)))
                {
                    throw new ArgumentException("A handler with that name already exists.", "name");
                }
                PSHttpHandler handler = createHandler();
                info = new PSHttpHandlerInfo(this, handler);
                _handlers.AddLast(info);
                try { handler.OnRegistered(hostCmdlet, this); }
                catch
                {
                    _handlers.Remove(info);
                    throw;
                }
            }
            finally { Monitor.Exit(_syncRoot); }
            return(info);
        }
Ejemplo n.º 2
0
 internal PSHttpHandlerInfo(PSHttpListener listener, PSHttpHandler handler)
 {
     _listener         = listener;
     _handler          = handler;
     listener.Closing += PSHttpListener_Closing;
 }