Skip to content

Commit d8a3d0c

Browse files
committed
Added information about file size limits and allowed file extensions (when binary files are submitted)
1 parent b9a618a commit d8a3d0c

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

Open Judge System/Web/OJS.Web/Areas/Contests/Controllers/CompeteController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ public ActionResult Submit(SubmissionModel participantSubmission, bool official)
288288
// TODO: Extract common logic between SubmitBinaryFile() and Submit()
289289
public ActionResult SubmitBinaryFile(BinarySubmissionModel participantSubmission, bool official)
290290
{
291+
if (participantSubmission == null || participantSubmission.File == null)
292+
{
293+
throw new HttpException((int)HttpStatusCode.BadRequest, "Please upload file.");
294+
}
295+
291296
var problem = this.Data.Problems.All().FirstOrDefault(x => x.Id == participantSubmission.ProblemId);
292297
if (problem == null)
293298
{
@@ -460,6 +465,7 @@ public ActionResult GetAllowedSubmissionTypes(int id)
460465
Value = x.Id.ToString(CultureInfo.InvariantCulture),
461466
Selected = x.IsSelectedByDefault,
462467
x.AllowBinaryFilesUpload,
468+
x.AllowedFileExtensions,
463469
});
464470

465471
return this.Json(submissionTypesSelectListItems, JsonRequestBehavior.AllowGet);

Open Judge System/Web/OJS.Web/Areas/Contests/ViewModels/Contests/ContestProblemViewModel.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class ContestProblemViewModel
1313

1414
private int timeLimitInMs;
1515

16+
private int? fileSizeLimitInBytes;
17+
1618
public ContestProblemViewModel(Problem problem)
1719
{
1820
this.ProblemId = problem.Id;
@@ -25,6 +27,7 @@ public ContestProblemViewModel(Problem problem)
2527
.Select(ContestProblemResourceViewModel.FromResource);
2628
this.TimeLimit = problem.TimeLimit;
2729
this.MemoryLimit = problem.MemoryLimit;
30+
this.FileSizeLimit = problem.SourceCodeSizeLimit;
2831
this.CheckerName = problem.Checker.Name;
2932
this.CheckerDescription = problem.Checker.Description;
3033
}
@@ -34,6 +37,7 @@ public ContestProblemViewModel()
3437
this.Resources = new HashSet<ContestProblemResourceViewModel>();
3538
}
3639

40+
// TODO: Constructor and this static property have the same code. Refactor.
3741
public static Expression<Func<Problem, ContestProblemViewModel>> FromProblem
3842
{
3943
get
@@ -45,6 +49,7 @@ public static Expression<Func<Problem, ContestProblemViewModel>> FromProblem
4549
ContestId = problem.ContestId,
4650
MemoryLimit = problem.MemoryLimit,
4751
TimeLimit = problem.TimeLimit,
52+
FileSizeLimit = problem.SourceCodeSizeLimit,
4853
ShowResults = problem.ShowResults,
4954
CheckerName = problem.Checker.Name,
5055
CheckerDescription = problem.Checker.Description,
@@ -89,6 +94,24 @@ public double TimeLimit
8994
this.timeLimitInMs = (int)value;
9095
}
9196
}
97+
98+
public double? FileSizeLimit
99+
{
100+
get
101+
{
102+
if (!this.fileSizeLimitInBytes.HasValue)
103+
{
104+
return null;
105+
}
106+
107+
return (double)this.fileSizeLimitInBytes / 1024;
108+
}
109+
110+
set
111+
{
112+
this.fileSizeLimitInBytes = (int?)value;
113+
}
114+
}
92115

93116
public string CheckerName { get; set; }
94117

