Esempio n. 1
0
        private SystemMessageCollection PrepareSystemMessages()
        {
            // Warning: always escape data to prevent XSS
            var messages = new SystemMessageCollection();

            if (this.TempData.ContainsKey(GlobalConstants.InfoMessage))
            {
                messages.Add(this.TempData[GlobalConstants.InfoMessage].ToString(), SystemMessageType.Informational, 1000);
            }

            if (this.TempData.ContainsKey(GlobalConstants.DangerMessage))
            {
                messages.Add(this.TempData[GlobalConstants.DangerMessage].ToString(), SystemMessageType.Error, 1000);
            }

            if (this.TempData.ContainsKey(GlobalConstants.WariningMessage))
            {
                messages.Add(this.TempData[GlobalConstants.WariningMessage].ToString(), SystemMessageType.Warning, 1000);
            }

            if (this.TempData.ContainsKey(GlobalConstants.SuccessMessage))
            {
                messages.Add(this.TempData[GlobalConstants.SuccessMessage].ToString(), SystemMessageType.Success, 1000);
            }

            return(messages);
        }
Esempio n. 2
0
        private SystemMessageCollection PrepareSystemMessages()
        {
            // Warning: always escape data to prevent XSS
            var messages = new SystemMessageCollection();

            if (this.TempData.ContainsKey(GlobalConstants.InfoMessage))
            {
                messages.Add(this.TempData[GlobalConstants.InfoMessage].ToString(), SystemMessageType.Success, 1000);
            }

            if (this.TempData.ContainsKey(GlobalConstants.DangerMessage))
            {
                messages.Add(this.TempData[GlobalConstants.DangerMessage].ToString(), SystemMessageType.Error, 1000);
            }

            if (this.UserProfile != null)
            {
                if (this.UserProfile.PasswordHash == null)
                {
                    messages.Add(Resources.Base.Main.Password_not_set, SystemMessageType.Warning, 0);
                }

                if (!Regex.IsMatch(this.UserProfile.UserName, "^[a-zA-Z]([/._]?[a-zA-Z0-9]+)+$") || this.UserProfile.UserName.Length < 5 || this.UserProfile.UserName.Length > 15)
                {
                    messages.Add(Resources.Base.Main.Username_in_invalid_format, SystemMessageType.Warning, 0);
                }
            }

            return(messages);
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Grid"/> class.
 /// </summary>
 public Grid()
 {
     m_DebugString    = new StringBuilder(string.Empty);
     m_SystemMessages = new SystemMessageCollection(this, SystemMessageStyle.WebGrid);
     MasterTable      = new Table(this);
     m_DesignRender   = new DesignRender(this);
     m_GridTrace      = new GridTrace(this);
     m_PagerSettings  = new Pager(this);
 }
Esempio n. 4
0
        private void SystemMessageCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            ErrorCount = SystemMessageCollection.Count();
            var collect = from msg in SystemMessageCollection where msg.MsgType == EnumMessageType.Error select msg;

            if (collect != null)
            {
                StrTotalError = $"Infomation ({collect.Count()}) Error";
            }
        }
Esempio n. 5
0
        private void ShowError(string strMsg)
        {
            lock (_msgLock)
            {
                SystemMessageCollection.Add(new MessageItem()
                {
                    MsgType = EnumMessageType.Error,
                    StrMsg  = strMsg
                });

                if (SystemMessageCollection.Count > 20)
                {
                    SystemMessageCollection.RemoveAt(0);
                }
            }
        }
