Esempio n. 1
0
        /// <summary>
        /// Performs an activation of the verification link.
        /// </summary>
        /// <returns>
        /// If the link does not exist the method returns null.
        /// If the link is already activated the method returns false.
        /// If the link exists and was not activated the method returns true.
        /// </returns>
        public async Task <bool?> ActivateLinkAsync(string link)
        {
            try
            {
                var filter = new EqualityFilter <string>("link", link);
                VerificationLink verificationLink = (await verificationLinksDatabase.Get(filter)).FirstOrDefault();

                if (verificationLink == null)
                {
                    return(null);
                }

                if (verificationLink.Used)
                {
                    return(false);
                }

                verificationLink.Used = true;
                await verificationLinksDatabase.Update(verificationLink, new[] { "Used" });

                return(true);
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error occured while working with the database");
            }
        }
Esempio n. 2
0
        private Filter <ITestDescriptor> GetNamespaceFilter(TestTreeNode namespaceNode)
        {
            var equalityFilter  = new EqualityFilter <string>(namespaceNode.Id);
            var namespaceFilter = new NamespaceFilter <ITestDescriptor>(equalityFilter);

            if (optionsController.NamespaceHierarchy == NamespaceHierarchy.Flat)
            {
                return(namespaceFilter);
            }

            var filters = new List <Filter <ITestDescriptor> > {
                namespaceFilter
            };

            foreach (var n in namespaceNode.Nodes)
            {
                var node = n as NamespaceNode;

                if (node == null)
                {
                    continue;
                }

                var filter = GetNamespaceFilter(node);

                if (filter != null)
                {
                    filters.Add(filter);
                }
            }

            return(filters.Count > 1 ? new OrFilter <ITestDescriptor>(filters)
                : filters[0]);
        }
Esempio n. 3
0
        public async Task <WordDownloadLink> GetUnusedDownloadLink(ObjectId linkID)
        {
            try
            {
                await wordLinksDatabase.Connect().ConfigureAwait(false);

                var filter           = new EqualityFilter <ObjectId>("_id", linkID);
                var wordDownloadLink = (await wordLinksDatabase.Get(filter).ConfigureAwait(false))
                                       .FirstOrDefault();
                if (wordDownloadLink is null)
                {
                    throw new ArgumentException("No link was found for given ID");
                }

                if (wordDownloadLink.Used)
                {
                    throw new ArgumentException("The link has already been used");
                }

                return(wordDownloadLink);
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error occured while working with the database");
            }
        }
        public void CreateFilter(string key, Type filterType)
        {
            Filter <string>          filterValue = new EqualityFilter <string>("");
            Filter <ITestDescriptor> filter      = (new TestDescriptorFilterFactory <ITestDescriptor>()).CreateFilter(key, filterValue);

            Assert.AreEqual(filter.GetType(), filterType);
        }
Esempio n. 5
0
        public async Task <TemplateDto> UpdateTemplate(TemplateUpdateDto dto)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                var      idFilter = new EqualityFilter <ObjectId>("_id", dto.TemplateID);
                Template template = (await database.Get(idFilter).ConfigureAwait(false)).FirstOrDefault();

                if (template is null)
                {
                    throw new ArgumentException("No template with such an ID");
                }

                var(newPublished, newName, newDesc, newOrg, newItems, newLogo) = dto;
                template.Update(newPublished, newName, newDesc, newOrg, newItems, newLogo);

                await database.Update(template).ConfigureAwait(false);

                var templateAuthor = await userService.GetAsync(template.AuthorID).ConfigureAwait(false);

                return(new TemplateDto(template, templateAuthor));
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error ocurred while updating the template");
            }
        }
Esempio n. 6
0
        public async Task <IEnumerable <TemplateDto> > SearchForUserTemplates(ObjectId userID, string query)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                var userFilter = new EqualityFilter <ObjectId>("authorID", userID);
                var nameFilter = new RegexFilter("name", query);
                var getFilter  = userFilter & nameFilter;

                var templates = await database.Get(getFilter).ConfigureAwait(false);

                var author = await userService.GetAsync(userID);

                if (author is null)
                {
                    throw new ArgumentException("No user fot given ID");
                }

                return(templates.Select(template => new TemplateDto(template, author)));
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error ocurred while searching for templates");
            }
        }
