Beispiel #1
0
 /// <summary>
 /// Removes the session.
 /// </summary>
 /// <param name="context">The database context.</param>
 /// <param name="sessionToken">The session token.</param>
 public void RemoveSession(OpenAccessContext context, string sessionToken)
 {
     if (this.sessionsByToken.ContainsKey(sessionToken))
     {
         this.sessionsByToken.Remove(sessionToken);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Updates the session.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="sessionToken">The session token.</param>
 public void UpdateSession(OpenAccessContext context, string sessionToken)
 {
     if (this.sessionsByToken.ContainsKey(sessionToken))
     {
         this.sessionsByToken[sessionToken].LastAccessDttm = DateTime.UtcNow;
     }
 }
Beispiel #3
0
 /// <summary>
 /// Gets the open access metadata container.
 /// </summary>
 /// <returns></returns>
 private MetadataContainer GetOpenAccessMetadata()
 {
     using (OpenAccessContext context = this.NewContext())
     {
         return(context.Metadata);
     }
 }
Beispiel #4
0
 public ApplicationContext(string connectionString)
 {
     _connectionString = connectionString;
     _context          = new OpenAccessContext(_connectionString,
                                               getPreinstanceName(), GetBackendConfiguration(),
                                               new MetaDataSource().GetModel());
 }
Beispiel #5
0
 /// <summary>
 /// Removes the session.
 /// </summary>
 /// <param name="context">The database context.</param>
 /// <param name="sessionToken">The session token.</param>
 public void RemoveSession(OpenAccessContext context, string sessionToken)
 {
     if (this.sessionsByToken.ContainsKey(sessionToken))
     {
         this.sessionsByToken.Remove(sessionToken);
     }
 }
Beispiel #6
0
 public SyncBase(OpenAccessContext context)
 {
     this.context  = context;
     Repository    = new CodeTimeRepository <TEntity>(context);
     MDRRepository = new MissingDataRecordRepository(context);
     Code          = typeof(TEntity).Name;
 }
Beispiel #7
0
 public SyncBase(OpenAccessContext context)
 {
     Repository    = new Repository <TEntity>(context);
     MDRRepository = new MissingDataRecordRepository(context);
     EntityName    = typeof(TEntity).Name;
     Logger        = LogManager.GetLogger <TEntity>();
 }
Beispiel #8
0
        public void OpenAccess_ConcurrentlyUpdateTheSameRecord_OptimisticConcurrencyExceptionShouldBeThrown()
        {
            //arrange
            var newRecordId = CreateNewOpenAccessRecord();

            using (var context1 = new OpenAccessContext())
            {
                var product1 = context1.GetAll <OpenAccessProduct>().First(p => p.Id == newRecordId);
                product1.Price = 1m;
                using (var context2 = new OpenAccessContext())
                {
                    var product2 = context2.GetAll <OpenAccessProduct>().First(p => p.Id == newRecordId);
                    product2.Price = 2m;

                    //act
                    context2.SaveChanges();
                }
                try
                {
                    context1.SaveChanges();
                }
                //assert
                catch (OptimisticVerificationException exception)
                {
                    System.Diagnostics.Trace.WriteLine(exception.ToString());
                    return;
                }
            }

            //We reached end of the test...it means that we assumed incorrect behaviour
            Assert.Fail();
        }
 // GET: MultiFileUpload
 public MultiFileUploadController(OpenAccessContext context, FileService fileService, EntityService entityService, IFileMailer fileMailer)
     : base(context)
 {
     _fileService = fileService;
     _entityService = entityService;
     _fileMailer = fileMailer;
 }
Beispiel #10
0
 /// <summary>
 /// Gets the user information from the session token.
 /// </summary>
 /// <param name="sessionToken">The session token.</param>
 /// <returns></returns>
 public IUserDto GetUserInfo(string sessionToken)
 {
     using (OpenAccessContext context = this.NewContext())
     {
         return(this.GetUserInfo(context, sessionToken));
     }
 }
 public MissingDataRecordRepository(OpenAccessContext context) : base(context)
 {
     if (!int.TryParse(ConfigurationManager.AppSettings["MaxMissTimes"], out maxMissTimes))
     {
         maxMissTimes = 30;
     }
 }
Beispiel #12
0
        /// <summary>
        /// Adds the session for user.
        /// </summary>
        /// <param name="context">The database context.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="sessionToken">The session token.</param>
        public void AddSessionForUser(OpenAccessContext context, long userId, string sessionToken)
        {
            this.RemoveSessionsOfUser(context, userId);
            object session = this.NewSession(userId, sessionToken);

            context.Add(session);
        }
Beispiel #13
0
 /// <summary>
 /// Logouts a session from the system.
 /// </summary>
 /// <param name="sessionToken">The session token.</param>
 /// <exception cref="System.NotImplementedException"></exception>
 public void Logout(string sessionToken)
 {
     using (OpenAccessContext context = this.NewContext())
     {
         this.SessionManager.RemoveSession(context, sessionToken);
         context.SaveChanges();
     }
 }
 /// <summary>
 /// Removes the session.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="sessionToken">The session token.</param>
 public void RemoveSession(OpenAccessContext context, string sessionToken)
 {
     object session = this.GetSessionByToken(context, sessionToken);
     if (session != null)
     {
         context.Delete(session);
     }
 }
Beispiel #15
0
 /// <summary>
 /// Gets the session data.
 /// </summary>
 /// <param name="context">The database context.</param>
 /// <param name="sessionToken">The session token.</param>
 /// <returns></returns>
 public ISessionDto GetSessionData(OpenAccessContext context, string sessionToken)
 {
     if (this.sessionsByToken.ContainsKey(sessionToken))
     {
         return this.sessionsByToken[sessionToken];
     }
     return null;
 }
Beispiel #16
0
 /// <summary>
 /// Gets the session data.
 /// </summary>
 /// <param name="context">The database context.</param>
 /// <param name="sessionToken">The session token.</param>
 /// <returns></returns>
 public ISessionDto GetSessionData(OpenAccessContext context, string sessionToken)
 {
     if (this.sessionsByToken.ContainsKey(sessionToken))
     {
         return(this.sessionsByToken[sessionToken]);
     }
     return(null);
 }
Beispiel #17
0
        /// <summary>
        /// Updates the session.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sessionToken">The session token.</param>
        public void UpdateSession(OpenAccessContext context, string sessionToken)
        {
            object session = this.GetSessionByToken(context, sessionToken);

            if (session != null)
            {
                this.UpdateSessionAccess(session);
            }
        }
Beispiel #18
0
        /// <summary>
        /// Removes the session.
        /// </summary>
        /// <param name="context">The database context.</param>
        /// <param name="sessionToken">The session token.</param>
        public void RemoveSession(OpenAccessContext context, string sessionToken)
        {
            object session = this.GetSessionByToken(context, sessionToken);

            if (session != null)
            {
                context.Delete(session);
            }
        }
Beispiel #19
0
        public DARepository(OpenAccessContext dbContext)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext), "OpenAccess database context cannot be null!");
            }

            this.dbContext = dbContext;
        }
