public async Task <IActionResult> Download(string sectionName)
        {
            var section = Classroom.Sections
                          .SingleOrDefault(s => s.Name == sectionName);

            if (section == null)
            {
                return(NotFound());
            }

            var archiveContents = await SubmissionService.DownloadSubmissionsAsync
                                  (
                ClassroomName,
                ProjectName,
                CheckpointName,
                sectionName
                                  );

            var timestamp = TimeZoneProvider.ToUserLocalTime(DateTime.UtcNow)
                            .ToString("yyyyMMdd-HHmmss");

            var filename = $"{Classroom.Name}-{Project.Name}-{Checkpoint.Name}-{timestamp}.zip";

            return(File(archiveContents, "application/zip", filename));
        }
        /// <summary>
        /// Once the user has chosen the download properties, made the student selections, and clicked
        /// the main form submit button, this initiates the actual download
        /// </summary>
        /// <param name="downloadSubmissionViewModel">ViewModel for the form</param>
        public async Task <IActionResult> DownloadSubmissionsAsync(DownloadSubmissionViewModel downloadSubmissionViewModel)
        {
            var selectedStudents = downloadSubmissionViewModel.SectionsAndStudents
                                   .Where
                                   (
                sas => sas.SectionName.Selected
                                   )
                                   .SelectMany
                                   (
                sas => sas.SelectedStudents
                .Where
                (
                    ss => ss.Selected &&
                    (ss.Submitted || downloadSubmissionViewModel.IncludeUnsubmitted)
                )
                .Select
                (
                    ss => ss.Id
                )
                                   ).ToList();

            if (selectedStudents.Count == 0)
            {
                return(NotFound());
            }

            var archiveContents = await SubmissionService.DownloadSubmissionsAsync
                                  (
                ClassroomName,
                ProjectName,
                CheckpointName,
                selectedStudents,
                downloadSubmissionViewModel.Format
                                  );

            var timestamp = TimeZoneProvider.ToUserLocalTime(DateTime.UtcNow)
                            .ToString("yyyyMMdd-HHmmss");

            var filename = $"{Classroom.Name}-{Project.Name}-{Checkpoint.Name}-{timestamp}.zip";

            return(File(archiveContents, "application/zip", filename));
        }
Example #3
0
        void Deserialize(DateDefinition date, XmlReader reader)
        {
            while (reader.Read())
            {
                while (reader.IsStartElement())
                {
                    try
                    {
                        switch (reader.Name)
                        {
                        case "date":
                            var matchD = Regex.Match(reader.ReadElementContentAsString(), @"(?<y>\d{4})-(?<m>\d{1,2})-(?<d>\d{1,2})");
                            if (matchD.Success)
                            {
                                date.Year  = int.Parse(matchD.Groups["y"].Value);
                                date.Month = int.Parse(matchD.Groups["m"].Value);
                                date.Day   = int.Parse(matchD.Groups["d"].Value);
                            }
                            break;

                        case "time":
                            var matchT = Regex.Match(reader.ReadElementContentAsString(), @"(?<h>\d{1,2}):(?<m>\d{1,2})(:(?<s>\d{1,2}))?(\.(?<l>\d{1,4}))?");
                            if (matchT.Success)
                            {
                                date.Hour        = int.Parse(matchT.Groups["h"].Value);
                                date.Minute      = int.Parse(matchT.Groups["m"].Value);
                                date.Second      = String.IsNullOrWhiteSpace(matchT.Groups["s"].Value) ? 0 : int.Parse(matchT.Groups["s"].Value);
                                date.MilliSecond = String.IsNullOrWhiteSpace(matchT.Groups["l"].Value) ? 0 : int.Parse(matchT.Groups["l"].Value);
                            }
                            break;

                        case "timezone":
                            String content = reader.ReadElementContentAsString();
                            if (!String.IsNullOrWhiteSpace(content) && TimeZoneProvider != null)
                            {
                                date.TimeZone = TimeZoneProvider.FindTimeZone(content);
                            }
                            break;

                        case "utc-offset":
                            if (date.TimeZone == null)
                            {
                                date.UtcOffset = TimeSpan.FromHours(Double.Parse(reader.ReadElementContentAsString(), System.Globalization.CultureInfo.InvariantCulture));
                            }
                            else
                            {
                                reader.Read();
                            }
                            break;

                        case "daylight":
                            DayLightDefinition dld;
                            if (Enum.TryParse <DayLightDefinition>(reader.ReadElementContentAsString(), true, out dld))
                            {
                                date.DayLight = dld;
                            }
                            break;

                        default:
                            reader.Read();
                            break;
                        }
                    }
                    catch
                    {
                        reader.Read();
                        throw;
                    }
                }
            }
        }
Example #4
0
        public ConfigResult GetMaintenanceState()
        {
            string maintMsg  = string.Empty;
            var    noticeMsg = conf["NOTICE_MESSAGE"] ?? string.Empty;

            var maintWarn    = conf["MAINTENANCE_WARNING"] ?? string.Empty;
            var maintPageMsg = conf["MAINTENANCE_PAGEDOWN"] ?? "Default";
            var maintTimeStr = conf["MAINTENANCE_START"] ?? string.Empty;

            DateTime maintTime;

            // Check for maintenance or other causes of outage
            var siteDown = false;

            // Check that maintTimeStr is valid datetime format
            if (DateTime.TryParse(maintTimeStr, out maintTime))
            {
                // Timestamp will be in Pacific, so convert local time for comparison
                var curtime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.Now.ToUniversalTime(), TimeZoneProvider.GetPSTTimeZone());

                if (maintTime <= curtime)
                {
                    siteDown = true;
                }
                else
                {
                    maintMsg = maintWarn;
                }
            }

            // Other options for site takedown via maintTimeStr
            if (maintTimeStr.ToLower() == "down")
            {
                siteDown = true;
            }
            else if (maintTimeStr.ToLower() == "warn")
            {
                maintMsg = maintWarn;
            }

            // If site is down, deliver maintenance page message instead of warning, and remove other Notification message
            if (siteDown)
            {
                maintMsg  = maintPageMsg;
                noticeMsg = string.Empty;
            }

            // Return object with details needed for frontend routing
            return(GetConfigResult(noticeMsg, maintMsg, siteDown));
        }