Skip to content

Commit

Permalink
Add ConfigureAwait(false) to all awaits in order to avoid capturing c…
Browse files Browse the repository at this point in the history
…ontext and causing potential deadlocks. Fixes #94.
  • Loading branch information
dpse authored and richardrandak committed Jul 7, 2020
1 parent d5f09de commit ff05085
Show file tree
Hide file tree
Showing 58 changed files with 264 additions and 264 deletions.
10 changes: 5 additions & 5 deletions FortnoxAPILibrary/Connectors/AbsenceTransactionConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,23 @@ public EntityCollection<AbsenceTransaction> Find()

public async Task<EntityCollection<AbsenceTransaction>> FindAsync()
{
return await BaseFind();
return await BaseFind().ConfigureAwait(false);
}
public async Task DeleteAsync(string employeeId, DateTime? date, AbsenceCauseCode? code)
{
await BaseDelete(employeeId, date?.ToString(APIConstants.DateFormat), code?.GetStringValue());
await BaseDelete(employeeId, date?.ToString(APIConstants.DateFormat), code?.GetStringValue()).ConfigureAwait(false);
}
public async Task<AbsenceTransaction> CreateAsync(AbsenceTransaction absenceTransaction)
{
return await BaseCreate(absenceTransaction);
return await BaseCreate(absenceTransaction).ConfigureAwait(false);
}
public async Task<AbsenceTransaction> UpdateAsync(AbsenceTransaction absenceTransaction)
{
return await BaseUpdate(absenceTransaction, absenceTransaction.EmployeeId, absenceTransaction.Date?.ToString(APIConstants.DateFormat), absenceTransaction.CauseCode?.GetStringValue());
return await BaseUpdate(absenceTransaction, absenceTransaction.EmployeeId, absenceTransaction.Date?.ToString(APIConstants.DateFormat), absenceTransaction.CauseCode?.GetStringValue()).ConfigureAwait(false);
}
public async Task<AbsenceTransaction> GetAsync(string employeeId, DateTime? date, AbsenceCauseCode? code)
{
return await BaseGet(employeeId, date?.ToString(APIConstants.DateFormat), code?.GetStringValue());
return await BaseGet(employeeId, date?.ToString(APIConstants.DateFormat), code?.GetStringValue()).ConfigureAwait(false);
}
}
}
2 changes: 1 addition & 1 deletion FortnoxAPILibrary/Connectors/AccountChartConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public EntityCollection<AccountChart> Find()

public async Task<EntityCollection<AccountChart>> FindAsync()
{
return await BaseFind();
return await BaseFind().ConfigureAwait(false);
}
}
}
10 changes: 5 additions & 5 deletions FortnoxAPILibrary/Connectors/AccountConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,23 @@ public EntityCollection<AccountSubset> Find()

public async Task<EntityCollection<AccountSubset>> FindAsync()
{
return await BaseFind();
return await BaseFind().ConfigureAwait(false);
}
public async Task DeleteAsync(int? id)
{
await BaseDelete(id.ToString());
await BaseDelete(id.ToString()).ConfigureAwait(false);
}
public async Task<Account> CreateAsync(Account account)
{
return await BaseCreate(account);
return await BaseCreate(account).ConfigureAwait(false);
}
public async Task<Account> UpdateAsync(Account account)
{
return await BaseUpdate(account, account.Number.ToString());
return await BaseUpdate(account, account.Number.ToString()).ConfigureAwait(false);
}
public async Task<Account> GetAsync(int? id)
{
return await BaseGet(id.ToString());
return await BaseGet(id.ToString()).ConfigureAwait(false);
}
}
}
30 changes: 15 additions & 15 deletions FortnoxAPILibrary/Connectors/ArchiveConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ public void DeleteFolder(string pathOrId)

public async Task<byte[]> DownloadFileAsync(string id)
{
return await BaseDownload(null, id);
return await BaseDownload(null, id).ConfigureAwait(false);
}