Beispiel #20
0
        public DataAccessGenericRepository(OpenAccessContext context)
        {
            if (context == null)
            {
                throw new ArgumentException("An instance of DbContext is required to use this repository.", nameof(context));
            }

            this.Context = context;
        }
Beispiel #21
0
        /// <summary>
        /// Removes all the sessions of an user.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="userId">The user identifier.</param>
        protected void RemoveSessionsOfUser(OpenAccessContext context, long userId)
        {
            IList sessions = this.GetAllSessionsOfUser(context, userId);

            if (sessions != null)
            {
                foreach (object session in sessions)
                {
                    context.Delete(session);
                }
            }
        }
Beispiel #22
0
        public static void AssemblyInitialize(TestContext context)
        {
            DropDatabaseIfExists();
            CreateDatabase();

            using (var dataContext = new OpenAccessContext())
            {
                var schemaHandler = dataContext.GetSchemaHandler();
                schemaHandler.CreateDatabase();
                schemaHandler.ForceExecuteDDLScript(schemaHandler.CreateDDLScript());
            }
        }
Beispiel #23
0
 /// <summary>
 /// Gets the user context from a session token.
 /// </summary>
 /// <param name="sessionToken">The session token.</param>
 /// <returns></returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public IUserContext GetUserContext(string sessionToken)
 {
     using (OpenAccessContext context = this.NewContext())
     {
         IUserDto user = this.GetUserInfo(context, sessionToken);
         if (user == null)
         {
             throw new ArgumentException("Invalid session Token");
         }
         this.SessionManager.UpdateSession(context, sessionToken);
         return(new UserContext(user));
     }
 }
Beispiel #24
0
        private Guid CreateNewOpenAccessRecord()
        {
            using (var context = new OpenAccessContext())
            {
                var product = new OpenAccessProduct()
                {
                    Id = Guid.NewGuid()
                };

                context.Add(product);
                context.SaveChanges();
                return(product.Id);
            }
        }
