示例#1
0
文件: users.cs 项目: lokygb/FrontDesk
        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);
        }
示例#2
0
        private IExternalSource CreateSource(HttpPostedFile tarchive)
        {
            ArchiveToolFactory afact = ArchiveToolFactory.GetInstance();
            IExternalSource    ztool = afact.CreateArchiveTool(".zip") as IExternalSource;

            ztool.CreateSource(tarchive.InputStream);

            return(ztool);
        }
示例#3
0
            private IExternalSource CreateSource(HttpPostedFile upfile)
            {
                string       ext   = Path.GetExtension(upfile.FileName);
                IArchiveTool etool =
                    ArchiveToolFactory.GetInstance().CreateArchiveTool(ext);

                (etool as IExternalSource).CreateSource(upfile.InputStream);

                return(etool as IExternalSource);
            }
示例#4
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (cmdSubmit.Enabled)
            {
                lblError.Visible = false;
            }

            if (!IsPostBack)
            {
                string[] types = ArchiveToolFactory.GetInstance().ListKeys();
                foreach (string type in types)
                {
                    lblTypes.Text += type + " ";
                }
            }
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
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);
        }