/// <summary>
        /// 删除指定数据库
        /// </summary>
        /// <param name="did">数据库ID</param>
        /// <returns>是否删除成功</returns>
        public static IMethodResult AdminDeleteDataBase(Int32 did)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

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

            FileInfo fi       = new FileInfo(DatabaseManager.AdminGetDataBaseFileName(did));
            String   filePath = Path.Combine(DatabaseManager.AccessDataDirectory, fi.Name);

            if (!File.Exists(filePath))
            {
                return(MethodResult.FailedAndLog("Database does not exist!"));
            }

            if (String.Equals(DatabaseManager.AccessDBFullPath, filePath, StringComparison.OrdinalIgnoreCase))
            {
                return(MethodResult.FailedAndLog("You can not delete the current database!"));
            }

            File.Delete(filePath);

            return(MethodResult.SuccessAndLog("Admin delete database, name = {0}", fi.Name));
        }
Exemple #2
0
        /// <summary>
        /// 获取提交列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="sids">提交ID集合</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="name">用户名</param>
        /// <param name="lang">提交语言</param>
        /// <param name="type">提交结果</param>
        /// <param name="startDate">开始时间</param>
        /// <param name="endDate">结束时间</param>
        /// <param name="order">排序顺序</param>
        /// <returns>提交列表</returns>
        public static PagedList <SolutionEntity> AdminGetSolutionList(Int32 pageIndex, String sids, String cid, String pid, String name, String lang, String type, String startDate, String endDate, String order)
        {
            if (!AdminManager.HasPermission(PermissionType.SolutionManage))
            {
                throw new NoPermissionException();
            }

            Int32 pageSize    = AdminManager.ADMIN_LIST_PAGE_SIZE;
            Int32 recordCount = SolutionManager.AdminCountSolutionList(sids, cid, pid, name, lang, type, startDate, endDate);

            String       solutionIDs = String.Empty;
            String       userName = String.Empty;
            Int32        problemID = -1, contestID = -1;
            LanguageType languageType = LanguageType.Null;
            ResultType?  resultType = new Nullable <ResultType>();
            DateTime?    dtStart = null, dtEnd = null;

            SolutionManager.AdminGetSolutionParams(sids, cid, pid, name, lang, type, startDate, endDate, out solutionIDs, out problemID, out contestID, out userName, out languageType, out resultType, out dtStart, out dtEnd);

            return(SolutionRepository.Instance
                   .GetEntities(solutionIDs, contestID, problemID, userName, languageType, resultType, dtStart, dtEnd,
                                (String.IsNullOrEmpty(order) ? -1 : Convert.ToInt32(order)),
                                pageIndex, pageSize, recordCount)
                   .ToPagedList(pageSize, recordCount));
        }
        /// <summary>
        /// 获取帖子列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="fpids">帖子ID列表</param>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="username">发帖用户名</param>
        /// <param name="title">帖子标题</param>
        /// <param name="content">帖子内容</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <param name="postip">发帖IP</param>
        /// <returns>帖子列表</returns>
        public static PagedList <ForumPostEntity> AdminGetForumPostList(Int32 pageIndex, String fpids, String ftids, String username, String title, String content, String isHide, String startDate, String endDate, String postip)
        {
            if (!AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException();
            }

            Int32 pageSize    = AdminManager.ADMIN_LIST_PAGE_SIZE;
            Int32 recordCount = ForumPostManager.AdminCountForumPosts(fpids, ftids, username, title, content, isHide, startDate, endDate, postip);

            DateTime dtStart = DateTime.MinValue, dtEnd = DateTime.MinValue;

            fpids = fpids.SearchOptimized();
            ftids = ftids.SearchOptimized();

            if (!String.IsNullOrEmpty(fpids) && !RegexVerify.IsNumericIDs(fpids))
            {
                throw new InvalidRequstException(RequestType.ForumPost);
            }

            if (!String.IsNullOrEmpty(ftids) && !RegexVerify.IsNumericIDs(ftids))
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            return(ForumPostRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount,
                                fpids, ftids, username, title, content,
                                (!String.IsNullOrEmpty(isHide) ? "1".Equals(isHide, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                (!String.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out dtStart) ? dtStart : new Nullable <DateTime>()),
                                (!String.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out dtEnd) ? dtEnd : new Nullable <DateTime>()), postip)
                   .ToPagedList(pageSize, recordCount));
        }
        /// <summary>
        /// 根据ID得到一个帖子实体
        /// </summary>
        /// <param name="id">帖子ID</param>
        /// <returns>帖子实体</returns>
        public static ForumPostEntity GetForumPost(Int32 id)
        {
            if (id <= 0)
            {
                throw new InvalidRequstException(RequestType.ForumPost);
            }

            ForumPostEntity entity = ForumPostCache.GetForumPostCache(id);

            if (entity == null)
            {
                entity = ForumPostRepository.Instance.GetEntity(id);
                ForumPostCache.SetForumPostCache(entity);
            }

            if (entity == null)
            {
                throw new NullResponseException(RequestType.ForumPost);
            }

            if (entity.IsHide && !AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException("You have no privilege to view the post!");
            }

            return(entity);
        }
        /// <summary>
        /// 根据主题ID得到一个帖子实体
        /// </summary>
        /// <param name="topicID">主题ID</param>
        /// <returns>帖子实体</returns>
        public static ForumPostEntity GetForumPostByTopicID(String topicID)
        {
            Int32 tid = 0;

            Int32.TryParse(topicID, out tid);

            if (tid <= 0)
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            ForumPostEntity entity = ForumPostRepository.Instance.GetEntityByTopicID(tid);

            if (entity == null)
            {
                throw new NullResponseException(RequestType.ForumPost);
            }

            if (entity.IsHide && !AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException("You have no privilege to view the post!");
            }

            return(entity);
        }