Beispiel #25
0
 /// <summary>
 /// Adds the session for user.
 /// </summary>
 /// <param name="context">The database context.</param>
 /// <param name="userId">The user identifier.</param>
 /// <param name="sessionToken">The session token.</param>
 public void AddSessionForUser(OpenAccessContext context, long userId, string sessionToken)
 {
     if (this.sessionsByUser.ContainsKey(userId))
     {
         MemorySessionDto session = this.sessionsByUser[userId];
         this.sessionsByUser.Remove(userId);
         this.sessionsByToken.Remove(session.SessionToken);
     }
     MemorySessionDto newsession = new MemorySessionDto();
     newsession.SessionToken = sessionToken;
     newsession.UserId = userId;
     newsession.CreationDttm = DateTime.UtcNow;
     newsession.LastAccessDttm = DateTime.UtcNow;
     this.sessionsByToken.Add(sessionToken, newsession);
     this.sessionsByUser.Add(userId, newsession);
 }
Beispiel #26
0
 /// <summary>
 /// Logins a user into the system.
 /// </summary>
 /// <param name="login">The login.</param>
 /// <param name="password">The password.</param>
 /// <returns></returns>
 /// <exception cref="System.ArgumentException">Login invalid</exception>
 public IUserDto Login(string login, string password)
 {
     using (OpenAccessContext context = this.NewContext())
     {
         object user = this.GetUserByLoginPass(context, login, password);
         if (user == null)
         {
             throw new ArgumentException("Login invalid");
         }
         IUserDto result = (IUserDto)ObjectProxyFactory.MapTo(this.UserDtoType, user);
         result.Password     = null;
         result.SessionToken = this.SessionManager.NewSessionToken();
         this.SessionManager.AddSessionForUser(context, result.UserId.Value, result.SessionToken);
         context.SaveChanges();
         return(result);
     }
 }
Beispiel #27
0
        /// <summary>
        /// Adds the session for user.
        /// </summary>
        /// <param name="context">The database context.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="sessionToken">The session token.</param>
        public void AddSessionForUser(OpenAccessContext context, long userId, string sessionToken)
        {
            if (this.sessionsByUser.ContainsKey(userId))
            {
                MemorySessionDto session = this.sessionsByUser[userId];
                this.sessionsByUser.Remove(userId);
                this.sessionsByToken.Remove(session.SessionToken);
            }
            MemorySessionDto newsession = new MemorySessionDto();

            newsession.SessionToken   = sessionToken;
            newsession.UserId         = userId;
            newsession.CreationDttm   = DateTime.UtcNow;
            newsession.LastAccessDttm = DateTime.UtcNow;
            this.sessionsByToken.Add(sessionToken, newsession);
            this.sessionsByUser.Add(userId, newsession);
        }
        public static void CreateOrUpdateDatabase(this OpenAccessContext context)
        {
            var schemaHandler = context.GetSchemaHandler();

            string script = null;

            if (schemaHandler.DatabaseExists())
            {
                script = schemaHandler.CreateUpdateDDLScript(null);
            }
            else
            {
                schemaHandler.CreateDatabase();
                script = schemaHandler.CreateDDLScript();
            }

            if (!string.IsNullOrEmpty(script))
            {
                schemaHandler.ExecuteDDLScript(script);
            }
        }
Beispiel #29
0
        /// <summary>
        /// Gets the user information.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sessionToken">The session token.</param>
        /// <returns></returns>
        protected virtual IUserDto GetUserInfo(OpenAccessContext context, string sessionToken)
        {
            ISessionDto sessionData = this.SessionManager.GetSessionData(context, sessionToken);

            if (sessionData == null)
            {
                return(null);
            }
            object user = this.GetUserById(context, sessionData.UserId);

            if (user == null)
            {
                this.SessionManager.RemoveSession(context, sessionToken);
                context.SaveChanges();
                return(null);
            }
            IUserDto result = (IUserDto)ObjectProxyFactory.MapTo(this.UserDtoType, user);

            result.Password     = null;
            result.SessionToken = sessionData.SessionToken;
            return(result);
        }
Beispiel #30
0
        public void UpdateSchema()
        {
            OpenAccessContextBase.ReplaceMetadata(_context, new MetaDataSource().GetModel(), null);
            _context = new OpenAccessContext(_connectionString,
                                             getPreinstanceName(), GetBackendConfiguration(),
                                             new MetaDataSource().GetModel());
            var    handler = this._context.GetSchemaHandler();
            string script  = null;

            try
            {
                script = handler.CreateUpdateDDLScript(null);
            }
            catch
            {
                bool throwException = false;

                try
                {
                    handler.CreateDatabase();

                    script = handler.CreateDDLScript();
                }
                catch
                {
                    throwException = true;
                }

                if (throwException)
                {
                    throw;
                }
            }
            if (string.IsNullOrEmpty(script) == false)
            {
                handler.ForceExecuteDDLScript(script);
            }
        }
