mirror of
https://github.com/bitwarden/mobile
synced 2025-12-20 18:23:51 +00:00
convert to local functions to avoid continuewith
This commit is contained in:
@@ -104,11 +104,14 @@ namespace Bit.Core.Models.Domain
|
||||
{
|
||||
model.Attachments = new List<AttachmentView>();
|
||||
var tasks = new List<Task>();
|
||||
async Task decryptAndAddAttachmentAsync(Attachment attachment)
|
||||
{
|
||||
var decAttachment = await attachment.DecryptAsync(OrganizationId);
|
||||
model.Attachments.Add(decAttachment);
|
||||
}
|
||||
foreach(var attachment in Attachments)
|
||||
{
|
||||
var t = attachment.DecryptAsync(OrganizationId)
|
||||
.ContinueWith(async decAttachment => model.Attachments.Add(await decAttachment));
|
||||
tasks.Add(t);
|
||||
tasks.Add(decryptAndAddAttachmentAsync(attachment));
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
@@ -116,11 +119,14 @@ namespace Bit.Core.Models.Domain
|
||||
{
|
||||
model.Fields = new List<FieldView>();
|
||||
var tasks = new List<Task>();
|
||||
async Task decryptAndAddFieldAsync(Field field)
|
||||
{
|
||||
var decField = await field.DecryptAsync(OrganizationId);
|
||||
model.Fields.Add(decField);
|
||||
}
|
||||
foreach(var field in Fields)
|
||||
{
|
||||
var t = field.DecryptAsync(OrganizationId)
|
||||
.ContinueWith(async decField => model.Fields.Add(await decField));
|
||||
tasks.Add(t);
|
||||
tasks.Add(decryptAndAddFieldAsync(field));
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
@@ -128,11 +134,14 @@ namespace Bit.Core.Models.Domain
|
||||
{
|
||||
model.PasswordHistory = new List<PasswordHistoryView>();
|
||||
var tasks = new List<Task>();
|
||||
async Task decryptAndAddHistoryAsync(PasswordHistory ph)
|
||||
{
|
||||
var decPh = await ph.DecryptAsync(OrganizationId);
|
||||
model.PasswordHistory.Add(decPh);
|
||||
}
|
||||
foreach(var ph in PasswordHistory)
|
||||
{
|
||||
var t = ph.DecryptAsync(OrganizationId)
|
||||
.ContinueWith(async decPh => model.PasswordHistory.Add(await decPh));
|
||||
tasks.Add(t);
|
||||
tasks.Add(decryptAndAddHistoryAsync(ph));
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
@@ -58,18 +58,14 @@ namespace Bit.Core.Models.Domain
|
||||
var viewModelType = viewModel.GetType();
|
||||
var domainType = domain.GetType();
|
||||
|
||||
Task<string> decCs(string propName)
|
||||
async Task decCsAndSetDec(string propName)
|
||||
{
|
||||
var domainPropInfo = domainType.GetProperty(propName);
|
||||
var domainProp = domainPropInfo.GetValue(domain) as CipherString;
|
||||
if(domainProp != null)
|
||||
string val = null;
|
||||
if(domainPropInfo.GetValue(domain) is CipherString domainProp)
|
||||
{
|
||||
return domainProp.DecryptAsync(orgId);
|
||||
val = await domainProp.DecryptAsync(orgId);
|
||||
}
|
||||
return Task.FromResult((string)null);
|
||||
};
|
||||
void setDec(string propName, string val)
|
||||
{
|
||||
var viewModelPropInfo = viewModelType.GetProperty(propName);
|
||||
viewModelPropInfo.SetValue(viewModel, val, null);
|
||||
};
|
||||
@@ -77,7 +73,7 @@ namespace Bit.Core.Models.Domain
|
||||
var tasks = new List<Task>();
|
||||
foreach(var prop in map)
|
||||
{
|
||||
tasks.Add(decCs(prop).ContinueWith(async val => setDec(prop, await val)));
|
||||
tasks.Add(decCsAndSetDec(prop));
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
return viewModel;
|
||||
|
||||
Reference in New Issue
Block a user