/// <summary>
        /// Removes all annotations in PDF document
        /// </summary>
        public static void RemoveAllAnnotationsFromDocument()
        {
            try
            {
                //ExStart:RemoveAllAnnotationsFromDocument
                // Initialize annotator
                IAnnotator annotator = new Annotator();

                // Get input file stream
                Stream inputFile = new FileStream(CommonUtilities.MapSourceFilePath(filePath), FileMode.Open, FileAccess.ReadWrite);

                // Get output file stream
                Stream result = annotator.RemoveAnnotationStream(inputFile, DocumentType.Pdf);

                // Save result stream to file.
                using (FileStream fileStream = new FileStream(CommonUtilities.MapDestinationFilePath("Annotated.pdf"), FileMode.Create))
                {
                    byte[] buffer = new byte[result.Length];
                    result.Seek(0, SeekOrigin.Begin);
                    result.Read(buffer, 0, buffer.Length);
                    fileStream.Write(buffer, 0, buffer.Length);
                    fileStream.Close();
                }
                //ExEnd:RemoveAllAnnotationsFromDocument
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
            }
        }
 public void Setup()
 {
     _annotator = new Annotator
     {
         Config = ScanConfig.Create(new[] { "c:\\tools\\xampp\\htdocs", "test" })
     };
 }
Exemplo n.º 3
0
        public static void UsingAnnotatorClass3()
        {
            Console.WriteLine("exgetann Using Annotator.IsEof and Annotator.ReadNext method.");
            var annotator = new Annotator();
            annotator.Name = "atr";
            annotator.Stat = Stat.Read;

            annotator.Open("data/100s");

            while (!annotator.IsEof)
            {
                var annotation = annotator.ReadNext();
                Console.WriteLine(annotation);
            }

            Console.WriteLine("Seeking to 00:50:00");
            annotator.Seek(Time.Parse("00:50:00.000"));
            while (!annotator.IsEof)
            {
                var annotation = annotator.ReadNext();
                Console.WriteLine(annotation);
            }

            annotator.Dispose();
        }