Exemple #6
0
        /// <summary>
        /// 更新主题锁定状态
        /// </summary>
        /// <param name="ids">主题ID列表</param>
        /// <param name="isLock">是否锁定</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateForumTopicIsLocked(String ids, Boolean isLocked)
        {
            if (!AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsNumericIDs(ids))
            {
                return(MethodResult.InvalidRequest(RequestType.ForumTopic));
            }

            Boolean success = ForumTopicRepository.Instance.UpdateEntityIsLocked(ids, isLocked) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No forum topic was {0}!", isLocked ? "locked" : "unlocked"));
            }

            ids.ForEachInIDs(',', id =>
            {
                ForumTopicCache.RemoveForumTopicCache(id);//删除缓存
            });

            return(MethodResult.SuccessAndLog("Admin {1} forum topic, id = {0}", ids, isLocked ? "lock" : "unlock"));
        }
Exemple #7
0
        /// <summary>
        /// 获取主题列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="username">发帖人</param>
        /// <param name="title">主题标题</param>
        /// <param name="type">主题类型</param>
        /// <param name="relativeID">相关ID</param>
        /// <param name="isLocked">是否锁定</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <returns>主题列表</returns>
        public static PagedList <ForumTopicEntity> AdminGetForumTopicList(Int32 pageIndex, String ftids, String username, String title, String type, String relativeID, String isLocked, String isHide, String startDate, String endDate)
        {
            if (!AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException();
            }

            Int32 pageSize    = AdminManager.ADMIN_LIST_PAGE_SIZE;
            Int32 recordCount = ForumTopicManager.AdminCountForumTopics(ftids, username, title, type, relativeID, isLocked, isHide, startDate, endDate);

            Byte     topictype = 0;
            Int32    rid = -1;
            DateTime dtStart = DateTime.MinValue, dtEnd = DateTime.MinValue;

            ftids = ftids.SearchOptimized();

            if (!String.IsNullOrEmpty(ftids) && !RegexVerify.IsNumericIDs(ftids))
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            if (!String.IsNullOrEmpty(relativeID) && !Int32.TryParse(relativeID, out rid))
            {
                throw new InvalidInputException("Relative ID is INVALID!");
            }

            return(ForumTopicRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount, ftids, username, title,
                                (!String.IsNullOrEmpty(type) && Byte.TryParse(type, out topictype) ? (ForumTopicType)topictype : new Nullable <ForumTopicType>()), rid,
                                (!String.IsNullOrEmpty(isLocked) ? "1".Equals(isLocked, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                (!String.IsNullOrEmpty(isHide) ? "1".Equals(isHide, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                (!String.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out dtStart) ? dtStart : new Nullable <DateTime>()),
                                (!String.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out dtEnd) ? dtEnd : new Nullable <DateTime>()))
                   .ToPagedList(pageSize, recordCount));
        }
Exemple #8
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <returns>是否成功增加</returns>
        public static IMethodResult AdminInsertResource(ResourceEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.ResourceManage))
            {
                throw new NoPermissionException();
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return(MethodResult.FailedAndLog("Resource title can not be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Url))
            {
                return(MethodResult.FailedAndLog("Resource url can not be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Type))
            {
                return(MethodResult.FailedAndLog("Resource type can not be NULL!"));
            }

            Boolean success = ResourceRepository.Instance.InsertEntity(entity) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No resource was added!"));
            }

            ResourceCache.RemoveResourceListCache();//删除缓存

            return(MethodResult.SuccessAndLog("Admin add resource, title = {0}", entity.Title));
        }
Exemple #9
0
        /// <summary>
        /// 根据ID得到一个对象实体
        /// </summary>
        /// <param name="id">实体ID</param>
        /// <returns>对象实体</returns>
        public static ForumTopicEntity GetForumTopic(Int32 id)
        {
            if (id <= 0)
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            ForumTopicEntity topic = ForumTopicCache.GetForumTopicCache(id);

            if (topic == null)
            {
                topic = ForumTopicRepository.Instance.GetEntity(id);
                ForumTopicCache.SetForumTopicCache(topic);
            }

            if (topic == null)
            {
                throw new NullResponseException(RequestType.ForumTopic);
            }

            if (topic.IsHide && !AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException("You have no privilege to view the topic!");
            }

            return(topic);
        }
Exemple #10
0
        /// <summary>
        /// 更新一条公告
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateNews(NewsEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.NewsManage))
            {
                throw new NoPermissionException();
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return(MethodResult.FailedAndLog("News title can not be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Description))
            {
                return(MethodResult.FailedAndLog("News content can not be NULL!"));
            }

            entity.PublishDate = DateTime.Now;

            Boolean success = NewsRepository.Instance.UpdateEntity(entity) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No news was updated!"));
            }

            NewsCache.SetNewsCache(entity);//更新缓存

            if (entity.AnnounceID != NewsRepository.DEFAULTID)
            {
                NewsCache.RemoveLastestNewsListCache();//删除缓存
            }

            return(MethodResult.SuccessAndLog("Admin update news, id = {0}", entity.AnnounceID.ToString()));
        }
Exemple #11
0
        /// <summary>
        /// 增加一条公告
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <returns>是否成功增加</returns>
        public static IMethodResult AdminInsertNews(NewsEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.NewsManage))
            {
                throw new NoPermissionException();
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return(MethodResult.FailedAndLog("News title can not be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Description))
            {
                return(MethodResult.FailedAndLog("News content can not be NULL!"));
            }

            entity.PublishDate = DateTime.Now;

            Boolean success = NewsRepository.Instance.InsertEntity(entity) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No news was added!"));
            }

            NewsCache.RemoveLastestNewsListCache(); //删除缓存
            NewsCache.RemoveNewsCountCache();       //删除缓存

            return(MethodResult.SuccessAndLog("Admin add news, title = {0}", entity.Title));
        }
        /// <summary>
        /// 根据ID得到一个主题页面实体
        /// </summary>
        /// <param name="name">页面名称</param>
        /// <returns>主题页面实体</returns>
        public static TopicPageEntity GetTopicPage(String name)
        {
            if (!RegexVerify.IsPageName(name))
            {
                throw new InvalidRequstException(RequestType.TopicPage);
            }

            TopicPageEntity topicpage = TopicPageCache.GetTopicPageCache(name);//读取缓存

            if (topicpage == null)
            {
                topicpage = TopicPageManager.GetReplacedContent(TopicPageRepository.Instance.GetEntity(name));
                TopicPageCache.SetTopicPageCache(topicpage);//设置缓存
            }

            if (topicpage == null)
            {
                throw new NullResponseException(RequestType.TopicPage);
            }

            if (topicpage.IsHide && !AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            return(topicpage);
        }
Exemple #13
0
        /// <summary>
        /// 还原指定数据库
        /// </summary>
        /// <param name="fileName">数据库文件名</param>
        /// <returns>是否还原成功</returns>
        public static IMethodResult AdminRestoreDataBase(String fileName)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

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

            String sourcePath = Path.Combine(DatabaseManager.AccessDataDirectory, fileName);
            String destPath   = DatabaseManager.AccessDBFullPath;

            if (!File.Exists(sourcePath))
            {
                return(MethodResult.FailedAndLog("Database does not exist!"));
            }

            if (String.Equals(destPath, sourcePath, StringComparison.OrdinalIgnoreCase))
            {
                return(MethodResult.FailedAndLog("You can not restore the current database!"));
            }

            File.Copy(sourcePath, destPath, true);
            CacheManager.RemoveAll();

            return(MethodResult.SuccessAndLog("Admin restore database, name = {0}", fileName));
        }
Exemple #14
0
        /// <summary>
        /// 获取数据库真实路径
        /// </summary>
        /// <param name="did">数据库ID</param>
        /// <returns>数据库真实路径</returns>
        public static IMethodResult AdminGetDataBaseDownloadPath(Int32 did)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

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

            FileInfo fi       = new FileInfo(DatabaseManager.AdminGetDataBaseFileName(did));
            String   filePath = Path.Combine(DatabaseManager.AccessDataDirectory, fi.Name);

            if (!File.Exists(filePath))
            {
                return(MethodResult.FailedAndLog("Database does not exist!"));
            }

            if (!String.Equals(fi.Extension, ".resx", StringComparison.OrdinalIgnoreCase))
            {
                return(MethodResult.FailedAndLog("Your can not download this file!"));
            }

            return(MethodResult.SuccessAndLog <String>(filePath, "Admin download database, name = {0}", fi.Name));
        }
Exemple #15
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)));
        }
