public async Task InitializeAsync() { using var store = _storeFactory.Invoke(_register.DataFilePath, true); if (await store.Database.EnsureCreatedAsync()) { store.Profiles.Add(new Profile() { EmailAddress = _register.EmailAddress, DisplayName = _register.EmailAddress, ProviderId = _register.ProviderId, }); store.FolderSynchronizationStates.Add(new FolderSynchronizationState() { Id = _register.EmailAddress, }); await store.SaveChangesAsync(); } }
public async Task RestoreAsync() { await _mailService.InitializeAsync(); MailBox.Restore(); using var store = _storeFactory.Invoke(_register.DataFilePath, false); var state = await store.Profiles.FirstAsync(); DisplayName = state.DisplayName; }
public ExchangeProfileViewModel(ProfileRegister register, ExchangeProfileDataStore.Factory storeFactory, ExchangeAuthenticationService authenticationService, AutoMapper.IMapper mapper) : base(register) { _storeFactory = storeFactory; _client = new GraphServiceClient( "https://graph.microsoft.com/v1.0", new DelegateAuthenticationProvider(async(request) => { try { var result = await authenticationService.AcquireTokenSilentAsync(EmailAddress); var token = result.AccessToken; request.Headers.Authorization = new AuthenticationHeaderValue("bearer", token); } catch (Exception ex) { IsAuthenticated = false; this.Log().Error(ex, $"Failed to silently authenticate {EmailAddress}."); } })); _mailService = new ExchangeMailService(register, _storeFactory, _client, mapper); var queryFactory = new RelayProfileDataQueryFactory(register.DataFilePath, path => storeFactory.Invoke(path, false)); MailBox = new MailBoxViewModel(queryFactory, _mailService); }