Exemplo n.º 1
0
        private User GetUser(string email, string passwordMd5)
        {
            if (String.IsNullOrEmpty(email))
            {
                throw new ArgumentNullException(nameof(email));
            }
            if (String.IsNullOrEmpty(passwordMd5))
            {
                throw new ArgumentNullException(nameof(passwordMd5));
            }

            DbExpression e = new DbExpression(
                _ORM.GetColumnName <User>(nameof(User.Id)),
                DbOperators.GreaterThan,
                0);

            e.PrependAnd(_ORM.GetColumnName <User>(nameof(User.Email)), DbOperators.Equals, email);
            e.PrependAnd(_ORM.GetColumnName <User>(nameof(User.PasswordMd5)), DbOperators.Equals, passwordMd5);
            User user = _ORM.SelectFirst <User>(e);

            if (user != null && user != default(User))
            {
                return(user);
            }
            return(null);
        }
Exemplo n.º 2
0
        internal void RemoveWriteLock(string url, string userGuid)
        {
            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));

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

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

            if (urlLocks != null && urlLocks.Count > 0)
            {
                foreach (UrlLock curr in urlLocks)
                {
                    _ORM.Delete <UrlLock>(curr);
                }
            }
        }
Exemplo n.º 3
0
        internal Obj GetObjectMetadata(string key, long version)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            DbExpression eKey = new DbExpression(
                _ORM.GetColumnName <Obj>(nameof(Obj.Key)),
                DbOperators.Equals,
                key);

            DbExpression eVersion = new DbExpression(
                _ORM.GetColumnName <Obj>(nameof(Obj.Version)),
                DbOperators.Equals,
                version);

            DbExpression eBucket = new DbExpression(
                _ORM.GetColumnName <Obj>(nameof(Obj.BucketGUID)),
                DbOperators.Equals,
                _Bucket.GUID);

            eKey.PrependAnd(eVersion);
            eKey.PrependAnd(eBucket);

            return(_ORM.SelectFirst <Obj>(eKey));
        }
Exemplo n.º 4
0
        private Entry GetPendingEntryInternal(string accountGuid, string entryGuid)
        {
            DbExpression e2 = new DbExpression(_ORM.GetColumnName <Entry>(nameof(Entry.AccountGUID)), DbOperators.Equals, accountGuid);

            e2.PrependAnd(_ORM.GetColumnName <Entry>(nameof(Entry.IsCommitted)), DbOperators.Equals, false);
            e2.PrependAnd(_ORM.GetColumnName <Entry>(nameof(Entry.CommittedUtc)), DbOperators.IsNull, null);
            e2.PrependAnd(_ORM.GetColumnName <Entry>(nameof(Entry.GUID)), DbOperators.Equals, entryGuid);
            return(_ORM.SelectFirst <Entry>(e2));
        }
Exemplo n.º 5
0
        private List <Entry> GetPendingEntriesInternal(string accountGuid)
        {
            DbExpression e = new DbExpression(_ORM.GetColumnName <Entry>(nameof(Entry.AccountGUID)), DbOperators.Equals, accountGuid);

            e.PrependAnd(_ORM.GetColumnName <Entry>(nameof(Entry.IsCommitted)), DbOperators.Equals, false);
            e.PrependAnd(_ORM.GetColumnName <Entry>(nameof(Entry.CommittedUtc)), DbOperators.IsNull, null);

            DbResultOrder[] ro = new DbResultOrder[1];
            ro[0] = new DbResultOrder(_ORM.GetColumnName <Entry>(nameof(Entry.CreatedUtc)), DbOrderDirection.Descending);
            return(_ORM.SelectMany <Entry>(null, null, e, ro));
        }