Exemple #16
0
        /// <summary>
        /// 重测提交
        /// </summary>
        /// <param name="sids">提交ID集合</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="name">用户名</param>
        /// <param name="lang">提交语言</param>
        /// <param name="type">提交结果</param>
        /// <param name="startDate">开始时间</param>
        /// <param name="endDate">结束时间</param>
        /// <returns>是否成功重测</returns>
        public static IMethodResult AdminRejudgeSolution(String sids, String cid, String pid, String name, String lang, String type, String startDate, String endDate)
        {
            if (!AdminManager.HasPermission(PermissionType.SolutionManage))
            {
                throw new NoPermissionException();
            }

            String       solutionIDs = String.Empty;
            String       userName = String.Empty;
            Int32        problemID = -1, contestID = -1;
            LanguageType languageType = LanguageType.Null;
            ResultType?  resultType = new Nullable <ResultType>();
            DateTime?    dtStart = null, dtEnd = null;
            Boolean      noCondition = SolutionManager.AdminGetSolutionParams(sids, cid, pid, name, lang, type, startDate, endDate, out solutionIDs, out problemID, out contestID, out userName, out languageType, out resultType, out dtStart, out dtEnd);

            if (noCondition)
            {
                return(MethodResult.FailedAndLog("You must set at least one condition!"));
            }

            Int32 result = SolutionRepository.Instance.UpdateEntityToRejudge(solutionIDs, contestID, problemID, userName, languageType, resultType, dtStart, dtEnd);

            if (result <= 0)
            {
                return(MethodResult.FailedAndLog("No solution was rejudged!"));
            }

            return(MethodResult.SuccessAndLog <Int32>(result, "Admin rejudge solution, sid = {0}, cid = {2}, pid = {1}, name = {3}, lang = {4}, type = {5}, start = {6}, end = {7}", solutionIDs.ToString(), contestID.ToString(), problemID.ToString(), name, languageType.ToString(), resultType.ToString(), dtStart.ToString(), dtEnd.ToString()));
        }