Esempio n. 6
0
        public ActionResult Create(int id, HttpPostedFileBase testArchive, DetailedProblemViewModel problem)
        {
            if (problem.Resources != null && problem.Resources.Any())
            {
                var validResources = problem.Resources
                                     .All(res => !string.IsNullOrEmpty(res.Name) &&
                                          ((res.Type == ProblemResourceType.AuthorsSolution && res.File != null && res.File.ContentLength > 0) ||
                                           (res.Type == ProblemResourceType.ProblemDescription && res.File != null && res.File.ContentLength > 0) ||
                                           (res.Type == ProblemResourceType.Video && !string.IsNullOrEmpty(res.Link))));

                if (!validResources)
                {
                    this.ModelState.AddModelError("Resources", GlobalResource.Resources_not_complete);
                }
            }

            if (this.ModelState.IsValid)
            {
                var newProblem = new Problem
                {
                    Name                 = problem.Name,
                    ContestId            = id,
                    MaximumPoints        = problem.MaximumPoints,
                    MemoryLimit          = problem.MemoryLimit,
                    TimeLimit            = problem.TimeLimit,
                    SourceCodeSizeLimit  = problem.SourceCodeSizeLimit,
                    ShowResults          = problem.ShowResults,
                    ShowDetailedFeedback = problem.ShowDetailedFeedback,
                    OrderBy              = problem.OrderBy,
                    Checker              = this.Data.Checkers.All().FirstOrDefault(x => x.Name == problem.Checker)
                };

                if (problem.Resources != null && problem.Resources.Any())
                {
                    this.AddResourcesToProblem(newProblem, problem.Resources);
                }

                if (testArchive != null && testArchive.ContentLength != 0)
                {
                    try
                    {
                        this.AddTestsToProblem(newProblem, testArchive);
                    }
                    catch (Exception ex)
                    {
                        // TempData is not working with return this.View
                        var systemMessages = new SystemMessageCollection
                        {
                            new SystemMessage
                            {
                                Content    = ex.Message,
                                Type       = SystemMessageType.Error,
                                Importance = 0
                            }
                        };
                        this.ViewBag.SystemMessages = systemMessages;
                        problem.AvailableCheckers   = this.Data.Checkers.All().Select(checker => new SelectListItem {
                            Text = checker.Name, Value = checker.Name
                        });
                        return(this.View(problem));
                    }
                }

                this.Data.Problems.Add(newProblem);
                this.Data.SaveChanges();

                this.TempData.AddInfoMessage(GlobalResource.Problem_added);
                return(this.RedirectToAction("Contest", new { id }));
            }

            problem.AvailableCheckers = this.Data.Checkers.All().Select(checker => new SelectListItem {
                Text = checker.Name, Value = checker.Name
            });

            return(this.View(problem));
        }
        private SystemMessageCollection PrepareSystemMessages()
        {
            // Warning: always escape data to prevent XSS
            var messages = new SystemMessageCollection();

            if (this.TempData.ContainsKey("InfoMessage"))
            {
                messages.Add(this.TempData["InfoMessage"].ToString(), SystemMessageType.Success, 1000);
            }

            if (this.TempData.ContainsKey("DangerMessage"))
            {
                messages.Add(this.TempData["DangerMessage"].ToString(), SystemMessageType.Error, 1000);
            }

            if (this.UserProfile != null)
            {
                if (this.UserProfile.PasswordHash == null)
                {
                    messages.Add(Resources.Base.Main.Password_not_set, SystemMessageType.Warning, 0);
                }

                if (!Regex.IsMatch(this.UserProfile.UserName, "^[a-zA-Z]([/._]?[a-zA-Z0-9]+)+$") || this.UserProfile.UserName.Length < 5 || this.UserProfile.UserName.Length > 15)
                {
                    messages.Add(Resources.Base.Main.Username_in_invalid_format, SystemMessageType.Warning, 0);
                }
            }
            else
            {
                // User is not logged-in
                messages.Add(Resources.Base.Main.Welcome_to_the_new_bgcoder_and_change_password, SystemMessageType.Informational, 2000);
            }

            return messages;
        }
        public ActionResult Create(int id, HttpPostedFileBase testArchive, DetailedProblemViewModel problem)
        {
            if (problem.Resources != null && problem.Resources.Any())
            {
                var validResources = problem.Resources
                .All(res => !string.IsNullOrEmpty(res.Name) &&
                    ((res.Type == ProblemResourceType.AuthorsSolution && res.File != null && res.File.ContentLength > 0) ||
                    (res.Type == ProblemResourceType.ProblemDescription && res.File != null && res.File.ContentLength > 0) ||
                    (res.Type == ProblemResourceType.Video && !string.IsNullOrEmpty(res.Link))));

                if (!validResources)
                {
                    this.ModelState.AddModelError("Resources", GlobalResource.Resources_not_complete);
                }
            }

            if (this.ModelState.IsValid)
            {
                var newProblem = new Problem
                {
                    Name = problem.Name,
                    ContestId = id,
                    MaximumPoints = problem.MaximumPoints,
                    MemoryLimit = problem.MemoryLimit,
                    TimeLimit = problem.TimeLimit,
                    SourceCodeSizeLimit = problem.SourceCodeSizeLimit,
                    ShowResults = problem.ShowResults,
                    ShowDetailedFeedback = problem.ShowDetailedFeedback,
                    OrderBy = problem.OrderBy,
                    Checker = this.Data.Checkers.All().FirstOrDefault(x => x.Name == problem.Checker)
                };

                if (problem.Resources != null && problem.Resources.Any())
                {
                    this.AddResourcesToProblem(newProblem, problem.Resources);
                }

                if (testArchive != null && testArchive.ContentLength != 0)
                {
                    try
                    {
                        this.AddTestsToProblem(newProblem, testArchive);
                    }
                    catch (Exception ex)
                    {
                        // TempData is not working with return this.View
                        var systemMessages = new SystemMessageCollection
                                {
                                    new SystemMessage
                                    {
                                        Content = ex.Message,
                                        Type = SystemMessageType.Error,
                                        Importance = 0
                                    }
                                };
                        this.ViewBag.SystemMessages = systemMessages;
                        problem.AvailableCheckers = this.Data.Checkers.All().Select(checker => new SelectListItem { Text = checker.Name, Value = checker.Name });
                        return this.View(problem);
                    }
                }

                this.Data.Problems.Add(newProblem);
                this.Data.SaveChanges();

                this.TempData.AddInfoMessage(GlobalResource.Problem_added);
                return this.RedirectToAction("Contest", new { id });
            }

            problem.AvailableCheckers = this.Data.Checkers.All().Select(checker => new SelectListItem { Text = checker.Name, Value = checker.Name });

            return this.View(problem);
        }
        public ActionResult Create(int id, ViewModelType problem)
        {
            if (!this.CheckIfUserHasContestPermissions(id))
            {
                return(this.RedirectToContestsAdminPanelWithNoPrivilegesMessage());
            }

            var contest = this.contestsData.GetById(id);

            if (contest == null)
            {
                this.TempData.AddDangerMessage(GlobalResource.Invalid_contest);
                return(this.RedirectToAction(c => c.Index()));
            }

            if (problem == null)
            {
                problem = this.PrepareProblemViewModelForCreate(contest);

                this.AddCheckersToProblemViewModel(problem);

                return(this.View(problem));
            }

            if (problem.Resources != null && problem.Resources.Any())
            {
                var validResources = problem.Resources
                                     .All(res => !string.IsNullOrEmpty(res.Name) &&
                                          ((res.Type == ProblemResourceType.AuthorsSolution && res.File != null && res.File.ContentLength > 0) ||
                                           (res.Type == ProblemResourceType.ProblemDescription && res.File != null && res.File.ContentLength > 0) ||
                                           (res.Type == ProblemResourceType.Link && !string.IsNullOrEmpty(res.Link))));

                if (!validResources)
                {
                    this.ModelState.AddModelError("Resources", GlobalResource.Resources_not_complete);
                }
            }

            if (problem.AdditionalFiles != null && problem.AdditionalFiles.ContentLength != 0)
            {
                this.ValidateUploadedFile(nameof(problem.AdditionalFiles), problem.AdditionalFiles);
            }

            if (problem.Tests != null && problem.Tests.ContentLength != 0)
            {
                this.ValidateUploadedFile(nameof(problem.Tests), problem.Tests);
            }

            if (!this.IsValidProblem(problem) || !this.ModelState.IsValid)
            {
                this.AddCheckersToProblemViewModel(problem);
                return(this.View(problem));
            }

            var newProblem = problem.GetEntityModel();

            newProblem.Checker = this.checkersData.GetByName(problem.Checker);

            problem.SubmissionTypes.ForEach(s =>
            {
                if (s.IsChecked && s.Id.HasValue)
                {
                    var submission = this.submissionTypesData.GetById(s.Id.Value);
                    newProblem.SubmissionTypes.Add(submission);
                }
            });

            if (problem.SolutionSkeletonData != null && problem.SolutionSkeletonData.Any())
            {
                newProblem.SolutionSkeleton = problem.SolutionSkeletonData;
            }

            if (problem.Resources != null && problem.Resources.Any())
            {
                this.AddResourcesToProblem(newProblem, problem.Resources);
            }

            if (problem.AdditionalFiles != null && problem.AdditionalFiles.ContentLength != 0)
            {
                newProblem.AdditionalFiles = problem.AdditionalFiles.ToByteArray();
            }

            if (problem.Tests != null && problem.Tests.ContentLength != 0)
            {
                try
                {
                    this.AddTestsToProblem(newProblem, problem.Tests);
                }
                catch (Exception ex)
                {
                    // TempData is not working with return this.View
                    var systemMessages = new SystemMessageCollection
                    {
                        new SystemMessage
                        {
                            Content    = string.Format(GlobalResource.Tests_cannot_be_improrted, ex.Message),
                            Type       = SystemMessageType.Error,
                            Importance = 0
                        }
                    };

                    this.ViewBag.SystemMessages = systemMessages;

                    this.AddCheckersToProblemViewModel(problem);

                    return(this.View(problem));
                }
            }

            if (newProblem.ProblemGroupId == default(int))
            {
                newProblem.ProblemGroup = new ProblemGroup
                {
                    ContestId = contest.Id,
                    OrderBy   = newProblem.OrderBy,
                    Type      = ((ProblemGroupType?)problem.ProblemGroupType).GetValidTypeOrNull()
                };
            }

            this.problemsData.Add(newProblem);

            this.TempData.AddInfoMessage(GlobalResource.Problem_added);
            return(this.RedirectToAction("Problem", "Tests", new { newProblem.Id }));
        }