Exemplo n.º 6
0
        private Permission GetPermission(string apiKey, PermissionType permType, out User user, out ApiKey key)
        {
            if (String.IsNullOrEmpty(apiKey))
            {
                throw new ArgumentNullException(nameof(apiKey));
            }
            key = GetApiKey(apiKey, out user);
            if (key == null || user == null)
            {
                return(null);
            }

            DbExpression e = new DbExpression(
                _ORM.GetColumnName <Permission>(nameof(Permission.Id)),
                DbOperators.GreaterThan,
                0);

            switch (permType)
            {
            case PermissionType.Search:
                e.PrependAnd(new DbExpression(_ORM.GetColumnName <Permission>(nameof(Permission.AllowSearch)), DbOperators.Equals, 1));
                break;

            case PermissionType.CreateDocument:
                e.PrependAnd(new DbExpression(_ORM.GetColumnName <Permission>(nameof(Permission.AllowCreateDocument)), DbOperators.Equals, 1));
                break;

            case PermissionType.DeleteDocument:
                e.PrependAnd(new DbExpression(_ORM.GetColumnName <Permission>(nameof(Permission.AllowDeleteDocument)), DbOperators.Equals, 1));
                break;

            case PermissionType.CreateIndex:
                e.PrependAnd(new DbExpression(_ORM.GetColumnName <Permission>(nameof(Permission.AllowCreateIndex)), DbOperators.Equals, 1));
                break;

            case PermissionType.DeleteIndex:
                e.PrependAnd(new DbExpression(_ORM.GetColumnName <Permission>(nameof(Permission.AllowDeleteIndex)), DbOperators.Equals, 1));
                break;

            default:
                throw new ArgumentException("Unknown permission type: " + permType.ToString());
            }

            Permission p = _ORM.SelectFirst <Permission>(e);

            if (p != null && p != default(Permission))
            {
                return(p);
            }
            return(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get document GUIDs that contain supplied terms.
        /// </summary>
        /// <param name="terms">List of terms.</param>
        /// <param name="indexStart">Index of results from which to begin returning records.</param>
        /// <param name="maxResults">Maximum number of records to return.</param>
        /// <param name="filter">Database filters.</param>
        /// <returns>List of document GUIDs.</returns>
        public List <string> GetDocumentGuidsByTerms(List <string> terms, int?indexStart, int?maxResults, DbExpression filter)
        {
            if (terms == null || terms.Count < 1)
            {
                throw new ArgumentNullException(nameof(terms));
            }

            List <string> ret = new List <string>();
            DbExpression  e   = new DbExpression(_ORM.GetColumnName <IndexEntry>(nameof(IndexEntry.Term)), DbOperators.In, terms);

            if (filter != null)
            {
                e.PrependAnd(filter);
            }

            List <IndexEntry> entries = _ORM.SelectMany <IndexEntry>(indexStart, maxResults, e);

            if (entries != null && entries.Count > 0)
            {
                ret = entries.Select(entry => entry.DocumentGuid).ToList();
                ret = ret.Distinct().ToList();
            }

            Log("returning " + ret.Count + " document GUIDs for terms query");
            return(ret);
        }
Exemplo n.º 8
0
        private void MonitorForExpiredLocks()
        {
            while (!_TokenSource.IsCancellationRequested)
            {
                DbExpression e = new DbExpression(
                    _ORM.GetColumnName <UrlLock>(nameof(UrlLock.ExpirationUtc)),
                    DbOperators.LessThan,
                    DateTime.Now.ToUniversalTime());

                e.PrependAnd(_ORM.GetColumnName <UrlLock>(nameof(UrlLock.ExpirationUtc)),
                             DbOperators.IsNotNull,
                             null);

                List <UrlLock> expired = _ORM.SelectMany <UrlLock>(e);
                if (expired != null && expired.Count > 0)
                {
                    foreach (UrlLock curr in expired)
                    {
                        _Logging.Info(_Header + "lock " + curr.GUID + " expired at " + curr.ExpirationUtc.ToString("s") + ", removing");
                        _ORM.Delete <UrlLock>(curr);
                    }
                }

                Task.Delay(10000).Wait();
            }
        }
Exemplo n.º 9
0
        internal bool Exists(string userGuid, string name)
        {
            if (String.IsNullOrEmpty(userGuid))
            {
                throw new ArgumentNullException(nameof(userGuid));
            }
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            DbExpression e = new DbExpression(
                _ORM.GetColumnName <Container>(nameof(Container.UserGUID)),
                DbOperators.Equals,
                userGuid);

            e.PrependAnd(new DbExpression(
                             _ORM.GetColumnName <Container>(nameof(Container.Name)),
                             DbOperators.Equals,
                             name));

            Container container = _ORM.SelectFirst <Container>(e);

            if (container != null)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 10
0
        internal List <ObjectAcl> GetObjectAcl(string key, long version)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            Obj obj = GetObjectMetadata(key, version);

            if (obj == null)
            {
                _Logging.Debug("GetAcl unable to find key " + _Bucket.Name + "/" + key + " version " + version);
                return(null);
            }

            DbExpression expr = new DbExpression(
                _ORM.GetColumnName <ObjectAcl>(nameof(ObjectAcl.BucketGUID)),
                DbOperators.Equals,
                _Bucket.GUID);

            DbExpression eObj = new DbExpression(
                _ORM.GetColumnName <ObjectAcl>(nameof(ObjectAcl.ObjectGUID)),
                DbOperators.Equals,
                obj.GUID);

            expr.PrependAnd(eObj);

            return(_ORM.SelectMany <ObjectAcl>(expr));
        }
Exemplo n.º 11
0
        internal bool BucketUserAclExists(string userGuid)
        {
            if (String.IsNullOrEmpty(userGuid))
            {
                throw new ArgumentNullException(nameof(userGuid));
            }

            DbExpression expr = new DbExpression(
                _ORM.GetColumnName <ObjectAcl>(nameof(ObjectAcl.BucketGUID)),
                DbOperators.Equals,
                _Bucket.GUID);

            DbExpression eUser = new DbExpression(
                _ORM.GetColumnName <ObjectAcl>(nameof(ObjectAcl.UserGUID)),
                DbOperators.Equals,
                userGuid);

            expr.PrependAnd(eUser);

            List <BucketAcl> acls = _ORM.SelectMany <BucketAcl>(expr);

            if (acls != null && acls.Count > 0)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 12
0
        internal void DeleteObjectTags(string key, long version)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            Obj obj = GetObjectMetadata(key, version);

            if (obj == null)
            {
                _Logging.Debug("Exists unable to find key " + _Bucket.Name + "/" + key + " version " + version);
                return;
            }

            DbExpression eBucket = new DbExpression(
                _ORM.GetColumnName <ObjectTag>(nameof(ObjectTag.BucketGUID)),
                DbOperators.Equals,
                _Bucket.GUID);

            DbExpression eObj = new DbExpression(
                _ORM.GetColumnName <ObjectTag>(nameof(ObjectTag.ObjectGUID)),
                DbOperators.Equals,
                obj.GUID);

            eBucket.PrependAnd(eObj);

            _ORM.DeleteMany <ObjectTag>(eBucket);
        }
Exemplo n.º 13
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);
                }
            }
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        internal void DeleteObjectAcl(string key)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            Obj obj = GetObjectMetadata(key);

            if (obj == null)
            {
                _Logging.Debug("DeleteAcl unable to find key " + _Bucket.Name + "/" + key);
                return;
            }

            DbExpression expr = new DbExpression(
                _ORM.GetColumnName <ObjectAcl>(nameof(ObjectAcl.BucketGUID)),
                DbOperators.Equals,
                _Bucket.GUID);

            DbExpression eObjGuid = new DbExpression(
                _ORM.GetColumnName <ObjectAcl>(nameof(ObjectAcl.ObjectGUID)),
                DbOperators.Equals,
                obj.GUID);

            expr.PrependAnd(eObjGuid);
            _ORM.DeleteMany <ObjectAcl>(expr);
        }