Exemple #17
0
        /// <summary>
        /// 删除指定ID的题目类型种类
        /// </summary>
        /// <param name="id">题目类型种类ID</param>
        /// <returns>是否成功删除</returns>
        public static IMethodResult AdminDeleteProblemCategory(Int32 id)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

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

            if (ProblemCategoryItemRepository.Instance.CountEntities(id) > 0)
            {
                return(MethodResult.FailedAndLog("This category still has some problems, please remove these problem from this category first!"));
            }

            Boolean success = ProblemCategoryRepository.Instance.DeleteEntity(id) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No problem category was deleted!"));
            }

            ProblemCategoryCache.RemoveProblemCategoryListCache();//删除缓存

            return(MethodResult.SuccessAndLog("Admin delete problem category, id = {0}", id.ToString()));
        }
Exemple #18
0
        /// <summary>
        /// 更新题目隐藏状态
        /// </summary>
        /// <param name="ids">题目ID列表</param>
        /// <param name="isHide">隐藏状态</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateProblemIsHide(String ids, Boolean isHide)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsNumericIDs(ids))
            {
                return(MethodResult.InvalidRequest(RequestType.Problem));
            }

            Boolean success = ProblemRepository.Instance.UpdateEntityIsHide(ids, isHide) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No problem was {0}!", isHide ? "hided" : "unhided"));
            }

            ids.ForEachInIDs(',', id =>
            {
                ProblemCache.RemoveProblemCache(id);                         //删除缓存
                ProblemCache.RemoveProblemSetCache(GetProblemPageIndex(id)); //删除缓存
            });

            return(MethodResult.SuccessAndLog("Admin {1} problem, id = {0}", ids, isHide ? "hide" : "unhide"));
        }
