Exemple #1
0
        internal void RemoveReadLock(UrlLock urlLock)
        {
            if (urlLock == null)
            {
                throw new ArgumentNullException(nameof(urlLock));
            }

            DbExpression e = new DbExpression(
                _ORM.GetColumnName <UrlLock>(nameof(UrlLock.Url)),
                DbOperators.Equals,
                urlLock.Url);

            e.PrependAnd(new DbExpression(
                             _ORM.GetColumnName <UrlLock>(nameof(UrlLock.LockType)),
                             DbOperators.Equals,
                             urlLock.LockType));

            List <UrlLock> locks = _ORM.SelectMany <UrlLock>(e);

            if (locks != null && locks.Count > 0)
            {
                foreach (UrlLock curr in locks)
                {
                    _ORM.Delete <UrlLock>(curr);
                }
            }
        }
Exemple #2
0
        private void InitializeTables()
        {
            List <string> tableNames = _Database.ListTables();

            tableNames = tableNames.ConvertAll(d => d.ToLower());

            if (!tableNames.Contains(USER_TABLE.ToLower()))
            {
                List <Column> userColumns = UserMaster.GetTableColumns();
                _Database.CreateTable(USER_TABLE, userColumns);
            }

            if (!tableNames.Contains(API_KEY_TABLE.ToLower()))
            {
                List <Column> apiKeyColumns = ApiKey.GetTableColumns();
                _Database.CreateTable(API_KEY_TABLE, apiKeyColumns);
            }

            if (!tableNames.Contains(PERMISSION_TABLE.ToLower()))
            {
                List <Column> permissionColumns = Permission.GetTableColumns();
                _Database.CreateTable(PERMISSION_TABLE, permissionColumns);
            }

            if (!tableNames.Contains(LOCKS_TABLE.ToLower()))
            {
                List <Column> locksColumns = UrlLock.GetTableColumns();
                _Database.CreateTable(LOCKS_TABLE, locksColumns);
            }

            if (!tableNames.Contains(CONTAINERS_TABLE.ToLower()))
            {
                List <Column> containerColumns = Container.GetTableColumns();
                _Database.CreateTable(CONTAINERS_TABLE, containerColumns);
            }

            if (!tableNames.Contains(OBJECTS_TABLE.ToLower()))
            {
                List <Column> objectColumns = ObjectMetadata.GetTableColumns();
                _Database.CreateTable(OBJECTS_TABLE, objectColumns);
            }

            if (!tableNames.Contains(CONTAINERS_KVP_TABLE.ToLower()))
            {
                List <Column> containerMetadataColumns = ContainerKeyValuePair.GetTableColumns();
                _Database.CreateTable(CONTAINERS_KVP_TABLE, containerMetadataColumns);
            }

            if (!tableNames.Contains(OBJECTS_KVP_TABLE.ToLower()))
            {
                List <Column> objectMetadataColumns = ObjectKeyValuePair.GetTableColumns();
                _Database.CreateTable(OBJECTS_KVP_TABLE, objectMetadataColumns);
            }

            if (!tableNames.Contains(AUDIT_LOG_TABLE.ToLower()))
            {
                List <Column> auditLogColumns = AuditLogEntry.GetTableColumns();
                _Database.CreateTable(AUDIT_LOG_TABLE, auditLogColumns);
            }
        }
Exemple #3
0
        internal bool WriteLockExists(string url)
        {
            if (String.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException(nameof(url));
            }

            DbExpression e = new DbExpression(
                _ORM.GetColumnName <UrlLock>(nameof(UrlLock.Url)),
                DbOperators.Equals,
                url);

            e.PrependAnd(new DbExpression(
                             _ORM.GetColumnName <UrlLock>(nameof(UrlLock.LockType)),
                             DbOperators.Equals,
                             LockType.Write));

            UrlLock urlLock = _ORM.SelectFirst <UrlLock>(e);

            if (urlLock != null)
            {
                return(true);
            }
            return(false);
        }
Exemple #4
0
        /*
         * Read operations cannot continue if the URL is being written, but can continue if being read elsewhere.
         *
         */

        internal string AddReadLock(RequestMetadata md)
        {
            if (md == null)
            {
                throw new ArgumentNullException(nameof(md));
            }

            if (WriteLockExists(md.Http.Request.Url.RawWithoutQuery))
            {
                return(null);
            }

            UrlLock  urlLock       = null;
            DateTime expirationUtc = DateTime.Now.ToUniversalTime().AddSeconds(_Settings.Storage.LockExpirationSeconds);

            if (md.Params.ExpirationUtc != null)
            {
                expirationUtc = md.Params.ExpirationUtc.Value.ToUniversalTime();
            }

            if (md.User != null && !String.IsNullOrEmpty(md.User.GUID))
            {
                urlLock = new UrlLock(LockType.Read, md.Http.Request.Url.RawWithoutQuery, md.User.GUID, expirationUtc);
            }
            else
            {
                urlLock = new UrlLock(LockType.Read, md.Http.Request.Url.RawWithoutQuery, null, expirationUtc);
            }

            urlLock = _ORM.Insert <UrlLock>(urlLock);
            return(urlLock.GUID);
        }
