Exemplo n.º 1
0
        /// <summary>
        /// 获取题目类型列表
        /// </summary>
        /// <param name="problemID">题目ID</param>
        /// <returns>题目选择的类型列表</returns>
        public static IMethodResult AdminGetProblemCategoryItemList(Int32 problemID)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

            List <ProblemCategoryItemEntity> lstPT = ProblemCategoryItemRepository.Instance.GetEntities(problemID);
            StringBuilder sb = new StringBuilder();

            List <ProblemCategoryEntity> lstSelectedList   = new List <ProblemCategoryEntity>();
            List <ProblemCategoryEntity> lstUnSelectedList = new List <ProblemCategoryEntity>(ProblemCategoryManager.GetProblemCategoryList());

            if (lstPT == null)
            {
                lstPT = new List <ProblemCategoryItemEntity>();
            }

            for (Int32 i = 0; i < lstPT.Count; i++)
            {
                sb.Append(lstPT[i].TypeID.ToString()).Append(",");

                for (Int32 j = 0; j < lstUnSelectedList.Count; j++)
                {
                    if (lstUnSelectedList[j].TypeID == lstPT[i].TypeID)
                    {
                        lstSelectedList.Add(lstUnSelectedList[j]);
                        lstUnSelectedList.RemoveAt(j);
                        break;
                    }
                }
            }

            return(MethodResult.Success(new Tuple <String, List <ProblemCategoryEntity>, List <ProblemCategoryEntity> >(sb.ToString(), lstUnSelectedList, lstSelectedList)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取竞赛题目列表
        /// </summary>
        /// <param name="cid">竞赛ID</param>
        /// <returns>竞赛题目列表</returns>
        public static IMethodResult AdminGetContestProblemList(Int32 cid)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            List <ContestProblemEntity> list = ContestProblemRepository.Instance.GetEntities(cid);

            return(MethodResult.Success(list));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 当前在线用户列表
        /// </summary>
        /// <returns>当前在线用户列表</returns>
        public static IMethodResult AdminGetOnlineUserNames()
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            List <String> list = UserMailCache.GetOnlineUserNames();

            return(MethodResult.Success(list));
        }
        /// <summary>
        /// 获取配置信息
        /// </summary>
        /// <returns>配置信息</returns>
        public static IMethodResult AdminGetConfigPairList()
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            NameValueCollection col = ConfigurationManager.GetConfigCollection();
            List <KeyValuePair <String, String> > list = new List <KeyValuePair <String, String> >();

            foreach (String key in col.AllKeys)
            {
                list.Add(new KeyValuePair <String, String>(key, col[key]));
            }

            return(MethodResult.Success(list));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 当前评测机列表
        /// </summary>
        /// <returns>当前评测机列表</returns>
        public static IMethodResult AdminGetJudgers()
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            List <UserEntity> list = UserManager.InternalAdminGetJudgerList();

            if (list != null && list.Count > 0)
            {
                for (Int32 i = 0; i < list.Count; i++)
                {
                    list[i].LastOnline = JudgeOnlineStatus.GetJudgeLastTime(list[i].UserName);
                }
            }

            return(MethodResult.Success(list));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取数据库列表
        /// </summary>
        /// <returns>数据库列表</returns>
        public static IMethodResult AdminGetDataBases()
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!DatabaseManager.IsAccessDB)
            {
                throw new DatabaseNotSupportException();
            }

            String[] files = Directory.GetFiles(DatabaseManager.AccessDataDirectory);
            Array.Sort <String>(files, Comparer <String> .Default);
            //recordCount = files.Length;

            List <FileInfo> fis        = new List <FileInfo>();
            Int32           startIndex = 0;
            Int32           endIndex   = files.Length - 1;

            //分页处理
            //Int32 startIndex = (pageIndex - 1) * pageSize;
            //Int32 endIndex = pageIndex * pageSize;

            //if (startIndex >= files.Length)
            //{
            //    return null;
            //}

            //if (endIndex >= files.Length)
            //{
            //    endIndex = files.Length - 1;
            //}

            for (Int32 i = startIndex; i <= endIndex; i++)
            {
                fis.Add(new FileInfo(files[i]));
            }

            return(MethodResult.Success(fis));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 根据ID得到一个题目实体
        /// </summary>
        /// <param name="id">题目ID</param>
        /// <returns>题目实体</returns>
        public static IMethodResult AdminGetProblem(Int32 id)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

            if (id < ConfigurationManager.ProblemSetStartID)
            {
                return(MethodResult.InvalidRequest(RequestType.Problem));
            }

            ProblemEntity entity = ProblemRepository.Instance.GetEntity(id);

            if (entity == null)
            {
                return(MethodResult.NotExist(RequestType.Problem));
            }

            return(MethodResult.Success(entity));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 根据ID得到一个竞赛实体
        /// </summary>
        /// <param name="id">竞赛ID</param>
        /// <returns>竞赛实体</returns>
        public static IMethodResult AdminGetContest(Int32 id)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            if (id < ContestRepository.NONECONTEST)
            {
                return(MethodResult.InvalidRequest(RequestType.Contest));
            }

            ContestEntity entity = ContestRepository.Instance.GetEntity(id);

            if (entity == null)
            {
                return(MethodResult.NotExist(RequestType.Contest));
            }

            return(MethodResult.Success(entity));
        }