Exemple #19
0
        /// <summary>
        /// 更新一条题目类型种类
        /// </summary>
        /// <param name="entity">题目类型种类实体</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateProblemCategory(ProblemCategoryEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

            if (entity.TypeID <= 0)
            {
                return(MethodResult.InvalidRequest(RequestType.ProblemCategory));
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return(MethodResult.FailedAndLog("Problem category title cannot be NULL!"));
            }

            Boolean success = ProblemCategoryRepository.Instance.UpdateEntity(entity) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No problem category was updated!"));
            }

            ProblemCategoryCache.RemoveProblemCategoryListCache();//删除缓存

            return(MethodResult.SuccessAndLog("Admin update problem category, id = {0}", entity.TypeID.ToString()));
        }
Exemple #20
0
        /// <summary>
        /// 更新竞赛隐藏状态
        /// </summary>
        /// <param name="ids">竞赛ID列表</param>
        /// <param name="isHide">隐藏状态</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateContestIsHide(String ids, Boolean isHide)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsNumericIDs(ids))
            {
                return(MethodResult.InvalidRequest(RequestType.Contest));
            }

            Boolean success = ContestRepository.Instance.UpdateEntityIsHide(ids, isHide) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No contest was {0}!", isHide ? "hided" : "unhided"));
            }

            ids.ForEachInIDs(',', id =>
            {
                ContestCache.RemoveContestCache(id);//删除缓存
            });

            ContestCache.RemoveContestListCountCache();//删除缓存

            return(MethodResult.SuccessAndLog("Admin {1} contest, id = {0}", ids, isHide ? "hide" : "unhide"));
        }