Exemplo n.º 4
0
        public void ParseVcfLine_line_with_only_non_informative_alleles_position_unchanged_but_variants_ignored()
        {
            const string vcfLine1 = "chr1	13133	.	T	<*>	36.00	PASS	SNVSB=0.0;SNVHPOL=4	GT:GQ:GQX:DP:DPF:AD	0/1:62:20:7:1:3,4";
            const string vcfLine2 = "chr1	13133	.	T	*	36.00	PASS	SNVSB=0.0;SNVHPOL=4	GT:GQ:GQX:DP:DPF:AD	0/1:62:20:7:1:3,4";
            const string vcfLine3 = "chr1	13133	.	T	<M>	36.00	PASS	SNVSB=0.0;SNVHPOL=4	GT:GQ:GQX:DP:DPF:AD	0/1:62:20:7:1:3,4";

            var chromosome       = new Chromosome("chr1", "1", 0);
            var refMinorProvider = new Mock <IRefMinorProvider>();

            refMinorProvider.Setup(x => x.IsReferenceMinor(chromosome, 13133)).Returns(false);
            var refNameToChromosome = new Dictionary <string, IChromosome> {
                ["chr1"] = chromosome
            };
            var variantFactory = new VariantFactory(refNameToChromosome, refMinorProvider.Object, false);

            var position1 = VcfReaderUtils.ParseVcfLine(vcfLine1, variantFactory, refNameToChromosome);
            var position2 = VcfReaderUtils.ParseVcfLine(vcfLine2, variantFactory, refNameToChromosome);
            var position3 = VcfReaderUtils.ParseVcfLine(vcfLine3, variantFactory, refNameToChromosome);

            var annotatedVariants1 = Annotator.GetAnnotatedVariants(position1.Variants);
            var annotatedVariants2 = Annotator.GetAnnotatedVariants(position2.Variants);
            var annotatedVariants3 = Annotator.GetAnnotatedVariants(position3.Variants);

            // SimplePositions unchanged
            Assert.Equal("<*>", position1.AltAlleles[0]);
            Assert.Equal("*", position2.AltAlleles[0]);
            Assert.Equal("<M>", position3.AltAlleles[0]);

            // Variants are null
            Assert.Null(annotatedVariants1);
            Assert.Null(annotatedVariants2);
            Assert.Null(annotatedVariants3);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a document data object in the storage
        /// </summary>
        public static void CreateDocument()
        {
            try
            {
                //ExStart:CreateDocument
                IRepositoryPathFinder pathFinder = new RepositoryPathFinder();
                var documentRepository           = new DocumentRepository(pathFinder);

                // Create instance of annotator
                IAnnotator annotator = new Annotator(
                    new UserRepository(pathFinder),
                    new DocumentRepository(pathFinder),
                    new AnnotationRepository(pathFinder),
                    new AnnotationReplyRepository(pathFinder),
                    new AnnotationCollaboratorRepository(pathFinder));

                // Create document data object in storage.
                var  document   = documentRepository.GetDocument("Document.pdf");
                long documentId = document != null ? document.Id : annotator.CreateDocument("Document.pdf");

                Console.WriteLine("Document ID : " + documentId);
                //ExEnd:CreateDocument
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
            }
        }
Exemplo n.º 6
0
        public void Annotate_null_position()
        {
            var annotator         = new Annotator(null, null, null, null, null, null);
            var annotatedPosition = annotator.Annotate(null);

            Assert.Null(annotatedPosition);
        }
Exemplo n.º 7
0
        public void IsEofTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");

            Assert.IsFalse(annotator.IsEof);

            // Reading some data
            annotator.ReadNext();
            Assert.IsFalse(annotator.IsEof);

            // Reading all available annotations.
            annotator.ReadAll();
            Assert.IsTrue(annotator.IsEof);

            // Seeking to the beginning.
            annotator.Seek(Time.Zero);
            Assert.IsFalse(annotator.IsEof);

            annotator.ReadAll();
            annotator.Close();
            Assert.IsFalse(annotator.IsOpen);
            // Reopening
            annotator.Open("data/100s");
            Assert.IsFalse(annotator.IsEof);
            annotator.Close();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets annotations from the storage file
        /// </summary>
        /// <returns>Returns a list of annotations</returns>
        public static ListAnnotationsResult GetAllDocumentAnnotation()
        {
            try
            {
                //ExStart:GetAllAnnotation
                // Create path finder
                IRepositoryPathFinder pathFinder = new RepositoryPathFinder();
                var documentRepository           = new DocumentRepository(pathFinder);

                // Create instance of annotator
                IAnnotator annotator = new Annotator(
                    new UserRepository(pathFinder),
                    new DocumentRepository(pathFinder),
                    new AnnotationRepository(pathFinder),
                    new AnnotationReplyRepository(pathFinder),
                    new AnnotationCollaboratorRepository(pathFinder));

                // Create document data object in storage.
                var  document   = documentRepository.GetDocument("Document.pdf");
                long documentId = document != null ? document.Id : annotator.CreateDocument("Document.pdf");

                // Get annotation from storage
                ListAnnotationsResult result = annotator.GetAnnotations(documentId);

                return(result);
                //ExEnd:GetAllAnnotation
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
                return(null);
            }
        }
Exemplo n.º 9
0
        public void ParseVcfLine_NonInformativeAlleles_Alone_NotFiltered()
        {
            const string vcfLine1 = "chr1	13133	.	T	<*>	36.00	PASS	SNVSB=0.0;SNVHPOL=4	GT:GQ:GQX:DP:DPF:AD	0/1:62:20:7:1:3,4";
            const string vcfLine2 = "chr1	13133	.	T	*	36.00	PASS	SNVSB=0.0;SNVHPOL=4	GT:GQ:GQX:DP:DPF:AD	0/1:62:20:7:1:3,4";
            const string vcfLine3 = "chr1	13133	.	T	<M>	36.00	PASS	SNVSB=0.0;SNVHPOL=4	GT:GQ:GQX:DP:DPF:AD	0/1:62:20:7:1:3,4";

            var refMinorProvider = new Mock <IRefMinorProvider>();
            var seqProvider      = ParserTestUtils.GetSequenceProvider(13133, "T", 'A', ChromosomeUtilities.RefNameToChromosome);
            var variantFactory   = new VariantFactory(seqProvider);

            var position1 = AnnotationUtilities.ParseVcfLine(vcfLine1, refMinorProvider.Object, variantFactory, seqProvider.RefNameToChromosome);
            var position2 = AnnotationUtilities.ParseVcfLine(vcfLine2, refMinorProvider.Object, variantFactory, seqProvider.RefNameToChromosome);
            var position3 = AnnotationUtilities.ParseVcfLine(vcfLine3, refMinorProvider.Object, variantFactory, seqProvider.RefNameToChromosome);

            var annotatedVariants1 = Annotator.GetAnnotatedVariants(position1.Variants);
            var annotatedVariants2 = Annotator.GetAnnotatedVariants(position2.Variants);
            var annotatedVariants3 = Annotator.GetAnnotatedVariants(position3.Variants);

            // SimplePositions unchanged
            Assert.Equal("<*>", position1.AltAlleles[0]);
            Assert.Equal("*", position2.AltAlleles[0]);
            Assert.Equal("<M>", position3.AltAlleles[0]);

            // Variants not filtered
            Assert.Equal("<*>", annotatedVariants1[0].Variant.AltAllele);
            Assert.Equal("*", annotatedVariants2[0].Variant.AltAllele);
            Assert.Equal("<M>", annotatedVariants3[0].Variant.AltAllele);
        }
Exemplo n.º 10
0
 public void IsEofUnopenedAnnotatorTest()
 {
     var annotator = new Annotator {
         Name = "atr", Stat = Stat.Read
     };
     var isEof = annotator.IsEof; // throws the exception.
 }
Exemplo n.º 11
0
        public void ReadAllOpenedAnnotatorTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");
            var expectedAnnotations = new List <Annotation>();

            while (!annotator.IsEof)
            {
                expectedAnnotations.Add(annotator.ReadNext());
            }
            Assert.IsTrue(annotator.IsEof);
            annotator.Seek(Time.Zero);

            var annotations = annotator.ReadAll();

            Assert.AreEqual(expectedAnnotations, annotations);
            annotator.Close();

            // Reopening
            annotator.Open("data/100s");
            annotations = annotator.ReadAll();
            Assert.AreEqual(expectedAnnotations, annotations);
            annotator.Close();
        }
 public void IsEofClosedAnnotatorTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Open("data/100s");
     annotator.Close();
     var isEof = annotator.IsEof; // throws the exception.
 }
