public IEnumerable <KeyValuePair <string, string> > GetPairs() { yield return(new KeyValuePair <string, string>("Sessions", _project.Sessions.Count.ToString())); yield return(new KeyValuePair <string, string>("People", _project.People.Count.ToString())); yield return(new KeyValuePair <string, string>("", "")); //TODO: this will need to be some kind of background operation foreach (var definition in SessionComponentDefinition.CreateHardCodedDefinitions().Where(def => def.MeasurementType == SessionComponentDefinition.MeasurementTypes.Time)) { yield return(new KeyValuePair <string, string>(definition.Name, GetRecordingDurations(definition).ToString())); } foreach (var definition in SessionComponentDefinition.CreateHardCodedDefinitions().Where(def => def.MeasurementType == SessionComponentDefinition.MeasurementTypes.Time)) { int megabytes = GetMegabytes(definition); string value; if (megabytes > 1000) //review: is a gigabyte 1000, or 1024 megabytes? { value = ((double)megabytes / 1000.0).ToString("N", CultureInfo.InvariantCulture) + " Gigabytes"; } else if (megabytes == 0) { value = "---"; } else { value = megabytes.ToString("###", CultureInfo.InvariantCulture) + " Megabytes"; } yield return(new KeyValuePair <string, string>(definition.Name, value)); } }
private TimeSpan GetDuration() { // TODO: What should we do if DirectX throws an exception (e.g. the path is really // not a valid audio or video stream)? For now, just ignore exceptions. try { if (SessionComponentDefinition.GetIsAudio(Path)) { using (var audio = new Microsoft.DirectX.AudioVideoPlayback.Audio(Path)) { return(TimeSpan.FromSeconds((int)audio.Duration)); } } else if (SessionComponentDefinition.GetIsVideo(Path)) { using (var video = new Microsoft.DirectX.AudioVideoPlayback.Video(Path)) { return(TimeSpan.FromSeconds((int)video.Duration)); } } } catch (ThreadAbortException) { //fine, just return } catch (Exception e) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem(e, "Could not get duration of " + Path); } return(new TimeSpan()); }
public void GetOriginalRecordingTime_NoRecording_Zero() { SessionComponentDefinition originalRecording = SessionComponentDefinition.CreateHardCodedDefinitions().First(); using (var test = new TestProjectWithSessions(1)) { SpongeProject project = test.Project; Assert.AreEqual(new TimeSpan(0), CreateModel(project).GetRecordingDurations(originalRecording)); } }
public void GetRecordingDurations_SomeRecording_MoreThanZero() { using (var test = new TestProjectWithSessions(1)) { SessionComponentDefinition firstRole = SessionComponentDefinition.CreateHardCodedDefinitions().First(); CreateCanonciallyNamedRecordingInSession(firstRole, test.Project.Sessions[0]); SpongeProject project = test.Project; Assert.Less(new TimeSpan(0), CreateModel(project).GetRecordingDurations(firstRole)); } }
private int GetMegabytes(SessionComponentDefinition definition) { long bytes = 0; foreach (FileStatistics stat in _backgroundStatisticsGather.GetAllStatistics()) { if (definition.MatchFilter(stat.Path)) { bytes += stat.LengthInBytes; } } return((int)((float)bytes / (float)(1024 * 1024))); }
public TimeSpan GetRecordingDurations(SessionComponentDefinition definition) { var total = new TimeSpan(0); foreach (FileStatistics stat in _backgroundStatisticsGather.GetAllStatistics()) { if (definition.MatchFilter(stat.Path)) { total += stat.Duration; } } return(total); }
public void GetRecordingDurations_DistinguishesBetweenRoles() { using (var test = new TestProjectWithSessions(1)) { SessionComponentDefinition firstRole = SessionComponentDefinition.CreateHardCodedDefinitions().First(); CreateCanonciallyNamedRecordingInSession(firstRole, test.Project.Sessions[0]); SessionComponentDefinition secondRole = SessionComponentDefinition.CreateHardCodedDefinitions().ToArray()[1]; SpongeProject project = test.Project; TimeSpan t = CreateModel(project).GetRecordingDurations(secondRole); Assert.AreEqual(new TimeSpan(0), t, "should not find any files with the second role"); } }
private static void CreateCanonciallyNamedRecordingInSession(SessionComponentDefinition roleDefinition, Session session) { var path = CreateRecording(session.Folder); File.Move(path, roleDefinition.GetCanoncialName(session.Id, path)); }