public async Task<FileInfo> DownloadFileAsync(string id, string localPath)
{
var data = await DownloadFileAsync(id);
return await data.ToFile(localPath);
var data = await DownloadFileAsync(id).ConfigureAwait(false);
return await data.ToFile(localPath).ConfigureAwait(false);
}

public async Task<ArchiveFile> UploadFileAsync(string name, byte[] data, string folderPathOrId = null)
Expand All @@ -154,23 +154,23 @@ public async Task<ArchiveFile> UploadFileAsync(string name, byte[] data, string
else
urlParams.Add("path", folderPathOrId);

return await BaseUpload(name, data, urlParams);
return await BaseUpload(name, data, urlParams).ConfigureAwait(false);
}

public async Task<ArchiveFile> UploadFileAsync(string name, Stream stream, string folderPathOrId = null)
{
return await UploadFileAsync(name, await stream.ToBytes(), folderPathOrId);
return await UploadFileAsync(name, await stream.ToBytes(), folderPathOrId).ConfigureAwait(false);
}

public async Task<ArchiveFile> UploadFileAsync(string localPath, string folderPathOrId = null)
{
var fileInfo = new FileInfo(localPath);
return await UploadFileAsync(fileInfo.Name, fileInfo.ToBytes().Result, folderPathOrId);
return await UploadFileAsync(fileInfo.Name, fileInfo.ToBytes().Result, folderPathOrId).ConfigureAwait(false);
}

public async Task DeleteFileAsync(string id)
{
await BaseDelete(id);
await BaseDelete(id).ConfigureAwait(false);
}

public async Task<ArchiveFolder> GetFolderAsync(string pathOrId = null)
Expand All @@ -179,18 +179,18 @@ public async Task<ArchiveFolder> GetFolderAsync(string pathOrId = null)
pathOrId = "root";

if (IsArchiveId(pathOrId) || IsPredefinedFolder(pathOrId))
return await BaseGet(pathOrId);
return await BaseGet(pathOrId).ConfigureAwait(false);
else
{
ParametersInjection = new Dictionary<string, string>();
ParametersInjection.Add("path", pathOrId);
return await BaseGet();
return await BaseGet().ConfigureAwait(false);
}
}

public async Task<ArchiveFolder> GetRootAsync()
{
return await GetFolderAsync();
return await GetFolderAsync().ConfigureAwait(false);
}

public async Task<ArchiveFolder> CreateFolderAsync(string folderName, string path = null)
Expand All @@ -200,17 +200,17 @@ public async Task<ArchiveFolder> CreateFolderAsync(string folderName, string pat
if (path != null)
ParametersInjection = new Dictionary<string, string> { { "path", path } };

return await BaseCreate(folder);
return await BaseCreate(folder).ConfigureAwait(false);
}

public async Task DeleteFolderAsync(string pathOrId)
{
if (IsArchiveId(pathOrId))
await BaseDelete(pathOrId);
await BaseDelete(pathOrId).ConfigureAwait(false);
else
{
ParametersInjection = new Dictionary<string, string> { { "path", pathOrId } };
await BaseDelete();
await BaseDelete().ConfigureAwait(false);
}
}

Expand All @@ -226,7 +226,7 @@ private async Task<ArchiveFile> BaseUpload(string name, byte[] data, Dictionary<
Indices = indices
};

return await UploadFile<ArchiveFile>(data, name);
return await UploadFile<ArchiveFile>(data, name).ConfigureAwait(false);
}

private async Task<byte[]> BaseDownload(Dictionary<string, string> parameters, params string[] indices)
Expand All @@ -239,7 +239,7 @@ private async Task<byte[]> BaseDownload(Dictionary<string, string> parameters, p
Indices = indices
};

return await DownloadFile();
return await DownloadFile().ConfigureAwait(false);
}

private static bool IsArchiveId(string str)
Expand Down
10 changes: 5 additions & 5 deletions FortnoxAPILibrary/Connectors/ArticleConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,23 @@ public EntityCollection<ArticleSubset> Find()