Exemplo n.º 16
0
        private ApiKey GetApiKey(string apiKey, out User user)
        {
            if (String.IsNullOrEmpty(apiKey))
            {
                throw new ArgumentNullException(nameof(apiKey));
            }
            user = null;

            DbExpression e = new DbExpression(
                _ORM.GetColumnName <ApiKey>(nameof(ApiKey.GUID)),
                DbOperators.Equals,
                apiKey);

            e.PrependAnd(_ORM.GetColumnName <ApiKey>(nameof(ApiKey.Active)), DbOperators.Equals, true);
            ApiKey key = _ORM.SelectFirst <ApiKey>(e);

            if (key == null || key == default(ApiKey))
            {
                return(null);
            }

            e = new DbExpression(
                _ORM.GetColumnName <User>(nameof(User.GUID)),
                DbOperators.Equals,
                key.UserGUID);

            user = _ORM.SelectFirst <User>(e);
            if (user == null || user == default(User))
            {
                return(null);
            }
            return(key);
        }
Exemplo n.º 17
0
        private List <Entry> GetEntriesByGuids(string accountGuid, List <string> guids)
        {
            DbExpression e3 = new DbExpression(_ORM.GetColumnName <Entry>(nameof(Entry.AccountGUID)), DbOperators.Equals, accountGuid);

            e3.PrependAnd(_ORM.GetColumnName <Entry>(nameof(Entry.GUID)), DbOperators.In, guids);
            return(_ORM.SelectMany <Entry>(e3));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Retrieve the list of role names to which the user is assigned.
        /// </summary>
        /// <param name="username">The name of the user.</param>
        /// <returns>List of role names.</returns>
        public List <string> GetUserRoles(string username)
        {
            if (String.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException(nameof(username));
            }
            DbExpression e = new DbExpression(_ORM.GetColumnName <UserRole>(nameof(UserRole.Id)), DbOperators.GreaterThan, 0);

            e.PrependAnd(_ORM.GetColumnName <UserRole>(nameof(UserRole.Username)), DbOperators.Equals, username);
            List <UserRole> u   = _ORM.SelectMany <UserRole>(e);
            List <string>   ret = new List <string>();

            if (u.Count > 0)
            {
                foreach (UserRole r in u)
                {
                    ret.Add(r.Rolename);
                }
                if (ret.Count > 0)
                {
                    ret = ret.Distinct().ToList();
                }
            }
            return(ret);
        }
Exemplo n.º 19
0
        internal bool ObjectUserAclExists(string userGuid, string key, long version)
        {
            if (String.IsNullOrEmpty(userGuid))
            {
                throw new ArgumentNullException(nameof(userGuid));
            }
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            Obj obj = GetObjectMetadata(key, version);

            if (obj == null)
            {
                _Logging.Debug("Exists unable to find key " + _Bucket.Name + "/" + key + " version " + version);
                return(false);
            }

            DbExpression expr = new DbExpression(
                _ORM.GetColumnName <ObjectAcl>(nameof(ObjectAcl.BucketGUID)),
                DbOperators.Equals,
                _Bucket.GUID);

            DbExpression eUser = new DbExpression(
                _ORM.GetColumnName <ObjectAcl>(nameof(ObjectAcl.UserGUID)),
                DbOperators.Equals,
                userGuid);

            DbExpression eObj = new DbExpression(
                _ORM.GetColumnName <ObjectAcl>(nameof(ObjectAcl.ObjectGUID)),
                DbOperators.Equals,
                obj.GUID);

            expr.PrependAnd(eUser);
            expr.PrependAnd(eObj);

            List <ObjectAcl> acls = _ORM.SelectMany <ObjectAcl>(expr);

            if (acls != null && acls.Count > 0)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Determine if a role has permissions defined to access a specified resource using a specific operation.
        /// </summary>
        /// <param name="rolename">The name of the role.</param>
        /// <param name="resource">The resource.</param>
        /// <param name="operation">The type of operation.</param>
        /// <returns>True if the role has permissions defined for the specified resource and specified operation.</returns>
        public bool RolePermissionExists(string rolename, string resource, string operation)
        {
            if (String.IsNullOrEmpty(rolename))
            {
                throw new ArgumentNullException(nameof(rolename));
            }
            if (String.IsNullOrEmpty(resource))
            {
                throw new ArgumentNullException(nameof(resource));
            }
            if (String.IsNullOrEmpty(operation))
            {
                throw new ArgumentNullException(nameof(operation));
            }
            DbExpression e = new DbExpression(_ORM.GetColumnName <RolePermission>(nameof(RolePermission.Rolename)), DbOperators.Equals, rolename);

            e.PrependAnd(_ORM.GetColumnName <RolePermission>(nameof(RolePermission.Resource)), DbOperators.Equals, resource);
            e.PrependAnd(_ORM.GetColumnName <RolePermission>(nameof(RolePermission.Operation)), DbOperators.Equals, operation);
            return(_ORM.Exists <RolePermission>(e));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Remove a permission entry from a role.
        /// </summary>
        /// <param name="rolename">The name of the role.</param>
        /// <param name="resource">The resource.</param>
        /// <param name="operation">The type of operation.</param>
        public void RemoveRolePermission(string rolename, string resource, string operation)
        {
            if (String.IsNullOrEmpty(rolename))
            {
                throw new ArgumentNullException(nameof(rolename));
            }
            if (String.IsNullOrEmpty(resource))
            {
                throw new ArgumentNullException(nameof(resource));
            }
            if (String.IsNullOrEmpty(operation))
            {
                throw new ArgumentNullException(nameof(operation));
            }
            DbExpression e = new DbExpression(_ORM.GetColumnName <RolePermission>(nameof(RolePermission.Rolename)), DbOperators.Equals, rolename);

            e.PrependAnd(_ORM.GetColumnName <RolePermission>(nameof(RolePermission.Resource)), DbOperators.Equals, resource);
            e.PrependAnd(_ORM.GetColumnName <RolePermission>(nameof(RolePermission.Operation)), DbOperators.Equals, operation);
            _ORM.DeleteMany <RolePermission>(e);
        }
Exemplo n.º 22
0
        private List <Account> GetAllAccountsInternal(string searchTerm = null)
        {
            DbResultOrder[] ro = new DbResultOrder[1];
            ro[0] = new DbResultOrder(_ORM.GetColumnName <Entry>(nameof(Account.CreatedUtc)), DbOrderDirection.Descending);
            DbExpression e1 = new DbExpression(_ORM.GetColumnName <Account>(nameof(Account.Id)), DbOperators.GreaterThan, 0);

            if (!String.IsNullOrEmpty(searchTerm))
            {
                e1.PrependAnd(_ORM.GetColumnName <Account>(nameof(Account.Name)), DbOperators.Contains, searchTerm);
            }
            return(_ORM.SelectMany <Account>(null, null, e1, ro));
        }
Exemplo n.º 23
0
        internal List <ObjectTag> GetObjectTags(string key, long version)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (version < 1)
            {
                throw new ArgumentException("Version ID must be one or greater.");
            }

            Obj obj = GetObjectMetadata(key, version);

            if (obj == null)
            {
                _Logging.Debug("GetTags unable to find key " + _Bucket.Name + "/" + key + " version " + version);
                return(null);
            }

            DbExpression eKey = new DbExpression(
                _ORM.GetColumnName <Obj>(nameof(Obj.Key)),
                DbOperators.Equals,
                key);

            DbExpression eVersion = new DbExpression(
                _ORM.GetColumnName <Obj>(nameof(Obj.Version)),
                DbOperators.Equals,
                version);

            DbExpression eBucket = new DbExpression(
                _ORM.GetColumnName <Obj>(nameof(Obj.BucketGUID)),
                DbOperators.Equals,
                _Bucket.GUID);

            eKey.PrependAnd(eVersion);
            eKey.PrependAnd(eBucket);

            return(_ORM.SelectMany <ObjectTag>(eKey));
        }
Exemplo n.º 24
0
        /// <summary>
        /// List the objects stored in the index.
        /// </summary>
        /// <param name="prefix">Prefix upon which to match object keys.</param>
        /// <param name="indexStart">The index (DedupeObject.Id) from which to begin the enumeration.</param>
        /// <param name="maxResults">Maximum number of results to retrieve.</param>
        /// <return>Enumeration result.</return>
        public override EnumerationResult ListObjects(string prefix, int indexStart, int maxResults)
        {
            if (indexStart < 0)
            {
                throw new ArgumentException("Starting index must be zero or greater.");
            }
            if (maxResults < 1 || maxResults > 100)
            {
                throw new ArgumentException("Max results must be greater than zero and less than or equal to 100.");
            }

            EnumerationResult ret = new EnumerationResult(prefix, indexStart, indexStart, maxResults, new List <DedupeObject>());

            DbExpression e = new DbExpression(
                _ORM.GetColumnName <DedupeObject>(nameof(DedupeObject.Id)),
                DbOperators.GreaterThan,
                indexStart);

            if (!String.IsNullOrEmpty(prefix))
            {
                e.PrependAnd(
                    _ORM.GetColumnName <DedupeObject>(nameof(DedupeObject.Key)),
                    DbOperators.StartsWith,
                    prefix);
            }

            List <DedupeObject> objects = _ORM.SelectMany <DedupeObject>(null, maxResults, e);

            if (objects != null && objects.Count > 0)
            {
                foreach (DedupeObject obj in objects)
                {
                    obj.Chunks    = GetChunks(obj.Key);
                    obj.ObjectMap = GetObjectMap(obj.Key);

                    if (obj.ObjectMap != null && obj.ObjectMap.Count > 0)
                    {
                        obj.ObjectMap = obj.ObjectMap.OrderBy(o => o.ChunkAddress).ToList();
                    }

                    ret.Objects.Add(obj);
                }
            }

            if (objects != null && objects.Count == maxResults)
            {
                ret.NextIndexStart = objects[(objects.Count - 1)].Id;
            }

            return(ret);
        }
Exemplo n.º 25
0
        internal List <UrlLock> GetWriteLocks()
        {
            DbExpression e = new DbExpression(
                _ORM.GetColumnName <UrlLock>(nameof(UrlLock.Id)),
                DbOperators.GreaterThan,
                0);

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

            return(_ORM.SelectMany <UrlLock>(e));
        }
Exemplo n.º 26
0
        internal void Delete(string userGuid, string name, bool cleanup)
        {
            if (String.IsNullOrEmpty(userGuid))
            {
                throw new ArgumentNullException(nameof(userGuid));
            }
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            ContainerClient client = GetContainerClient(userGuid, name);

            if (client != null)
            {
                DbExpression e = new DbExpression(
                    _ORM.GetColumnName <Container>(nameof(Container.UserGUID)),
                    DbOperators.Equals,
                    userGuid);

                e.PrependAnd(new DbExpression(
                                 _ORM.GetColumnName <Container>(nameof(Container.Name)),
                                 DbOperators.Equals,
                                 name));

                Container container = _ORM.SelectFirst <Container>(e);
                if (container != null)
                {
                    _ORM.Delete <Container>(container);
                }

                if (cleanup)
                {
                    client.Destroy();
                }
                else
                {
                    client.Dispose();
                }

                lock (_ContainersLock)
                {
                    if (_ContainerClients.Contains(client))
                    {
                        _ContainerClients.Remove(client);
                    }
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Determine if a user is mapped to a role.
        /// </summary>
        /// <param name="username">The name of the user.</param>
        /// <param name="rolename">The name of the role.</param>
        /// <returns>True if the user is mapped to the role.</returns>
        public bool UserRoleExists(string username, string rolename)
        {
            if (String.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException(nameof(username));
            }
            if (String.IsNullOrEmpty(rolename))
            {
                throw new ArgumentNullException(nameof(rolename));
            }
            DbExpression e = new DbExpression(_ORM.GetColumnName <UserRole>(nameof(UserRole.Username)), DbOperators.Equals, username);

            e.PrependAnd(_ORM.GetColumnName <UserRole>(nameof(UserRole.Rolename)), DbOperators.Equals, rolename);
            return(_ORM.Exists <UserRole>(e));
        }
Exemplo n.º 28
0
        /// <summary>
        /// Remove a user's mapping to a role.
        /// </summary>
        /// <param name="username">The name of the user.</param>
        /// <param name="rolename">The name of the role.</param>
        public void RemoveUserRole(string username, string rolename)
        {
            if (String.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException(nameof(username));
            }
            if (String.IsNullOrEmpty(rolename))
            {
                throw new ArgumentNullException(nameof(rolename));
            }
            DbExpression e = new DbExpression(_ORM.GetColumnName <UserRole>(nameof(UserRole.Username)), DbOperators.Equals, username);

            e.PrependAnd(_ORM.GetColumnName <UserRole>(nameof(UserRole.Rolename)), DbOperators.Equals, rolename);
            _ORM.DeleteMany <UserRole>(e);
        }
Exemplo n.º 29
0
        private Entry GetLatestBalanceEntryInternal(string accountGuid)
        {
            DbExpression e = new DbExpression(_ORM.GetColumnName <Entry>(nameof(Entry.AccountGUID)), DbOperators.Equals, accountGuid);

            e.PrependAnd(_ORM.GetColumnName <Entry>(nameof(Entry.Type)), DbOperators.Equals, EntryType.Balance);

            DbResultOrder[] ro = new DbResultOrder[1];
            ro[0] = new DbResultOrder(_ORM.GetColumnName <Entry>(nameof(Entry.CreatedUtc)), DbOrderDirection.Descending);
            List <Entry> balanceEntries = _ORM.SelectMany <Entry>(null, 1, e, ro);

            if (balanceEntries != null && balanceEntries.Count == 1)
            {
                return(balanceEntries[0]);
            }
            return(null);
        }
Exemplo n.º 30
0
        internal ContainerClient GetContainerClient(string userGuid, string name)
        {
            if (String.IsNullOrEmpty(userGuid))
            {
                throw new ArgumentNullException(nameof(userGuid));
            }
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            ContainerClient client = null;

            lock (_ContainersLock)
            {
                client = _ContainerClients.Where(c => c.Container.UserGUID.Equals(userGuid) && c.Container.Name.Equals(name)).FirstOrDefault();
                if (client != null && client != default(ContainerClient))
                {
                    return(client);
                }
            }

            DbExpression e = new DbExpression(
                _ORM.GetColumnName <Container>(nameof(Container.UserGUID)),
                DbOperators.Equals,
                userGuid);

            e.PrependAnd(new DbExpression(
                             _ORM.GetColumnName <Container>(nameof(Container.Name)),
                             DbOperators.Equals,
                             name));

            Container container = _ORM.SelectFirst <Container>(e);

            if (container != null)
            {
                client = InitializeContainerClient(container);
                if (client != null)
                {
                    return(client);
                }
            }

            return(null);
        }