public void RetrieveElements() { try { sourceLocation = string.Empty; projectFileLocation = string.Empty; projectName = String.Empty; processTime = 0; buildType = String.Empty; buildPath = String.Empty; AssignmentM assign = AssignmentM.Load(studentAssignment.AssignmentID); sourceLocation = assign.StorageDirectory + studentAssignment.UserID; sourceLocation = SharedSupport.AddBackSlashToDirectory(sourceLocation.Trim()); //Get the allowable time to compile processTime = Convert.ToInt32(SharedSupport.GetSetting(Constants.MAX_PROCESS_SETTING)); // get project file location and project name ProjectInfo objPI = new ProjectInfo(sourceLocation); projectFileLocation = objPI.ProjectFile.Trim(); projectName = objPI.ProjectName.Trim(); buildType = objPI.ConfigName.Trim(); buildPath = objPI.BuildPath.Trim(); //Copy UserAssignment files to temp location ServerAction.CopyDirectories(sourceLocation, workingDirectory, true, true); // get the projectFile from the path string projectFile = Path.GetFileName(projectFileLocation); // change the projectFileLocation because we copied to the working directory projectFileLocation = SharedSupport.AddBackSlashToDirectory(workingDirectory) + projectFile; } catch (Exception ex) { SharedSupport.HandleError(ex); } }
public void RetrieveElements() { try { AssignmentM assign = AssignmentM.Load(studentAssignment.AssignmentID); processTime = Convert.ToInt32(SharedSupport.GetSetting(Constants.MAX_PROCESS_SETTING)); // student source location sourceLocation = assign.StorageDirectory + studentAssignment.UserID; // get compiled file name (already built by build process) ProjectInfo objPI = new ProjectInfo(sourceLocation); compiledFileName = objPI.OutputFile; inputFileLocation = assign.InputFile; expectedOutputFileLocation = assign.OutputFile; actualOutputFile = expectedOutputFileLocation; commandLineParams = assign.CommandLineArgs; compiledFileLocation = SharedSupport.AddBackSlashToDirectory(workingDirectory) + compiledFileName; expectedOutputFileLocation = assign.StorageDirectory + expectedOutputFileLocation; //change to use inputFileLocation in tempworkarea inputFileLocation = SharedSupport.AddBackSlashToDirectory(assign.StorageDirectory) + inputFileLocation; //Get the user's submission folder location string userSubmissionRootFolder = SharedSupport.AddBackSlashToDirectory(sourceLocation); //Copy all files under the student's submission directory, to the working area. ServerAction.CopyDirectories(userSubmissionRootFolder, workingDirectory, true, true); } catch (Exception ex) { SharedSupport.HandleError(ex); } }
// validates, processes directions inside XML Message; returns true if ok to remove msg from queue internal bool ProcessMessage(string message, string label) { // always return true because always want to remove message from queue in this implementation try { // raise error if no label or message label = label.Trim(); message = message.Trim(); if (label.Equals(String.Empty)) { SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_MissingLabel"))); } if (message.Equals(String.Empty)) { SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_MissingBody"))); } // xml object declarations XmlDocument doc = new XmlDocument(); doc.LoadXml(message); //load the string as xml XPathNavigator nav = ((IXPathNavigable)doc).CreateNavigator(); // misc vars bool bCheckRequested = false; // track if check requested bool bBuildSuccessful = false; // track if build successful int buildUserAssnId = 0; // build userAssignmentId int checkUserAssnId = 0; // check userAssignmentId string buildResults = string.Empty; // results of the build string checkResults = string.Empty; // results of the check string workingDirectory = string.Empty; // working directory //------------------------------------------------------------------------------------------------------------- // evaluate label, parse xml message; extract instructions //------------------------------------------------------------------------------------------------------------- switch (label) { //////////////////////////////////////////////////////////////// // This is a submit action //////////////////////////////////////////////////////////////// case Constants.AM_SUBMIT_ACTION: // select the serverActions XPathNodeIterator serverActionsIterator = nav.Select("serverActions/serverAction"); // retrieve all serverAction actions from xml while (serverActionsIterator.MoveNext()) { // perform the appropriate action evaluating the serverAction attribute string actionCommand = serverActionsIterator.Current.GetAttribute("name", doc.NamespaceURI).ToString().Trim(); switch (actionCommand) { ////////////////////////////////////////////////////////////// // AutoBuild ///////////////////////////////////////////////////////////// case Constants.AM_BUILD: // grab the userAssignmentId from the xml buildUserAssnId = Convert.ToInt32(serverActionsIterator.Current.Value.ToString()); ///////////////////////////////////////////////// // extensibility: add custom parameters here ///////////////////////////////////////////////// break; ///////////////////////////////////////////////////////////// // AutoCheck ///////////////////////////////////////////////////////////// case Constants.AM_CHECK: // set check flag bCheckRequested = true; // grab the userAssignmentId from the xml checkUserAssnId = Convert.ToInt32(serverActionsIterator.Current.Value.ToString()); ///////////////////////////////////////////////// // extensibility: add custom parameters here ///////////////////////////////////////////////// break; ///////////////////////////////////////////////// // extensibility: add future submit actions here ///////////////////////////////////////////////// // 1. load all actions from ServerActions table // 2. loop actions; do any match xml serverAction element? // 3. if so, retrieve parameters from ServerActions // 4. make 'late bound' call to proper class, method ///////////////////////////////////////////////// default: break; } } break; ///////////////////////////////////////////////// // extensibility: add future actions here ///////////////////////////////////////////////// default: throw new System.NotImplementedException(SharedSupport.GetLocalizedString("ServerAction_ActionNotImplemented")); } //------------------------------------------------------------------------------------------------------------- // execute instructions from xml message in proper order //------------------------------------------------------------------------------------------------------------- // perform prep work, execute build, record results; returns true if successful // we always do the build: necessary for check and expected by custom actions // set the working directory workingDirectory = getUserWorkingDirectory(); //////////////////////////////////////////// // Perform AutoBuild //////////////////////////////////////////// // check to make sure we have a valid userAssignmentId if (buildUserAssnId == 0) { if (checkUserAssnId == 0) { // raise error SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_MissingUserAssignmentElement"))); } else { // set the buildUserAssnId = check buildUserAssnId = checkUserAssnId; } } // raise error if no buildUserAssnId if (buildUserAssnId <= 0) { SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_MissingUserAssignmentElement"))); } // raise error if build disabled on the server if (!Convert.ToBoolean(SharedSupport.GetSetting(Constants.AUTOBUILD_SETTING))) { SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_BuildDisabled"))); } // delete any previous user assignment detail records for this userassignment and detail type deleteUserAssignmentDetails(buildUserAssnId, Constants.AUTO_COMPILE_DETAILTYPE); bBuildSuccessful = AutoBuild.Run(buildUserAssnId, workingDirectory); // was check requested? if (bCheckRequested) { //////////////////////////////////////////// // Perform AutoCheck //////////////////////////////////////////// // raise error if no checkUserAssnId if (checkUserAssnId <= 0) { SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_MissingUserAssignmentElement"))); } // check that checkUserAssnId = buildUserAssnId; if (checkUserAssnId != buildUserAssnId) { // raise error SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_DifferentUserAssignmentIDs"))); } else { // did the build execute ok if it was requested? if (bBuildSuccessful) { // raise error if check disabled on the server if (!Convert.ToBoolean(SharedSupport.GetSetting(Constants.AUTOCHECK_SETTING))) { SharedSupport.HandleError(new System.Exception(SharedSupport.GetLocalizedString("ServerAction_CheckDisabled"))); } AutoCheck.Run(buildUserAssnId, workingDirectory); } } } //////////////////////////////////////////// // extensibility: CUSTOM ACTIONS //////////////////////////////////////////// } catch (System.Exception ex) { SharedSupport.LogMessage(ex.Message + " " + SharedSupport.GetLocalizedString("ServerAction_GeneralProcessError") + " " + label + " " + SharedSupport.GetLocalizedString("ServerAction_GeneralProcessErrorBody") + " " + message + " ", SharedSupport.GetLocalizedString("ServerAction_MethodName"), System.Diagnostics.EventLogEntryType.Warning); } // returning true here ensures message is removed from the queue return(true); }