public async Task<EntityCollection<ArticleSubset>> FindAsync()
{
return await BaseFind();
return await BaseFind().ConfigureAwait(false);
}
public async Task DeleteAsync(string id)
{
await BaseDelete(id);
await BaseDelete(id).ConfigureAwait(false);
}
public async Task<Article> CreateAsync(Article article)
{
return await BaseCreate(article);
return await BaseCreate(article).ConfigureAwait(false);
}
public async Task<Article> UpdateAsync(Article article)
{
return await BaseUpdate(article, article.ArticleNumber);
return await BaseUpdate(article, article.ArticleNumber).ConfigureAwait(false);
}
public async Task<Article> GetAsync(string id)
{
return await BaseGet(id);
return await BaseGet(id).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ public EntityCollection<ArticleFileConnection> Find()

public async Task<EntityCollection<ArticleFileConnection>> FindAsync()
{
return await BaseFind();
return await BaseFind().ConfigureAwait(false);
}
public async Task DeleteAsync(string id)
{
await BaseDelete(id);
await BaseDelete(id).ConfigureAwait(false);
}
public async Task<ArticleFileConnection> CreateAsync(ArticleFileConnection articleFileConnection)
{
return await BaseCreate(articleFileConnection);
return await BaseCreate(articleFileConnection).ConfigureAwait(false);
}
public async Task<ArticleFileConnection> GetAsync(string id)
{
return await BaseGet(id);
return await BaseGet(id).ConfigureAwait(false);
}
}
}
10 changes: 5 additions & 5 deletions FortnoxAPILibrary/Connectors/AssetConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ public EntityCollection<AssetSubset> Find()

public async Task<EntityCollection<AssetSubset>> FindAsync()
{
return await BaseFind();
return await BaseFind().ConfigureAwait(false);
}
public async Task DeleteAsync(string id)
{
await BaseDelete(id);
await BaseDelete(id).ConfigureAwait(false);
}
public async Task<Asset> CreateAsync(Asset asset)
{
FixResponseContent = (json) => new Regex("Assets").Replace(json, "Asset", 1);

var result = await BaseCreate(asset);
var result = await BaseCreate(asset).ConfigureAwait(false);

FixResponseContent = null;
return result;
Expand All @@ -105,7 +105,7 @@ public async Task<Asset> UpdateAsync(Asset asset)
asset.Id = null;
FixResponseContent = (json) => new Regex("Assets").Replace(json, "Asset", 1);

var result = await BaseUpdate(asset, id);
var result = await BaseUpdate(asset, id).ConfigureAwait(false);

FixResponseContent = null;
asset.Id = id;
Expand All @@ -116,7 +116,7 @@ public async Task<Asset> GetAsync(string id)
{
FixResponseContent = (json) => new Regex("Assets").Replace(json, "Asset", 1);

var result = await BaseGet(id);
var result = await BaseGet(id).ConfigureAwait(false);

FixResponseContent = null;
return result;
Expand Down
8 changes: 4 additions & 4 deletions FortnoxAPILibrary/Connectors/AssetFileConnectionConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ public EntityCollection<AssetFileConnection> Find()

public async Task<EntityCollection<AssetFileConnection>> FindAsync()
{
return await BaseFind();
return await BaseFind().ConfigureAwait(false);
}
public async Task DeleteAsync(string id)
{
await BaseDelete(id);
await BaseDelete(id).ConfigureAwait(false);
}
public async Task<AssetFileConnection> CreateAsync(AssetFileConnection assetFileConnection)
{
return await BaseCreate(assetFileConnection);
return await BaseCreate(assetFileConnection).ConfigureAwait(false);
}
public async Task<AssetFileConnection> GetAsync(string id)
{
return await BaseGet(id);
return await BaseGet(id).ConfigureAwait(false);
}
}
}
10 changes: 5 additions & 5 deletions FortnoxAPILibrary/Connectors/AssetTypesConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,20 @@ public async Task<EntityCollection<AssetTypesSubset>> FindAsync()
return fixedJson;
};