Exemplo n.º 9
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns>用户实体</returns>
        public static IMethodResult AdminGetUserInfo(String userName)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsUserName(userName))
            {
                return(MethodResult.InvalidRequest(RequestType.User));
            }

            UserEntity entity = UserRepository.Instance.GetEntityWithAllInfo(userName);

            if (entity == null)
            {
                return(MethodResult.NotExist(RequestType.User));
            }

            return(MethodResult.Success(entity));
        }
Exemplo n.º 10
0
        /// <summary>
        /// 更新指定ID的用户的用户权限
        /// </summary>
        /// <param name="userNames">用户名</param>
        /// <param name="permission">权限类型</param>
        /// <returns>是否成功更新</returns>
        internal static IMethodResult InternalAdminUpdatePermission(String userName, PermissionType permission)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsUserName(userName))
            {
                return(MethodResult.InvalidRequest(RequestType.User));
            }

            Boolean success = UserRepository.Instance.UpdateEntityPermision(userName, permission) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("Failed to update user's permission!"));
            }

            return(MethodResult.Success());
        }
Exemplo n.º 11
0
        /// <summary>
        /// 根据ID得到一个对象实体
        /// </summary>
        /// <param name="resourceID">实体ID</param>
        /// <returns>对象实体</returns>
        public static IMethodResult AdminGetResource(Int32 id)
        {
            if (!AdminManager.HasPermission(PermissionType.ResourceManage))
            {
                throw new NoPermissionException();
            }

            if (id <= 0)
            {
                return(MethodResult.InvalidRequest(RequestType.Resource));
            }

            ResourceEntity entity = ResourceRepository.Instance.GetEntity(id);

            if (entity == null)
            {
                return(MethodResult.NotExist(RequestType.Resource));
            }

            return(MethodResult.Success(entity));
        }
Exemplo n.º 12
0
        /// <summary>
        /// 保存题目数据文件到磁盘
        /// </summary>
        /// <param name="problemID">题目ID</param>
        /// <param name="problemdata">题目数据文件</param>
        /// <returns>是否保存成功</returns>
        internal static IMethodResult InternalAdminSaveProblemData(Int32 problemID, Byte[] problemdata)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

            if (problemID < ConfigurationManager.ProblemSetStartID)
            {
                return(MethodResult.InvalidRequest(RequestType.Problem));
            }

            String fileNewName = problemID.ToString() + ".zip";
            String savePath    = Path.Combine(ConfigurationManager.ProblemDataPath, fileNewName);

            File.WriteAllBytes(savePath, problemdata);

            ProblemDataCache.RemoveProblemDataVersionCache(problemID);

            return(MethodResult.Success());
        }