Exemple #21
0
        /// <summary>
        /// 根据ID得到一个竞赛实体
        /// </summary>
        /// <param name="id">竞赛ID</param>
        /// <returns>竞赛实体</returns>
        public static ContestEntity GetContest(Int32 id)
        {
            if (id < ContestRepository.NONECONTEST)
            {
                throw new InvalidRequstException(RequestType.Contest);
            }

            ContestEntity contest = ContestCache.GetContestCache(id);//获取缓存

            if (contest == null)
            {
                contest = ContestRepository.Instance.GetEntity(id);
                ContestCache.SetContestCache(contest);//设置缓存
            }

            if (contest == null)
            {
                throw new NullResponseException(RequestType.Contest);
            }

            if (contest.IsHide && !AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException("You have no privilege to view the contest!");
            }

            return(contest);
        }
Exemple #22
0
        /// <summary>
        /// 重置用户密码
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="passWord">新密码</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminResetUserPassword(String userName, String passWord)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

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

            if (String.IsNullOrEmpty(passWord))
            {
                return(MethodResult.FailedAndLog("New password can not be NULL!"));
            }
            else
            {
                passWord = PassWordEncrypt.Encrypt(userName, passWord);
            }

            Boolean success = UserRepository.Instance.UpdateEntityPassword(userName, passWord) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No user's password was reset!"));
            }

            return(MethodResult.SuccessAndLog("User reset password, name = {0}", userName));
        }
Exemple #23
0
        /// <summary>
        /// 保存单个文件到磁盘
        /// </summary>
        /// <param name="fileContent">文件内容</param>
        /// <param name="fileNewName">文件新名称</param>
        /// <returns>是否保存成功</returns>
        internal static Boolean InternalAdminSaveUploadFile(Byte[] fileContent, String fileNewName)
        {
            if (!AdminManager.HasPermission(PermissionType.Administrator))
            {
                throw new NoPermissionException();
            }

            if (String.IsNullOrEmpty(fileNewName))
            {
                throw new InvalidInputException("Filename can not be NULL!");
            }

            FileInfo fi = new FileInfo(fileNewName);

            if (!UploadsManager.CheckFileExtension(fi.Extension, ALLOW_EXTENSTIONS))
            {
                throw new InvalidInputException("Filename is INVALID!");
            }

            String savePath = Path.Combine(ConfigurationManager.UploadDirectoryPath, fileNewName);

            if (File.Exists(savePath))
            {
                throw new InvalidInputException("Filename exists!");
            }

            File.WriteAllBytes(savePath, fileContent);

            return(true);
        }
Exemple #24
0
        /// <summary>
        /// 获取上传文件数量
        /// </summary>
        /// <returns>上传文件数量</returns>
        private static Int32 AdminCountUploadFiles()
        {
            if (!AdminManager.HasPermission(PermissionType.Administrator))
            {
                throw new NoPermissionException();
            }

            String[] files = Directory.GetFiles(ConfigurationManager.UploadDirectoryPath);

            return(files.Length);
        }
Exemple #25
0
        /// <summary>
        /// 获取提交统计信息
        /// </summary>
        /// <param name="dateTime">所在月日期</param>
        /// <param name="ACOnly">是否仅有AC题目</param>
        /// <returns>提交统计信息</returns>
        public static IDictionary <Int32, Int32> AdminGetMonthlySubmitStatus(DateTime dateTime, Boolean ACOnly)
        {
            if (!AdminManager.HasPermission(PermissionType.Administrator))
            {
                throw new NoPermissionException();
            }

            DateTime dayStart = dateTime.AddDays(1 - dateTime.Day);

            return(SolutionRepository.Instance.GetSubmitStatus(dayStart, dayStart.AddMonths(1), ACOnly));
        }
        /// <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));
        }