Exemplo n.º 13
0
        public void OpenAllNTest()
        {
            var annotators = new Annotator[2];

            annotators[0] = new Annotator {
                Name = "atr", Stat = Stat.Read
            };
            annotators[1] = new Annotator {
                Name = "hrv", Stat = Stat.Read
            };
            Annotator.OpenAll(annotators, "data/100s");

            int counter = 0;

            foreach (var annotator in annotators)
            {
                Assert.IsTrue(annotator.IsOpen);
                Assert.AreEqual(counter, annotator.Number);
                counter++;
            }

            Annotator.CloseAll();
            foreach (var annotator in annotators)
            {
                Assert.IsFalse(annotator.IsOpen);
            }
        }
Exemplo n.º 14
0
        public void OpenAll0Test()
        {
            var annotators = new Annotator[0];

            Annotator.OpenAll(annotators, "data/100s");
            Annotator.CloseAll();
        }
Exemplo n.º 15
0
        public void ParseVcfLine_NonInformativeAlleles_WithNormalAllele_NotFiltered()
        {
            const string vcfLine1 = "chr1	13133	.	T	<*>,G	36.00	PASS	SNVSB=0.0;SNVHPOL=4	GT:GQ:GQX:DP:DPF:AD	0/1:62:20:7:1:3,4";
            const string vcfLine2 = "chr1	13133	.	T	*,C	36.00	PASS	SNVSB=0.0;SNVHPOL=4	GT:GQ:GQX:DP:DPF:AD	0/1:62:20:7:1:3,4";
            const string vcfLine3 = "chr1	13133	.	T	<M>,A	36.00	PASS	SNVSB=0.0;SNVHPOL=4	GT:GQ:GQX:DP:DPF:AD	0/1:62:20:7:1:3,4";
            const string vcfLine4 = "chr1	13133	.	T	A,<NON_REF>	36.00	PASS	SNVSB=0.0;SNVHPOL=4	GT:GQ:GQX:DP:DPF:AD	0/1:62:20:7:1:3,4";

            var refMinorProvider    = new Mock <IRefMinorProvider>();
            var seqProvider         = ParserTestUtils.GetSequenceProvider(13133, "T", 'A', ChromosomeUtilities.RefNameToChromosome);
            var refNameToChromosome = seqProvider.RefNameToChromosome;

            var variantFactory = new VariantFactory(seqProvider);

            var position1 = AnnotationUtilities.ParseVcfLine(vcfLine1, refMinorProvider.Object, variantFactory, refNameToChromosome);
            var position2 = AnnotationUtilities.ParseVcfLine(vcfLine2, refMinorProvider.Object, variantFactory, refNameToChromosome);
            var position3 = AnnotationUtilities.ParseVcfLine(vcfLine3, refMinorProvider.Object, variantFactory, refNameToChromosome);
            var position4 = AnnotationUtilities.ParseVcfLine(vcfLine4, refMinorProvider.Object, variantFactory, refNameToChromosome);

            var annotatedVariants1 = Annotator.GetAnnotatedVariants(position1.Variants);
            var annotatedVariants2 = Annotator.GetAnnotatedVariants(position2.Variants);
            var annotatedVariants3 = Annotator.GetAnnotatedVariants(position3.Variants);
            var annotatedVariants4 = Annotator.GetAnnotatedVariants(position4.Variants);

            // SimplePositions
            Assert.Equal(new[] { "<*>", "G" }, position1.AltAlleles);
            Assert.Equal(new[] { "*", "C" }, position2.AltAlleles);
            Assert.Equal(new[] { "<M>", "A" }, position3.AltAlleles);
            Assert.Equal(new[] { "A", "<NON_REF>" }, position4.AltAlleles);

            // Variants
            Assert.Equal(new[] { "<*>", "G" }, annotatedVariants1.Select(x => x.Variant.AltAllele).ToArray());
            Assert.Equal(new[] { "*", "C" }, annotatedVariants2.Select(x => x.Variant.AltAllele).ToArray());
            Assert.Equal(new[] { "<M>", "A" }, annotatedVariants3.Select(x => x.Variant.AltAllele).ToArray());
            Assert.Equal(new[] { "A", "<NON_REF>" }, annotatedVariants4.Select(x => x.Variant.AltAllele).ToArray());
        }