var result = await BaseFind();
var result = await BaseFind().ConfigureAwait(false);

FixResponseContent = null;
return result;
}
public async Task DeleteAsync(int? id)
{
await BaseDelete(id.ToString());
await BaseDelete(id.ToString()).ConfigureAwait(false);
}
public async Task<AssetType> CreateAsync(AssetType assetType)
{
FixResponseContent = (json) => new Regex("Type").Replace(json, "AssetType", 1);

var result = await BaseCreate(assetType);
var result = await BaseCreate(assetType).ConfigureAwait(false);

FixResponseContent = null;
return result;
Expand All @@ -106,7 +106,7 @@ public async Task<AssetType> UpdateAsync(AssetType assetTypes)
{
FixResponseContent = (json) => new Regex("Type").Replace(json, "AssetType", 1);

var result = await BaseUpdate(assetTypes, assetTypes.Id.ToString());
var result = await BaseUpdate(assetTypes, assetTypes.Id.ToString()).ConfigureAwait(false);

FixResponseContent = null;
return result;
Expand All @@ -115,7 +115,7 @@ public async Task<AssetType> GetAsync(int? id)
{
FixResponseContent = (json) => new Regex("Type").Replace(json, "AssetType", 1);

var result = await BaseGet(id.ToString());
var result = await BaseGet(id.ToString()).ConfigureAwait(false);

FixResponseContent = null;
return result;
Expand Down
10 changes: 5 additions & 5 deletions FortnoxAPILibrary/Connectors/AttendanceTransactionsConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ public EntityCollection<AttendanceTransactionSubset> Find()

public async Task<EntityCollection<AttendanceTransactionSubset>> FindAsync()
{
return await BaseFind();
return await BaseFind().ConfigureAwait(false);
}
public async Task DeleteAsync(string employeeId, DateTime? date, AttendanceCauseCode? code)
{
await BaseDelete(employeeId, date?.ToString(APIConstants.DateFormat), code?.GetStringValue());
await BaseDelete(employeeId, date?.ToString(APIConstants.DateFormat), code?.GetStringValue()).ConfigureAwait(false);
}
public async Task<AttendanceTransaction> CreateAsync(AttendanceTransaction attendanceTransaction)
{
return await BaseCreate(attendanceTransaction);
return await BaseCreate(attendanceTransaction).ConfigureAwait(false);
}
public async Task<AttendanceTransaction> UpdateAsync(AttendanceTransaction attendanceTransaction)
{
return await BaseUpdate(attendanceTransaction, attendanceTransaction.EmployeeId, attendanceTransaction.Date?.ToString(APIConstants.DateFormat), attendanceTransaction.CauseCode?.GetStringValue());
return await BaseUpdate(attendanceTransaction, attendanceTransaction.EmployeeId, attendanceTransaction.Date?.ToString(APIConstants.DateFormat), attendanceTransaction.CauseCode?.GetStringValue()).ConfigureAwait(false);
}
public async Task<AttendanceTransaction> GetAsync(string employeeId, DateTime? date, AttendanceCauseCode? code)
{
return await BaseGet(employeeId, date?.ToString(APIConstants.DateFormat), code?.GetStringValue());
return await BaseGet(employeeId, date?.ToString(APIConstants.DateFormat), code?.GetStringValue()).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public CompanyInformation Get()

public async Task<CompanyInformation> GetAsync()
{
return (await BaseFind())?.Entity;
return (await BaseFind().ConfigureAwait(false))?.Entity;
}
}
}
2 changes: 1 addition & 1 deletion FortnoxAPILibrary/Connectors/CompanySettingsConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public CompanySettings Get()

public async Task<CompanySettings> GetAsync()
{
return (await BaseFind())?.Entity;
return (await BaseFind().ConfigureAwait(false))?.Entity;
}
}
}
Loading

0 comments on commit ff05085

Please sign in to comment.