Esempio n. 7
0
        public async Task <UserInfo> GetAsync(string email, string password)
        {
            try
            {
                await database.Connect();

                FilterBase emailFilter = new EqualityFilter <string>(
                    typeof(UserInfo).GetBsonPropertyName("Email"), email);
                FilterBase passwordFilter = new EqualityFilter <string>(
                    typeof(UserInfo).GetBsonPropertyName("Password"), password);

                var users = (await database.Get(emailFilter & passwordFilter)).ToList();

                if (users.Count != 1)
                {
                    return(null);
                }

                return(users[0]);
            }
            catch (Exception ex) when(ex.GetType() != typeof(DatabaseException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error occured while working with the database");
            }
        }
Esempio n. 8
0
        public async Task <DocumentElementDto> DeleteNodeAsync(ObjectId documentElementID, ObjectId branchNodeID,
                                                               ObjectId userID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                FilterBase getFilter = new EqualityFilter <ObjectId>("_id", documentElementID);
                var        element   = (await database.Get(getFilter).ConfigureAwait(false)).FirstOrDefault();
                if (element is null)
                {
                    throw new ArgumentException("No document element was found for id");
                }

                element.DeleteNode(branchNodeID);

                await database.Update(element).ConfigureAwait(false);

                var dto = new DocumentElementDto(element);
                dto.SetBranches(element.Branches, userID);

                return(dto);
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error occurred while deleting node");
            }
        }
Esempio n. 9
0
        public async Task <DocumentElementDto> CreateNewBranchAsync(ObjectId documentElementID, string branchName,
                                                                    ObjectId userID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                FilterBase getFilter = new EqualityFilter <ObjectId>("_id", documentElementID);
                var        element   = (await database.Get(getFilter).ConfigureAwait(false)).FirstOrDefault();
                if (element is null)
                {
                    throw new ArgumentException("No document element was found for id");
                }

                element.Branches.Add(Branch.GetNewBranch(branchName, dateService, element.Type,
                                                         new List <BranchAccess>()
                {
                    new BranchAccess(userID, BranchAccessType.ReadWrite)
                }, userID));

                await database.Update(element).ConfigureAwait(false);

                var dto = new DocumentElementDto(element);
                dto.SetBranches(element.Branches, userID);

                return(dto);
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error occurred while creating new branch");
            }
        }
Esempio n. 10
0
        public async Task <TemplateDto> IncreaseDocumentCountForTemplate(ObjectId templateID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                var      idFilter = new EqualityFilter <ObjectId>("_id", templateID);
                Template template = (await database.Get(idFilter).ConfigureAwait(false)).FirstOrDefault();

                if (template is null)
                {
                    throw new ArgumentException("No template with such an ID");
                }

                ++template.DocumentCount;

                await database.Update(template).ConfigureAwait(false);

                var templateAuthor = await userService.GetAsync(template.AuthorID);

                if (templateAuthor is null)
                {
                    throw new ArgumentException("No user fot given ID");
                }

                return(new TemplateDto(template, templateAuthor));
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error ocurred while increasing documents count for templates");
            }
        }
Esempio n. 11
0
        public async Task ActivateCodeAsync(string code)
        {
            try
            {
                FilterBase codeFilter = new EqualityFilter <string>(typeof(ActivationCode)
                                                                    .GetBsonPropertyName("Code"), code);
                FilterBase usedFilter = new EqualityFilter <bool>(typeof(ActivationCode)
                                                                  .GetBsonPropertyName("Used"), false);

                await database.Connect().ConfigureAwait(false);

                ActivationCode activationCode = (await database.Get(codeFilter & usedFilter)
                                                 .ConfigureAwait(false)).FirstOrDefault();

                if (activationCode == null)
                {
                    throw new DatabaseException("Such a code does not exist");
                }

                activationCode.Used      = true;
                activationCode.UsageDate = DateTime.UtcNow;

                await database.Update(activationCode, new[] { "Used", "UsageDate" }).ConfigureAwait(false);
            }
            catch (Exception ex) when(ex.GetType() != typeof(DatabaseException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("THe error happened while activating the code");
            }
        }
Esempio n. 12
0
        public async Task <DocumentElementDto> CreateNewNodeAsync(ObjectId documentElementID, ObjectId branchID,
                                                                  ObjectId userID, string nodeName, string comment)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                FilterBase getFilter = new EqualityFilter <ObjectId>("_id", documentElementID);
                var        element   = (await database.Get(getFilter).ConfigureAwait(false)).FirstOrDefault();
                if (element is null)
                {
                    throw new ArgumentException("No document element was found for id");
                }

                var branch = element.Branches.Find(b => b.BranchID == branchID);
                if (branch is null)
                {
                    throw new ArgumentException("No branch found for this id");
                }

                branch.BranchNodes.Add(BranchNode.GetEmptyNode(element.Type, dateService, userID, nodeName, comment));

                await database.Update(element).ConfigureAwait(false);

                var dto = new DocumentElementDto(element);
                dto.SetBranches(element.Branches, userID);

                return(dto);
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error occurred while creating new node");
            }
        }
