示例#1
0
        void CloseListOfServices(List<IService> services, IServiceHost host, 
            ServiceExceptionKind closeExceptionKind)
        {
            List<IService> reverseList = new List<IService>(services);
            reverseList.Reverse();

            foreach (IService service in reverseList)
            {
                try
                {
                    service.Close(host);
                }
                catch (Exception ex)
                {
                    if (UnhandledException != null) UnhandledException(this,
                        new ServiceExceptionEventArgs(closeExceptionKind, ex));
                }
            }
        }
示例#2
0
        bool OpenListOfServices(List<IService> services, IServiceHost host, 
            ServiceExceptionKind openExceptionKind, ServiceExceptionKind openAbortExceptionKind)
        {
            Stack<IService> startedServices = new Stack<IService>();

            try
            {
                foreach (IService service in services)
                {
                    service.Open(host);

                    startedServices.Push(service);
                }

                return true;
            }
            catch (Exception ex)
            {
                while (startedServices.Count > 0)
                {
                    IService serviceToShutdown = startedServices.Pop();

                    try
                    {
                        serviceToShutdown.Close(host);
                    }
                    catch (Exception nestedEx)
                    {
                        if (UnhandledException != null) UnhandledException(this,
                            new ServiceExceptionEventArgs(openAbortExceptionKind, nestedEx));
                    }
                }

                if (UnhandledException != null) UnhandledException(this,
                    new ServiceExceptionEventArgs(openExceptionKind, ex));

                return false;
            }
        }
 public ServiceExceptionEventArgs(ServiceExceptionKind kind, Exception ex)
 {
     _kind = kind;
     _ex = ex;
     _handled = false;
 }