Exemplo n.º 16
0
        public void NumberTest()
        {
            var annotator1 = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator1.Open("data/100s");
            Assert.AreEqual(0, annotator1.Number);

            var annotator2 = new Annotator {
                Name = "hrv", Stat = Stat.Read
            };

            annotator2.Open("data/100s");
            Assert.AreEqual(0, annotator1.Number);
            Assert.AreEqual(1, annotator2.Number);

            annotator1.Close();
            Assert.AreEqual(-1, annotator1.Number);
            Assert.AreEqual(0, annotator2.Number);

            annotator1.Open("data/100s");
            Assert.AreEqual(0, annotator2.Number);
            Assert.AreEqual(1, annotator1.Number);
            Annotator.CloseAll();

            Assert.AreEqual(-1, annotator1.Number);
            Assert.AreEqual(-1, annotator2.Number);
        }
Exemplo n.º 17
0
        public void ParseVcfLine_line_with_only_NonRef_is_refMinor()
        {
            const string vcfLine = "1	10628385	.	C	<NON_REF>	.	LowGQX;HighDPFRatio	END=10628385;BLOCKAVG_min30p3a	GT:GQX:DP:DPF	0/0:24:9:18";

            var chromosome       = new Chromosome("chr1", "1", 0);
            var refMinorProvider = new Mock <IRefMinorProvider>();

            refMinorProvider.Setup(x => x.IsReferenceMinor(chromosome, 10628385)).Returns(true);
            refMinorProvider.Setup(x => x.GetGlobalMajorAlleleForRefMinor(chromosome, 10628385)).Returns("T");
            var refNameToChromosome = new Dictionary <string, IChromosome> {
                ["1"] = chromosome
            };
            var variantFactory = new VariantFactory(refNameToChromosome, refMinorProvider.Object, false);

            var position          = VcfReaderUtils.ParseVcfLine(vcfLine, variantFactory, refNameToChromosome);
            var annotatedVariants = Annotator.GetAnnotatedVariants(position.Variants);

            Assert.Equal("C", position.RefAllele);
            Assert.Equal(new[] { "<NON_REF>" }, position.AltAlleles);
            Assert.Equal("T", position.Variants[0].RefAllele);
            Assert.Equal("C", position.Variants[0].AltAllele);

            // Variants
            Assert.Equal(new[] { "C" }, annotatedVariants.Select(x => x.Variant.AltAllele).ToArray());
        }
Exemplo n.º 18
0
        public static void UsingAnnotatorClass3()
        {
            Console.WriteLine("exgetann Using Annotator.IsEof and Annotator.ReadNext method.");
            var annotator = new Annotator();

            annotator.Name = "atr";
            annotator.Stat = Stat.Read;

            annotator.Open("data/100s");

            while (!annotator.IsEof)
            {
                var annotation = annotator.ReadNext();
                Console.WriteLine(annotation);
            }

            Console.WriteLine("Seeking to 00:50:00");
            annotator.Seek(Time.Parse("00:50:00.000"));
            while (!annotator.IsEof)
            {
                var annotation = annotator.ReadNext();
                Console.WriteLine(annotation);
            }

            annotator.Dispose();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Assigns/sets document access rights
        /// </summary>
        public static void AssignAccessRights()
        {
            try
            {
                //ExStart:AssignAccessRight
                // Creat path finder
                IRepositoryPathFinder pathFinder = new RepositoryPathFinder();
                var documentRepository           = new DocumentRepository(pathFinder);

                // Create instance of annotator
                IAnnotator annotator = new Annotator(
                    new UserRepository(pathFinder),
                    new DocumentRepository(pathFinder),
                    new AnnotationRepository(pathFinder),
                    new AnnotationReplyRepository(pathFinder),
                    new AnnotationCollaboratorRepository(pathFinder));


                // Create document data object in storage.
                var  document   = documentRepository.GetDocument("Document.pdf");
                long documentId = document != null ? document.Id : annotator.CreateDocument("Document.pdf");

                // Set document access rights
                annotator.SetDocumentAccessRights(documentId, AnnotationReviewerRights.All);
                //ExEnd:AssignAccessRight
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
            }
        }
Exemplo n.º 20
0
        public void ReadNextTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll();

            annotator.Seek(Time.Zero);
            var annotations = new List <Annotation>();

            while (!annotator.IsEof)
            {
                annotations.Add(annotator.ReadNext());
            }

            Assert.AreEqual(expectedAllAnnotations, annotations);
            Assert.IsTrue(annotator.IsEof);

            try
            {
                annotator.ReadNext();
                Assert.Fail("InvalidOperationException should have been thrown.");
            }
            catch (InvalidOperationException) // end of file reached
            {
            }
        }
Exemplo n.º 21
0
        static void UsingPInvoke()
        {
            Annotator a = new Annotator();

            a.Name = "data/100s"; // just use 100s for demo
            a.Stat = Stat.Read;

            Annotation annot = new Annotation();

            PInvoke.sampfreq("data/100s");

            if (PInvoke.annopen("data/100s", ref a, 1) < 0)
            {
                return;
            }
            while (PInvoke.getann(0, ref annot) == 0)
            {
                Console.WriteLine("{0} ({1}) {2} {3} {4} {5} {6}",
                                  Marshal.PtrToStringAuto(PInvoke.timstr(-(annot.Time))),
                                  annot.Time,
                                  Marshal.PtrToStringAuto(PInvoke.annstr(annot.Type)),
                                  annot.SubType,
                                  annot.ChannelNumber,
                                  annot.AnnotatorNumber,
                                  (!string.IsNullOrEmpty(annot.Aux)) ? annot.Aux + 1 : "");
            }
        }