Exemple #5
0
        internal void RemoveWriteLock(UrlLock urlLock)
        {
            if (urlLock == null)
            {
                throw new ArgumentNullException(nameof(urlLock));
            }

            DbExpression e = new DbExpression(
                _ORM.GetColumnName <UrlLock>(nameof(UrlLock.Url)),
                DbOperators.Equals,
                urlLock.Url);

            e.PrependAnd(new DbExpression(
                             _ORM.GetColumnName <UrlLock>(nameof(UrlLock.LockType)),
                             DbOperators.Equals,
                             LockType.Write));

            if (!String.IsNullOrEmpty(urlLock.UserGUID))
            {
                e.PrependAnd(new DbExpression(
                                 _ORM.GetColumnName <UrlLock>(nameof(UrlLock.UserGUID)),
                                 DbOperators.Equals,
                                 urlLock.UserGUID));
            }

            List <UrlLock> urlLocks = _ORM.SelectMany <UrlLock>(e);

            if (urlLocks != null && urlLocks.Count > 0)
            {
                foreach (UrlLock curr in urlLocks)
                {
                    _ORM.Delete <UrlLock>(curr);
                }
            }
        }
Exemple #6
0
 internal bool AddReadLock(UrlLock urlLock)
 {
     if (urlLock == null)
     {
         throw new ArgumentNullException(nameof(urlLock));
     }
     if (WriteLockExists(urlLock.Url))
     {
         return(false);
     }
     _ORM.Insert <UrlLock>(urlLock);
     return(true);
 }
Exemple #7
0
        internal bool AddWriteLock(string url, string userGuid)
        {
            if (String.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException(nameof(url));
            }
            if (String.IsNullOrEmpty(userGuid))
            {
                throw new ArgumentNullException(nameof(userGuid));
            }
            UrlLock urlLock = new UrlLock(LockType.Write, url, userGuid);

            return(AddWriteLock(urlLock));
        }
        public bool AddReadLock(string url, string userGuid)
        {
            if (String.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException(nameof(url));
            }
            if (String.IsNullOrEmpty(userGuid))
            {
                throw new ArgumentNullException(nameof(userGuid));
            }

            UrlLock urlLock = new UrlLock(LockType.Read, url, userGuid);

            return(AddReadLock(urlLock));
        }
        public bool AddReadLock(UrlLock urlLock)
        {
            if (urlLock == null)
            {
                throw new ArgumentNullException(nameof(urlLock));
            }
            if (WriteLockExists(urlLock.Url))
            {
                return(false);
            }

            Dictionary <string, object> insertVals = urlLock.ToInsertDictionary();

            _Database.Insert(LOCKS_TABLE, insertVals);
            return(true);
        }
        public List <UrlLock> GetWriteLocks()
        {
            List <UrlLock> ret = new List <UrlLock>();
            Expression     e   = new Expression("Id", Operators.GreaterThan, 0);

            e.PrependAnd(new Expression("LockType", Operators.Equals, LockType.Write.ToString()));
            DataTable result = _Database.Select(LOCKS_TABLE, null, null, null, e, null);

            if (result != null && result.Rows.Count > 0)
            {
                foreach (DataRow row in result.Rows)
                {
                    ret.Add(UrlLock.FromDataRow(row));
                }
            }
            return(ret);
        }
Exemple #11
0
        internal bool WriteLockExists(string url)
        {
            if (String.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException(nameof(url));
            }
            Expression e = new Expression("url", Operators.Equals, url);

            e.PrependAnd(new Expression("locktype", Operators.Equals, LockType.Write.ToString()));
            UrlLock urlLock = _Database.SelectByFilter <UrlLock>(e, "ORDER BY id DESC");

            if (urlLock != null)
            {
                return(true);
            }
            return(false);
        }
        public void RemoveWriteLock(UrlLock urlLock)
        {
            if (urlLock == null)
            {
                throw new ArgumentNullException(nameof(urlLock));
            }

            Expression e = new Expression("Url", Operators.Equals, urlLock.Url);

            e.PrependAnd(new Expression("LockType", Operators.Equals, LockType.Write.ToString()));

            if (!String.IsNullOrEmpty(urlLock.UserGuid))
            {
                e.PrependAnd(new Expression("UserGuid", Operators.Equals, urlLock.UserGuid));
            }

            _Database.Delete(LOCKS_TABLE, e);
        }