Esempio n. 10
0
        private SystemMessageCollection PrepareSystemMessages()
        {
            // Warning: always escape data to prevent XSS
            var messages = new SystemMessageCollection();

            if (this.TempData.ContainsKey("InfoMessage"))
            {
                messages.Add(this.TempData["InfoMessage"].ToString(), SystemMessageType.Success, 1000);
            }

            if (this.TempData.ContainsKey("DangerMessage"))
            {
                messages.Add(this.TempData["DangerMessage"].ToString(), SystemMessageType.Error, 1000);
            }

            if (this.UserProfile != null)
            {
                if (this.UserProfile.PasswordHash == null)
                {
                    messages.Add("Нямате парола за вход в сайта. Моля сложете си парола от <a href=\"/Account/Manage\">този линк</a>.", SystemMessageType.Warning, 0);
                }

                if (!Regex.IsMatch(this.UserProfile.UserName, "^[a-zA-Z]([/._]?[a-zA-Z0-9]+)+$"))
                {
                    messages.Add("Вашето потребителско име съдържа непозволени символи. Можете да я смените от <a href=\"/Account/ChangeUsername\">този линк</a>.", SystemMessageType.Warning, 0);
                }
            }

            return messages;
        }
Esempio n. 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Grid"/> class.
 /// </summary>
 public Grid()
 {
     m_DebugString = new StringBuilder(string.Empty);
     m_SystemMessages = new SystemMessageCollection(this, SystemMessageStyle.WebGrid);
     MasterTable = new Table(this);
     m_DesignRender = new DesignRender(this);
     m_GridTrace = new GridTrace(this);
     m_PagerSettings = new Pager(this);
 }
