コード例 #1
0
        public TestorTreeItem[] GetServerTree(int parentId, int levelsNumber, TestingServerItemType itemType)
        {
            Debug.Assert(parentId >= 0);

            Provider.TestRoles(TestorUserRole.Anonymous, TestorUserRole.Administrator, TestorUserRole.Teacher, TestorUserRole.Laboratorian,
                               TestorUserRole.Student);

            using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString))
            {
                int i = -1;
                if (itemType == TestingServerItemType.TestTree || itemType == TestingServerItemType.ActiveTestTree || itemType == TestingServerItemType.FolderTree)
                {
                    if (Provider.CurrentUser.UserRole == TestorUserRole.Anonymous && parentId == 0)
                    {
                        if (!CoreConfiguration.GetAnonymousPolicy(ref parentId))
                        {
                            return new TestorTreeItem[] { }
                        }
                    }
                    ;
                }
                switch (itemType)
                {
                case TestingServerItemType.TestTree:
                {
                    var results = dataContext.GetTestTreeByLevel(GetId(parentId), GetId(levelsNumber), false, false).ToArray();
                    return(GetTestTreeItems(ref i, results, false));
                };

                case TestingServerItemType.ActiveTestTree:
                {
                    var results = dataContext.GetTestTreeByLevel(GetId(parentId), GetId(levelsNumber), false, true).ToArray();
                    return(GetTestTreeItems(ref i, results, true));
                };

                case TestingServerItemType.FolderTree:
                {
                    var results = dataContext.GetTestTreeByLevel(GetId(parentId), GetId(levelsNumber), false, false).Where(c => c.NodeType == (byte)TestorItemType.Folder).ToArray();
                    return(GetTestTreeItems(ref i, results, false));
                };

                case TestingServerItemType.GroupTree:
                {
                    var results = dataContext.GetUserGroupTree(Provider.CurrentUser.UserRole == TestorUserRole.Administrator ||
                                                               Provider.CurrentUser.UserRole == TestorUserRole.Anonymous ? 0 : Provider.CurrentUser.UserId,
                                                               GetId(parentId), true, GetId(levelsNumber)).ToArray();
                    return(GetGroupTreeItems(ref i, results));
                };

                default:
                    return(null);
                }
            }
        }
コード例 #2
0
        public TestorTreeItem[] GetTestParents(int itemId)
        {
            Debug.Assert(itemId >= 0);

            using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString))
            {
                GetTestTreeByLevelResult[] results = null;
                if (Provider.CurrentUser.UserRole == TestorUserRole.Anonymous)
                {
                    int xId = 0;
                    if (!CoreConfiguration.GetAnonymousPolicy(ref xId))
                    {
                        return new TestorTreeItem[] { }
                    }
                    ;
                    results = dataContext.GetTestTreeByLevel(itemId, 0, true, false).ToArray();
                    List <GetTestTreeByLevelResult> newResults = new List <GetTestTreeByLevelResult>();
                    if (xId > 0)
                    {
                        bool hasBreak = false;

                        foreach (var res in results.Reverse())
                        {
                            if (res.NodeId == xId)
                            {
                                hasBreak = true;
                                break;
                            }
                            newResults.Add(res);
                        }
                        if (!hasBreak && results.Length != 0)
                        {
                            return(null);
                        }
                        newResults.Reverse();
                        results = newResults.ToArray();
                    }
                }
                else
                {
                    results = dataContext.GetTestTreeByLevel(itemId, 0, true, false).ToArray();
                }
                int i = -1;
                return(GetTestTreeItems(ref i, results, false));
            }
        }