Exemple #13
0
 private List <T> DataTableToListObject <T>(DataTable result)
 {
     if (result == null || result.Rows.Count < 1)
     {
         return(new List <T>());
     }
     if (typeof(T) == typeof(ApiKey))
     {
         return(ApiKey.FromDataTable(result) as List <T>);
     }
     else if (typeof(T) == typeof(UserMaster))
     {
         return(UserMaster.FromDataTable(result) as List <T>);
     }
     else if (typeof(T) == typeof(Permission))
     {
         return(Permission.FromDataTable(result) as List <T>);
     }
     else if (typeof(T) == typeof(UrlLock))
     {
         return(UrlLock.FromDataTable(result) as List <T>);
     }
     else if (typeof(T) == typeof(Container))
     {
         return(Container.FromDataTable(result) as List <T>);
     }
     else if (typeof(T) == typeof(ObjectMetadata))
     {
         return(ObjectMetadata.FromDataTable(result) as List <T>);
     }
     else if (typeof(T) == typeof(ContainerKeyValuePair))
     {
         return(ContainerKeyValuePair.FromDataTable(result) as List <T>);
     }
     else if (typeof(T) == typeof(ObjectKeyValuePair))
     {
         return(ObjectKeyValuePair.FromDataTable(result) as List <T>);
     }
     else if (typeof(T) == typeof(AuditLogEntry))
     {
         return(AuditLogEntry.FromDataTable(result) as List <T>);
     }
     throw new ArgumentException("Unknown object type: " + typeof(T).Name);
 }
Exemple #14
0
        internal void RemoveReadLock(UrlLock urlLock)
        {
            if (urlLock == null)
            {
                throw new ArgumentNullException(nameof(urlLock));
            }
            Expression e = new Expression("url", Operators.Equals, urlLock.Url);

            e.PrependAnd(new Expression("locktype", Operators.Equals, urlLock.LockType.ToString()));
            List <UrlLock> locks = _Database.SelectMany <UrlLock>(null, null, e, "ORDER BY id DESC");

            if (locks != null && locks.Count > 0)
            {
                foreach (UrlLock curr in locks)
                {
                    _Database.Delete <UrlLock>(curr);
                }
            }
        }
Exemple #15
0
        internal void RemoveReadLock(RequestMetadata md)
        {
            if (md == null)
            {
                throw new ArgumentNullException(nameof(md));
            }

            UrlLock urlLock = null;

            if (md.User != null && !String.IsNullOrEmpty(md.User.GUID))
            {
                urlLock = new UrlLock(LockType.Read, md.Http.Request.RawUrlWithoutQuery, md.User.GUID);
            }
            else
            {
                urlLock = new UrlLock(LockType.Read, md.Http.Request.RawUrlWithoutQuery, null);
            }

            RemoveReadLock(urlLock);
        }
Exemple #16
0
        /*
         * Write operations cannot continue if the URL is being read or written elsewhere.
         *
         */

        internal bool AddWriteLock(RequestMetadata md)
        {
            if (md == null)
            {
                throw new ArgumentNullException(nameof(md));
            }

            UrlLock urlLock = null;

            if (md.User != null && !String.IsNullOrEmpty(md.User.GUID))
            {
                urlLock = new UrlLock(LockType.Write, md.Http.Request.RawUrlWithoutQuery, md.User.GUID);
            }
            else
            {
                urlLock = new UrlLock(LockType.Write, md.Http.Request.RawUrlWithoutQuery, null);
            }

            return(AddWriteLock(urlLock));
        }
Exemple #17
0
        internal void RemoveWriteLock(UrlLock urlLock)
        {
            if (urlLock == null)
            {
                throw new ArgumentNullException(nameof(urlLock));
            }
            Expression e = new Expression("url", Operators.Equals, urlLock.Url);

            e.PrependAnd(new Expression("locktype", Operators.Equals, LockType.Write.ToString()));
            if (!String.IsNullOrEmpty(urlLock.UserGUID))
            {
                e.PrependAnd(new Expression("userguid", Operators.Equals, urlLock.UserGUID));
            }
            List <UrlLock> urlLocks = _Database.SelectMany <UrlLock>(null, null, e, "ORDER BY id DESC");

            if (urlLocks != null && urlLocks.Count > 0)
            {
                foreach (UrlLock curr in urlLocks)
                {
                    _Database.Delete <UrlLock>(curr);
                }
            }
        }
        private void InitializeTables()
        {
            List <string> tableNames = _Database.ListTables();

            tableNames = tableNames.ConvertAll(d => d.ToLower());

            if (!tableNames.Contains(USER_TABLE.ToLower()))
            {
                List <Column> userColumns = UserMaster.GetTableColumns();
                _Database.CreateTable(USER_TABLE, userColumns);
            }

            if (!tableNames.Contains(API_KEY_TABLE.ToLower()))
            {
                List <Column> apiKeyColumns = ApiKey.GetTableColumns();
                _Database.CreateTable(API_KEY_TABLE, apiKeyColumns);
            }

            if (!tableNames.Contains(PERMISSION_TABLE.ToLower()))
            {
                List <Column> permissionColumns = Permission.GetTableColumns();
                _Database.CreateTable(PERMISSION_TABLE, permissionColumns);
            }

            if (!tableNames.Contains(LOCKS_TABLE.ToLower()))
            {
                List <Column> locksColumns = UrlLock.GetTableColumns();
                _Database.CreateTable(LOCKS_TABLE, locksColumns);
            }

            if (!tableNames.Contains(CONTAINERS_TABLE.ToLower()))
            {
                List <Column> containerColumns = Container.GetTableColumns();
                _Database.CreateTable(CONTAINERS_TABLE, containerColumns);
            }
        }