Пример #1
0
        public async Task UpdateAsync(Consent consent)
        {
            using (var scope = DataAccessScope.CreateReadCommitted())
            {
                var item = dataModel.Consents.SingleOrDefault(x => x.Subject == consent.Subject && x.ClientId == consent.ClientId);

                if (consent.Scopes == null || !consent.Scopes.Any())
                {
                    item?.Delete();
                }
                else
                {
                    if (item == null)
                    {
                        item          = dataModel.Consents.Create();
                        item.Id       = Guid.NewGuid();
                        item.Subject  = consent.Subject;
                        item.ClientId = consent.ClientId;
                    }

                    item.Scopes = StringifyScopes(consent.Scopes);
                }

                await scope.CompleteAsync();
            }
        }
Пример #2
0
        public override string Log(Error error)
        {
            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }

            var errorXml = ErrorXml.EncodeString(error);

            using (var scope = DataAccessScope.CreateReadCommitted())
            {
                var dbElmahError = dataModel.ElmahErrors.Create();

                dbElmahError.Application = ApplicationName;
                dbElmahError.Host        = error.HostName;
                dbElmahError.Type        = error.Type;
                dbElmahError.Source      = error.Source;
                dbElmahError.Message     = error.Message;
                dbElmahError.User        = error.User;
                dbElmahError.StatusCode  = error.StatusCode;
                dbElmahError.TimeUtc     = error.Time;
                dbElmahError.AllXml      = errorXml;

                scope.Complete();

                return(dbElmahError.Id.ToString());
            }
        }
Пример #3
0
        public async Task RevokeAsync(string subject, string client)
        {
            using (var scope = DataAccessScope.CreateReadCommitted())
            {
                await dataModel.Consents.DeleteAsync(x => x.Subject == subject && x.ClientId == client);

                await scope.CompleteAsync();
            }
        }
Пример #4
0
        public async Task RemoveAsync(string key)
        {
            using (var scope = DataAccessScope.CreateReadCommitted())
            {
                await DataModel.Tokens.DeleteAsync(x => x.Key == key && x.TokenType == TokenType);

                await scope.CompleteAsync();
            }
        }
Пример #5
0
        public LoadTests(string providerName)
            : base(providerName)
        {
            using (var scope = DataAccessScope.CreateReadCommitted())
            {
                this.model.Cats.Create();

                scope.Complete();
            }
        }
Пример #6
0
        public async Task <List <dynamic> > GetCategoriesAsync(int iteration)
        {
            using (var scope = DataAccessScope.CreateReadCommitted())
            {
                var result = await GetCatsNoDataAccessScopeAsync(iteration);

                await scope.CompleteAsync();

                return(result);
            }
        }
Пример #7
0
        public override async Task StoreAsync(string key, Token value)
        {
            using (var scope = DataAccessScope.CreateReadCommitted())
            {
                var token = this.DataModel.Tokens.Create();

                token.Id        = Guid.NewGuid();
                token.Key       = key;
                token.SubjectId = value.SubjectId;
                token.ClientId  = value.ClientId;
                token.JsonCode  = ConvertToJson(value);
                token.Expiry    = DateTimeOffset.UtcNow.AddSeconds(value.Lifetime);
                token.TokenType = this.TokenType;

                await scope.CompleteAsync();
            }
        }
Пример #8
0
        public override async Task StoreAsync(string key, AuthorizationCode code)
        {
            using (var scope = DataAccessScope.CreateReadCommitted())
            {
                var authCode = this.DataModel.Tokens.Create();

                authCode.Id        = Guid.NewGuid();
                authCode.Key       = key;
                authCode.SubjectId = code.SubjectId;
                authCode.ClientId  = code.ClientId;
                authCode.JsonCode  = ConvertToJson(code);
                authCode.Expiry    = DateTimeOffset.UtcNow.AddSeconds(code.Client.AuthorizationCodeLifetime);
                authCode.TokenType = this.TokenType;

                await scope.CompleteAsync();
            }
        }
Пример #9
0
        private async Task ClearTokens()
        {
            try
            {
                using (var scope = DataAccessScope.CreateReadCommitted())
                {
                    // TODO is this correct with DateTimeOffsets (can't use Expiry property as it is a local property, not persisted)
                    await dataModel.Tokens.DeleteAsync(x => x.ExpiryDateTime < DateTime.UtcNow);

                    await scope.CompleteAsync();
                }
            }
            catch (Exception ex)
            {
                Logger.ErrorException("Error clearing tokens", ex);
            }
        }
Пример #10
0
        private async Task Test_Insert_And_Nplus1_Query_Async_Private()
        {
            long schoolId;

            using (var scope = DataAccessScope.CreateReadCommitted())
            {
                var school = this.model.Schools.Create();

                var s1 = school.Students.Create();

                await scope.FlushAsync().ContinueOnAnyContext();

                schoolId = school.Id;

                await scope.CompleteAsync().ContinueOnAnyContext();
            }

            using (var scope = DataAccessScope.CreateReadCommitted())
            {
                var school = await this.model.Schools.SingleAsync(c => c.Id == schoolId);

                var x = await school.Students.ToListAsync().ContinueOnAnyContext();

                var newSchool = this.model.Schools.Create();

                var y = await school.Students.ToListAsync();

                Assert.AreEqual(1, y.Count);

                var s1 = await school.Students.FirstAsync();

                school.Name = "Hello";

                await scope.FlushAsync();

                var y2 = await school.Students.ToListAsync().ContinueOnAnyContext();

                var s2 = await school.Students.SingleAsync().ContinueOnAnyContext();

                var newSchool2 = this.model.Schools.Create();

                await scope.CompleteAsync().ContinueOnAnyContext();
            }
        }
        public async Task Test_DataAccessScope_CreateFlushComplete_Calls_DataModelHook_Async(bool flush, bool complete)
        {
            using (var scope = DataAccessScope.CreateReadCommitted())
            {
                var cat = this.model.Cats.Create();

                Console.WriteLine("===");

                if (flush)
                {
                    await scope.FlushAsync();
                }
                if (complete)
                {
                    await scope.CompleteAsync();
                }
            }

            Assert.AreEqual(complete ? 1 : 0, this.testDataModelHook.CommitCount);
            Assert.AreEqual(complete || !flush ? 0 : 1, this.testDataModelHook.RollbackCount);
        }
Пример #12
0
        public override async Task StoreAsync(string key, RefreshToken value)
        {
            using (var scope = DataAccessScope.CreateReadCommitted())
            {
                var token = await DataModel.Tokens.SingleOrDefaultAsync(x => x.Key == key && x.TokenType == this.TokenType);

                if (token == null)
                {
                    token = DataModel.Tokens.Create();

                    token.Id        = Guid.NewGuid();
                    token.Key       = key;
                    token.SubjectId = value.SubjectId;
                    token.ClientId  = value.ClientId;
                    token.JsonCode  = ConvertToJson(value);
                    token.TokenType = this.TokenType;
                }

                token.Expiry = value.CreationTime.AddSeconds(value.LifeTime);

                await scope.CompleteAsync();
            }
        }