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); } }
public void Fill(DataSet ds) { adap.SelectCommand = cmd; try { adap.Fill(ds); } catch (System.Exception e) { SharedSupport.HandleError(e); } }
public void Execute() { try { con.Open(); cmd.ExecuteNonQuery(); } catch (System.Exception e) { SharedSupport.HandleError(e); } finally { con.Close(); } }
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); } }
internal static bool SecurityIsAllowed(SecurityAction action, out PermissionsID maxPermID) { int userID = SharedSupport.GetUserIdentity(); System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection(SharedSupport.ConnectionString); System.Data.OleDb.OleDbDataAdapter cmd = new System.Data.OleDb.OleDbDataAdapter("Security_GlobalIsAllowed", con); System.Data.DataSet ds = new System.Data.DataSet(); System.Data.OleDb.OleDbParameter param; cmd.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure; param = new System.Data.OleDb.OleDbParameter("@UserID", System.Data.OleDb.OleDbType.Integer); param.Value = userID; cmd.SelectCommand.Parameters.Add(param); param = new System.Data.OleDb.OleDbParameter("@ActionID", System.Data.OleDb.OleDbType.Integer); param.Value = (int)action; cmd.SelectCommand.Parameters.Add(param); maxPermID = PermissionsID.Student; try { cmd.Fill(ds); } catch (System.Exception e) { SharedSupport.HandleError(e); } try { if (Convert.ToInt32(ds.Tables[0].Rows[0]["UserID"]) == userID) { maxPermID = (PermissionsID)Convert.ToInt32(ds.Tables[0].Rows[0]["RoleID"]); return(true); } } catch { return(false); } return(false); }
/// <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); } }
/// <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); } }
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); } }
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); } }
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); } }