public string StarterFilesXML(System.Guid guid) { try { DataSet ds = new DataSet(); string downloadRoot = SharedSupport.AddBackSlashToDirectory(System.Web.HttpContext.Current.Request.MapPath(String.Empty, Constants.ASSIGNMENTMANAGER_DOWNLOAD_DIRECTORY, true)); string storageLocation = String.Empty; AssignmentM assign = AssignmentM.Load(_assignmentID); storageLocation = SharedSupport.AddBackSlashToDirectory(assign.StorageDirectory + Constants.STARTER_PROJECT_PATH); //add unique guid to download path downloadRoot = downloadRoot + SharedSupport.AddBackSlashToDirectory(guid.ToString()); DatabaseCall dbc = new DatabaseCall("Assignments_GetFiles", DBCallType.Select); dbc.AddParameter("@AssignmentID", _assignmentID); dbc.Fill(ds); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string source = String.Empty; string destination = String.Empty; string filename = ds.Tables[0].Rows[i]["FileName"].ToString().Trim(); filename = filename.Replace(@"\", @"/"); source = SharedSupport.RemoveIllegalFilePathCharacters(storageLocation + filename); destination = SharedSupport.RemoveIllegalFilePathCharacters(downloadRoot + filename); //check to see if destination directory exists string destinationDir = destination.Substring(0, destination.LastIndexOf("\\") + 1); if (!Directory.Exists(destinationDir)) { Directory.CreateDirectory(destinationDir); } //check if file is there if (System.IO.File.Exists(source)) { System.IO.File.Copy(source, destination, true); } else { throw new System.IO.FileNotFoundException(SharedSupport.GetLocalizedString("Assignment_UploadedFileNotFound")); } if (filename.StartsWith(@"/")) { ds.Tables[0].Rows[i]["FileName"] = guid + filename; } else { ds.Tables[0].Rows[i]["FileName"] = guid + @"/" + filename; } } return(ds.GetXml()); } catch (Exception e) { return(e.Message); } }
internal AssignmentM GetAssignmentAt(int index) { if (this.assignmentDS == null) { return(null); } else { int assignmentID = Convert.ToInt32(assignmentDS.Tables[0].Rows[index]["AssignmentID"]); return(AssignmentM.Load(assignmentID)); } }
internal static AssignmentM Load(int assignmentID) { //set courseID = 0, it will get overwritten when we load. AssignmentM retVal = new AssignmentM(0); DatabaseCall dbc = new DatabaseCall("Assignments_LoadAssignment", DBCallType.Select); dbc.AddParameter("@AssignmentID", assignmentID); DataSet ds = new DataSet(); dbc.Fill(ds); if (ds.Tables.Count <= 0) { return(null); } // Populate the return value. retVal._assignmentID = assignmentID; retVal.Description = ds.Tables[0].Rows[0]["Description"].ToString(); retVal.StarterProjectFlag = Convert.ToBoolean(ds.Tables[0].Rows[0]["StarterProjectFlag"]); retVal.ShortName = ds.Tables[0].Rows[0]["ShortName"].ToString(); retVal.CompilerType = ds.Tables[0].Rows[0]["CompilerType"].ToString(); retVal.LastUpdatedDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["LastUpdatedDate"].ToString()); retVal.LastUpdatedUserID = Convert.ToInt32(ds.Tables[0].Rows[0]["LastUpdatedUserID"]); retVal.DueDate = Convert.ToDateTime(ds.Tables[0].Rows[0]["DueDate"].ToString()); retVal.AssignmentURL = ds.Tables[0].Rows[0]["AssignmentURL"].ToString(); retVal.CommandLineArgs = ds.Tables[0].Rows[0]["CommandLineArgs"].ToString(); retVal.InputFile = ds.Tables[0].Rows[0]["InputFile"].ToString(); retVal.OutputFile = ds.Tables[0].Rows[0]["OutputFile"].ToString(); retVal.MultipleSubmitsFlag = Convert.ToBoolean(ds.Tables[0].Rows[0]["MultipleSubmitsFlag"]); retVal.AutoGradeFlag = Convert.ToBoolean(ds.Tables[0].Rows[0]["AutoGradeFlag"]); retVal.AutoCompileFlag = Convert.ToBoolean(ds.Tables[0].Rows[0]["AutoCompileFlag"]); retVal.SendReminders = Convert.ToBoolean(ds.Tables[0].Rows[0]["SendReminders"]); retVal.SendPastDue = Convert.ToBoolean(ds.Tables[0].Rows[0]["SendPastDue"]); retVal.SendNewProject = Convert.ToBoolean(ds.Tables[0].Rows[0]["SendNewProject"]); retVal.SendUpdatedProject = Convert.ToBoolean(ds.Tables[0].Rows[0]["SendUpdatedProject"]); retVal.GradeType = Convert.ToByte(ds.Tables[0].Rows[0]["GradeType"]); retVal.CourseAssignmentID = Convert.ToInt32(ds.Tables[0].Rows[0]["CourseAssignmentID"]); retVal.ReminderWarningDays = Convert.ToInt32(ds.Tables[0].Rows[0]["ReminderWarningDays"]); retVal.PastDueWarningDays = Convert.ToInt32(ds.Tables[0].Rows[0]["PastDueWarningDays"]); retVal.CourseID = Convert.ToInt32(ds.Tables[0].Rows[0]["CourseID"]); return(retVal); }
private void saveFileList(string xmlFileList, string guid) { System.Data.DataSet ds = new System.Data.DataSet(); System.IO.StringReader reader = new System.IO.StringReader(xmlFileList); System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(reader); ds.ReadXml(xmlReader); AssignmentM assign = AssignmentM.Load(_assignmentID); string targetdir = SharedSupport.AddBackSlashToDirectory(assign.StorageDirectory + _userID); string uploadDir = SharedSupport.AddBackSlashToDirectory(System.Web.HttpContext.Current.Request.MapPath(String.Empty, Constants.ASSIGNMENTMANAGER_UPLOAD_DIRECTORY, true)) + SharedSupport.AddBackSlashToDirectory(guid); try { if (Directory.Exists(targetdir)) { // If the directory exists, remove it so we are not left with extra files around. Directory.Delete(targetdir, true); } Directory.CreateDirectory(targetdir); } catch { } //get max project size from settings table (in megabytes) Int64 maxProjectSize = new Int64(); maxProjectSize = Convert.ToInt32(SharedSupport.GetSetting(Constants.MAX_PROJECT_SETTING)) * Constants.BytesInMegaByte; //create variable to track project size Int64 currentProjectSize = new Int64(); currentProjectSize = 0; //Cycle through all uploaded files and save a record for each in the user assignment files table for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string filename = ds.Tables[0].Rows[i]["Filename"].ToString(); //make sure the file name is not blank if (filename != null && filename != String.Empty) { filename = filename.Replace("/", @"\"); if (filename.StartsWith(@"\")) { filename = filename.Remove(0, 1); } this.AddFile(filename); } else { //Throw an error because the file name for the given record is blank throw new ApplicationException(SharedSupport.GetLocalizedString("StudentAssignment_BlankFileName_Error")); } string uploadFilePath = uploadDir + filename; string targetFilePath = targetdir + filename; string fullTargetDir = targetFilePath.Substring(0, targetFilePath.LastIndexOf(@"\")); if (!Directory.Exists(fullTargetDir)) { Directory.CreateDirectory(fullTargetDir); } if (!File.Exists(uploadFilePath)) { throw new ApplicationException(SharedSupport.GetLocalizedString("SharedSupport_InvalidFileLocation_Error")); } else { //Get the size of the file and add it to other's to see if project exceeds // the maximum size limit held in the settings table currentProjectSize += new FileInfo(uploadFilePath).Length; if (currentProjectSize > maxProjectSize) { //delete all files Directory.Delete(uploadDir, true); Directory.Delete(targetdir, true); throw new ApplicationException(SharedSupport.GetLocalizedString("StudentAssignment_ProjectTooLarge") + maxProjectSize.ToString() + SharedSupport.GetLocalizedString("StudentAssignment_Megabytes")); } } File.Copy(uploadFilePath, targetFilePath, true); } }
public void Submit(int assignmentID, int courseID, string xmlFileList, string pathGUID) { try { bool bBuildAssignment = false; // indicates if build indicated by faculty for this assignment bool bCheckAssignment = false; // indicates if check indicated by faculty for this assignment //For each file uploaded - move to secure directory this._assignmentID = assignmentID; this._userID = SharedSupport.GetUserIdentity(); //Check to see if the user has already submitted an assignment and if the assignment allows for multiple submissions. //If not allowed, and the user has already submitted an assignment for this assignment then throw error. AssignmentM assign = AssignmentM.Load(assignmentID); if (assign.IsValid) { // build / check indicated for this assignment? bBuildAssignment = assign.AutoCompileFlag; bCheckAssignment = assign.AutoGradeFlag; if (!assign.MultipleSubmitsFlag) { if (this.HasSubmitted) { throw new ApplicationException(SharedSupport.GetLocalizedString("StudentAssignment_NoMultipleSubmits")); } } } else { throw new ApplicationException(SharedSupport.GetLocalizedString("StudentAssignment_NoCourseOfferingAssignment_Error")); } // delete any previous submissions this.ClearSubmissions(); if (bBuildAssignment) { this._autoCompileStatus = Constants.AUTOCOMPILE_PENDING_STATUS; } else { this._autoCompileStatus = Constants.AUTOCOMPILE_NOTAPPLICABLE_STATUS; } if (bCheckAssignment) { this._autoGradeStatus = Constants.AUTOGRADE_PENDING_STATUS; } else { this._autoGradeStatus = Constants.AUTOGRADE_NOTAPPLICABLE_STATUS; } this._lastSubmitDate = DateTime.Now; this._lastUpdatedDate = DateTime.Now; this.SaveToDatabase(StoredProcType.New); this.saveFileList(xmlFileList, pathGUID); // queue action requests if (bBuildAssignment || bCheckAssignment) { try { SendActionToQueue(this._userAssignmentID, bBuildAssignment, bCheckAssignment); } catch (Exception ex) { // this is the student submitting, so log it and continue SharedSupport.LogMessage(ex.Message, this.ToString(), System.Diagnostics.EventLogEntryType.Warning); } } } catch (Exception ex) { SharedSupport.HandleError(ex); } }