Exemple #1
0
        private byte[] GetDirectoryData(CFile dir)
        {
            FileSystem fs = new FileSystem(Globals.CurrentIdentity);

            //Create our external sink (gonna be an archive, so safe cast)
            IMemorySink extsink =
                ArchiveToolFactory.GetInstance().CreateArchiveTool(".zip") as IMemorySink;
            extsink.CreateSink(null);

            //Export data
            fs.ExportData("", dir, extsink, false);
            byte[] data = extsink.GetSinkData();
            extsink.CloseSink();

            return data;
        }
Exemple #2
0
        public string Backup(string username, int courseID, int asstID, IExternalSink extsink)
        {
            string zfile, wzfile, backdesc=username+": ";
            //Create our external sink file
            if (extsink == null) {
                extsink = ArchiveToolFactory.GetInstance().CreateArchiveTool(".zip") as IExternalSink;
                zfile = username+DateTime.Now.Hour+DateTime.Now.Minute+DateTime.Now.Second+".zip";
                wzfile = Globals.BackupDirectoryName + "/" + zfile;
                zfile = Path.Combine(Globals.BackupDirectory, zfile);
                extsink.CreateSink(zfile);
            }
            else {
                wzfile = zfile = ""; // In the middle of a backup
            }
            //Backup Results

            //Back up submissions
            FileSystem fs = new FileSystem(m_ident);
            Components.Submission.SubmissionList subs;
            if (asstID < 0) {
                if (zfile != "")
                    backdesc += (new Courses(m_ident).GetInfo(courseID)).Name;
                subs = GetCourseSubmissions(username, courseID);
            }
            else {
                if (zfile != "")
                    backdesc += new Assignments(m_ident).GetInfo(asstID).Description;
                subs = GetAsstSubmissions(username, asstID);
            }

            foreach (Components.Submission sub in subs)
                fs.ExportData(username, sub.LocationID, extsink, true);

            //If we are doing this not in a batch
            if (zfile != "") extsink.CloseSink();

            //Log backup in database
            if (zfile != "") new Backups(Globals.CurrentIdentity).Create(
                                 backdesc, wzfile, courseID);

            return zfile;
        }
Exemple #3
0
        private string ExportToTemp(AutoEvaluation eval)
        {
            FileSystem fs = new FileSystem(Globals.CurrentIdentity);

            string tpath = Path.Combine(Globals.TempDirectory, Globals.CurrentUserName);
            try { Directory.Delete(tpath); } catch (Exception) { }
            Directory.CreateDirectory(tpath);

            IExternalSink tsink = new OSFileSystemSink();
            tsink.CreateSink("");

            //Export eval files (JUnit test suite)
            try {
                fs.ExportData(tpath, fs.GetFile(eval.ZoneID), tsink, false);
            } catch (Exception er) {
                string mike = er.Message;
            }

            //Export jdisco program
            try {
                fs.ExportData(tpath, fs.GetFile(@"c:\system\junit"), tsink, false);
            } catch (Exception er) {
                string mike = er.Message;
            }

            return tpath;
        }
Exemple #4
0
        protected bool CreateZone(IZoneComponent eval)
        {
            FileSystem fs = new FileSystem(m_ident);
            DataSet desc = new DataSet();

            //Create initial zone directory
            string zpath = Path.Combine(TestConfig.LocalZonePath,
                m_prefix + eval.GetZoneID().ToString());
            Directory.CreateDirectory(zpath);

            //Export the zone files into local store
            IExternalSink zdir = new OSFileSystemSink();

            zdir.CreateSink("");
            try {
                desc = fs.ExportData(zpath, fs.GetFile(eval.GetZoneID()), zdir, false);

                //Write XML descriptor
                desc.Tables["Export"].Rows[0]["Mod"] = eval.GetZoneModified().Ticks;
                desc.WriteXml(Path.Combine(zpath, ZONE_FILE));
                m_logger.Log("Zone retrieved successfully");

            } catch (FileOperationException e) {
                m_logger.Log("File error: " + e.Message, TestLogger.LogType.ERROR);
                zdir.CloseSink();
                return false;
            } catch (DataAccessException er) {
                m_logger.Log("Data error: " + er.Message, TestLogger.LogType.ERROR);
                zdir.CloseSink();
                return false;
            } catch (Exception e) {
                m_logger.Log("Unexpected error: " + e.Message, TestLogger.LogType.ERROR);
                m_logger.Log("Trace: " + e.StackTrace, TestLogger.LogType.ERROR);
                zdir.CloseSink();
                return false;
            }

            return true;
        }