public static void SaveToFileSystem(SubmitEvent submit) { using (var zipStream = new MemoryStream()) { zipStream.Write(submit.SolutionData, 0, submit.SolutionData.Length); zipStream.Position = 0; using ( var connection = new SqlConnection(StringConstants.ConnectionString)) { var teamId = connection.Query <int>("dbo.GetAssignmentTeam", new { assignmentId = submit.AssignmentId, userId = submit.SenderId }, commandType: CommandType.StoredProcedure).SingleOrDefault(); int timezoneOffset = connection.Query <int>("SELECT ISNULL(TimeZoneOffset, -8) FROM AbstractCourses WHERE ID = @courseId ", new { courseId = submit.CourseId }).SingleOrDefault(); TimeZoneInfo tzInfo = GetTimeZone(timezoneOffset); DateTime utcKind = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); DateTime submitTimeStamp = TimeZoneInfo.ConvertTimeFromUtc(utcKind, tzInfo); try { string submitTimestampInCourseTime = submitTimeStamp.ToString("MM-dd-yyyy-HH-mm-ss"); OSBLE.Models.FileSystem.Directories.GetAssignmentWithId(submit.CourseId ?? 1 , submit.AssignmentId, teamId).AddFile(string.Format("{0}-{1}.zip", submit.Sender.FullName, submitTimestampInCourseTime), zipStream); } catch (ZipException ze) { throw new Exception("SaveToFileSystem() failure...", ze); } } } }
private void ForwardClicked(object o, EventArgs e) { PaymentMethod selectedPaymentMethod = PaymentMethod.CARD_ONLINE; switch (choiceList.SelectedItem?.ToString()) { case "Картой online": selectedPaymentMethod = PaymentMethod.CARD_ONLINE; break; case "Картой при получении": selectedPaymentMethod = PaymentMethod.CARD_UPON_RECEIPT; break; case "Наличными при получении": selectedPaymentMethod = PaymentMethod.CASH_UPON_RECEIPT; break; } if (choiceList.SelectedItem == null) { selectedPaymentMethod = PaymentMethod.NOT_SELECTED; } SubmitEvent?.Invoke(selectedPaymentMethod); }
/// <summary> /// Called when the user selects the "submit assignment" menu option /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SubmitAssignmentCallback(object sender, EventArgs e) { IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); Guid clsid = Guid.Empty; SubmitEvent evt = new SubmitEvent(); DTE2 dte = (DTE2)this.GetService(typeof(SDTE)); if (dte.Solution.FullName.Length == 0) { MessageBox.Show("No solution is currently open."); return; } object cacheItem = _cache[StringConstants.AuthenticationCacheKey]; if (cacheItem != null && string.IsNullOrEmpty(cacheItem.ToString()) == false) { evt.SolutionName = dte.Solution.FullName; SubmitAssignmentViewModel vm = new SubmitAssignmentViewModel( _cache[StringConstants.UserNameCacheKey] as string, _cache[StringConstants.AuthenticationCacheKey] as string, evt ); MessageBoxResult result = SubmitAssignmentWindow.ShowModalDialog(vm); //assume that data was changed and needs to be saved if (result == MessageBoxResult.OK) { } } else { MessageBox.Show("You must be logged into OSBIDE in order to submit an assignment."); } }
public void SubmitClicked(object o, EventArgs e) { if (string.IsNullOrEmpty(address.Text)) { address.PlaceholderColor = Color.Red; return; } if (string.IsNullOrEmpty(street.Text)) { street.PlaceholderColor = Color.Red; return; } if (string.IsNullOrEmpty(house.Text)) { house.PlaceholderColor = Color.Red; return; } if (string.IsNullOrEmpty(entrance.Text)) { entrance.PlaceholderColor = Color.Red; return; } if (string.IsNullOrEmpty(floor.Text)) { floor.PlaceholderColor = Color.Red; return; } if (string.IsNullOrEmpty(flat.Text)) { flat.PlaceholderColor = Color.Red; return; } if (string.IsNullOrEmpty(name.Text)) { name.PlaceholderColor = Color.Red; return; } if (string.IsNullOrEmpty(surname.Text)) { surname.PlaceholderColor = Color.Red; return; } if (string.IsNullOrEmpty(email.Text)) { email.PlaceholderColor = Color.Red; return; } if (string.IsNullOrEmpty(phoneNumber.Text)) { phoneNumber.PlaceholderColor = Color.Red; return; } Buyer buyer = new Buyer(address.Text, street.Text, house.Text, building.Text, entrance.Text, floor.Text, flat.Text, name.Text, surname.Text, email.Text, phoneNumber.Text, comment.Text); SubmitEvent?.Invoke(buyer); }
/// <summary> /// Saves the active word document and zips the file in the local directory. /// </summary> /// <param name="state"></param> /// <param name="course"></param> /// <param name="assignment"></param> /// <param name="doc"></param> /// <returns></returns> public static SaveResult Save(OSBLEState state, int courseId, int assignmentId, Document doc) { //if the document doesn't exist or contains changes then request the user to save if (!File.Exists(doc.FullName) || !doc.Saved) { return(new SaveResult(false, "Please save the current document before submitting.")); } string zipPath = null; byte[] zipData = null; //zip document try { zipPath = SaveFileToZip(state.FullName, doc); zipData = File.ReadAllBytes(zipPath); } catch (Exception e) { return(new SaveResult(true, "Failed to package document before sending to the server.")); } //package assignment information var submitevent = new SubmitEvent(); submitevent.AssignmentId = assignmentId; submitevent.CourseId = courseId; submitevent.SolutionData = zipData; HttpResponseMessage response = null; //call asynchronous web api helper function try { response = AsyncServiceClient.SubmitAssignment(submitevent, state.AuthToken).Result; } catch (Exception e) { return(new SaveResult(false, "Failed to submit document to the server.")); } if (response.IsSuccessStatusCode) { return(new SaveResult(true, null)); } else { return(new SaveResult(false, "The server failed to process the submission.")); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (this.grid_Root.BindingGroup.CommitEdit()) { if (this.SubmitEvent != null) { SubmitEvent.Invoke(this); } } else { MessageBox.Show("请填写正确的数据"); } }
private void button1_Click(object sender, RoutedEventArgs e) { BindingExpression b = this.textBox2.GetBindingExpression(TextBox.TextProperty); b.UpdateSource(); if (CommonHelper.GetUIElementError(this)) { MessageBox.Show("请输入正确的数据"); return; } if (SubmitEvent != null) { SubmitEvent.Invoke(this); } }
/// <summary> /// Asynchronous web api call to submit an assinment to the server. /// </summary> /// <param name="submitEvent">submitevent for the assignment to be submitted</param> /// <param name="authToken">authorization token</param> /// <returns>HttpResponseMessage</returns> public static async Task <HttpResponseMessage> SubmitAssignment(SubmitEvent submitEvent, string authToken) { using (var client = ServiceClient.GetClient()) { //package submitevent and authtoken within a SubmissionRequest var request = new SubmissionRequest { AuthToken = authToken, SubmitEvent = submitEvent, }; var response = await client.PostAsXmlAsync("api/course/post", request); return(response); } }
public static async Task <int> SubmitAssignment(SubmitEvent submitEvent, string authToken) { using (var client = GetClient()) { var request = new SubmissionRequest { AuthToken = authToken, SubmitEvent = submitEvent, }; var response = await client.PostAsXmlAsync("api/course/post", request); return(response.IsSuccessStatusCode ? JsonConvert.DeserializeObject <int>(response.Content.ReadAsStringAsync().Result) : 0); } }
public FileStreamResult DownloadStudentAssignment(int id) { //students can only download their own work SubmitEvent submit = Db.SubmitEvents.Where(s => s.EventLogId == id).FirstOrDefault(); if (submit != null && submit.EventLog.SenderId == CurrentUser.Id) { return(DownloadSingle(id)); } else { return(new FileStreamResult(new MemoryStream(), "application/zip") { FileDownloadName = "bad file" }); } }
public FileStreamResult DownloadSingle(int id) { MemoryStream stream = new MemoryStream(); SubmitEvent submit = Db.SubmitEvents.Where(s => s.EventLogId == id).FirstOrDefault(); string fileName = "bad download"; if (submit != null) { stream.Write(submit.SolutionData, 0, submit.SolutionData.Length); stream.Position = 0; fileName = string.Format("{0} - {1}.zip", submit.Assignment.Name, submit.EventLog.Sender.FullName); } return(new FileStreamResult(stream, "application/zip") { FileDownloadName = fileName }); }
public override void SolutionSubmitted(object sender, SubmitAssignmentArgs e) { base.SolutionSubmitted(sender, e); var submit = new SubmitEvent { AssignmentId = e.AssignmentId, SolutionName = string.Empty, }; submit.CreateSolutionBinary(submit.GetSolutionBinary()); //let others know that we have a new event NotifyEventCreated(this, new EventCreatedArgs(submit)); CheckInterventionStatus(); }
public SubmitAssignmentViewModel(string userName, string authToken, SubmitEvent submitEvent) { _authToken = authToken; _submitEvent = submitEvent; UserName = userName; SolutionName = Path.GetFileNameWithoutExtension(submitEvent.SolutionName); ContinueCommand = new DelegateCommand(Continue, CanIssueCommand); CancelCommand = new DelegateCommand(Cancel, CanIssueCommand); Assignments = new ObservableCollection <SubmisionAssignment>(); Courses = new ObservableCollection <ICourse>(); LastSubmitted = "N/A"; // load courses IsLoading = true; GetCoursesForUserAsync(authToken); }
//确定 private void Button_Click_1(object sender, RoutedEventArgs e) { BindingGroup bg = this.grid_Root.BindingGroup; foreach (var item in bg.BindingExpressions) { item.UpdateSource(); } if (CommonHelper.GetUIElementError(this)) { MessageBox.Show("请输入正确的数据"); return; } if (this.SubmitEvent != null) { SubmitEvent.Invoke(this); } }
// // Get latest submission time (if any) public DateTime LatestSubmissionTime(int assignmentId, int currentUserId) { //get the newest submit event for this assignment and user SubmitEvent submitEvent = Db.SubmitEvents .Where(se => se.AssignmentId == assignmentId) .Where(s => s.EventLog.SenderId == currentUserId) .OrderByDescending(se => se.EventLog.DateReceived) .FirstOrDefault(); if (submitEvent != null) { return(submitEvent.EventLog.DateReceived); } else { //return default date value return(new DateTime()); } }
private static async Task <bool> RunAsync() { using (var client = new HttpClient()) { client.BaseAddress = new Uri(StringConstants.DataServiceRoot); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); SubmitEvent temp = CreateSubmitEvent(); var request = new SubmissionRequest { AuthToken = "83-B6-77-B8-54-83-30-7D-0F-EE-68-38-6D-E7-42-5E-2A-D1-3A-72", SubmitEvent = temp, }; var response = await client.PostAsJsonAsync("api/course/post", request); return(response.IsSuccessStatusCode); } }
private void SubmitAssignmentCallback(object sender, EventArgs e) { var evt = new SubmitEvent(); var dte = (DTE2)GetService(typeof(SDTE)); dte.Solution.Projects.DTE.Documents.SaveAll(); var build = dte.Solution.SolutionBuild.BuildState; var result = MessageBox.Show(@"If you do not build your soultion, all your files may not be submitted, would you like to build? If not, you may still submit your assignment.", "", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { dte.Solution.SolutionBuild.Build(true); } if (dte.Solution.FullName.Length == 0) { MessageBox.Show(@"No solution is currently open."); return; } var cacheItem = _cache[StringConstants.AuthenticationCacheKey]; if (cacheItem != null && string.IsNullOrEmpty(cacheItem.ToString()) == false) { evt.SolutionName = dte.Solution.FullName; var vm = new SubmitAssignmentViewModel( _cache[StringConstants.UserNameCacheKey] as string, _cache[StringConstants.AuthenticationCacheKey] as string, evt ); SubmitAssignmentWindow.ShowModalDialog(vm); } else { MessageBox.Show(@"You must be logged into OSBLE+ in order to submit an assignment."); } }
private void button1_Click(object sender, EventArgs e) { var currentUserId = service.CurrentUserLoggedIn().ModelIdentity; string regTitle = TitleBoxSelector.Text, activityId = ActivityComboBoxSelector.Text, description = DescriptionBoxSelector.Text, Hours = HourBoxSelector.Text; if (!int.TryParse(Hours, out int hours)) { throw new ArgumentException("Something went wrong with conversion from string to int."); } var ParentActivity = service.Activity(activityId); var rObject = new HourRegistrationModel(regTitle, hours, currentUserId, description, ParentActivity); var sEvent = new SubmitEvent(rObject); Close(); }
public void CanPostSubmitEvent() { // Arrange var log = new SubmitEvent { SolutionName = "dummy submit solution", CourseId = 4, AssignmentId = 1, SenderId = 1, Sender = new User { FirstName = "Test", LastName = "User" } }; // Act var result = Posts.SaveEvent(log); // Assert using (var connection = new SqlConnection(StringConstants.ConnectionString)) { var savedlog = connection.Query <SubmitEvent>( @"select b.EventLogId, a.EventTypeId, a.SenderId, b.SolutionName, a.CourseId, b.AssignmentId from EventLogs a inner join SubmitEvents b on b.EventLogId=a.Id where a.Id=@id", new { @Id = result }).SingleOrDefault(); Assert.IsTrue(savedlog != null); Assert.IsTrue(savedlog.SenderId == log.SenderId); Assert.IsTrue(savedlog.EventType == log.EventType); Assert.IsTrue(savedlog.SolutionName == log.SolutionName); Assert.IsTrue(savedlog.CourseId == log.CourseId); Assert.IsTrue(savedlog.AssignmentId == log.AssignmentId); } }
public SubmitAssignmentViewModel(string userName, string authToken, SubmitEvent submitEvent) { UserName = userName; _authToken = authToken; _submitEvent = submitEvent; SolutionName = Path.GetFileNameWithoutExtension(submitEvent.SolutionName); _client = new OsbideWebServiceClient(ServiceBindings.OsbideServiceBinding, ServiceBindings.OsbideServiceEndpoint); ContinueCommand = new DelegateCommand(Continue, CanIssueCommand); CancelCommand = new DelegateCommand(Cancel, CanIssueCommand); Assignments = new ObservableCollection <Assignment>(); Courses = new ObservableCollection <Course>(); LastSubmitted = "N/A"; //set up event listeners _client.GetCoursesForUserCompleted += _client_GetCoursesForUserCompleted; _client.GetAssignmentsForCourseCompleted += _client_GetAssignmentsForCourseCompleted; _client.SubmitAssignmentCompleted += _client_SubmitAssignmentCompleted; _client.GetLastAssignmentSubmitDateCompleted += _client_GetLastAssignmentSubmitDateCompleted; //load courses IsLoading = true; _client.GetCoursesForUserAsync(authToken); }
private static SubmitEvent CreateSubmitEvent() { var submit = new SubmitEvent { //SolutionName = "C:/SubmissionTest/Source/TestSolution.sln", CourseId = 4, AssignmentId = 3, SenderId = 1, Sender = new User { FirstName = "Test", LastName = "User" } }; //submit.GetSolutionBinary(); string path = "testfile.txt"; using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine("CourseId = 4"); sw.WriteLine("AssignmentId = 3"); sw.WriteLine("SenderId = 1"); sw.WriteLine("Name = Test User"); } var stream = new MemoryStream(); using (var zip = new ZipFile()) { zip.AddFile(path); zip.Save(stream); stream.Position = 0; submit.CreateSolutionBinary(stream.ToArray()); } File.Delete(path); return(submit); }
public SolutionDownloadedEventArgs(IUser downloadingUser, SubmitEvent downloadedSubmission) { DownloadingUser = downloadingUser; DownloadedSubmission = downloadedSubmission; }
public void NotifySolutionDownloaded(SubmitEvent downloadedSubmission) { SolutionDownloaded(downloadedSubmission.Sender, new SolutionDownloadedEventArgs(downloadedSubmission.Sender, downloadedSubmission)); }
private void FillAbsenceDialog_OnSaveClicked(object sender, SubmitEvent e) { var activity = e.Activity(); service.AddAbsenceActivity(activity); }
public ActionResult Create(int?id, IEnumerable <HttpPostedFileBase> files, int?authorTeamID = null) { if (id != null) { Assignment assignment = db.Assignments.Find(id); //submit event to the eventlog try { if (assignment != null) { var sub = new SubmitEvent { AssignmentId = id.Value, SenderId = CurrentUser.ID, SolutionName = assignment.AssignmentName, CourseId = assignment.CourseID, }; int eventLogId = Posts.SaveEvent(sub); DBHelper.AddToSubmitEventProperties(eventLogId); if (eventLogId == -1) { throw new Exception("Failed to log submit event to the eventlog table -- Posts.SaveEvent returned -1"); } else { if (DBHelper.InterventionEnabledForCourse(assignment.CourseID ?? -1)) { //process suggestions if interventions are enabled for this course. using (EventCollectionController ecc = new EventCollectionController()) { ecc.ProcessLogForInterventionSync((ActivityEvent)sub); string authKey = Request.Cookies["AuthKey"].Value.Split('=').Last(); ecc.NotifyNewSuggestion(CurrentUser.ID, assignment.CourseID ?? 0, authKey); } } } } else { var sub = new SubmitEvent { AssignmentId = id.Value, SenderId = CurrentUser.ID, SolutionName = "NULL ASSIGNMENT", }; int eventLogId = Posts.SaveEvent(sub); if (eventLogId == -1) { throw new Exception("Failed to log submit event to the eventlog table -- Posts.SaveEvent returned -1 -- Assignment is null"); } } } catch (Exception e) { throw new Exception("Failed to log submit event to the eventlog table: ", e); } if (assignment != null && (assignment.HasDeliverables == true || assignment.Type == AssignmentTypes.CriticalReview || assignment.Type == AssignmentTypes.AnchoredDiscussion)) { List <Deliverable> deliverables; if (assignment.Type == AssignmentTypes.CriticalReview) { deliverables = new List <Deliverable>((assignment.PreceedingAssignment).Deliverables); } else if (assignment.Type == AssignmentTypes.AnchoredDiscussion) { //TODO: need to keep deliverables if no changes have been made. //need to remove old deliverables assignment.Deliverables.Clear(); db.SaveChanges(); deliverables = new List <Deliverable>((assignment).Deliverables); List <string> deliverableNames = new List <string>(); foreach (var file in files) { deliverables.Add(new Deliverable { Assignment = assignment, AssignmentID = assignment.ID, DeliverableType = DeliverableType.PDF, Name = Path.GetFileNameWithoutExtension(file.FileName), }); } foreach (Deliverable d in deliverables) { assignment.Deliverables.Add(d); } db.Entry(assignment).State = System.Data.EntityState.Modified; db.SaveChanges(); } else { deliverables = new List <Deliverable>((assignment).Deliverables); } if (assignment.CourseID == ActiveCourseUser.AbstractCourseID && (ActiveCourseUser.AbstractRole.CanSubmit == true || ActiveCourseUser.AbstractRole.CanUploadFiles == true)) { AssignmentTeam assignmentTeam = GetAssignmentTeam(assignment, ActiveCourseUser); int i = 0; //the files variable is null when submitting an in-browser text submission if (files != null) { int anchoredDiscussionDocumentCount = 0; foreach (var file in files) { anchoredDiscussionDocumentCount++; if (file != null && file.ContentLength > 0) { DeliverableType type = (DeliverableType)deliverables[i].Type; //jump over all DeliverableType.InBrowserText as they will be handled separately while (type == DeliverableType.InBrowserText) { i++; type = (DeliverableType)deliverables[i].Type; } string fileName = Path.GetFileName(file.FileName); string extension = Path.GetExtension(file.FileName).ToLower(); string deliverableName = string.Format("{0}{1}", deliverables[i].Name, extension); string[] allowFileExtensions = GetFileExtensions(type); if (allowFileExtensions.Contains(extension)) { if (assignment.Type == AssignmentTypes.CriticalReview || assignment.Type == AssignmentTypes.AnchoredDiscussion) { //TODO: clean this up AssignmentTeam authorTeam = new AssignmentTeam(); ReviewTeam reviewTeam = new ReviewTeam(); if (assignment.Type == AssignmentTypes.AnchoredDiscussion) { authorTeam = new AssignmentTeam { Assignment = assignment, AssignmentID = assignment.ID, Team = null, TeamID = anchoredDiscussionDocumentCount, }; reviewTeam = new ReviewTeam { Assignment = assignment, AssignmentID = assignment.ID, //AuthorTeam = null, AuthorTeamID = anchoredDiscussionDocumentCount, //ReviewingTeam = null, ReviewTeamID = ActiveCourseUser.AbstractCourse.ID, }; assignment.ReviewTeams.Add(reviewTeam); //db.Entry(assignment).State = System.Data.EntityState.Modified; db.SaveChanges(); } else { authorTeam = (from at in db.AssignmentTeams where at.TeamID == authorTeamID && at.AssignmentID == assignment.PrecededingAssignmentID select at).FirstOrDefault(); reviewTeam = (from tm in db.TeamMembers join t in db.Teams on tm.TeamID equals t.ID join rt in db.ReviewTeams on t.ID equals rt.ReviewTeamID where tm.CourseUserID == ActiveCourseUser.ID && rt.AssignmentID == assignment.ID select rt).FirstOrDefault(); } //MG&MK: file system for critical review assignments is laid out a bit differently, so //critical review assignments must use different file system functions //remove all prior files OSBLE.Models.FileSystem.AssignmentFilePath fs = Models.FileSystem.Directories.GetAssignment( ActiveCourseUser.AbstractCourseID, assignment.ID); fs.Review(authorTeam.TeamID, reviewTeam.ReviewTeamID) .File(deliverableName) .Delete(); if (assignment.Type != AssignmentTypes.AnchoredDiscussion) // handle assignments that are not anchored discussion { //We need to remove the zipfile corresponding to the authorTeamId being sent in as well as the regularly cached zip. AssignmentTeam precedingAuthorAssignmentTeam = (from at in assignment.PreceedingAssignment.AssignmentTeams where at.TeamID == authorTeamID select at).FirstOrDefault(); FileSystem.RemoveZipFile(ActiveCourseUser.AbstractCourse as Course, assignment, precedingAuthorAssignmentTeam); FileSystem.RemoveZipFile(ActiveCourseUser.AbstractCourse as Course, assignment, assignmentTeam); } else //anchored discussion type TODO: this does nothing right now, fix! { //We need to remove the zipfile corresponding to the authorTeamId being sent in as well as the regularly cached zip. AssignmentTeam precedingAuthorAssignmentTeam = (from at in assignment.AssignmentTeams where at.TeamID == authorTeamID select at).FirstOrDefault(); FileSystem.RemoveZipFile(ActiveCourseUser.AbstractCourse as Course, assignment, precedingAuthorAssignmentTeam); FileSystem.RemoveZipFile(ActiveCourseUser.AbstractCourse as Course, assignment, assignmentTeam); } //add in the new file //authorTeamID is the deliverable file counter, and reviewTeamID is the courseID fs.Review(authorTeam.TeamID, reviewTeam.ReviewTeamID) .AddFile(deliverableName, file.InputStream); //unzip and rezip xps files because some XPS generators don't do it right if (extension.ToLower().CompareTo(".xps") == 0) { //XPS documents require the actual file path, so get that. OSBLE.Models.FileSystem.FileCollection fileCollection = OSBLE.Models.FileSystem.Directories.GetAssignment( ActiveCourseUser.AbstractCourseID, assignment.ID) .Review(authorTeam.TeamID, reviewTeam.ReviewTeamID) .File(deliverables[i].Name); string path = fileCollection.FirstOrDefault(); string extractPath = Path.Combine(FileSystem.GetTeamUserSubmissionFolderForAuthorID(true, ActiveCourseUser.AbstractCourse as Course, (int)id, assignmentTeam, authorTeam.Team), "extract"); using (ZipFile oldZip = ZipFile.Read(path)) { oldZip.ExtractAll(extractPath, ExtractExistingFileAction.OverwriteSilently); } using (ZipFile newZip = new ZipFile()) { newZip.AddDirectory(extractPath); newZip.Save(path); } } } else { //If a submission of any extension exists delete it. This is needed because they could submit a .c file and then a .cs file and the teacher would not know which one is the real one. string submission = FileSystem.GetDeliverable(ActiveCourseUser.AbstractCourse as Course, assignment.ID, assignmentTeam, deliverables[i].Name, allowFileExtensions); if (submission != null) { FileInfo oldSubmission = new FileInfo(submission); if (oldSubmission.Exists) { oldSubmission.Delete(); } } FileSystem.RemoveZipFile(ActiveCourseUser.AbstractCourse as Course, assignment, assignmentTeam); string path = Path.Combine(FileSystem.GetTeamUserSubmissionFolder(true, ActiveCourseUser.AbstractCourse as Course, (int)id, assignmentTeam), deliverables[i].Name + extension); file.SaveAs(path); //unzip and rezip xps files because some XPS generators don't do it right if (extension.ToLower().CompareTo(".xps") == 0) { string extractPath = Path.Combine(FileSystem.GetTeamUserSubmissionFolder(true, ActiveCourseUser.AbstractCourse as Course, (int)id, assignmentTeam), "extract"); using (ZipFile oldZip = ZipFile.Read(path)) { oldZip.ExtractAll(extractPath, ExtractExistingFileAction.OverwriteSilently); } using (ZipFile newZip = new ZipFile()) { newZip.AddDirectory(extractPath); newZip.Save(path); } } } DateTime?dueDate = assignment.DueDate; if (dueDate != null) { //TODO: add case for anchored discussion assignment (new NotificationController()).SendFilesSubmittedNotification(assignment, assignmentTeam, deliverables[i].Name); } } else { //The submission view handles incorrect extension types, so this area of code is unlikely to be reached. In the case that it does a occur, //we will ineloquently redirect them to assignment index without feedback. Cache["SubmissionReceived"] = false; return(RedirectToAction("Index", "Assignment")); } } i++; } } // Creates the text files from text boxes int j = 0; string delName; do { if (Request != null) { //delName = Request.Params["desiredName[" + j + "]"]; delName = Request.Unvalidated.Form["desiredName[" + j + "]"]; } else //TODO: change this to releveant string { delName = null; } if (delName != null) { string inbrowser; if (Request != null) { //inbrowser = Request.Params["inBrowserText[" + j + "]"]; inbrowser = Request.Unvalidated.Form["inBrowserText[" + j + "]"]; if (inbrowser.Length > 0) { var path = Path.Combine(FileSystem.GetTeamUserSubmissionFolder(true, ActiveCourseUser.AbstractCourse as Course, (int)id, assignmentTeam), CurrentUser.LastName + "_" + CurrentUser.FirstName + "_" + delName + ".txt"); System.IO.File.WriteAllText(path, inbrowser); } } } j++; } while (delName != null); Cache["SubmissionReceived"] = true; Cache["SubmissionReceivedAssignmentID"] = assignment.ID; if (authorTeamID != null) { Cache["SubmissionForAuthorTeamID"] = authorTeamID; } if (assignment.Type == AssignmentTypes.AnchoredDiscussion) { return(RedirectToAction("Index", "AnchoredDiscussionController")); } else { return(Redirect(Request.UrlReferrer.ToString())); } } } } return(Create(id)); }
public ActionResult SubmitAssignmentFile(HttpPostedFileBase file) { //make sure that we have both a course id and assignment id int assignmentId = 0; int courseId = 0; Int32.TryParse(Request.Form["AssignmentId"], out assignmentId); Int32.TryParse(Request.Form["CourseId"], out courseId); if (courseId < 1 || assignmentId < 1) { return(RedirectToAction("MyCourses")); } //get file information and continue if not null if (file != null) { //create submit event SubmitEvent submitEvent = new SubmitEvent(); if (file.ContentLength > 0 && file.ContentLength < 5000000) //limit size to 5 MB { submitEvent.SolutionName = Path.GetFileName(file.FileName); byte[] fileData = null; using (var binaryReader = new BinaryReader(file.InputStream)) { fileData = binaryReader.ReadBytes(file.ContentLength); } MemoryStream stream = new MemoryStream(); using (ZipFile zip = new ZipFile()) { zip.AddEntry(submitEvent.SolutionName, fileData); zip.Save(stream); stream.Position = 0; } //add the solution data to the event submitEvent.CreateSolutionBinary(stream.ToArray()); } else { //TODO: handle specific errors return(RedirectToAction("GenericError", "Error")); } submitEvent.AssignmentId = assignmentId; //create event log with solution to submit EventLog eventLog = new EventLog(submitEvent); eventLog.Sender = CurrentUser; eventLog.SenderId = CurrentUser.Id; //create client to submit assignment to the db OsbideWebService client = new OsbideWebService(); client.SubmitAssignment(assignmentId, eventLog, CurrentUser); return(RedirectToAction("Details", new { id = courseId })); } else { //TODO: handle specific errors return(RedirectToAction("GenericError", "Error")); } }
private void OK_Click(object sender, EventArgs e) { SubmitEvent?.Invoke(this.citizendList.SelectedIndices.Cast <int>().Where(x => x != currentIndex).ToList(), currentIndex); Close(); }
private void Submit_Click(object sender, EventArgs e) { SubmitEvent?.Invoke(this.nameTextBox.Text); Close(); }