Ejemplo n.º 1
0
        public void EqualityCorrect()
        {
            AnnotationSegment annotationSegment1 = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm());
            AnnotationSegment annotationSegment2 = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm());

            Assert.True(annotationSegment1.Equals(annotationSegment2));
        }
Ejemplo n.º 2
0
        public void TermSetCorrectly()
        {
            IEdmTerm          term    = HardCodedTestModel.GetPrimitiveAnnotationTerm();
            AnnotationSegment segment = new AnnotationSegment(term);

            segment.Term.Should().Be(term);
        }
Ejemplo n.º 3
0
 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()
         });
Ejemplo n.º 4
0
        public void EqualityCorrect()
        {
            AnnotationSegment annotationSegment1 = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm());
            AnnotationSegment annotationSegment2 = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm());

            annotationSegment1.Equals(annotationSegment2).Should().BeTrue();
        }
Ejemplo n.º 5
0
        /// ------------------------------------------------------------------------------------
        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);
        }
Ejemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
        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);
            }
        }
Ejemplo n.º 7
0
        /// ------------------------------------------------------------------------------------
        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));
        }
Ejemplo n.º 8
0
        /// ------------------------------------------------------------------------------------
        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);
        }
Ejemplo n.º 9
0
        public void TermSetCorrectly()
        {
            IEdmTerm          term    = HardCodedTestModel.GetPrimitiveAnnotationTerm();
            AnnotationSegment segment = new AnnotationSegment(term);

            Assert.Same(term, segment.Term);
        }
Ejemplo n.º 10
0
        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));
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
 /// ------------------------------------------------------------------------------------
 protected override void OnSegmentDeleted(AnnotationSegment segment)
 {
     base.OnSegmentDeleted(segment);
     if (segment == CurrentUnannotatedSegment)
     {
         SetNextUnannotatedSegment();
     }
 }
Ejemplo n.º 13
0
        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();
        }
Ejemplo n.º 14
0
        /// ------------------------------------------------------------------------------------
        public TimeSpan GetAnnotationFileAudioDuration(AnnotationSegment segment)
        {
            var path = GetFullPathToAnnotationFileForSegment(segment);

            lock (_segmentsAnnotationSamplesToDraw)
            {
                return(_segmentsAnnotationSamplesToDraw.First(h => h.AudioFilePath == path).AudioDuration);
            }
        }
Ejemplo n.º 15
0
        public void Setup()
        {
            var tier = new TextTier("tier");

            _segment = new AnnotationSegment(tier, "segText");

            Assert.AreEqual(tier, _segment.Tier);
            Assert.AreEqual("segText", _segment.Text);
        }
Ejemplo n.º 16
0
        /// ------------------------------------------------------------------------------------
        public bool GetDoesSegmentHaveAnnotationFile(AnnotationSegment segment)
        {
            if (segment == null || segment.TimeRange == _segmentBeingRecorded)
            {
                return(false);
            }
            var path = GetFullPathToAnnotationFileForSegment(segment);

            return(File.Exists(path) && AudioUtils.GetDoesFileSeemToBeWave(path));
        }
Ejemplo n.º 17
0
        /// ------------------------------------------------------------------------------------
        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);
        }
Ejemplo n.º 18
0
 /// ----------------------------------------------------------------------------------------
 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));
     }
 }
Ejemplo n.º 19
0
        /// ------------------------------------------------------------------------------------
        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 }
            });
        }
Ejemplo n.º 20
0
        /// ------------------------------------------------------------------------------------
        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);
        }
Ejemplo n.º 21
0
 /// ------------------------------------------------------------------------------------
 protected virtual void PlaySource(AnnotationSegment segment)
 {
     _waveControl.Play(segment.TimeRange);
 }
Ejemplo n.º 22
0
 /// ------------------------------------------------------------------------------------
 private bool SegmentNeedsAnnotation(AnnotationSegment s)
 {
     return(!GetDoesSegmentHaveAnnotationFile(s) && !GetIsSegmentIgnored(s));
 }
Ejemplo n.º 23
0
 /// <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);
 }
Ejemplo n.º 24
0
 /// ------------------------------------------------------------------------------------
 public string GetFullPathToOtherAnnotationFileForSegment(AnnotationSegment segment)
 {
     return(GetFullPathOfOtherAnnotationFileForTimeRange(segment.TimeRange));
 }
Ejemplo n.º 25
0
        public void ChangeSegmentsEndBoundary_WhenSegmentDoesNotExist_ReturnsNotSuccess()
        {
            var segment = new AnnotationSegment(null, 2.5f, 4.5f);

            Assert.AreEqual(BoundaryModificationResult.SegmentNotFound, _tier.ChangeSegmentsEndBoundary(segment, 25f));
        }
Ejemplo n.º 26
0
        public void IdentifierSetToAnnotationName()
        {
            AnnotationSegment annotationSegment = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm());

            annotationSegment.Term.FullName().Should().Be(HardCodedTestModel.GetPrimitiveAnnotationTerm().FullName());
        }
Ejemplo n.º 27
0
 /// ------------------------------------------------------------------------------------
 protected virtual void OnSegmentDeleted(AnnotationSegment segment)
 {
     _undoStack.Push(new SegmentChange(SegmentChangeType.Deletion, segment.TimeRange.Copy(), null, null));
 }
Ejemplo n.º 28
0
 /// ------------------------------------------------------------------------------------
 public bool GetIsSegmentIgnored(AnnotationSegment segment)
 {
     return(GetIsSegmentIgnored(TimeTier.GetIndexOfSegment(segment)));
 }
Ejemplo n.º 29
0
 /// ------------------------------------------------------------------------------------
 protected virtual Action GetActionToRestoreStateWhenUndoingAnIgnore(AnnotationSegment segment)
 {
     return(() => { });
 }
Ejemplo n.º 30
0
        public void TargetEdmTypeIsAnnotationTypeDefinition()
        {
            AnnotationSegment annotationSegment = new AnnotationSegment(HardCodedTestModel.GetPrimitiveAnnotationTerm());

            annotationSegment.TargetEdmType.Should().BeSameAs(HardCodedTestModel.GetPrimitiveAnnotationTerm().Type.Definition);
        }