Check service existence before use in Debug mode
This commit is contained in:
parent
3efbca6c90
commit
0a9e4a3f9d
2 changed files with 20 additions and 1 deletions
|
|
@ -302,6 +302,9 @@ namespace Yavsc.Controllers
|
||||||
public async Task<IActionResult> SetGoogleCalendar(string returnUrl, string pageToken)
|
public async Task<IActionResult> SetGoogleCalendar(string returnUrl, string pageToken)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
#if Debug
|
||||||
|
if (_calendarManager==null) throw new Exception("No service!");
|
||||||
|
#endif
|
||||||
var calendar = await _calendarManager.GetCalendarsAsync(User.GetUserId(), pageToken);
|
var calendar = await _calendarManager.GetCalendarsAsync(User.GetUserId(), pageToken);
|
||||||
if (calendar == null)
|
if (calendar == null)
|
||||||
return new ChallengeResult();
|
return new ChallengeResult();
|
||||||
|
|
|
||||||
|
|
@ -101,8 +101,21 @@ namespace Yavsc.Services
|
||||||
if (string.IsNullOrWhiteSpace(userId))
|
if (string.IsNullOrWhiteSpace(userId))
|
||||||
throw new Exception("the user id is not specified");
|
throw new Exception("the user id is not specified");
|
||||||
var service = await CreateUserCalendarServiceAsync(userId);
|
var service = await CreateUserCalendarServiceAsync(userId);
|
||||||
|
#if Debug
|
||||||
|
if (service==null) throw new Exception("Could not get service");
|
||||||
|
#endif
|
||||||
|
_logger.LogInformation("Got a service");
|
||||||
|
|
||||||
|
#if Debug
|
||||||
|
if (service.CalendarList==null) throw new Exception("Could not get calendar list");
|
||||||
|
#endif
|
||||||
CalendarListResource.ListRequest calListReq = service.CalendarList.List ();
|
CalendarListResource.ListRequest calListReq = service.CalendarList.List ();
|
||||||
calListReq.PageToken = pageToken;
|
|
||||||
|
#if Debug
|
||||||
|
if (calListReq==null) throw new Exception ("list is null");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
calListReq.PageToken = pageToken;
|
||||||
return calListReq.Execute ();
|
return calListReq.Execute ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -241,12 +254,15 @@ namespace Yavsc.Services
|
||||||
{
|
{
|
||||||
var login = await _dbContext.GetGoogleUserLoginAsync(userId);
|
var login = await _dbContext.GetGoogleUserLoginAsync(userId);
|
||||||
if (login == null) return null;
|
if (login == null) return null;
|
||||||
|
_logger.LogInformation("Got a Google login");
|
||||||
var token = await _flow.LoadTokenAsync(login.ProviderKey, CancellationToken.None);
|
var token = await _flow.LoadTokenAsync(login.ProviderKey, CancellationToken.None);
|
||||||
|
_logger.LogInformation("Got a Google token");
|
||||||
var c = SystemClock.Default;
|
var c = SystemClock.Default;
|
||||||
if (token.IsExpired(c)) {
|
if (token.IsExpired(c)) {
|
||||||
token = await RefreshToken(token);
|
token = await RefreshToken(token);
|
||||||
}
|
}
|
||||||
UserCredential cred = new UserCredential(_flow,login.ProviderKey,token);
|
UserCredential cred = new UserCredential(_flow,login.ProviderKey,token);
|
||||||
|
_logger.LogInformation("Got creadential");
|
||||||
return new CalendarService(new BaseClientService.Initializer()
|
return new CalendarService(new BaseClientService.Initializer()
|
||||||
{
|
{
|
||||||
HttpClientInitializer = cred,
|
HttpClientInitializer = cred,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue