Exemplo n.º 1
0
        public async Task PrepareSync()
        {
            using (ApplicationDbContext dbContext = ApplicationDbContext.Create())
            {
                this.DropboxModel = dbContext.DropboxAccounts.Where(d => d.UID == this.UserId).FirstOrDefault();

                if (this.DropboxModel != null)
                {
                    string accountId = DropboxModel.AspNetUID;
                    this.ExactOnlineModel = dbContext.ExactOnlineAccounts.Where(d => d.AspNetUID == accountId).FirstOrDefault();

                    if (this.ExactOnlineModel != null)
                    {
                        try
                        {
                            TimeSpan time = this.ExactOnlineModel.AccessTokenExpirationUtc.Subtract(DateTime.UtcNow);
                            if (time.Minutes < 1)
                            {
                                OAuth2ResponseExact response = await new ExactOnlineService().RefreshTokenAsync(this.ExactOnlineModel.RefreshToken, this.ExactOnlineModel.AccessToken);
                                if (response != null)
                                {
                                    this.ExactOnlineModel.AccessTokenExpirationUtc = DateTime.UtcNow.Add(new TimeSpan(0, 0, (response.ExpiresIn - 120)));
                                    this.ExactOnlineModel.AccessToken = response.AccessToken;
                                    this.ExactOnlineModel.TokenType = response.TokenType;
                                    this.ExactOnlineModel.ExpiresIn = response.ExpiresIn;
                                    this.ExactOnlineModel.RefreshToken = response.RefreshToken;

                                    dbContext.Entry(this.ExactOnlineModel).State = EntityState.Modified;
                                    await dbContext.SaveChangesAsync();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            AuditLogService.Log(Level.Error, EventType.Exception, EventAction.PrepareSyncAction, String.Format("UID: {0} - {1}", this.UserId, ex.Message));
                        }
                    }
                    else
                    {
                        await AuditLogService.LogAsync(Level.Error, EventType.Exception, EventAction.PrepareSyncAction, String.Format("UID: {0} - ExactOnline Integration Settings Not Found", this.UserId));
                    }
                }
                else
                {
                    await AuditLogService.LogAsync(Level.Error, EventType.Exception, EventAction.PrepareSyncAction, String.Format("UID: {0} - Dropbox Integration Settings Not Found", this.UserId));
                }
            }
        }
Exemplo n.º 2
0
 public ExactSyncService(DropboxAccountModel dropboxModel = null, ExactOnlineAccountModel exactOnlineModel = null)
 {
     this.DropboxModel = dropboxModel;
     this.ExactOnlineModel = exactOnlineModel;
 }
Exemplo n.º 3
0
        public void PostSync()
        {
            if (this.DropboxModel != null)
            {
                this.DropboxModel = null;
            }

            if (this.ExactOnlineModel != null)
            {
                this.ExactOnlineModel = null;
            }
        }