Example #1
0
        private void OnChangeServiceStatus(ServiceStateRequest ssr, string title)
        {
            PerformServiceStateRequest pssr = new PerformServiceStateRequest(ssr);

            foreach (ServiceDataObject sdo in MainListView.SelectedItems)
            {
                pssr.Services.Add(sdo);
            }
            if (pssr.Services.Count > 0)
            {
                new LongRunningFunctionWindow(pssr, title).ShowDialog();
            }
        }
Example #2
0
 public ChangeServiceStatus(IServiceView serviceView, IEnumerable<ServiceObject> selectedItems, ServiceStateRequest ssr)
 {
     Trace.TraceInformation("ChangeServiceStatus() dialog created for {0}", ssr);
     SSR = ssr;
     ServiceView = serviceView;
     int nItem = 0;
     foreach (ServiceObject so in selectedItems)
     {
         Services.Add(so);
         Trace.TraceInformation("- Item {0}: {1}", nItem++, so);
     }
     InitializeComponent();
 }
Example #3
0
        public void PerformExplicitRequest(ServiceStateRequest ssr, List <string> serviceNames, string title)
        {
            PerformServiceStateRequest pssr = new PerformServiceStateRequest(ssr);

            // OK, so this code is not very efficient and I should really be using a dictionary.
            // BUT. I expect one or at max two services to be passed, so who cares?
            foreach (ServiceDataObject sdo in MainListView.Items)
            {
                foreach (string serviceName in serviceNames)
                {
                    if (serviceName.Equals(sdo.InternalID, StringComparison.OrdinalIgnoreCase))
                    {
                        pssr.Services.Add(sdo);
                        break;
                    }
                }
            }
            if (pssr.Services.Count > 0)
            {
                new LongRunningFunctionWindow(pssr, title).ShowDialog();
            }
        }
Example #4
0
 private void OnChangeServiceStatus(ServiceStateRequest ssr, string title)
 {
     PerformServiceStateRequest pssr = new PerformServiceStateRequest(ssr);
     foreach(ServiceDataObject sdo in MainListView.SelectedItems)
     {
         pssr.Services.Add(sdo);
     }
     if( pssr.Services.Count > 0 )
     {
         new LongRunningFunctionWindow(pssr, title).ShowDialog();
     }
 }
Example #5
0
        public void PerformExplicitRequest(ServiceStateRequest ssr, List<string> serviceNames, string title)
        {
            PerformServiceStateRequest pssr = new PerformServiceStateRequest(ssr);

            // OK, so this code is not very efficient and I should really be using a dictionary.
            // BUT. I expect one or at max two services to be passed, so who cares?
            foreach (ServiceDataObject sdo in MainListView.Items)
            {
                foreach(string serviceName in serviceNames)
                {
                    if(serviceName.Equals(sdo.InternalID, StringComparison.OrdinalIgnoreCase) )
                    {
                        pssr.Services.Add(sdo);
                        break;
                    }
                }
            }
            if (pssr.Services.Count > 0)
            {
                new LongRunningFunctionWindow(pssr, title).ShowDialog();
            }
        }
Example #6
0
        void context_ChangeServiceStatus(ServiceStateRequest ssr)
        {
            new ChangeServiceStatus(ServiceView, SelectedServices, ssr).ShowDialog();

            foreach (ServiceObject so in Services)
            {
                //ServiceView.Update(so);
            }
            ServiceView.UpdateDisplay();
        }
Example #7
0
 void StateRequestEventFired(IAsyncResult result, object state)
 {
     lock (_stateRequestLock)
     {
         _pendingRequest = _stateRequest;
         _stateRequest = ServiceStateRequest.None;
         _stateRequestEvent.Reset();
     }
 }
Example #8
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);
        }
Example #9
0
 /// <summary>
 /// Attempts to bring the service up, or to restart it if it is already 
 /// started.
 /// </summary>
 public void OpenServices()
 {
     lock (_stateRequestLock)
     {
         if (_stateRequest != ServiceStateRequest.Shutdown)
         {
             _stateRequest = ServiceStateRequest.Open;
             _stateRequestEvent.Set();
         }
     }
 }