Esempio n. 13
0
        public async Task <ProjectShortDto> UpdateProject(ProjectUpdateDto update)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                var     getFilter = new EqualityFilter <ObjectId>("_id", update.ProjectID);
                Project project   = (await database.Get(getFilter).ConfigureAwait(false)).FirstOrDefault();
                if (project is null)
                {
                    throw new ArgumentException("No project was found for given ID");
                }

                UpdateProject(project, update);

                await database.Update(project).ConfigureAwait(false);

                return(new ProjectShortDto(project));
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error ocurred while updating project");
            }
        }
Esempio n. 14
0
        public async Task DeleteProject(ObjectId projectID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                var     getFilter = new EqualityFilter <ObjectId>("_id", projectID);
                Project project   = (await database.Get(getFilter).ConfigureAwait(false)).FirstOrDefault();
                if (project is null)
                {
                    throw new ArgumentException("Project was not found for given ID");
                }

                ObjectId authorID = project.Users.Where(u => u.Role == ProjectRole.Creator).First().UserID;
                UserInfo author   = await userService.GetAsync(authorID).ConfigureAwait(false);

                if (author is null)
                {
                    throw new ArgumentException("No author was found for project");
                }

                author.UserRelatedProjects.Remove(project.ID);
                await userService.UpdateAsync(author).ConfigureAwait(false);

                await database.Delete(getFilter).ConfigureAwait(false);
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error ocurred while deleting project");
            }
        }
        public async Task AssociateFileWithDocumentAsync(ObjectId fileID, ObjectId documentID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                FilterBase fileIDGetFilter = new EqualityFilter <ObjectId>("FileID", fileID);

                var fileToDoc = (await database.Get(fileIDGetFilter).
                                 ConfigureAwait(false)).FirstOrDefault();

                if (fileToDoc is null)
                {
                    fileToDoc = new Models.FileToDocument(fileID, documentID);
                    await database.Insert(fileToDoc).ConfigureAwait(false);
                }
                else
                {
                    if (fileToDoc.DocumentID == documentID)
                    {
                        return;
                    }

                    fileToDoc.DocumentID = documentID;

                    await database.Update(fileToDoc).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("The error occured while associating file with document", ex);
            }
        }
Esempio n. 16
0
        public async Task RenameFolder(ObjectId folderID, string newFolderName)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                var getFilter = new EqualityFilter <ObjectId>(typeof(DocumentFolder).GetBsonPropertyName("ID"), folderID);

                DocumentFolder documentFolder = (await database.Get(getFilter).ConfigureAwait(false)).FirstOrDefault();

                if (documentFolder == null)
                {
                    throw new ArgumentException();
                }

                documentFolder.FolderName = newFolderName;

                await database.Update(documentFolder).ConfigureAwait(false);
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("The error occured while renaming the folder");
            }
        }
Esempio n. 17
0
        public async Task <IEnumerable <ProjectShortDto> > GetUserShortProjectsAsync(ObjectId userID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                UserInfo user = await userService.GetAsync(userID).ConfigureAwait(false);

                List <ObjectId> projectsIDs = user.UserRelatedProjects;
                if (projectsIDs is null || projectsIDs.Count == 0)
                {
                    return(new List <ProjectShortDto>());
                }

                return(projectsIDs.Select(projectID =>
                {
                    var filter = new EqualityFilter <ObjectId>("_id", projectID);
                    Project project = database.Get(filter).GetAwaiter().GetResult().FirstOrDefault();
                    if (project is null)
                    {
                        throw new ArgumentException("Project was not found for given id");
                    }

                    return project;
                }).Select(project => new ProjectShortDto(project)));
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error ocurred while getting user projects");
            }
        }