Beispiel #31
0
 public AdminController(OpenAccessContext context, UserProfilePersistenceService userPersistenceService, RegistrantPersistenceService registrantPersistenceService) : base(context)
 {
     _userPersistenceService       = userPersistenceService;
     _registrantPersistenceService = registrantPersistenceService;
 }
 /// <summary>
 /// Gets a session by its session token.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="sessionToken">The session token.</param>
 /// <returns></returns>
 protected abstract object GetSessionByToken(OpenAccessContext context, string sessionToken);
 /// <summary>
 /// Gets all sessions of user.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="userId">The user identifier.</param>
 /// <returns></returns>
 protected abstract IList GetAllSessionsOfUser(OpenAccessContext context, long userId);
 /// <summary>
 /// Adds a session for a gien user
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="userId">The user identifier.</param>
 /// <param name="sessionToken">The session token.</param>
 public void AddSessionForUser(OpenAccessContext context, long userId, string sessionToken)
 {
     this.RemoveSessionsOfUser(context, userId);
     object session = NewSession(userId, sessionToken);
     context.Add(session);
 }
Beispiel #35
0
 /// <summary>
 /// Gets all sessions of user.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="userId">The user identifier.</param>
 /// <returns></returns>
 protected override IList GetAllSessionsOfUser(OpenAccessContext context, long userId)
 {
     return context.GetAll<WebSession>().Where(p => p.UserId == userId).ToList();
 }
Beispiel #36
0
 public AQIMRCDDSync(OpenAccessContext context) : base(context)
 {
     Interval = TimeSpan.FromDays(1);
 }
 public DataAccessUnitOfWork(OpenAccessContext dbContext)
 {
     this.dbContext = dbContext;
 }
Beispiel #38
0
 public AQCIMSyncBase(OpenAccessContext context) : base(context)
 {
     Interval           = TimeSpan.FromDays(1);
     AQIMRCDDRepository = new Repository <AQIMRCDD>(context);
 }
 public AQIMSyncBase(OpenAccessContext context) : base(context)
 {
 }
Beispiel #40
0
 public BaseController(OpenAccessContext context)
 {
     _context = context;
 }
Beispiel #41
0
 /// <summary>
 /// Gets the session data.
 /// </summary>
 /// <param name="context">The database context.</param>
 /// <param name="sessionToken">The session token.</param>
 /// <returns></returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public ISessionDto GetSessionData(OpenAccessContext context, string sessionToken)
 {
     object session = this.GetSessionByToken(context, sessionToken);
     return session == null ? null : (ISessionDto)ObjectProxyFactory.MapTo(this.sessionDtoType, session);
 }
Beispiel #42
0
 /// <summary>
 /// Updates the session.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="sessionToken">The session token.</param>
 public void UpdateSession(OpenAccessContext context, string sessionToken)
 {
     object session = this.GetSessionByToken(context, sessionToken);
     if (session != null)
     {
         this.UpdateSessionAccess(session);
     }
 }
Beispiel #43
0
 /// <summary>
 /// Gets the user by identifier.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="userId">The user identifier.</param>
 /// <returns></returns>
 protected override object GetUserById(OpenAccessContext context, long userId)
 {
     return context.GetAll<User>().Where(p => p.UserId == userId).FirstOrDefault();
 }
Beispiel #44
0
 /// <summary>
 /// Gets a user by login and password.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="login">The login.</param>
 /// <param name="password">The password.</param>
 /// <returns></returns>
 protected override object GetUserByLoginPass(OpenAccessContext context, string login, string password)
 {
     return context.GetAll<User>().Where(p => p.Email == login && p.Password == password).FirstOrDefault();
 }
 /// <summary>
 /// Removes all the sessions of an user.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="userId">The user identifier.</param>
 protected void RemoveSessionsOfUser(OpenAccessContext context, long userId)
 {
     IList sessions = this.GetAllSessionsOfUser(context, userId);
     if (sessions != null)
     {
         foreach (object item in sessions)
         {
             context.Delete(item);
         }
     }
 }
Beispiel #46
0
 /// <summary>
 /// Gets a session by its session token.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="sessionToken">The session token.</param>
 /// <returns></returns>
 protected override object GetSessionByToken(OpenAccessContext context, string sessionToken)
 {
     return context.GetAll<WebSession>().Where(p => p.SessionToken == sessionToken).FirstOrDefault();
 }
Beispiel #47
0
 /// <summary>
 /// Updates the session.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="sessionToken">The session token.</param>
 public void UpdateSession(OpenAccessContext context, string sessionToken)
 {
     if (this.sessionsByToken.ContainsKey(sessionToken))
     {
         this.sessionsByToken[sessionToken].LastAccessDttm = DateTime.UtcNow;
     }
 }