Example #10
0
        public void StopServiceHost()
        {
            lock (_stateRequestLock)
            {
                _stateRequest = ServiceStateRequest.Shutdown;
                _stateRequestEvent.Set();
            }

            bool joined = _thread.Join(_serviceHostStopTimeout);

            if (!joined)
            {
                _thread.Abort();

                throw new InvalidOperationException(
                    "The service host thread failed to shut down in the specified time.");
            }
        }
Example #11
0
 /// <summary>
 /// Attempts to shutdown the services.
 /// </summary>
 public void CloseServices()
 {
     lock (_stateRequestLock)
     {
         if (_stateRequest != ServiceStateRequest.Shutdown)
         {
             _stateRequest = ServiceStateRequest.Close;
             _stateRequestEvent.Set();
         }
     }
 }
Example #12
0
 public PerformServiceStateRequest(ServiceStateRequest ssr)
 {
     SSR = ssr;
 }
Example #13
0
        public static IEnumerable<ENUM_SERVICE_STATUS_PROCESS> GetServices(
            string machineName, string databaseName, AccessFlags accessFlags,   // From OpenSCManager
            ServiceEnumType infoLevel, ServiceType serviceType, ServiceStateRequest serviceStateRequest // From EnumServicesStatusEx
            )
        {
            List<ENUM_SERVICE_STATUS_PROCESS> results = new List<ENUM_SERVICE_STATUS_PROCESS>();

            IntPtr handle = OpenSCManager(machineName, databaseName, accessFlags);
            if (handle == IntPtr.Zero)
            {
                return null;
            }

            IntPtr serviceStatusBuffer = IntPtr.Zero;

            try
            {
                uint bytesNeeded = 0;
                uint servicesReturned = 0;
                uint resumeHandle = 0;

                if (!EnumServicesStatusEx(handle, infoLevel, serviceType, serviceStateRequest, IntPtr.Zero, 0, out bytesNeeded, out servicesReturned, ref resumeHandle, null))
                {
                    // allocate our memory to receive the data for all the services (including the names)
                    serviceStatusBuffer = Marshal.AllocHGlobal((int)bytesNeeded);

                    if (!EnumServicesStatusEx(handle, infoLevel, serviceType, serviceStateRequest, serviceStatusBuffer, bytesNeeded, out bytesNeeded, out servicesReturned, ref resumeHandle, null))
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }

                    ENUM_SERVICE_STATUS_PROCESS serviceStatus;

                    // check if 64 bit system which has different pack sizes
                    if (IntPtr.Size == 8)
                    {
                        long pointer = serviceStatusBuffer.ToInt64();
                        for (int i = 0; i < (int)servicesReturned; i++)
                        {
                            serviceStatus = (ENUM_SERVICE_STATUS_PROCESS)Marshal.PtrToStructure(new IntPtr(pointer), typeof(ENUM_SERVICE_STATUS_PROCESS));
                            results.Add(serviceStatus);

                            // incremement by sizeof(ENUM_SERVICE_STATUS_PROCESS) allow Packing of 8
                            pointer += ENUM_SERVICE_STATUS_PROCESS.SizePack8;
                        }

                    }
                    else
                    {
                        int pointer = serviceStatusBuffer.ToInt32();
                        for (int i = 0; i < (int)servicesReturned; i++)
                        {
                            serviceStatus = (ENUM_SERVICE_STATUS_PROCESS)Marshal.PtrToStructure(new IntPtr(pointer), typeof(ENUM_SERVICE_STATUS_PROCESS));
                            results.Add(serviceStatus);

                            // incremement by sizeof(ENUM_SERVICE_STATUS_PROCESS) allow Packing of 4
                            pointer += ENUM_SERVICE_STATUS_PROCESS.SizePack4;
                        }
                    }
                }
            }
            catch (Exception /*e*/)
            {
                ;
            }
            finally
            {
                if (handle != IntPtr.Zero)
                {
                    CloseServiceHandle(handle);
                }

                if (serviceStatusBuffer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(serviceStatusBuffer);
                }
            }

            return results;
        }
Example #14
0
 private static extern bool EnumServicesStatusEx(IntPtr hSCManager,
     ServiceEnumType infoLevel, ServiceType dwServiceType,
     ServiceStateRequest dwServiceState, IntPtr lpServices, UInt32 cbBufSize,
     out uint pcbBytesNeeded, out uint lpServicesReturned,
     ref uint lpResumeHandle, string pszGroupName);
 public PerformServiceStateRequest(ServiceStateRequest ssr)
 {
     SSR = ssr;
 }