public async Task<AuthorizationResult> AuthorizeAsync(AuthorizationParameters parameters) { _taskCompletionSource = new TaskCompletionSource<AuthorizationResult>(); if (parameters == null) throw new NullReferenceException("Параметры авторизации не могут иметь значение null"); if (_form != null) { _form.Close(); _taskCompletionSource = new TaskCompletionSource<AuthorizationResult>(); } _form = new AuthorizationForm(parameters.Culture, parameters.AuthUri, parameters.BlankUri, parameters.AvailableHostNames); if (parameters.AuthorizationTitle != null) _form.SetTitle(parameters.AuthorizationTitle); if (parameters.PageErrorText != null) _form.PageErrorText = parameters.PageErrorText; _form.Authorized += Authorized; _form.Closing += Closing; if (_form.Visibility != Visibility.Visible) _form.ShowDialog(); return await _taskCompletionSource.Task; }
public void Selected() { if (!_sessionRepository.Authorized) { var url = _authorizer.GenerateUrl(); var form = new AuthorizationForm(new CultureInfo(Languages.Current.Key), url, VkApiConstants.VkBlankUrl); form.Authorized += (sender, args) => { var sessionInfo = _authorizer.GetSessionInfo(args.Url); _sessionRepository.Set(sessionInfo, DataSourceType.Api); SetAppContent(); }; form.ShowDialog(); } else { SetAppContent(); } }