示例#1
0
        /// <summary>
        /// Stop the OpenVPN Service.
        /// Temporary configurations will also be deleted, and the tracking object will be emptied.
        /// </summary>
        public void Stop()
        {
            LogState("Stop");

            // We should probably think about if we want this to throw an exception instead, because the invocation would effectively be illegal at that stage.
            if (_state != ServiceState.Running)
            {
                return;
            }

            // Stop all running configurations
            _processRunner.CloseAllBelongingToService(this);

            // Iterate through each configuration on the disk.
            foreach (var fileOnDisk in _configsOnDisk)
            {
                File.Delete(fileOnDisk);
            }

            // Clear the list of configurations on the disk.
            _configsOnDisk.Clear();

            _state = ServiceState.Halted;

            LogState("Stop");
        }