public void StoreResult() { // copy the resulting exe file(s) to the root of the working directory for use in checking if build successful if (buildSuccessful) { string binDirectory = SharedSupport.AddBackSlashToDirectory(workingDirectory) + buildPath; ServerAction.CopyDirectories(binDirectory, sourceLocation, true, false); //store the failure studentAssignment.BuildDetails = buildResults; studentAssignment.LastUpdatedDate = System.DateTime.Now; studentAssignment.AutoCompileStatus = Constants.AUTOCOMPILE_SUCCESSFUL_STATUS; studentAssignment.BuildResultCode = Constants.AUTOCOMPILE_RETURN_CODE_SUCCESS.ToString(); studentAssignment.Update(); } else { //store the failure studentAssignment.BuildDetails = buildResults; studentAssignment.LastUpdatedDate = System.DateTime.Now; studentAssignment.AutoCompileStatus = Constants.AUTOCOMPILE_FAILURE_STATUS; studentAssignment.BuildResultCode = Constants.AUTOCOMPILE_RETURN_CODE_FAILURE.ToString(); studentAssignment.Update(); } }
private string getUserWorkingDirectory() { string workingDirectory = string.Empty; //Get system temp location, add guid string newGuid = System.Guid.NewGuid().ToString(); workingDirectory = SharedSupport.AddBackSlashToDirectory(System.Environment.GetEnvironmentVariable(Constants.TEMP_ENVIRON_VARIABLE)); workingDirectory += SharedSupport.AddBackSlashToDirectory(Constants.ASSIGNMENT_MANAGER_DIRECTORY); workingDirectory += SharedSupport.AddBackSlashToDirectory(newGuid); workingDirectory = workingDirectory.Trim(); return(workingDirectory); }
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); } }
/// <summary> /// Copies one directory, all files, and all sub directories to another directory. /// </summary> /// <param name="sourceDirectory">Directory to copy files and sub-directories from. </param> /// <param name="destinationDirectory">Directory to copy files and sub-directories to. </param> /// <param name="overwriteFlag">Determines whether or not to overwrite a file if it already exists at the given location</param> internal static void CopyDirectories(string sourceDirectory, string destinationDirectory, bool overwriteFlag, bool useImpersonation) { SecurityACL dacl = null; try { sourceDirectory = SharedSupport.AddBackSlashToDirectory(sourceDirectory); destinationDirectory = SharedSupport.AddBackSlashToDirectory(destinationDirectory); if (!Directory.Exists(sourceDirectory)) { //If the source directory does not exist throw a new error. throw new DirectoryNotFoundException(SharedSupport.GetLocalizedString("StudentAssignment_DirectoryNotFound") + sourceDirectory); } if (!Directory.Exists(destinationDirectory)) { if (useImpersonation) { // Impersonate the AM User ImpersonateUser User = null; try { User = new ImpersonateUser(); // Login User.Logon(); // start impersonating User.Start(); //if the destination does not exist, create it. Directory.CreateDirectory(destinationDirectory); } finally { if (User != null) { // stop impersonating User.Stop(); User.Dispose(); } } } else { Directory.CreateDirectory(destinationDirectory); } } //copy each file in the current directory string[] f = Directory.GetFiles(sourceDirectory); dacl = new SecurityACL(Constants.AMUserName); for (int i = 0; i < f.Length; i++) { if (!File.Exists(f[i].ToString())) { throw new FileNotFoundException(sourceDirectory + f[i].ToString()); } else { string sourceFile = sourceDirectory + Path.GetFileName(f[i].ToString()); string destinationFile = destinationDirectory + Path.GetFileName(f[i].ToString()); File.Copy(sourceFile, destinationFile, overwriteFlag); dacl.ApplyACLToFile(destinationFile); } } // recursively copy each subdirectory in the current directory string[] d = Directory.GetDirectories(sourceDirectory); if (d.Length > 0) { for (int i = 0; i < d.Length; i++) { string sourceDir = d[i].ToString(); string destDir = destinationDirectory + d[i].ToString().Replace(sourceDirectory, String.Empty); if (!Directory.Exists(destDir)) { if (useImpersonation) { // Impersonate the AM User ImpersonateUser User = null; try { User = new ImpersonateUser(); // Login User.Logon(); // start impersonating User.Start(); //if the destination does not exist, create it. Directory.CreateDirectory(destDir); } finally { if (User != null) { // stop impersonating User.Stop(); User.Dispose(); } } } else { Directory.CreateDirectory(destDir); } } ServerAction.CopyDirectories(sourceDir, destDir, overwriteFlag, useImpersonation); } } } catch (Exception ex) { SharedSupport.HandleError(ex); } finally { if (dacl != null) { dacl.Dispose(); } } }
public void RunService() { //Create a new Process UserProcess compile = new UserProcess(); try { System.Text.ASCIIEncoding AE = new System.Text.ASCIIEncoding(); byte[] ByteArray = { 34 }; // " string singleQuote = AE.GetString(ByteArray); // path to output file string outputFilePath = SharedSupport.AddBackSlashToDirectory(workingDirectory) + OUTPUT_FILE; if (File.Exists(outputFilePath)) { File.Delete(outputFilePath); } //put quotes around command line arguments to avoid problems with spaces projectFileLocation = "\"" + projectFileLocation + "\""; buildType = "\"" + buildType + "\""; projectName = "\"" + projectName + "\""; //populate the process information compile.StartInfo.WorkingDirectory = workingDirectory; compile.StartInfo.FileName = getDevEnvPath() + DEVENV; compile.StartInfo.Arguments = projectFileLocation + BACKSLASH_BUILD + buildType + BACKSLASH_PROJECT + projectName + BACKSLASH_OUT + OUTPUT_FILE; compile.OutputFile = outputFilePath; compile.StartInfo.RedirectStandardOutput = true; compile.StartInfo.RedirectStandardError = false; compile.StartInfo.UseShellExecute = false; //start the compile process if (!compile.Run(processTime)) { throw new System.Exception(SharedSupport.GetLocalizedString("ServerAction_FailedCreateBuildProcess")); } // if the process exceeds allotted time, kill if (!compile.HasExited) { outputExitCode = Constants.AUTOCOMPILE_RETURN_CODE_FAILURE; buildResults = SharedSupport.GetLocalizedString("StudentAssignment_Killed"); } else { // ok: exited before allotted time outputExitCode = (int)compile.ExitCode; // retrieve outcome from output.log file StreamReader sr = new StreamReader(new FileStream(outputFilePath, FileMode.Open, FileAccess.Read)); buildResults = sr.ReadToEnd(); sr.Close(); } // return compile results (true/false) if (outputExitCode == Constants.AUTOCOMPILE_RETURN_CODE_SUCCESS) { buildSuccessful = true; } } catch (System.Exception ex) { buildResults = ex.Message; buildSuccessful = false; } }