Exemplo n.º 13
0
        /// <summary>
        /// 根据ID得到一个主题页面实体
        /// </summary>
        /// <param name="id">主题页面ID</param>
        /// <returns>主题页面实体</returns>
        public static IMethodResult AdminGetTopicPage(String name)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsPageName(name))
            {
                return(MethodResult.InvalidRequest(RequestType.TopicPage));
            }

            TopicPageEntity entity = TopicPageRepository.Instance.GetEntity(name);

            if (entity == null)
            {
                return(MethodResult.NotExist(RequestType.TopicPage));
            }

            return(MethodResult.Success(entity));
        }
Exemplo n.º 14
0
        /// <summary>
        /// 导出竞赛用户列表
        /// </summary>
        /// <param name="cid">竞赛ID</param>
        /// <param name="maskcode">导出内容掩码</param>
        /// <param name="withTitle">包括标题行</param>
        /// <returns>竞赛用户列表</returns>
        /// <remarks>
        /// 第1位-竞赛ID      (0x01)
        /// 第2位-用户名      (0x02)
        /// 第3位-真实姓名    (0x04)
        /// 第4位-注册时间    (0x08)
        /// 第5位-是否启用    (0x10)
        /// </remarks>
        public static IMethodResult AdminGetContestUserList(Int32 cid, Int32 maskcode, Boolean withTitle)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            if (maskcode <= 0)
            {
                return(MethodResult.FailedAndLog("You must select at least one item to export!"));
            }

            Dictionary <String, ContestUserEntity> dict = ContestUserRepository.Instance.GetEntities(cid);
            StringBuilder sb = new StringBuilder();

            if (dict != null)
            {
                StringBuilder line = new StringBuilder();

                if (withTitle)
                {
                    if ((maskcode & 0x1) == 0x1)
                    {
                        line.Append(line.Length > 0 ? "\t" : "").Append("Contest ID");
                    }

                    if ((maskcode & 0x2) == 0x2)
                    {
                        line.Append(line.Length > 0 ? "\t" : "").Append("User Name");
                    }

                    if ((maskcode & 0x4) == 0x4)
                    {
                        line.Append(line.Length > 0 ? "\t" : "").Append("Real Name");
                    }

                    if ((maskcode & 0x8) == 0x8)
                    {
                        line.Append(line.Length > 0 ? "\t" : "").Append("Register Time");
                    }

                    if ((maskcode & 0x10) == 0x10)
                    {
                        line.Append(line.Length > 0 ? "\t" : "").Append("Enabled");
                    }

                    sb.AppendLine(line.ToString());
                }

                foreach (ContestUserEntity user in dict.Values)
                {
                    line = new StringBuilder();

                    if ((maskcode & 0x1) == 0x1)
                    {
                        line.Append(line.Length > 0 ? "\t" : "").Append(user.ContestID.ToString());
                    }

                    if ((maskcode & 0x2) == 0x2)
                    {
                        line.Append(line.Length > 0 ? "\t" : "").Append(user.UserName);
                    }

                    if ((maskcode & 0x4) == 0x4)
                    {
                        line.Append(line.Length > 0 ? "\t" : "").Append(user.RealName);
                    }

                    if ((maskcode & 0x8) == 0x8)
                    {
                        line.Append(line.Length > 0 ? "\t" : "").Append(user.RegisterTime.ToString("yyyy-MM-dd HH:mm:ss"));
                    }

                    if ((maskcode & 0x10) == 0x10)
                    {
                        line.Append(line.Length > 0 ? "\t" : "").Append(user.IsEnable ? "Y" : "N");
                    }

                    sb.AppendLine(line.ToString());
                }
            }

            return(MethodResult.Success(sb.ToString()));
        }