Exemplo n.º 22
0
        public void Annotate_mito_GRCh37()
        {
            var position = new Mock <IPosition>();

            position.SetupGet(x => x.Variants).Returns(GetVariants);
            position.SetupGet(x => x.Chromosome).Returns(ChromosomeUtilities.ChrM);

            var csProvider = new Mock <IAnnotationProvider>();

            csProvider.SetupGet(x => x.Assembly).Returns(GenomeAssembly.GRCh37);
            csProvider.Setup(x => x.Annotate(It.IsAny <IAnnotatedPosition>())).
            Callback((IAnnotatedPosition x) => { x.CytogeneticBand = "testCytoBand"; });

            var taProvider = new Mock <IAnnotationProvider>();

            taProvider.SetupGet(x => x.Assembly).Returns(GenomeAssembly.GRCh37);
            taProvider.Setup(x => x.Annotate(It.IsAny <IAnnotatedPosition>())).Callback((IAnnotatedPosition x) => { });//do nothing

            var annotator = new Annotator(taProvider.Object, null, null, csProvider.Object, null, null);

            annotator.EnableMitochondrialAnnotation();

            var annotatedPosition = annotator.Annotate(position.Object);

            Assert.NotNull(annotatedPosition.CytogeneticBand);
        }
Exemplo n.º 23
0
        public void ReadNextCountTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/100s");

            // Gets the total number of annotations available in the current annotator file.
            var availableAnnotationsCount = annotator.ReadAll().Count;

            // Reset the pointer to the first annotation.
            annotator.Seek(Time.Zero);

            // Read all using ReadNext(Count)
            var readCount = annotator.ReadNext(availableAnnotationsCount).Count;

            Assert.AreEqual(availableAnnotationsCount, readCount);
            Assert.IsTrue(annotator.IsEof);

            // Cant read when the
            readCount = annotator.ReadNext(1).Count;
            Assert.AreEqual(0, readCount);

            // Seeking to the middle of the file.
            var middle = availableAnnotationsCount / 2;

            annotator.Seek(Time.Zero);
            annotator.Seek(middle);

            readCount = annotator.ReadNext(availableAnnotationsCount).Count;
            Assert.AreEqual(availableAnnotationsCount - middle, readCount);

            Assert.IsTrue(annotator.IsEof);

            // Testing boundaries
            annotator.Seek(Time.Zero);
            readCount = annotator.ReadNext(1).Count;
            Assert.AreEqual(1, readCount);

            annotator.Seek(Time.Zero);
            readCount = annotator.ReadNext(availableAnnotationsCount + 1).Count;
            Assert.AreEqual(availableAnnotationsCount, readCount);

            annotator.Seek(Time.Zero);
            readCount = annotator.ReadNext(int.MaxValue).Count;
            Assert.AreEqual(availableAnnotationsCount, readCount);

            // Testing invalid values.
            try
            {
                annotator.ReadNext(-1);
                Assert.Fail("ArgumentOutOfRangeException should have been thrown.");
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            annotator.Close();
        }
Exemplo n.º 24
0
        /// <summary>
        /// Updates the text in the annotation
        /// </summary>
        public static void EditTextFieldAnnotation()
        {
            try
            {
                //ExStart:EditTextFieldAnnotation
                // Create path finder
                IRepositoryPathFinder pathFinder = new RepositoryPathFinder();
                var documentRepository           = new DocumentRepository(pathFinder);

                // Create instance of annotator
                IAnnotator annotator = new Annotator(
                    new UserRepository(pathFinder),
                    new DocumentRepository(pathFinder),
                    new AnnotationRepository(pathFinder),
                    new AnnotationReplyRepository(pathFinder),
                    new AnnotationCollaboratorRepository(pathFinder));

                // Create document data object in storage.
                var  document   = documentRepository.GetDocument("Document.pdf");
                long documentId = document != null ? document.Id : annotator.CreateDocument("Document.pdf");

                // Create annotation object
                AnnotationInfo textFieldAnnotation = new AnnotationInfo
                {
                    AnnotationPosition = new Point(852.0, 201.0),
                    FieldText          = "text in the box",
                    FontFamily         = "Arial",
                    FontSize           = 10,
                    Box          = new Rectangle(66f, 201f, 64f, 37f),
                    PageNumber   = 0,
                    Type         = AnnotationType.TextField,
                    CreatorName  = "Anonym",
                    DocumentGuid = documentId
                };

                //Add annotation to storage
                CreateAnnotationResult createTextFieldAnnotationResult = annotator.CreateAnnotation(textFieldAnnotation);

                // Update text in the annotation
                SaveAnnotationTextResult saveTextFieldResult = annotator.SaveTextField(
                    createTextFieldAnnotationResult.Id,
                    new TextFieldInfo
                {
                    FieldText  = "new text",
                    FontFamily = "Colibri",
                    FontSize   = 12
                });


                // Set text field color
                SaveAnnotationTextResult saveTextFieldColorResult = annotator.SetTextFieldColor
                                                                        (createTextFieldAnnotationResult.Id, 16753920);
                //ExEnd:EditTextFieldAnnotation
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
            }
        }