Open Judge System/Web/OJS.Web/Areas/Contests/ViewModels/Submissions/SubmissionDetailsViewModel.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static Expression<Func<Submission, SubmissionDetailsViewModel>> FromSubmi
2121
UserName = submission.Participant.User.UserName,
2222
CompilerComment = submission.CompilerComment,
2323
Content = submission.Content,
24+
FileExtension = submission.FileExtension,
2425
CreatedOn = submission.CreatedOn,
2526
IsCompiledSuccessfully = submission.IsCompiledSuccessfully,
2627
IsDeleted = submission.IsDeleted,
@@ -49,12 +50,27 @@ public static Expression<Func<Submission, SubmissionDetailsViewModel>> FromSubmi
4950

5051
public string CompilerComment { get; set; }
5152

53+
public string FileExtension { get; set; }
54+
5255
public byte[] Content { get; set; }
5356

57+
public bool IsBinaryFile
58+
{
59+
get
60+
{
61+
return !string.IsNullOrWhiteSpace(this.FileExtension);
62+
}
63+
}
64+
5465
public string ContentAsString
5566
{
5667
get
5768
{
69+
if (this.IsBinaryFile)
70+
{
71+
return "Binary file.";
72+
}
73+
5874
return this.Content.Decompress();
5975
}
6076
}

Open Judge System/Web/OJS.Web/Areas/Contests/Views/Shared/_ProblemPartial.cshtml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,26 @@
8787
{
8888
@Html.HiddenFor(x => x.ProblemId)
8989
<div id="submisionDataFields">
90-
<textarea class="code-for-problem" id="[email protected]" name="Content"></textarea>
91-
@(Html.Kendo().Upload().Name("File").Multiple(false).ShowFileList(true).HtmlAttributes(new { id = "file-problem-" + Model.ProblemId }))
90+
<div id="[email protected]">
91+
<textarea class="code-for-problem" id="[email protected]" name="Content"></textarea>
92+
</div>
93+
<div id="[email protected]">
94+
@(Html.Kendo().Upload().Name("File").Multiple(false).ShowFileList(true).HtmlAttributes(new { id = "file-problem-" + Model.ProblemId }))
95+
<div id="[email protected]"></div>
96+
</div>
9297
</div>
9398
<div class="col-md-12">
9499
<div class="pull-left submit-container">
95100
<strong>@Resource.Allowed_working_time:</strong> @string.Format("{0:0.00}", Model.TimeLimit) sec.
96101
<br />
97102
<strong>@Resource.Allowed_memory:</strong> @string.Format("{0:0.00}", Model.MemoryLimit) MB
98103
<br />
104+
@if (Model.FileSizeLimit.HasValue)
105+
{
106+
<strong>Size limit:</strong> @(string.Format("{0:0.00}", Model.FileSizeLimit.Value)) @:KB
107+
<br />
108+
}
109+
99110
<strong>Checker:</strong> @Model.CheckerName <span class="glyphicon glyphicon-question-sign" id="checkers-tooltip"></span>
100111
@if (!string.IsNullOrWhiteSpace(Model.CheckerDescription))
101112
{
@@ -108,14 +119,16 @@
108119
var index = this.selectedIndex;
109120
var dataItem = this.dataItem(index);
110121
var form = $("#[email protected]");
111-
var fileUpload = $("#[email protected]").data("kendoUpload").wrapper;
112-
var codeArea = $($("#[email protected]").data('CodeMirrorInstance').getWrapperElement());
122+
var fileUpload = $("#[email protected]");
123+
var codeArea = $("#[email protected]");
124+
var fileExtensionsInfo = $("#[email protected]");
113125
114126
if (dataItem.AllowBinaryFilesUpload) {
115127
form.attr("action", form.attr("action").replace("/Submit/", "/SubmitBinaryFile/"));
116128
form.attr("data-ajax", "false");
117129
fileUpload.show();
118130
codeArea.hide();
131+
fileExtensionsInfo.html("<b>Allowed file extensions:</b> " + dataItem.AllowedFileExtensions);
119132
} else {
120133
form.attr("action", form.attr("action").replace("/SubmitBinaryFile/", "/Submit/"));
121134
form.attr("data-ajax", "true");

0 commit comments

Comments
 (0)