Class VpnServiceOptionsFile
- Namespace
- VpnHood.Core.Client.VpnServices.Abstractions
- Assembly
- VpnHood.Core.Client.VpnServices.Abstractions.dll
Represents the options a VPN service runs with, saved in its config folder as VpnConfigFileName.
public class VpnServiceOptionsFile
- Inheritance
-
VpnServiceOptionsFile
- Inherited Members
Remarks
The app writes them at each connect and makes them again at each change of its settings or servers; the service reads them at each start, including one the app does not make — always-on, the quick-settings tile, the system's VPN settings, the system restarting the service — which then runs with what the app shows. As the two processes share the file, an access that finds it held by the other tries again for up to 2 seconds.
Constructors
VpnServiceOptionsFile(string)
Represents the options a VPN service runs with, saved in its config folder as VpnConfigFileName.
public VpnServiceOptionsFile(string configFolder)
Parameters
configFolderstringThe VPN service's config folder.
Remarks
The app writes them at each connect and makes them again at each change of its settings or servers; the service reads them at each start, including one the app does not make — always-on, the quick-settings tile, the system's VPN settings, the system restarting the service — which then runs with what the app shows. As the two processes share the file, an access that finds it held by the other tries again for up to 2 seconds.
Properties
Exists
Gets a value indicating whether the file exists.
public bool Exists { get; }
Property Value
FilePath
Gets the file's path.
public string FilePath { get; }
Property Value
Methods
Delete(CancellationToken)
Deletes the file; one already gone is no error.
public Task Delete(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that completes once the file is gone.
Exceptions
- IOException
The file could not be reached, as where the other process still holds it after 2 seconds.
- UnauthorizedAccessException
The file may not be deleted.
- OperationCanceledException
cancellationTokenwas canceled.
Read(CancellationToken)
Reads the options.
public Task<VpnServiceOptions> Read(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<VpnServiceOptions>
A task whose result is the options.
Exceptions
- FileNotFoundException
There is no file.
- IOException
The file could not be reached, as where the other process still holds it after 2 seconds.
- JsonException
The file is not JSON of the options.
- InvalidDataException
The file holds
null.- UnauthorizedAccessException
The file may not be read.
- OperationCanceledException
cancellationTokenwas canceled.
TryRead(CancellationToken)
Reads the options where there is a file that can be read.
public Task<VpnServiceOptions?> TryRead(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<VpnServiceOptions>
A task whose result is the options, or null where there is no file or it cannot be read, which it logs.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.
Update(VpnServiceOptions, CancellationToken)
Writes options made again from the app's settings, connected or not, where there is a file, which only a connect makes; without one, it does nothing.
public Task Update(VpnServiceOptions serviceOptions, CancellationToken cancellationToken)
Parameters
serviceOptionsVpnServiceOptionsThe options. What only a connect knows, its plan (PlanId) and whether always-on made it (IsAlwaysOn), is set to the saved options'.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that completes once the file is written, or found missing.
Remarks
The saved options are read under the lock this instance's writes take, so a connect's write in between is kept.
Exceptions
- IOException
The file could not be reached, as where the other process still holds it after 2 seconds.
- JsonException
The saved file is not JSON of the options.
- InvalidDataException
The saved file holds
null.- UnauthorizedAccessException
The file may not be read or written.
- OperationCanceledException
cancellationTokenwas canceled.
Write(VpnServiceOptions, CancellationToken)
Writes the options, replacing the file whole, so the service never reads a part of it.
public Task Write(VpnServiceOptions serviceOptions, CancellationToken cancellationToken)
Parameters
serviceOptionsVpnServiceOptionsThe options.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that completes once the file is written.
Exceptions
- IOException
The file could not be reached, as where the other process still holds it after 2 seconds.
- UnauthorizedAccessException
The file may not be written.
- OperationCanceledException
cancellationTokenwas canceled.