Exemplo n.º 25
0
        public void OpenInexistingRecordTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("some inexistent record");
        }
Exemplo n.º 26
0
        public void OpenInvalidRecordTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Open("data/invalid");
        }
Exemplo n.º 27
0
        public void SeekTimeUnopenedAnnotatorTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Seek(Time.Zero);
        }
Exemplo n.º 28
0
        public void OpenIllegalStatAnotator()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.AhaRead
            };

            annotator.Open("data/100s");
        }
Exemplo n.º 29
0
        public void SeekCountUnopenedAnnotatorTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Seek(3);
        }
Exemplo n.º 30
0
        public void ReadNextCountUnopenedAnnotatorTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.ReadNext(5);
        }
        public void CloseClosedAnnotatorTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");
            annotator.Close();

            annotator.Close();
        }
Exemplo n.º 32
0
        public void CloseUnopenedAnnotatorTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.Close();
        }
Exemplo n.º 33
0
        public void ReadAllUnopenedAnnotatorTest()
        {
            var annotator = new Annotator {
                Name = "atr", Stat = Stat.Read
            };

            annotator.ReadAll(); // throws NotSupportedException
        }
Exemplo n.º 34
0
 public static void UsingAnnotatorClass1()
 {
     Console.WriteLine("exgetann Using Annotator.ReadAll method");
     var annotator = new Annotator();
     annotator.Name = "atr";
     annotator.Stat = Stat.Read;
     annotator.Open("data/100s");
     foreach (var annotation in annotator.ReadAll())
     {
         Console.WriteLine(annotation.ToString());
     }
     annotator.Close();
 }
Exemplo n.º 35
0
        public static void UsingAnnotatorClass2()
        {
            Console.WriteLine("exgetann Using Annotator.ReadNext(int count) method, reading 50 annotation.");
            var annotator = new Annotator();
            annotator.Name = "atr";
            annotator.Stat = Stat.Read;
            annotator.Open("data/100s");

            foreach (var annotation in annotator.ReadNext(50))
            {
                Console.WriteLine(annotation.ToString());
            }

            annotator.Close();
        }
 public void ReadAllClosedAnnotatorTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Open("data/100s");
     annotator.Close();
     annotator.ReadAll().ToList(); // force a loop
 }
        public void ReadAllOpenedAnnotatorTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");
            var expectedAnnotations = new List<Annotation>();

            while (!annotator.IsEof)
            {
                expectedAnnotations.Add(annotator.ReadNext());
            }
            Assert.IsTrue(annotator.IsEof);
            annotator.Seek(Time.Zero);

            var annotations = annotator.ReadAll();
            Assert.AreEqual(expectedAnnotations, annotations);
            annotator.Close();

            // Reopening
            annotator.Open("data/100s");
            annotations = annotator.ReadAll();
            Assert.AreEqual(expectedAnnotations, annotations);
            annotator.Close();
        }
        public void IsEofTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };

            annotator.Open("data/100s");

            Assert.IsFalse(annotator.IsEof);

            // Reading some data
            annotator.ReadNext();
            Assert.IsFalse(annotator.IsEof);

            // Reading all available annotations.
            annotator.ReadAll().ToList(); // force a loop over the enumerator.
            Assert.IsTrue(annotator.IsEof);

            // Seeking to the beginning.
            annotator.Seek(Time.Zero);
            Assert.IsFalse(annotator.IsEof);

            annotator.ReadAll();
            annotator.Close();
            Assert.IsFalse(annotator.IsOpen);
            // Reopening
            annotator.Open("data/100s");
            Assert.IsFalse(annotator.IsEof);
            annotator.Close();
        }
 public void OpenAllNWithInvalidAnnotatorTest()
 {
     var annotators = new Annotator[2];
     annotators[0] = new Annotator { Name = "atr", Stat = Stat.Read };
     // annotators[1] has not been set
     Annotator.OpenAll(annotators, "data/100s");
 }
 public void OpenIllegalStatAnotator()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.AhaRead };
     annotator.Open("data/100s");
 }
