Skip to content

Commit 99f4574

Browse files
committed
Add check for disposing
1 parent 53b4ac9 commit 99f4574

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

WebUntisAPI.Client/WebUntisClient.User.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@ public partial class WebUntisClient
4646
/// <exception cref="WebUntisException">Thrown when the WebUntis API returned an error</exception>
4747
/// <exception cref="UnauthorizedAccessException">Thrown when you don't logged in</exception>
4848
/// <exception cref="HttpRequestException">Thrown when there was an error while the http request</exception>
49+
/// <exception cref="ObjectDisposedException">Thrown when the object is disposed</exception>
4950
public async Task<Student[]> GetAllStudentsAsync(string id = "getStudents", CancellationToken ct = default)
5051
{
52+
// Check for disposing
53+
if (_disposedValue)
54+
throw new ObjectDisposedException(GetType().FullName);
55+
56+
// Check if you logged in
5157
if (!LoggedIn)
5258
throw new UnauthorizedAccessException("You're not logged in");
5359

@@ -89,8 +95,14 @@ public async Task<Student[]> GetAllStudentsAsync(string id = "getStudents", Canc
8995
/// <exception cref="UnauthorizedAccessException">Thrown when you don't logged in</exception>
9096
/// <exception cref="HttpRequestException">Thrown when there was an error while the http request</exception>
9197
/// <exception cref="WebUntisException">Thrown when the WebUntis API returned an error</exception>
98+
/// <exception cref="ObjectDisposedException">Thrown when the object is disposed</exception>
9299
public async Task<Teacher[]> GetAllTeachersAsync(string id = "getTeachers", CancellationToken ct = default)
93100
{
101+
// Check for disposing
102+
if (_disposedValue)
103+
throw new ObjectDisposedException(GetType().FullName);
104+
105+
// Check if you logged in
94106
if (!LoggedIn)
95107
throw new UnauthorizedAccessException("You're not logged in");
96108

WebUntisAPI.Client/WebUntisClient.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public WebUntisClient(string clientName, int timeout = 500)
9797
/// <exception cref="ArgumentException">The server name is invalid</exception>
9898
/// <exception cref="HttpRequestException">There was an error while the request</exception>
9999
/// <exception cref="WebUntisException">The WebUntis server returned an error</exception>
100+
/// <exception cref="ObjectDisposedException">Thrown when the object is disposed</exception>
100101
public async Task<bool> LoginAsync(School school, string username, string password, string id = "getStudents", CancellationToken ct = default) =>
101102
await LoginAsync(school.Server, school.LoginName, username, password, id, ct);
102103

@@ -116,8 +117,13 @@ public async Task<bool> LoginAsync(School school, string username, string passwo
116117
/// <exception cref="ArgumentException">The server name is invalid</exception>
117118
/// <exception cref="HttpRequestException">There was an error while the request</exception>
118119
/// <exception cref="WebUntisException">The WebUntis server returned an error</exception>
120+
/// <exception cref="ObjectDisposedException">Thrown when the object is disposed</exception>
119121
public async Task<bool> LoginAsync(string server, string loginName, string username, string password, string id = "getStudents", CancellationToken ct = default)
120122
{
123+
// Check for disposing
124+
if (_disposedValue)
125+
throw new ObjectDisposedException(GetType().FullName);
126+
121127
// Check if you already logged in
122128
if (LoggedIn)
123129
return false;
@@ -186,8 +192,13 @@ public async Task<bool> LoginAsync(string server, string loginName, string usern
186192
/// <param name="ct">Cancellation token</param>
187193
/// <returns>Task for the proccess</returns>
188194
/// <exception cref="HttpRequestException">There was an error while the request</exception>
195+
/// <exception cref="ObjectDisposedException">Thrown when the object is disposed</exception>
189196
public async Task LogoutAsync(string id = "getStudents", CancellationToken ct = default)
190197
{
198+
// Check for disposing
199+
if (_disposedValue)
200+
throw new ObjectDisposedException(GetType().FullName);
201+
191202
// Check if you logged in
192203
if (!LoggedIn)
193204
return;

0 commit comments

Comments
 (0)