Exemple #27
0
        /// <summary>
        /// 更新竞赛信息
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateContest(ContestEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return(MethodResult.FailedAndLog("Contest title cannot be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Description))
            {
                return(MethodResult.FailedAndLog("Contest description cannot be NULL!"));
            }

            if (entity.StartTime >= entity.EndTime)
            {
                return(MethodResult.FailedAndLog("Start time must be less than end time!"));
            }

            if (entity.ContestType == ContestType.RegisterPrivate || entity.ContestType == ContestType.RegisterPublic)
            {
                if (!entity.RegisterStartTime.HasValue || !entity.RegisterEndTime.HasValue)
                {
                    return(MethodResult.FailedAndLog("Register time cannot be NULL!"));
                }

                if (entity.RegisterStartTime >= entity.RegisterEndTime)
                {
                    return(MethodResult.FailedAndLog("Register start time must be less than register end time!"));
                }

                if (entity.RegisterEndTime >= entity.StartTime)
                {
                    return(MethodResult.FailedAndLog("Register end time must be less than contest start time!"));
                }
            }

            entity.LastDate = DateTime.Now;

            Boolean success = ContestRepository.Instance.UpdateEntity(entity) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No contest was updated!"));
            }

            ContestCache.RemoveContestCache(entity.ContestID); //删除缓存
            ContestCache.RemoveContestListCountCache();        //删除缓存

            return(MethodResult.SuccessAndLog("Admin update contest, id = {0}", entity.ContestID.ToString()));
        }
Exemple #28
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));
        }
Exemple #29
0
        /// <summary>
        /// 获取上传文件预览Url
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <returns>上传文件真实路径</returns>
        public static String AdminPreviewUploadFileUrl(String fileName)
        {
            if (!AdminManager.HasPermission(PermissionType.Administrator))
            {
                throw new NoPermissionException();
            }

            String fileUrl = String.Format("{0}{1}", ConfigurationManager.UploadDirectoryUrl, fileName);

            return(fileUrl);
        }
Exemple #30
0
        /// <summary>
        /// 增加一条提交
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <param name="userip">用户IP</param>
        /// <returns>是否成功增加</returns>
        public static Boolean InsertSolution(SolutionEntity entity, String userip)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

            if (String.IsNullOrEmpty(entity.SourceCode) || entity.SourceCode.Length < SolutionRepository.SOURCECODE_MINLEN)
            {
                throw new InvalidInputException("Code is too short!");
            }

            if (entity.SourceCode.Length > SolutionRepository.SOURCECODE_MAXLEN)
            {
                throw new InvalidInputException("Code is too long!");
            }

            if (LanguageType.IsNull(entity.LanguageType))
            {
                throw new InvalidInputException("Language Type is INVALID!");
            }

            if (!UserSubmitStatus.CheckLastSubmitSolutionTime(UserManager.CurrentUserName))
            {
                throw new InvalidInputException(String.Format("You can not submit code more than twice in {0} seconds!", ConfigurationManager.SubmitInterval.ToString()));
            }

            ProblemEntity problem = ProblemManager.InternalGetProblemModel(entity.ProblemID);

            if (problem == null)//判断题目是否存在
            {
                throw new NullResponseException(RequestType.Problem);
            }

            if (entity.ContestID <= 0 && problem.IsHide && !AdminManager.HasPermission(PermissionType.ProblemManage))//非竞赛下判断是否有权访问题目
            {
                throw new NoPermissionException("You have no privilege to submit the problem!");
            }

            entity.UserName   = UserManager.CurrentUserName;
            entity.SubmitTime = DateTime.Now;
            entity.SubmitIP   = userip;

            Boolean success = SolutionRepository.Instance.InsertEntity(entity) > 0;

            if (success)
            {
                ProblemCache.UpdateProblemCacheSubmitCount(entity.ProblemID, -1);//更新缓存
                SolutionCache.RemoveProblemIDListCache(entity.UserName, true);
            }

            return(success);
        }