Esempio n. 18
0
        public async Task <IEnumerable <TemplateDto> > GetUserTemplates(ObjectId userID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                var getFilter = new EqualityFilter <ObjectId>("authorID", userID);

                var templates = await database.Get(getFilter).ConfigureAwait(false);

                var templatesAuthor = await userService.GetAsync(userID);

                if (templatesAuthor is null)
                {
                    throw new ArgumentException("No author for this template");
                }

                return(templates.Select(template => new TemplateDto(template, templatesAuthor)));
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error ocurred while getting user templates");
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Gets the collection of the single user's activities with a given userID.
        /// </summary>
        /// <returns>
        /// Can return null if the user with a given ID does not exist.
        /// </returns>
        public async Task <IEnumerable <SingleUserActivity> > GetUserSingleActivitiesAsync(ObjectId userID)
        {
            await database.Connect();

            var filter = new EqualityFilter <ObjectId>("userID", userID);

            return((await database.Get(filter).ConfigureAwait(false)).FirstOrDefault()?.Activities);
        }
Esempio n. 20
0
        /// <summary>
        /// Gets the user activity for a user with a given ID.
        /// </summary>
        /// <returns>
        /// Can return null if theere is no user with a given ID.
        /// </returns>
        public async Task <Domain.UserActivity.UserActivity> GetUserActivityAsync(ObjectId userID)
        {
            await database.Connect();

            var filter = new EqualityFilter <ObjectId>("userID", userID);

            return((await database.Get(filter).ConfigureAwait(false)).FirstOrDefault());
        }
Esempio n. 21
0
        public async Task <DocumentElementDto> DeleteBranchAsync(ObjectId elementID, ObjectId branchID, ObjectId userID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                FilterBase getFilter = new EqualityFilter <ObjectId>("_id", elementID);
                var        element   = (await database.Get(getFilter).ConfigureAwait(false)).FirstOrDefault();
                if (element is null)
                {
                    throw new ArgumentException("No document element was found for id");
                }

                var branch = element.Branches.Find(branch => branch.BranchID == branchID);
                if (branch is null)
                {
                    throw new ArgumentException("There is no branch for given id");
                }

                element.Branches.Remove(branch);
                if (element.Branches.Count == 0)
                {
                    element.Branches.Add(Branch.GetNewBranch("New branch", dateService, element.Type,
                                                             new List <BranchAccess>()
                    {
                        new BranchAccess(userID, BranchAccessType.ReadWrite)
                    }, userID));
                }

                element.CurrentBranchID = element.Branches.First().BranchID;
                if (element.Branches.First().BranchNodes.Count == 0)
                {
                    element.Branches.First().BranchNodes.Add(BranchNode.GetEmptyNode(element.Type, dateService,
                                                                                     userID, "New node", "Comment"));
                }

                element.CurrentBranchNodeID = element.Branches.First().BranchNodes.First().BranchNodeID;

                await database.Update(element).ConfigureAwait(false);

                var dto = new DocumentElementDto(element);
                dto.SetBranches(element.Branches, userID);

                return(dto);
            }
            catch (Exception ex) when(ex.GetType() != typeof(ArgumentException))
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error occurred while deleting branch");
            }
        }
        public async Task DeleteDeskStateAsync(ObjectId userID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                IFilter deletionFilter = new EqualityFilter <ObjectId>("userID", userID);
                await database.Delete(deletionFilter).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("The error occured while creating new document desk state");
            }
        }
        public static void SafeAnd(this DomainCriteria value, EqualityFilter filter)
        {
            if (filter.IsNotNull())
            {
                if (filter.Value.IsNotNull())
                {
                    if (filter.Value is string && filter.Value.AsString().IsNullOrEmpty())
                    {
                        return;
                    }

                    value.Filter &= filter;
                }
            }
        }
        public async Task <Domain.Workplace.DocumentsDeskState.DocumentDeskState> GetDeskStateAsync(ObjectId userID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                var getFilter = new EqualityFilter <ObjectId>(typeof(Domain.Workplace.DocumentsDeskState.DocumentDeskState).GetBsonPropertyName("UserID"), userID);
                return((await database.Get(getFilter).ConfigureAwait(false)).FirstOrDefault());
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("The error occured while getting the desk state", ex);
            }
        }