Exemplo n.º 41
0
 public static void Init(string record, Annotator[] annotators, Signal[] signals)
 {
     var ret = PInvoke.wfdbinit(record, annotators, (int)annotators.Length, signals, (int)signals.Length);
     if (ret < 0)
     {
         switch (ret)
         {
             case -1:
                 throw new InvalidOperationException("Failure: Unable to read header file.");
             case -2:
                 throw new InvalidOperationException("Failure: Incorrect header file format.");
             case -3:
                 throw new InvalidOperationException("Failure: Unable to open input annotation file.");
             case -4:
                 throw new InvalidOperationException("Failure: Unable to open output annotation file.");
             case -5:
                 throw new InvalidOperationException("Failure: illegal Stat specified for annotation file.");
         }
     }
 }
        public void OpenNAnnotatorCloseOldValidRecord()
        {
            var annotator = new Annotator {Name = "atr", Stat = Stat.Read};
            annotator.Open("data/100s");
            Assert.IsTrue(annotator.IsOpen);

            var annotator2 = new Annotator {Name = "hrv", Stat = Stat.Read};
            annotator2.Open("data/100s", false);
            Assert.IsFalse(annotator.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);

            annotator2.Close();
        }
 public void SeekCountNegativeValue()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Open("data/100s");
     annotator.Seek(-1);
 }
        public void SeekCountTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll().ToList();
            var maxCount = expectedAllAnnotations.Count;
            int midCount = expectedAllAnnotations.Count / 2;
            var firstAnnotation = expectedAllAnnotations[0];
            var lastAnnotation = expectedAllAnnotations[expectedAllAnnotations.Count - 1];

            annotator.Seek(Time.Zero);

            annotator.Seek(0);
            Assert.AreEqual(firstAnnotation, annotator.ReadNext());
            Assert.IsFalse(annotator.IsEof);

            annotator.Seek(Time.Zero);

            annotator.Seek(maxCount - 1);
            Assert.AreEqual(lastAnnotation, annotator.ReadNext());
            Assert.IsTrue(annotator.IsEof);

            annotator.Seek(Time.Zero);

            var annotations = new List<Annotation>();
            annotator.Seek(midCount);
            while (!annotator.IsEof)
            {
                annotations.Add(annotator.ReadNext());
            }

            expectedAllAnnotations.RemoveRange(0, midCount);
            Assert.AreEqual(expectedAllAnnotations, annotations);
        }
 public void SeekCountUnopenedAnnotatorTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Seek(3);
 }
        public void SeekInvalidTime()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll().ToList();
            var maxTime = expectedAllAnnotations[expectedAllAnnotations.Count - 1].Time;

            annotator.Seek(Time.Zero);

            Time invalidTime = (maxTime + 60); // + 60 seconds
            annotator.Seek(invalidTime);
        }
        public void SeekTimeTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll().ToList();
            var maxTime = expectedAllAnnotations[expectedAllAnnotations.Count - 1].Time;
            int midIndex = expectedAllAnnotations.Count/2;

            var midTime = expectedAllAnnotations[midIndex].Time;

            // Seek to zero
            Assert.IsTrue(annotator.IsEof);
            annotator.Seek(Time.Zero);
            Assert.IsFalse(annotator.IsEof);
            Assert.AreEqual(expectedAllAnnotations, annotator.ReadAll()); // all annotations are there.

            annotator.Seek(Time.Zero);
            annotator.Seek(maxTime);
            Assert.IsFalse(annotator.IsEof); // not the end of file, we still have to read another annotation.

            Assert.AreEqual(expectedAllAnnotations[expectedAllAnnotations.Count - 1], annotator.ReadNext());
            Assert.IsTrue(annotator.IsEof);

            annotator.Seek(Time.Zero);
            annotator.Seek(midTime);
            Assert.IsFalse(annotator.IsEof);

            var annotations = new List<Annotation>();
            var annotation = annotator.ReadNext();
            annotations.Add(annotation);
            Assert.AreEqual(annotation, expectedAllAnnotations[midIndex]);

            while (!annotator.IsEof)
            {
                annotations.Add(annotator.ReadNext());
            }

            Assert.AreEqual(expectedAllAnnotations.Count - midIndex, annotations.Count);
            expectedAllAnnotations.RemoveRange(0, midIndex);
            Assert.AreEqual(expectedAllAnnotations, annotations);
        }
 public void SeekTimeUnopenedAnnotatorTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Seek(Time.Zero);
 }
 public void CloseUnopenedAnnotatorTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Close();
 }
 public void OpenOpenedAnnotator()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Open("data/100s");
     annotator.Open("data/100s");
 }
        public void OpenNAnnotatorValidRecord()
        {
            var annotator1 = new Annotator { Name = "atr", Stat = Stat.Read };

            // Opening another annotator without closing the old annotator
            annotator1.Open("data/100s");
            Assert.IsTrue(annotator1.IsOpen);
            var expectedAnnotations1 = annotator1.ReadAll().ToList();

            var annotator2 = new Annotator { Name = "hrv", Stat = Stat.Read };
            annotator2.Open("data/100s");
            Assert.IsTrue(annotator1.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);
            var expectedAnnotations2 = annotator2.ReadAll().ToList();

            // Closing the first annotator and keeping the second one
            annotator1.Close();
            Assert.IsFalse(annotator1.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);

            var annotations2 = annotator2.ReadAll();
            Assert.AreEqual(expectedAnnotations2, annotations2);

            // Reopening the first annotator, this time it should have the 1 number
            annotator1.Open("data/100s");
            var annotations1 = annotator1.ReadAll();
            Assert.AreEqual(expectedAnnotations1, annotations1);

            annotator1.Close();
            annotator2.Close();
            Assert.IsFalse(annotator1.IsOpen);
            Assert.IsFalse(annotator2.IsOpen);

            // Reopening in the same order
            annotator1.Open("data/100s"); //0
            Assert.IsTrue(annotator1.IsOpen);
            Assert.IsFalse(annotator2.IsOpen);

            annotator2.Open("data/100s"); //1
            Assert.IsTrue(annotator1.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);

            // Reading Some data
            annotations1 = annotator1.ReadAll();  // 0
            Assert.AreEqual(expectedAnnotations1, annotations1);

            annotations2 = annotator2.ReadAll(); // 1
            Assert.AreEqual(expectedAnnotations2, annotations2);

            annotator1.Close();
            annotator2.Close();

            // reopening in an inversed order
            annotator2.Open("data/100s"); //0
            Assert.IsTrue(annotator2.IsOpen);
            Assert.IsFalse(annotator1.IsOpen);

            annotator1.Open("data/100s"); //1
            Assert.IsTrue(annotator1.IsOpen);
            Assert.IsTrue(annotator2.IsOpen);

            // Reading Some data
            annotations1 = annotator1.ReadAll();  // 0
            Assert.AreEqual(expectedAnnotations1, annotations1);

            annotations2 = annotator2.ReadAll(); // 1
            Assert.AreEqual(expectedAnnotations2, annotations2);

            annotator1.Close();
            annotator2.Close();
        }
 public void ReadNextUnopenedAnnotatorTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.ReadNext();
 }
 public void OpenInvalidRecordTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.Open("data/invalid");
 }
        public void ReadNextTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");
            var expectedAllAnnotations = annotator.ReadAll();

            annotator.Seek(Time.Zero);
            var annotations = new List<Annotation>();
            while (!annotator.IsEof)
            {
                annotations.Add(annotator.ReadNext());
            }

            Assert.AreEqual(expectedAllAnnotations, annotations);
            Assert.IsTrue(annotator.IsEof);

            try
            {
                annotator.ReadNext();
                Assert.Fail("InvalidOperationException should have been thrown.");
            }
            catch (InvalidOperationException) // end of file reached
            {
            }
        }
 public void OpenInexistingRecordTest()
 {
     var annotator = new Annotator {Name = "atr", Stat = Stat.Read};
     annotator.Open("some inexistent record");
 }
 public void ReadNextCountUnopenedAnnotatorTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.ReadNext(5).ToList(); // force a loop
 }
        public void OpenClose1AnnotatorValidRecordTest()
        {
            // Valid annotator

            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };

            // ****************************
            // Keeping old annotators open.
            // ****************************

            annotator.Open("data/100s");
            Assert.IsTrue(annotator.IsOpen);
            annotator.Close();
            Assert.IsFalse(annotator.IsOpen);

            // Reopening the same annotator.
            annotator.Open("data/100s");
            Assert.IsTrue(annotator.IsOpen);
            annotator.Close();
            Assert.IsFalse(annotator.IsOpen);
        }
        public void ReadNextCountTest()
        {
            var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
            annotator.Open("data/100s");

            // Gets the total number of annotations available in the current annotator file.
            var availableAnnotationsCount = annotator.ReadAll().Count();
            // Reset the pointer to the first annotation.
            annotator.Seek(Time.Zero);

            // Read all using ReadNext(Count)
            var readCount = annotator.ReadNext(availableAnnotationsCount).Count();
            Assert.AreEqual(availableAnnotationsCount, readCount);
            Assert.IsTrue(annotator.IsEof);

            // Cant read when the
            readCount = annotator.ReadNext(1).Count();
            Assert.AreEqual(0, readCount);

            // Seeking to the middle of the file.
            var middle = availableAnnotationsCount / 2;
            annotator.Seek(Time.Zero);
            annotator.Seek(middle);

            readCount = annotator.ReadNext(availableAnnotationsCount).Count();
            Assert.AreEqual(availableAnnotationsCount - middle, readCount);

            Assert.IsTrue(annotator.IsEof);

            // Testing boundaries
            annotator.Seek(Time.Zero);
            readCount = annotator.ReadNext(1).Count();
            Assert.AreEqual(1, readCount);

            annotator.Seek(Time.Zero);
            readCount = annotator.ReadNext(availableAnnotationsCount + 1).Count();
            Assert.AreEqual(availableAnnotationsCount, readCount);

            annotator.Seek(Time.Zero);
            readCount = annotator.ReadNext(int.MaxValue).Count();
            Assert.AreEqual(availableAnnotationsCount, readCount);

            // Testing invalid values.
            try
            {
                annotator.ReadNext(-1).ToList(); // force loop
                Assert.Fail("ArgumentOutOfRangeException should have been thrown.");
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            annotator.Close();
        }
Exemplo n.º 59
0
 public static extern int annopen(string record, ref Annotator ai, int nann);
 public void ReadAllUnopenedAnnotatorTest()
 {
     var annotator = new Annotator { Name = "atr", Stat = Stat.Read };
     annotator.ReadAll().ToList(); // force a loop, throws NotSupportedException
 }