示例#1
0
        /// <summary>
        /// Returns the requested course document.
        /// </summary>
        /// <param name="courseId"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public ActionResult GetCourseDocument(int courseId, string file)
        {
            Course course = Db.Courses.Where(a => a.Id == courseId).FirstOrDefault();

            if (course == null)
            {
                //course does not exist
                return(RedirectToAction("Index", "Feed"));
            }

            FileSystem     fs         = new FileSystem();
            FileCollection collection = fs.Course(course).CourseDocs().File(file);

            if (collection.Count == 0)
            {
                //file does not exist
                return(RedirectToAction("Details", "Course", new { id = course.Id }));
            }
            FileStream stream = System.IO.File.OpenRead(collection.FirstOrDefault());

            return(new FileStreamResult(stream, "application/octet-stream")
            {
                FileDownloadName = Path.GetFileName(collection.FirstOrDefault())
            });
        }
示例#2
0
        /// <summary>
        /// Returns the requested file attached to the supplied assignment.
        /// </summary>
        /// <param name="assignmentId"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public ActionResult GetAssignmentAttachment(int assignmentId, string file)
        {
            Assignment assignment = Db.Assignments.Where(a => a.Id == assignmentId).FirstOrDefault();

            if (assignment == null)
            {
                //assignment does not exist
                return(RedirectToAction("Index", "Feed"));
            }

            FileSystem     fs         = new FileSystem();
            FileCollection collection = fs.Course(assignment.CourseId).Assignment(assignment).Attachments().File(file);

            if (collection.Count == 0)
            {
                //file does not exist
                return(RedirectToAction("Details", "Course", new { id = assignment.CourseId }));
            }
            FileStream stream = System.IO.File.OpenRead(collection.FirstOrDefault());

            return(new FileStreamResult(stream, "application/octet-stream")
            {
                FileDownloadName = Path.GetFileName(collection.FirstOrDefault())
            });
        }
示例#3
0
 void _files_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (_files.TotalUploadedFiles == 0)
     {
         if (_files.Count == 0)
         {
             VisualStateManager.GoToState(this, "Empty", true);
             SelectFilesButton.Visibility = System.Windows.Visibility.Visible;
         }
         else
         {
             if (_files.FirstOrDefault(f => f.State == Enums.FileStates.Uploading) != null)
             {
                 VisualStateManager.GoToState(this, "Uploading", true);
             }
             else if (_files.FirstOrDefault(f => f.State == Enums.FileStates.Finished) != null)
             {
                 VisualStateManager.GoToState(this, "Finished", true);
             }
             else
             {
                 SelectFilesButton.Visibility = System.Windows.Visibility.Collapsed;
                 VisualStateManager.GoToState(this, "Selected", true);
             }
         }
     }
 }
示例#4
0
 void _files_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (_files.Count == 0)
     {
         VisualStateManager.GoToState(this, "Empty", true);
     }
     else
     {
         if (_files.FirstOrDefault(f => f.State == Enums.FileStates.Uploading) != null)
         {
             VisualStateManager.GoToState(this, "Uploading", true);
         }
         else if (_files.FirstOrDefault(f => f.State == Enums.FileStates.Finished) != null)
         {
             VisualStateManager.GoToState(this, "Finished", true);
         }
         else
         {
             VisualStateManager.GoToState(this, "Selected", true);
         }
     }
 }
示例#5
0
        /// <summary>
        /// Sets up ViewBags for the given gradebookName. The assumption made in this function is that the StudentID number is in
        /// column 0.
        /// </summary>
        /// <param name="gradebookName"></param>
        private void SetUpViewBagForGradebook(CourseUserRelationship courseUser, string gradebookName)
        {
            //Get the GradebookFilePath for current course, then the FileCollection for the given gradebookName
            FileSystem        fs        = new FileSystem();
            GradebookFilePath gfp       = fs.Course(courseUser.CourseId).Gradebook();
            FileCollection    gradebook = gfp.File(gradebookName + ".csv");;

            //Getting the filePath, which is the filename in the file collction
            string filePath = gradebook.FirstOrDefault();

            //Open the file as a FileStream. For this, we want to wrap it in a try/catch block, as others might be attempting to use this stream
            //at the same time. We'll allow it attempt to open the stream for up to maxTime.
            FileStream stream    = null;
            TimeSpan   interval  = new TimeSpan(0, 0, 0, 0, 50);
            TimeSpan   totalTime = new TimeSpan();
            TimeSpan   maxTime   = new TimeSpan(0, 0, 0, 4, 0); //4second max wait before giving up

            while (stream == null)
            {
                try
                {
                    //Get the stream related to the current file
                    stream = new FileStream(filePath, FileMode.Open);
                }
                catch (IOException ex)
                {
                    Thread.Sleep(interval);
                    totalTime += interval;

                    //if we've waited longer than maxTime, throw the original exception
                    if (totalTime > maxTime)
                    {
                        throw ex;
                    }
                }
            }

            //reading the file into a List of List of strings using CSVReader.
            List <List <string> > table     = new List <List <string> >();
            CsvReader             csvReader = new CsvReader(stream);

            table = csvReader.Parse();
            stream.Close(); //close the stream to allow others to access it.

            //If the user is NOT an instructor or TA, then only display them rows that match their UserProfileID.
            if (courseUser.Role == CourseRole.Student)
            {
                table = ParseStudentTable(courseUser, table);
            }
            else
            {
                List <int> globalRows    = new List <int>();
                List <int> hiddenColumns = new List <int>();
                //find which rows should be displayed as "globals"
                for (int i = 0; i < table.Count; i++)
                {
                    //Add global rows (denoted by a leading '#').
                    if (table[i][0].Length > 0 && table[i][0][0] == '#')
                    {
                        globalRows.Add(i);
                        for (int j = 0; j < table[i].Count; j++) //go through each cell in global row and check for hidden column values
                        {
                            if (table[i][j].Length > 2 && table[i][j][0] == '!' && table[i][j][1] == '!')
                            {
                                hiddenColumns.Add(j);
                            }
                        }
                    }
                }



                ViewBag.Instructor_ColumnsToHide = hiddenColumns;
                ViewBag.NameColumnIndex          = 1; //AC: ??
                ViewBag.GlobalRows = globalRows;
            }


            ViewBag.TableData = table;
        }