Esempio n. 12
0
        public ActionResult Create(int id, DetailedProblemViewModel problem)
        {
            if (!this.CheckIfUserHasContestPermissions(id))
            {
                this.TempData.AddDangerMessage(GlobalConstants.NoPrivilegesMessage);
                return(this.RedirectToAction("Index", "Contests", new { area = "Administration" }));
            }

            var contest = this.Data.Contests.All().FirstOrDefault(x => x.Id == id);

            if (contest == null)
            {
                this.TempData.AddDangerMessage(GlobalResource.Invalid_contest);
                return(this.RedirectToAction(nameof(this.Index)));
            }

            if (problem == null)
            {
                problem = this.PrepareProblemViewModelForCreate(contest);
                problem.AvailableCheckers = this.Data.Checkers.All()
                                            .Select(checker => new SelectListItem
                {
                    Text  = checker.Name,
                    Value = checker.Name
                });
                return(this.View(problem));
            }

            if (problem.Resources != null && problem.Resources.Any())
            {
                var validResources = problem.Resources
                                     .All(res => !string.IsNullOrEmpty(res.Name) &&
                                          ((res.Type == ProblemResourceType.AuthorsSolution && res.File != null && res.File.ContentLength > 0) ||
                                           (res.Type == ProblemResourceType.ProblemDescription && res.File != null && res.File.ContentLength > 0) ||
                                           (res.Type == ProblemResourceType.Link && !string.IsNullOrEmpty(res.Link))));

                if (!validResources)
                {
                    this.ModelState.AddModelError("Resources", GlobalResource.Resources_not_complete);
                }
            }

            if (problem.AdditionalFiles != null && problem.AdditionalFiles.ContentLength != 0)
            {
                this.ValidateUploadedFile(nameof(problem.AdditionalFiles), problem.AdditionalFiles);
            }

            if (problem.Tests != null && problem.Tests.ContentLength != 0)
            {
                this.ValidateUploadedFile(nameof(problem.Tests), problem.Tests);
            }

            if (!this.IsValidProblem(problem) || !this.ModelState.IsValid)
            {
                problem.AvailableCheckers = this.Data.Checkers.All()
                                            .Select(checker => new SelectListItem {
                    Text = checker.Name, Value = checker.Name
                });
                return(this.View(problem));
            }

            var newProblem = problem.GetEntityModel();

            newProblem.Checker = this.Data.Checkers.All().FirstOrDefault(x => x.Name == problem.Checker);

            problem.SubmissionTypes.ForEach(s =>
            {
                if (s.IsChecked)
                {
                    var submission = this.Data.SubmissionTypes.All().FirstOrDefault(t => t.Id == s.Id);
                    newProblem.SubmissionTypes.Add(submission);
                }
            });

            if (problem.SolutionSkeletonData != null && problem.SolutionSkeletonData.Any())
            {
                newProblem.SolutionSkeleton = problem.SolutionSkeletonData;
            }

            if (problem.Resources != null && problem.Resources.Any())
            {
                this.AddResourcesToProblem(newProblem, problem.Resources);
            }

            if (problem.AdditionalFiles != null && problem.AdditionalFiles.ContentLength != 0)
            {
                newProblem.AdditionalFiles = problem.AdditionalFiles.ToByteArray();
            }

            if (problem.Tests != null && problem.Tests.ContentLength != 0)
            {
                try
                {
                    this.AddTestsToProblem(newProblem, problem.Tests);
                }
                catch (Exception ex)
                {
                    // TempData is not working with return this.View
                    var systemMessages = new SystemMessageCollection
                    {
                        new SystemMessage
                        {
                            Content    = ex.Message,
                            Type       = SystemMessageType.Error,
                            Importance = 0
                        }
                    };
                    this.ViewBag.SystemMessages = systemMessages;
                    problem.AvailableCheckers   = this.Data.Checkers.All()
                                                  .Select(checker => new SelectListItem
                    {
                        Text  = checker.Name,
                        Value = checker.Name
                    });
                    return(this.View(problem));
                }
            }

            this.Data.Problems.Add(newProblem);
            this.Data.SaveChanges();

            this.TempData.AddInfoMessage(GlobalResource.Problem_added);
            return(this.RedirectToAction("Problem", "Tests", new { newProblem.Id }));
        }