protected void Page_Load(object sender, System.EventArgs e) { try { // standard error label this.lblErrorEncountered.Text = SharedSupport.GetLocalizedString("ErrorPage_ErrorEncountered"); // localize token on querystring AssignmentManager.Common.Functions func = new AssignmentManager.Common.Functions(); string errorDetail = func.ValidateStringQueryStringParameter(this.Request, "ErrorDetail"); if (!errorDetail.Equals(null) && !errorDetail.Equals(String.Empty)) { this.lblErrorDetail.Text = SharedSupport.GetLocalizedString(errorDetail); } else { this.lblErrorDetail.Text = String.Empty; } // link to Core Tools this.hlCoreTools.Text = SharedSupport.GetLocalizedString("ErrorPage_BackToStartPage"); this.hlCoreTools.NavigateUrl = AssignmentManager.Common.constants.BACK_TO_CORETOOLS_LINK; // log off ...otherwise, after returning to core tools, previous identity persists System.Web.Security.FormsAuthentication.SignOut(); } catch (System.Exception ex) { this.lblErrorDetail.Text = ex.Message; } }
private static void updateService(string serviceName, System.UInt32 startType) { bool updateStatus = false; // open the service db System.IntPtr scm = OpenSCManager(null, null, SC_MANAGER_ALL_ACCESS); // get a handle to the service System.IntPtr service = OpenService(scm, serviceName, SERVICE_CHANGE_CONFIG); // update the service updateStatus = ChangeServiceConfig(service, SERVICE_NO_CHANGE, startType, SERVICE_NO_CHANGE, null, null, null, null, null, null, null); // release the handle to the service CloseServiceHandle(service); // close the service db CloseServiceHandle(scm); if (!updateStatus) { // if the config change failed, throw an exception throw new Exception(SharedSupport.GetLocalizedString("Setting_UnableToUpdateService_Error")); } }
public static RoleM[] GetAllRoles() { DatabaseCall dbc = new DatabaseCall("Roles_BrowseAll", DBCallType.Select); System.Data.DataSet ds = new System.Data.DataSet(); dbc.Fill(ds); if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { return(new RoleM[0]); } else { RoleM[] roles = new RoleM[(ds.Tables[0].Rows.Count)]; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { int roleID = Convert.ToInt32(ds.Tables[0].Rows[i]["RoleID"]); string roleName = ds.Tables[0].Rows[i]["Name"].ToString(); // replace with localized name if available string localizedName = SharedSupport.GetLocalizedString("UserRole_" + roleName); if (localizedName != String.Empty) { roleName = localizedName; } roles[i] = new RoleM(roleID, roleName); } return(roles); } }
internal static System.Data.DataSet ParseDelimitedFile(string textFileName, string delimiter, int numRows) { //verify that file is there. if (!System.IO.File.Exists(textFileName)) { throw new System.IO.FileNotFoundException(); } //Create a new dataset DataSet ds = new DataSet(); //Create a new DataTable inside the dataset DataTable dt = ds.Tables.Add(); //Open text file and read into stream. System.IO.StreamReader sReader = System.IO.File.OpenText(textFileName); //Read the first line into the string string strline = sReader.ReadLine(); // make sure we have a valid file w/data if (strline == null) { throw new System.IO.FileNotFoundException(SharedSupport.GetLocalizedString("User_UploadFileNotFound")); } string[] strArray = strline.Split(delimiter.ToCharArray()); for (int c = 0; c < strArray.Length; c++) { //add a column to the data table dt.Columns.Add(); } //Only grab the number of rows from the parameter passed in. //If numRows = -1 then the function has been overloaded and loop through entire file. //initialize counter int i = 0; while (strline != null && (i < numRows || numRows == -1)) { //Split string into array strArray = strline.Split(delimiter.ToCharArray()); //Create the row System.Data.DataRow dr = dt.NewRow(); for (int c = 0; c < strArray.Length; c++) { dr[c] = strArray[c].Trim(); } //add the row to the table. dt.Rows.Add(dr); //Increment the counter i++; //Read the next line in the file strline = sReader.ReadLine(); strArray = null; } //Close the stream reader for the text file sReader.Close(); //return the created dataset return(ds); }
protected void LocalizeLabels() { this.lblPassword.Text = SharedSupport.GetLocalizedString("Login_Password"); this.lblUserName.Text = SharedSupport.GetLocalizedString("Login_Username1"); this.btnLogin.Text = SharedSupport.GetLocalizedString("Login_Login1"); this.lblSubTitle.Text = SharedSupport.GetLocalizedString("Login_Title1"); lblFeedback.Text = ""; }
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); } }
private void saveCourseXML() { string dir = System.Web.HttpContext.Current.Server.MapPath("..\\") + "\\Courses\\"; try { //Check to see if folder and file exist if (Directory.Exists(dir)) { // Use the CourseID to create a unique xml filename for the course. string filename = this.CourseID + ".xml"; //Create CourseID.xml file System.Xml.XmlTextWriter xmlwriter = new System.Xml.XmlTextWriter(dir + filename, null); xmlwriter.Formatting = System.Xml.Formatting.Indented; xmlwriter.WriteStartDocument(false); // xmlwriter.WriteDocType("Course", null, null, null); xmlwriter.WriteStartElement("course"); xmlwriter.WriteStartElement("name"); if (this.Name != null && this.Name != "") { xmlwriter.WriteCData(this.Name); } xmlwriter.WriteEndElement(); xmlwriter.WriteStartElement("assnmgr"); xmlwriter.WriteStartElement("amurl"); if (SharedSupport.UsingSsl == true) { xmlwriter.WriteCData(@"https://" + SharedSupport.BaseUrl); } else { xmlwriter.WriteCData(@"http://" + SharedSupport.BaseUrl); } xmlwriter.WriteEndElement(); xmlwriter.WriteStartElement("guid"); xmlwriter.WriteCData(this._courseGUID.ToString()); xmlwriter.WriteEndElement(); xmlwriter.WriteEndElement(); xmlwriter.WriteEndElement(); //write the xml to the file and close xmlwriter.Flush(); xmlwriter.Close(); } else { throw new Exception(SharedSupport.GetLocalizedString("Course_DirectoryDoesNotExist")); //"Directory could not be found. " + dir); } } catch (System.Exception ex) { SharedSupport.HandleError(ex); } }
private void SendPasswordToUser(string password) { // email if new user if (SharedSupport.UsingSmtp) { string subject = SharedSupport.GetLocalizedString("ChangePassword_NewPasswordEmailSubject"); string body = SharedSupport.GetLocalizedString("ChangePassword_NewPassword_UsernameMessage") + " " + this._username + "\n"; body += SharedSupport.GetLocalizedString("ChangePassword_NewPassword_Message") + " " + password; UserM amsaUser = UserM.Load(Constants.ASSIGNMENTMANAGER_SYSTEM_ADMIN_USERID); MessageM.SendMessage(amsaUser.EmailAddress, this._emailAddress, subject, body); } }
protected void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here // load the captions lblTitle.Text = ""; lblLogoffMsg.Text = SharedSupport.GetLocalizedString("LOGOFF_MESSAGE"); HyperLink1.Text = SharedSupport.GetLocalizedString("LOGOFF_RETURN_TO_START_PAGE"); HyperLink1.NavigateUrl = AssignmentManager.Common.constants.BACK_TO_CORETOOLS_LINK; // log the user off System.Web.Security.FormsAuthentication.SignOut(); }
public void SendPasswordToUser() { // use Assignment Manager sysadmin email UserM amsaUser = UserM.Load(Constants.ASSIGNMENTMANAGER_SYSTEM_ADMIN_USERID); string sentByEmail = amsaUser.EmailAddress; string emailSubject = SharedSupport.GetLocalizedString("User_EmailSubject"); string[] replacements = new string[2] { this._username, this._password }; string emailBody = SharedSupport.GetLocalizedString("User_EmailBody", replacements); MessageM.SendMessage(sentByEmail, this._emailAddress, emailSubject, emailBody); }
internal static void SendMessage(string from, string mailTo, string subject, string body) { //this code calls the SendMessage function to send an EMAIL message. try { MailMessage mail = new MailMessage(); mail.From = from; mail.Subject = subject; mail.Body = body; mail.Bcc = mailTo; SmtpMail.Send(mail); } catch (System.Web.HttpException) { throw new System.Exception(SharedSupport.GetLocalizedString("ComposeMessage_SMTPError")); } }
public static void sendEmailMessageToCourse(string subject, string body, string link, int courseId) { if (!Convert.ToBoolean(SharedSupport.UsingSmtp)) { throw (new System.Exception(SharedSupport.GetLocalizedString("Global_NoSMTP"))); } try { // validation if (body.Equals(String.Empty)) { throw new ArgumentException(SharedSupport.GetLocalizedString("SendEmailMessage_InvalidBody")); } if (subject.Equals(String.Empty)) { throw new ArgumentException(SharedSupport.GetLocalizedString("SendEmailMessage_InvalidSubject")); } string mailTo = ""; System.Data.DataSet ds = new System.Data.DataSet(); //use generic Assignment Manager From string sentByEmail = string.Empty; UserList ul = UserList.GetListFromCourse(courseId); int[] userIDs = ul.UserIDList; for (int i = 0; i < userIDs.Length; i++) { UserM user = UserM.Load(userIDs[i]); mailTo += user.EmailAddress + ";"; } // use Assignment Manager sysadmin email UserM amsaUser = UserM.Load(Constants.ASSIGNMENTMANAGER_SYSTEM_ADMIN_USERID); sentByEmail = amsaUser.EmailAddress; // add the formatting and action link body += "\n" + "\n" + link; // send email SendMessage(sentByEmail, mailTo, subject, body); } catch (System.Exception ex) { SharedSupport.HandleError(ex); } }
/// <summary> /// Retrieves value from Settings table /// </summary> /// <param name="settingName"> </param> internal static string GetSetting(string settingName) { try { // validate parameter if (settingName == null || settingName == String.Empty) { throw new ArgumentNullException(SharedSupport.GetLocalizedString("SharedSupport_SettingNameField"), SharedSupport.GetLocalizedString("SharedSupport_Missing_SettingName")); } if (settingName.Equals(Constants.AUTOBUILD_SETTING) || settingName.Equals(Constants.AUTOCHECK_SETTING)) { // query the status of the actual service return(getServiceStatus(Constants.ACTION_SERVICE_NAME)); } else { DatabaseCall dbc = new DatabaseCall("Settings_GetSetting", DBCallType.Select); dbc.AddParameter("@Setting", settingName); System.Data.DataSet ds = new System.Data.DataSet(); dbc.Fill(ds); try { string returnval = ds.Tables[0].Rows[0]["Value"].ToString().Trim(); return(returnval); } catch { return(String.Empty); } } } catch (System.Exception e) { SharedSupport.HandleError(e); return(null); } }
/// <summary> /// Sets value in Settings table /// </summary> /// <param name="settingName"> </param> /// <param name="settingValue"> </param> internal static void SetSetting(string settingName, string settingValue) { try { // validate parameters if (settingName.Equals(null) || settingName == String.Empty) { throw new ArgumentNullException(SharedSupport.GetLocalizedString("SharedSupport_SettingNameField"), SharedSupport.GetLocalizedString("SharedSupport_Missing_SettingName")); } if (settingValue.Equals(null) || settingValue == String.Empty) { throw new ArgumentNullException(SharedSupport.GetLocalizedString("SharedSupport_SettingValueField"), SharedSupport.GetLocalizedString("SharedSupport_Missing_SettingValue")); } // if they are changing the AutoBuild/AutoCheck update the Service Status if ((settingName.Equals(Constants.AUTOBUILD_SETTING)) || (settingName.Equals(Constants.AUTOCHECK_SETTING))) { // change the service status if (!changeServiceStatus(settingValue, Constants.ACTION_SERVICE_NAME)) { // throw an exception b/c we couldn't update the service throw new System.Exception(GetLocalizedString("Setting_UnableToUpdateService_Error")); } // no database interaction for the Actions Service } else { //We're changing a setting stored in the database DatabaseCall dbc = new DatabaseCall("Settings_UpdateSetting", DBCallType.Execute); dbc.AddParameter("@Setting", settingName); dbc.AddParameter("@Value", settingValue); dbc.Execute(); } } catch (System.Exception e) { SharedSupport.HandleError(e); } }
public void btnLogin_Click(object sender, System.EventArgs e) { try { // field validation lblFeedback.Text = String.Empty; if (this.txtUserName.Text.Trim() == String.Empty) { lblFeedback.Text = SharedSupport.GetLocalizedString("Login_InvalidCredentials"); return; } if (this.txtPassword.Text.Trim() == String.Empty) { lblFeedback.Text = SharedSupport.GetLocalizedString("Login_InvalidCredentials"); return; } //AuthenticateUser returns User UserM user = UserM.AuthenticateUser(this.txtUserName.Text.Trim(), this.txtPassword.Text.Trim()); if (user.IsValid) { // Trigger off of field visibilty to determine whether we're updating with a new // password or are attempting a first-time login. if (!txtNewPwd.Visible) { // In this case, we've authenticated the user, and are attempting to log in // directly. Make sure that they're valid for direct login, though (i.e. that // they've already changed their password!). if (!user.ChangedPassword) { // Uncover the fields for the 'need to change password' funtionality // and update the text. lblConfirmPwd.Visible = true; lblNewPwd.Visible = true; txtNewPwd.Visible = true; txtConfirmPwd.Visible = true; this.lblConfirmPwd.Text = SharedSupport.GetLocalizedString("ChangePassword_ConfirmPwdHeader"); this.lblNewPwd.Text = SharedSupport.GetLocalizedString("ChangePassword_NewPwdHeader1"); this.lblPassword.Text = SharedSupport.GetLocalizedString("ChangePassword_CurrentPwdHeader"); this.lblSubTitle.Text = SharedSupport.GetLocalizedString("Login_ChangePasswordSubTitle"); } else { // The user has already changed their password and can be logged directly // in, using forms based authentication and redirect; see config.web for // authentication cookie config FormsAuthentication.RedirectFromLoginPage(user.UserID.ToString(), false); } } else { // They hadn't changed their password yet, so this is the second attempt to log // in. Since they authenticated, if the two entries for the new password match, // update the entry in the database. if (this.txtConfirmPwd.Text == "") { throw new Exception(SharedSupport.GetLocalizedString("ChangePassword_ConfirmPassword_RequiredField")); } else if (this.txtNewPwd.Text == "") { throw new Exception(SharedSupport.GetLocalizedString("ChangePassword_NewPassword_RequiredField")); } if ((this.txtNewPwd.Text.Length < 4) || (this.txtNewPwd.Text.Length > 50)) { this.txtNewPwd.Text = ""; this.txtConfirmPwd.Text = ""; throw new Exception(SharedSupport.GetLocalizedString("ChangePassword_PwdLengthError")); } // New password can't be the same as the previous password if (this.txtNewPwd.Text == this.txtPassword.Text) { this.txtNewPwd.Text = ""; this.txtConfirmPwd.Text = ""; throw new Exception(SharedSupport.GetLocalizedString("ChangePassword_PwdSameAsOld")); } if (this.txtNewPwd.Text != this.txtConfirmPwd.Text) { this.txtNewPwd.Text = ""; this.txtConfirmPwd.Text = ""; throw new Exception(SharedSupport.GetLocalizedString("ChangePassword_ConfirmationError")); } // Update the password in the server, setting the 'changed' flag. user.SetPassword(txtNewPwd.Text.Trim(), true); // Now, redirect the user back to what they were doing before we // interrupted their login. FormsAuthentication.RedirectFromLoginPage(user.UserID.ToString(), false); } } else { lblFeedback.Text = SharedSupport.GetLocalizedString("Login_InvalidCredentials"); } } catch (System.Exception ex) { lblFeedback.Text = ex.Message; } }
public bool SubmitStarter(string xmlFileListing, string pathGuid) { if (this.IsValid) { bool submitSuccess = true; try { System.Data.DataSet dsXmlFileListing = new System.Data.DataSet(); System.IO.StringReader reader = new System.IO.StringReader(xmlFileListing); try { System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(reader); dsXmlFileListing.ReadXml(xmlReader); } catch (Exception ex) { throw new Exception(SharedSupport.GetLocalizedString("UploadDownload_UnableToCopyToServer"), ex); } this.ClearStarter(); string uploadPath = SharedSupport.AddBackSlashToDirectory(System.Web.HttpContext.Current.Request.MapPath(String.Empty, Constants.ASSIGNMENTMANAGER_UPLOAD_DIRECTORY, true)); uploadPath += SharedSupport.AddBackSlashToDirectory(pathGuid); string destinationPath = SharedSupport.AddBackSlashToDirectory(this.StorageDirectory + Constants.STARTER_PROJECT_PATH); try { //Clear old directory if (Directory.Exists(destinationPath)) { Directory.Delete(destinationPath, true); } Directory.CreateDirectory(destinationPath); } catch { } //Save all files and relative paths to assignmentfile table for (int i = 0; i < dsXmlFileListing.Tables[0].Rows.Count; i++) { string filename = dsXmlFileListing.Tables[0].Rows[i]["FileName"].ToString(); if (filename.StartsWith(@"\") || filename.StartsWith(@"/")) { filename = filename.Remove(0, 1); } string sourceFile = String.Empty; string destinationFile = String.Empty; sourceFile = SharedSupport.RemoveIllegalFilePathCharacters(uploadPath + filename); destinationFile = SharedSupport.RemoveIllegalFilePathCharacters(destinationPath + filename); //check to make sure the target directory exists string targetDirectory = destinationFile.Substring(0, destinationFile.LastIndexOf("\\")); if (!Directory.Exists(targetDirectory)) { Directory.CreateDirectory(targetDirectory); } //check if file is there if (System.IO.File.Exists(sourceFile)) { System.IO.File.Copy(sourceFile, destinationFile, true); } else { throw new System.IO.FileNotFoundException(SharedSupport.GetLocalizedString("Assignment_UploadedFileNotFound")); } this.AddFile(filename); } try { Directory.Delete(uploadPath, true); } catch { } // Send new Starter project notice. if (_sendNewProject && SharedSupport.UsingSmtp) { string[] AssignmentName = new string[] { _shortName }; string subject = SharedSupport.GetLocalizedString("Notification_UpdatedProjectSubject", AssignmentName); string body = SharedSupport.GetLocalizedString("Notification_UpdatedProjectBody", AssignmentName); MessageM.sendEmailMessageToCourse(subject, body, String.Empty, _courseId); } } catch (Exception ex) { SharedSupport.HandleError(ex); submitSuccess = false; } if (submitSuccess) { this.StarterProjectFlag = true; this.Update(); } return(submitSuccess); } else { return(false); } }
internal void SendActionToQueue(bool build, bool check) { try { // at least one action must be true if (!build && !check) { throw new ApplicationException(SharedSupport.GetLocalizedString("StudentAssignment_Must_Choose_Action")); } // validate userAssignmentId if (_userAssignmentID <= 0) { throw new ApplicationException(SharedSupport.GetLocalizedString("StudentAssignment_InvalidUserAssignmentId")); } // generate the xml System.IO.MemoryStream ms = new System.IO.MemoryStream(); System.Xml.XmlTextWriter xmlwriter = new System.Xml.XmlTextWriter(ms, System.Text.Encoding.ASCII); xmlwriter.Formatting = System.Xml.Formatting.Indented; xmlwriter.WriteStartDocument(false); xmlwriter.WriteStartElement("serverActions"); // build requested? if (build) { // update auto build status - set to pending this._autoCompileStatus = Constants.AUTOCOMPILE_PENDING_STATUS; } // include serverAction element for auto build xmlwriter.WriteStartElement("serverAction"); xmlwriter.WriteAttributeString("name", "AutoBuild"); xmlwriter.WriteElementString("userAssignmentID", this.UserAssignmentID.ToString()); xmlwriter.WriteEndElement(); // check requested? if (check) { // update auto check status - set to pending this._autoGradeStatus = Constants.AUTOGRADE_PENDING_STATUS; this._autoCompileStatus = Constants.AUTOCOMPILE_PENDING_STATUS; // include serverAction element for auto build xmlwriter.WriteStartElement("serverAction"); xmlwriter.WriteAttributeString("name", "AutoCheck"); xmlwriter.WriteElementString("userAssignmentID", this.UserAssignmentID.ToString()); xmlwriter.WriteEndElement(); } xmlwriter.WriteEndElement(); xmlwriter.Flush(); //read all of the stream and convert to a string string msg = System.Text.Encoding.ASCII.GetString(ms.GetBuffer()); // close xmlwriter.Close(); ms.Close(); try { SharedSupport.SendMessageToQueue(Constants.ACTION_QUEUE_PATH, Constants.ACTION_QUEUE_NAME, Constants.AM_SUBMIT_ACTION, msg); } catch (Exception e) { SharedSupport.HandleError(e, "ServerAction_InvalidQueue"); } // update the status of the userAssignments this.LastUpdatedDate = DateTime.Now; this.Update(); } catch (Exception ex) { SharedSupport.HandleError(ex); } }
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); } }