Example #1
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);
        }
Example #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;
        }
Example #3
0
        public string Backup(int asstID)
        {
            string zfile, wzfile;

            Assignment asst = GetInfo(asstID);

            //Check permission
            Authorize(asst.CourseID, "createbackup", asstID, null);

            //Create our external sink file
            IExternalSink extsink =
                ArchiveToolFactory.GetInstance().CreateArchiveTool(".zip") as IExternalSink;

            zfile = Globals.PurifyString(asst.Description) +
                    DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".zip";
            wzfile = Globals.BackupDirectoryName + "/" + zfile;
            zfile  = Path.Combine(Globals.BackupDirectory, zfile);
            extsink.CreateSink(zfile);

            //Backup Info
            //Backup Results

            //Back up submissions
            Users users = new Users(m_ident);

            User.UserList mems = new Courses(m_ident).GetMembers(asst.CourseID, null);

            foreach (User mem in mems)
            {
                users.Backup(mem.UserName, asst.CourseID, asstID, extsink);
            }

            extsink.CloseSink();

            new Backups(m_ident).Create(asst.Description, wzfile, asst.CourseID);

            return(zfile);
        }
Example #4
0
        public DataSet ExportData(string prefix, CFile dir, IExternalSink extsink,
                                  bool exportfp)
        {
            //Init dataset descriptor
            DataSet expdata = new DataSet();

            expdata.DataSetName = "ExportData";
            expdata.Tables.Add("Export"); expdata.Tables.Add("File");
            expdata.Tables["Export"].Columns.Add("Mod");
            expdata.Tables["Export"].Columns.Add("ID");
            expdata.Tables["File"].Columns.Add("type");
            expdata.Tables["File"].Columns.Add("path");
            DataRow toprow = expdata.Tables["Export"].NewRow();

            toprow["Mod"] = dir.FileModified.ToString();
            toprow["ID"]  = dir.ID.ToString();
            expdata.Tables["Export"].Rows.Add(toprow);

            //Do the export
            ExportData(expdata, prefix, dir, extsink, exportfp, "");

            return(expdata);
        }
Example #5
0
        public string Backup(int courseID)
        {
            string zfile, wzfile;

            Authorize(courseID, Permission.COURSE, "createback", courseID, null);

            //Create our external sink file
            IExternalSink extsink =
                ArchiveToolFactory.GetInstance().CreateArchiveTool(".zip") as IExternalSink;
            Course course = GetInfo(courseID);

            zfile  = course.Name + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".zip";
            wzfile = Globals.BackupDirectoryName + "/" + zfile;
            zfile  = Path.Combine(Globals.BackupDirectory, zfile);
            extsink.CreateSink(zfile);

            //Backup Info
            //Backup Results

            //Back up submissions
            Users users = new Users(m_ident);

            User.UserList mems = GetMembers(courseID, null);

            foreach (User mem in mems)
            {
                users.Backup(mem.UserName, courseID, extsink);
            }

            extsink.CloseSink();

            //Log in database
            new Backups(m_ident).Create(GetInfo(courseID).Name, wzfile, courseID);

            return(zfile);
        }
Example #6
0
 public string Backup(string username, int courseID, IExternalSink extsink)
 {
     return Backup(username, courseID, -1, extsink);
 }
Example #7
0
        /// <summary>
        /// Export data to the specified external sink
        /// </summary>
        public void ExportData(DataSet expdata, string prefix, CFile dir, IExternalSink extsink,
                               bool exportfp, string relpath)
        {
            if (!dir.IsDirectory())
            {
                throw new FileOperationException("Cannot export a single file");
            }

            //Authorize
            if (!Authorize(dir, FileAction.READ))
            {
                throw new FileOperationException("Permission denied for operation: READ");
            }

            CFile.FileList dirlist = ListDirectory(dir);
            foreach (CFile file in dirlist)
            {
                string epath;

                if (prefix.Length > 0 && prefix[prefix.Length - 1] != '\\')
                {
                    prefix += @"\";
                }
                if (exportfp)
                {
                    epath = prefix + GetExportPath(file);
                }
                else
                {
                    epath = prefix + relpath + file.Name;
                }

                DataRow dirrow = expdata.Tables["File"].NewRow();
                if (!exportfp)
                {
                    dirrow["path"] = relpath + file.Name;
                }
                else
                {
                    dirrow["path"] = epath;
                }

                ExternalFile extfile = new ExternalFile();
                extfile.Path = epath;

                if (file.IsDirectory())
                {
                    dirrow["type"] = "dir";
                    expdata.Tables["File"].Rows.Add(dirrow);

                    //Create the directory
                    extfile.Directory = true;
                    extsink.PutFile(extfile);

                    ExportData(expdata, prefix, file, extsink, exportfp, relpath + file.Name + @"\");
                }
                else
                {
                    new FileSystem(m_ident).LoadFileData(file);
                    extfile.Size       = file.RawData.Length;
                    extfile.DataStream = new MemoryStream(file.RawData, 0, file.RawData.Length);

                    //File row
                    dirrow["type"] = "file";
                    expdata.Tables["File"].Rows.Add(dirrow);

                    extsink.PutFile(extfile);
                }
            }
        }
Example #8
0
 /// <summary>
 /// Export data to the specified external sink
 /// </summary>
 public DataSet ExportData(string prefix, int id, IExternalSink extsink, bool exportfp)
 {
     return(ExportData(prefix, m_dp.GetFile(id), extsink, exportfp));
 }
Example #9
0
 /// <summary>
 /// Export data to the specified external sink
 /// </summary>
 public DataSet ExportData(string prefix, string fullpath, IExternalSink extsink, bool exportfp)
 {
     return(ExportData(prefix, m_dp.GetFile(fullpath), extsink, exportfp));
 }
Example #10
0
 /// <summary>
 /// Export data to the specified external sink
 /// </summary>
 public DataSet ExportData(string prefix, string name, string path, IExternalSink extsink, bool exportfp)
 {
     return(ExportData(prefix, Path.Combine(path, name), extsink, exportfp));
 }
Example #11
0
 public string Backup(string username, int courseID, IExternalSink extsink)
 {
     return(Backup(username, courseID, -1, extsink));
 }