示例#1
0
        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();
            }
        }
        /// <summary>
        /// Event fires when a message arrives on the queue.  Pulls the message and hands
        /// the information off to the AssignmentManager.ServerAction class to process
        /// </summary>
        public void OnReceiveCompleted(Object source, System.Messaging.ReceiveCompletedEventArgs e)
        {
            ServerAction sa = new ServerAction();

            // grab the queue information
            MessageQueue mq = (MessageQueue)source;

            // grab the message
            System.Messaging.Message m = mq.EndReceive(e.AsyncResult);
            m.Formatter = new System.Messaging.XmlMessageFormatter(new String[] { "System.String" });

            // process the message
            string msgBody = (string)m.Body;

            try
            {
                bool result = sa.ProcessMessage(msgBody, m.Label);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry(this.ServiceName.ToString(), ex.ToString());
            }
            finally
            {
                // continue listening on the queue
                mq.BeginReceive();
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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);
            }
        }
示例#5
0
        /// <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();
                }
            }
        }