public void EqualityCorrect() { AnnotationSegment annotationSegment1 = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm()); AnnotationSegment annotationSegment2 = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm()); Assert.True(annotationSegment1.Equals(annotationSegment2)); }
public void TermSetCorrectly() { IEdmTerm term = HardCodedTestModel.GetPrimitiveAnnotationTerm(); AnnotationSegment segment = new AnnotationSegment(term); segment.Term.Should().Be(term); }
public async Task VisitAsync(ODataPath path) { NotFound = false; BadRequest = false; Result = null; ResultType = null; PropertySetter = null; Index = 0; foreach (var segment in path) { await(segment switch { TypeSegment typeSegment => VisitAsync(typeSegment), NavigationPropertySegment navigationPropertySegment => VisitAsync(navigationPropertySegment), EntitySetSegment entitySetSegment => VisitAsync(entitySetSegment), SingletonSegment singletonSegment => VisitAsync(singletonSegment), KeySegment keySegment => VisitAsync(keySegment), PropertySegment propertySegment => VisitAsync(propertySegment), AnnotationSegment annotationSegment => VisitAsync(annotationSegment), OperationImportSegment operationImportSegment => VisitAsync(operationImportSegment), OperationSegment operationSegment => VisitAsync(operationSegment), DynamicPathSegment dynamicPathSegment => VisitAsync(dynamicPathSegment), CountSegment countSegment => VisitAsync(countSegment), FilterSegment filterSegment => VisitAsync(filterSegment), ReferenceSegment referenceSegment => VisitAsync(referenceSegment), EachSegment eachSegment => VisitAsync(eachSegment), NavigationPropertyLinkSegment navigationPropertyLinkSegment => VisitAsync(navigationPropertyLinkSegment), ValueSegment valueSegment => VisitAsync(valueSegment), BatchSegment batchSegment => VisitAsync(batchSegment), BatchReferenceSegment batchReferenceSegment => VisitAsync(batchReferenceSegment), MetadataSegment metadataSegment => VisitAsync(metadataSegment), PathTemplateSegment pathTemplateSegment => VisitAsync(pathTemplateSegment), _ => throw new NotSupportedException() });
public void EqualityCorrect() { AnnotationSegment annotationSegment1 = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm()); AnnotationSegment annotationSegment2 = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm()); annotationSegment1.Equals(annotationSegment2).Should().BeTrue(); }
/// ------------------------------------------------------------------------------------ public bool InitializeAnnotationPlayer(AnnotationSegment segment) { CloseAnnotationPlayer(); var filename = GetFullPathToAnnotationFileForSegment(segment); if (!File.Exists(filename)) { return(false); } var fi = new FileInfo(filename); if (fi.Length == 0) { fi.Delete(); return(false); } AudioUtils.NAudioExceptionThrown += HandleNAudioExceptionThrownDuringPlayback; _annotationPlayer = new AudioPlayer(); _annotationPlayer.LoadFile(filename); _annotationPlayer.PlaybackStarted += (sender, args) => InvokeUpdateDisplayAction(); _annotationPlayer.Stopped += delegate { InvokeUpdateDisplayAction(); CloseAnnotationPlayer(); }; return(true); }
/// ------------------------------------------------------------------------------------ public void SetIgnoredFlagForSegment(AnnotationSegment segment, bool ignore) { if (segment != null) { var segmentIndex = TimeTier.GetIndexOfSegment(segment); var timeRange = segment.TimeRange.Copy(); if (ignore) { Action restoreState = GetActionToRestoreStateWhenUndoingAnIgnore(segment); Tiers.MarkSegmentAsIgnored(segmentIndex); _undoStack.Push(new SegmentChange(SegmentChangeType.Ignored, timeRange, timeRange, sc => { Tiers.MarkSegmentAsUnignored(segmentIndex); restoreState(); })); } else { Tiers.MarkSegmentAsUnignored(segmentIndex); _undoStack.Push(new SegmentChange(SegmentChangeType.Unignored, timeRange, timeRange, sc => Tiers.MarkSegmentAsIgnored(segmentIndex))); } } else { if (!ignore) { throw new InvalidOperationException("New segment can never be unignored."); } AddIgnoredSegment(VirtualBoundaryBeyondLastSegment); } }
/// ------------------------------------------------------------------------------------ protected override Action GetActionToRestoreStateWhenUndoingAnIgnore(AnnotationSegment segment) { var timeRange = segment.TimeRange.Copy(); Action restoreOtherFileIfNeeded = () => { }; var otherPath = GetFullPathOfOtherAnnotationFileForTimeRange(timeRange); if (File.Exists(otherPath)) { BackupOralAnnotationSegmentFile(otherPath, true); restoreOtherFileIfNeeded = () => RestorePreviousVersionOfAnnotation(otherPath); } var path = GetFullPathOfAnnotationFileForTimeRange(timeRange); if (File.Exists(path)) { BackupOralAnnotationSegmentFile(path, true); return(() => { RestorePreviousVersionOfAnnotation(timeRange); restoreOtherFileIfNeeded(); }); } if (segment == CurrentUnannotatedSegment) { return () => { CurrentUnannotatedSegment = segment; restoreOtherFileIfNeeded(); } } ; return(base.GetActionToRestoreStateWhenUndoingAnIgnore(segment)); }
/// ------------------------------------------------------------------------------------ protected bool ConfirmDeletionOfOralAnnotations(AnnotationSegment segment, bool hasCarefulSpeech, bool hasOralTranslation) { if (AllowDeletionOfOralAnnotations == null || !AllowDeletionOfOralAnnotations(hasCarefulSpeech, hasOralTranslation)) { return(false); } _oralAnnotationFilesToDelete = new List <string>(2); var carefulSpeechAnnotationPath = segment.GetFullPathToCarefulSpeechFile(); if (carefulSpeechAnnotationPath != null && File.Exists(carefulSpeechAnnotationPath)) { _oralAnnotationFilesToDelete.Add(carefulSpeechAnnotationPath); } var oralTranslationAnnotationPath = segment.GetFullPathToOralTranslationFile(); if (oralTranslationAnnotationPath != null && File.Exists(oralTranslationAnnotationPath)) { _oralAnnotationFilesToDelete.Add(oralTranslationAnnotationPath); } return(true); }
public void TermSetCorrectly() { IEdmTerm term = HardCodedTestModel.GetPrimitiveAnnotationTerm(); AnnotationSegment segment = new AnnotationSegment(term); Assert.Same(term, segment.Term); }
public static AndConstraint <AnnotationSegment> ShouldBeAnnotationSegment(this ODataPathSegment segment, IEdmTerm expectedTerm) { segment.Should().BeOfType <AnnotationSegment>(); AnnotationSegment annotationSegment = segment.As <AnnotationSegment>(); annotationSegment.Term.Should().Be(expectedTerm); return(new AndConstraint <AnnotationSegment>(annotationSegment)); }
public static AnnotationSegment ShouldBeAnnotationSegment(this ODataPathSegment segment, IEdmTerm expectedTerm) { Assert.NotNull(segment); AnnotationSegment annotationSegment = Assert.IsType <AnnotationSegment>(segment); Assert.Equal(expectedTerm, annotationSegment.Term); return(annotationSegment); }
/// ------------------------------------------------------------------------------------ protected override void OnSegmentDeleted(AnnotationSegment segment) { base.OnSegmentDeleted(segment); if (segment == CurrentUnannotatedSegment) { SetNextUnannotatedSegment(); } }
public void InequalityCorrect() { AnnotationSegment annotationSegment1 = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm()); AnnotationSegment annotationSegment2 = new AnnotationSegment(HardCodedTestModel.GetComplexAnnotationTerm()); BatchSegment batchSegment = BatchSegment.Instance; annotationSegment1.Equals(annotationSegment2).Should().BeFalse(); annotationSegment1.Equals(batchSegment).Should().BeFalse(); }
/// ------------------------------------------------------------------------------------ public TimeSpan GetAnnotationFileAudioDuration(AnnotationSegment segment) { var path = GetFullPathToAnnotationFileForSegment(segment); lock (_segmentsAnnotationSamplesToDraw) { return(_segmentsAnnotationSamplesToDraw.First(h => h.AudioFilePath == path).AudioDuration); } }
public void Setup() { var tier = new TextTier("tier"); _segment = new AnnotationSegment(tier, "segText"); Assert.AreEqual(tier, _segment.Tier); Assert.AreEqual("segText", _segment.Text); }
/// ------------------------------------------------------------------------------------ public bool GetDoesSegmentHaveAnnotationFile(AnnotationSegment segment) { if (segment == null || segment.TimeRange == _segmentBeingRecorded) { return(false); } var path = GetFullPathToAnnotationFileForSegment(segment); return(File.Exists(path) && AudioUtils.GetDoesFileSeemToBeWave(path)); }
/// ------------------------------------------------------------------------------------ private bool UpdateSegmentBoundary(AnnotationSegment seg, TimeSpan newEndTime) { var origTimeRange = seg.TimeRange.Copy(); if (TimeTier.ChangeSegmentsEndBoundary(seg.TimeRange.EndSeconds, (float)newEndTime.TotalSeconds) != BoundaryModificationResult.Success) { return(false); } _undoStack.Push(new SegmentChange(SegmentChangeType.EndBoundaryMoved, origTimeRange, seg.TimeRange.Copy(), c => SegmentBoundaryMoved(c.NewRange.End, c.OriginalRange.End))); return(true); }
/// ---------------------------------------------------------------------------------------- public Tuple <float, float>[,] GetSegmentSamples(AnnotationSegment segment, uint numberOfSamplesToReturn) { lock (_segmentsAnnotationSamplesToDraw) { // If the samples for this oral annotation have not been calculated, then create a // helper to get those samples and cache them. var audioFilePath = GetFullPathToAnnotationFileForSegment(segment); var helper = _segmentsAnnotationSamplesToDraw.FirstOrDefault(h => h.AudioFilePath == audioFilePath); if (helper == null) { helper = new AudioFileHelper(audioFilePath); _segmentsAnnotationSamplesToDraw.Add(helper); } return(helper.GetSamples(numberOfSamplesToReturn)); } }
/// ------------------------------------------------------------------------------------ public void StartAnnotationPlayback(AnnotationSegment segment, Action <PlaybackProgressEventArgs> playbackProgressAction, Action playbackStoppedAction) { if (!GetDoesSegmentHaveAnnotationFile(segment)) { return; } if (InitializeAnnotationPlayer(segment)) { _annotationPlayer.PlaybackProgress += (sender, args) => playbackProgressAction(args); _annotationPlayer.Stopped += (sender, args) => playbackStoppedAction(); _annotationPlayer.StartPlaying(); } Analytics.Track("Play Annotation", new Dictionary <string, string> { { "ProgramAreaForUsageReporting", ProgramAreaForUsageReporting } }); }
/// ------------------------------------------------------------------------------------ private bool ConfirmOralAnnotationDeletion(AnnotationSegment segmentPreceding, AnnotationSegment segmentFollowing) { string msg; if (segmentFollowing == null) { msg = LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.DeletionOfBreakWillDeleteOralAnnotations", "Deleting this segment break would delete a segment which has existing oral " + "annotations:"); } else { msg = LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.JoinSegmentsWithOralAnnotations", "Deleting this segment break would join segments which have existing oral " + "annotations:"); } var parameter = new StringBuilder(); parameter.AppendLine(); parameter.AppendLine(); bool displayPrecedingLabel = (segmentFollowing != null); bool displayFollowingLabel = displayPrecedingLabel; if (segmentPreceding.GetHasOralAnnotation(OralAnnotationType.CarefulSpeech)) { parameter.Append(" "); if (displayPrecedingLabel) { var str = LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.PrecedingSegment", "Preceding Segment ({0})"); parameter.AppendLine(string.Format(str, segmentPreceding.TimeRange)); parameter.Append(" "); displayPrecedingLabel = false; } parameter.AppendLine(LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.CarefulSpeechAnnotation", "Careful Speech", "Type of oral annotation listed in message box to confirm deletion")); } if (segmentPreceding.GetHasOralAnnotation(OralAnnotationType.Translation)) { parameter.Append(" "); if (displayPrecedingLabel) { var str = LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.PrecedingSegment", "Preceding Segment ({0})"); parameter.AppendLine(string.Format(str, segmentPreceding.TimeRange)); parameter.Append(" "); } else if (segmentFollowing != null) { parameter.Append(" "); } parameter.AppendLine(LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.OralTranslationAnnotation", "Oral Translation", "Type of oral annotation listed in message box to confirm deletion")); } if (segmentFollowing != null) { if (segmentFollowing.GetHasOralAnnotation(OralAnnotationType.CarefulSpeech)) { parameter.Append(" "); var str = LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.FollowingSegment", "Following Segment ({0})"); parameter.AppendLine(string.Format(str, segmentFollowing.TimeRange)); parameter.Append(" "); displayFollowingLabel = false; parameter.AppendLine(LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.CarefulSpeechAnnotation", "Careful Speech", "Type of oral annotation listed in message box to confirm deletion")); } if (segmentFollowing.GetHasOralAnnotation(OralAnnotationType.Translation)) { parameter.Append(" "); if (displayFollowingLabel) { var str = LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.FollowingSegment", "Following Segment ({0})"); parameter.AppendLine(string.Format(str, segmentFollowing.TimeRange)); parameter.Append(" "); } else { parameter.Append(" "); } parameter.AppendLine(LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.OralTranslationAnnotation", "Oral Translation", "Type of oral annotation listed in message box to confirm deletion")); } } parameter.AppendLine(); msg += parameter + LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.ConfirmDeletionOfOralAnnotationsForDeletedBreak", "Would you like to proceed with the deletion of this segment break and delete" + " the oral annotations?"); return(MessageBox.Show(this, msg, Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes); }
/// ------------------------------------------------------------------------------------ protected virtual void PlaySource(AnnotationSegment segment) { _waveControl.Play(segment.TimeRange); }
/// ------------------------------------------------------------------------------------ private bool SegmentNeedsAnnotation(AnnotationSegment s) { return(!GetDoesSegmentHaveAnnotationFile(s) && !GetIsSegmentIgnored(s)); }
/// <summary> /// Handle validating a AnnotationSegment /// </summary> /// <param name="segment">The annotation segment to valdiate.</param> public override void Handle(AnnotationSegment segment) { ValidateItemAndType(segment); ValidateItem(segment.Term); }
/// ------------------------------------------------------------------------------------ public string GetFullPathToOtherAnnotationFileForSegment(AnnotationSegment segment) { return(GetFullPathOfOtherAnnotationFileForTimeRange(segment.TimeRange)); }
public void ChangeSegmentsEndBoundary_WhenSegmentDoesNotExist_ReturnsNotSuccess() { var segment = new AnnotationSegment(null, 2.5f, 4.5f); Assert.AreEqual(BoundaryModificationResult.SegmentNotFound, _tier.ChangeSegmentsEndBoundary(segment, 25f)); }
public void IdentifierSetToAnnotationName() { AnnotationSegment annotationSegment = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm()); annotationSegment.Term.FullName().Should().Be(HardCodedTestModel.GetPrimitiveAnnotationTerm().FullName()); }
/// ------------------------------------------------------------------------------------ protected virtual void OnSegmentDeleted(AnnotationSegment segment) { _undoStack.Push(new SegmentChange(SegmentChangeType.Deletion, segment.TimeRange.Copy(), null, null)); }
/// ------------------------------------------------------------------------------------ public bool GetIsSegmentIgnored(AnnotationSegment segment) { return(GetIsSegmentIgnored(TimeTier.GetIndexOfSegment(segment))); }
/// ------------------------------------------------------------------------------------ protected virtual Action GetActionToRestoreStateWhenUndoingAnIgnore(AnnotationSegment segment) { return(() => { }); }
public void TargetEdmTypeIsAnnotationTypeDefinition() { AnnotationSegment annotationSegment = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm()); annotationSegment.TargetEdmType.Should().BeSameAs(HardCodedTestModel.GetPrimitiveAnnotationTerm().Type.Definition); }