Esempio n. 1
0
        bool OpenAll()
        {
            _environment = new Dictionary<string, object>();

            IServiceHost host = new ServiceHostImplementation(_reactor, _environment, null);

            foreach (KeyValuePair<string, object> pair in _defaultEnvironment)
            {
                _environment.Add(pair.Key, pair.Value);
            }

            return OpenListOfServices(_services, host, ServiceExceptionKind.DuringOpen, ServiceExceptionKind.DuringOpenAbort);
        }
Esempio n. 2
0
        void ThreadMain()
        {
            ServiceHostImplementation host = new ServiceHostImplementation(_reactor, _defaultEnvironment, _services);

            _reactor.AddPermanentHandle(_stateRequestEvent, StateRequestEventFired);
            _reactor.AddRepeatingTimer(new TimeSpan(0, 0, 10), ExceptionWaitTimer, null);

            bool permanentServicesOpened = OpenListOfServices(_permanentServices, host,
                ServiceExceptionKind.DuringPermanentOpen, ServiceExceptionKind.DuringPermanentOpenAbort);

            try
            {
                SortServices(_services);
            }
            catch (Exception ex)
            {
                if (UnhandledException != null) UnhandledException(this,
                    new ServiceExceptionEventArgs(ServiceExceptionKind.DuringPermanentOpen, ex));

                permanentServicesOpened = false;
            }

            bool running = true;

            while (running)
            {
                _reactor.RunLoopIteration();

                ServiceStateRequest request = _pendingRequest;
                _pendingRequest = ServiceStateRequest.None;

                switch (request)
                {
                    case ServiceStateRequest.Open:
                        if (permanentServicesOpened) OpenWasRequested();
                        break;

                    case ServiceStateRequest.Close:
                        if (permanentServicesOpened) CloseWasRequested();
                        break;

                    case ServiceStateRequest.Shutdown:
                        running = false;
                        break;
                }
            }

            if (_state == ServiceState.Up)
            {
                CloseAll();
                _state = ServiceState.Down;
            }

            if (permanentServicesOpened) CloseListOfServices(_permanentServices, host, ServiceExceptionKind.DuringPermanentClose);
        }
Esempio n. 3
0
        void CloseAll()
        {
            IServiceHost host = new ServiceHostImplementation(_reactor, _environment, null);

            CloseListOfServices(_services, host, ServiceExceptionKind.DuringClose);

            _environment = null;
        }