Esempio n. 25
0
        public async Task <DocumentFolder> GetFolderData(ObjectId folderID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                var getFilter = new EqualityFilter <ObjectId>(typeof(DocumentFolder).GetBsonPropertyName("ID"), folderID);

                return((await database.Get(getFilter).ConfigureAwait(false)).FirstOrDefault());
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("The error occured while getting the folder data");
            }
        }
        public async Task <Models.FileToDocument> GetFileToDocumentModelAsync(ObjectId fileID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                FilterBase getFilter = new EqualityFilter <ObjectId>("fileID", fileID);

                return((await database.Get(getFilter).ConfigureAwait(false)).FirstOrDefault());
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error ocured while getting the file-document info");
            }
        }
Esempio n. 27
0
        public async Task DeleteFolder(ObjectId folderID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                var deletionFilter = new EqualityFilter <ObjectId>(typeof(DocumentFolder).GetBsonPropertyName("ID"),
                                                                   folderID);

                await database.Delete(deletionFilter).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("The error occured while deleting the folder");
            }
        }
Esempio n. 28
0
        public async Task <IEnumerable <DocumentFolder> > GetFolders(ObjectId userID, string searchQuery)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                FilterBase idFilter         = new EqualityFilter <ObjectId>(typeof(DocumentFolder).GetBsonPropertyName("ID"), userID);
                FilterBase folderNameFilter = new RegexFilter(typeof(DocumentFolder).GetBsonPropertyName("FolderName"), $"/{searchQuery}/");

                return(await database.Get(idFilter& folderNameFilter).ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("The error occured while searching for folders");
            }
        }
Esempio n. 29
0
        public async Task <IEnumerable <DocumentFolder> > GetFolders(ObjectId userID, ObjectId parentFolderID)
        {
            try
            {
                await database.Connect().ConfigureAwait(false);

                FilterBase userIDFilter       = new EqualityFilter <ObjectId>(typeof(DocumentFolder).GetBsonPropertyName("UserID"), userID);
                FilterBase parentFolderFilter = new EqualityFilter <ObjectId>(typeof(DocumentFolder).GetBsonPropertyName("ParentFolderID"), parentFolderID);

                return(await database.Get(userIDFilter& parentFolderFilter).ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("The error occured while getting your folders");
            }
        }
Esempio n. 30
0
        public async Task <UserInfo> GetAsync(string token)
        {
            try
            {
                JwtSecurityToken jwtSecurityToken = new JwtSecurityTokenHandler().ReadToken(token) as JwtSecurityToken;
                string           email            = jwtSecurityToken.Claims.ToList().Find(c => c.Type == "Email").Value;

                await database.Connect().ConfigureAwait(false);

                var filter = new EqualityFilter <string>("email", email);
                return((await database.Get(filter)).FirstOrDefault());
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error occured while working with the database");
            }
        }
Esempio n. 31
0
        private Filter<ITestDescriptor> GetNamespaceFilter(TestTreeNode namespaceNode)
        {
            var equalityFilter = new EqualityFilter<string>(namespaceNode.Id);
            var namespaceFilter = new NamespaceFilter<ITestDescriptor>(equalityFilter);
            
            if (optionsController.NamespaceHierarchy == NamespaceHierarchy.Flat)
                return namespaceFilter;

            var filters = new List<Filter<ITestDescriptor>> { namespaceFilter };

            foreach (var n in namespaceNode.Nodes)
            {
                var node = n as NamespaceNode;

                if (node == null)
                    continue;

                var filter = GetNamespaceFilter(node);

                if (filter != null)
                {
                    filters.Add(filter);
                }
            }

            return filters.Count > 1 ? new OrFilter<ITestDescriptor>(filters)
                : filters[0];
        }
Esempio n. 32
0
        private Filter<ITestDescriptor> GenerateFilter(TestTreeNode node)
        {
            var equalityFilter = new EqualityFilter<string>(node.Id);

            if (node is NamespaceNode)
            {
                return GetNamespaceFilter(node);
            }

            if (node is TestDataNode)
            {
                return new IdFilter<ITestDescriptor>(equalityFilter);
            }

            if (node is MetadataNode && node.Id != "None")
            {
                return new MetadataFilter<ITestDescriptor>(node.TestKind, equalityFilter);
            }

            return CreateFilter(node.Nodes);
        }
 public void CreateFilter(string key, Type filterType)
 {
     Filter<string> filterValue = new EqualityFilter<string>("");
     Filter<ITestDescriptor> filter = (new TestDescriptorFilterFactory<ITestDescriptor>()).CreateFilter(key, filterValue);
     Assert.AreEqual(filter.GetType(), filterType);
 }