Exemplo n.º 1
0
        public void AnimlDocumentValidatedCorrectly()
        {
            //// Create a new minimal AnIML document and add one sample
            //// Using "1" as Id should result in a validation error b/c this name is not compliant with the
            //// AnIML standard as xsd:ID does not allow numbers as first character

            AnimlDocument animlDoc = new AnimlDocument()
            {
                SampleSet = new SampleSet()
            };

            animlDoc.SampleSet.Samples.Add(new Sample("TestSample", "1st sample")
            {
                Id = "1"
            });

            bool validationOutcome;

            AnimlDocumentValidator validatorFail = AnimlDocumentValidator.CreateValidatorForAnimlDocument(animlDoc);

            validationOutcome = validatorFail.Validate();

            validationOutcome.Should().BeFalse();
            validatorFail.ValidationMessages.Should().HaveCount(1);

            //// Change the ID to a valid value and perform the validation once again.
            animlDoc.SampleSet.Samples[0].Id = "ID-1";

            AnimlDocumentValidator validatorSucceed = AnimlDocumentValidator.CreateValidatorForAnimlDocument(animlDoc);

            validationOutcome = validatorSucceed.Validate();

            validationOutcome.Should().BeTrue();
            validatorSucceed.ValidationMessages.Should().BeEmpty();
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            List <double> values = GenerateValues(50, 0, 14);

            AnimlDocumentBuilder documentBuilder = new AnimlDocumentBuilder()
                                                   .WithSampleSet(
                new SampleSetBuilder()
                .WithId("ID-SampleSet")
                .WithSample(
                    new SampleBuilder("TestSample", "ID-TestSample")
                    .WithBarcode("B1234567890")
                    .WithComment("This is a test sample.")
                    .WithContainerInfo("CONT-123", ContainerType.Determinate, "A/1")
                    .WithDerived(false)
                    .WithId("S-1")
                    .WithSourceDataLocation("http://documentstore/B1234567890/data")
                    .Build())
                .Build())
                                                   .WithExperimentStepSet(
                new ExperimentStepSetBuilder()
                .WithId("ID-ExperimentStepSet")
                .WithExperimentStep(
                    new ExperimentStepBuilder("TestExperimentStep", "ID-ExperimentStep")
                    .WithComment("This is a test experiment step.")
                    .WithId("E-1")
                    .WithInfrastructure(
                        new InfrastructureBuilder()
                        .WithTimestamp(DateTime.Now)
                        .WithSampleReferenceSet(
                            new SampleReferenceSetBuilder()
                            .WithSampleReference(new SampleReference("ID-TestSample", "Test sample", SamplePurpose.Consumed))
                            .Build())
                        .Build())
                    .WithMethod(
                        new MethodBuilder()
                        .WithAuthor(
                            new AuthorBuilder("John Doe", UserType.Human)
                            .WithAffiliation("Black Mesa Corp.")
                            .WithEmail("*****@*****.**")
                            .WithLocation("New Mexico")
                            .WithPhone("+1 505 1234567")
                            .WithRole("Lab Technician")
                            .Build())
                        .WithDevice(
                            new DeviceBuilder("pH Meter")
                            .WithDeviceIdentifier("PH-11-1")
                            .WithFirmwareVersion("1.21a")
                            .WithManufacturer("pH Meter Manufacturing Corp.")
                            .WithSerialNumber("PHM0815")
                            .Build())
                        .WithId("M-1")
                        .WithName("pH Value")
                        .WithSoftware(
                            new SoftwareBuilder("pH Meter PC Software")
                            .WithManufacturer("pH Meter Manufacturing Corp.")
                            .WithOperatingSystem(Environment.OSVersion.ToString())
                            .WithVersion("2.08")
                            .Build())
                        .Build())
                    .WithResult(
                        new ResultBuilder("pH")
                        .WithSeriesSet(
                            new SeriesSetBuilder("pH Measurement", values.Count)
                            .WithSeries(
                                new SeriesBuilder("Time", "SER-PH-TIME", Dependency.Independent, SeriesType.Int32)
                                .WithId("SER-TIME")
                                .WithPlotScale(PlotScale.Linear)
                                .WithUnit(Units.Second)
                                .WithAutoIncrementedValueSet(0, 1)
                                .WithVisible(true)
                                .Build())
                            .WithSeries(
                                new SeriesBuilder("pH values", "SER-PH-VALS", Dependency.Dependent, SeriesType.Float64)
                                .WithId("SER-VALS")
                                .WithPlotScale(PlotScale.Linear)
                                .WithUnit(Units.Arbitrary)
                                .WithEncodedValueSet(values)
                                .WithVisible(true)
                                .Build())
                            .Build())
                        .Build())
                    .Build())
                .Build());

            AnimlDocument document  = documentBuilder.Build();
            string        docString = documentBuilder.Build().ToXml();

            //// Print the XML to the console
            Console.WriteLine("Generated AnIML document using builders:");
            Console.WriteLine("=========================");
            Console.WriteLine(docString);
            Console.WriteLine();

            if (!string.IsNullOrEmpty(outputFilePath))
            {
                document.SaveAsFile(outputFilePath);

                Console.WriteLine("Saved AnIML document to file:");
                Console.WriteLine("=========================");
                Console.WriteLine($"--> {outputFilePath}");
                Console.WriteLine();
            }

            //// Validate the AnIML document against the AnIML core schema
            Console.WriteLine("Validating document against the AnIML Core Schema:");
            Console.WriteLine("==================================================");

            AnimlDocumentValidator validator = AnimlDocumentValidator.CreateValidatorForAnimlDocumentString(docString);

            if (!validator.Validate())
            {
                Console.WriteLine("Validation failed.");
                validator.ValidationMessages.ForEach(Console.WriteLine);
            }
            else
            {
                Console.WriteLine("Validation succeeded.");
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //// Create a new AnimlDocument
            AnimlDocument document = new AnimlDocument();

            //// Create Sample(s) in the AnimlDocument
            CreateSamples(ref document);

            //// Create ExperimentStep(s) in the AnimlDocument
            CreateExperimentSteps(ref document);

            ////Create AuditTrailEntry(s) in the AnimlDocument
            CreateAuditTrailEntries(ref document);

            //// Generate the AnIML document XML from the AnimlDocument object
            string docString = document.ToXml();

            //// Print the XML to the console
            Console.WriteLine("Generated AnIML document:");
            Console.WriteLine("=========================");
            Console.WriteLine(docString);
            Console.WriteLine();

            if (!string.IsNullOrEmpty(outputFilePath))
            {
                document.SaveAsFile(outputFilePath);

                Console.WriteLine("Saved AnIML document to file:");
                Console.WriteLine("=========================");
                Console.WriteLine($"--> {outputFilePath}");
                Console.WriteLine();
            }

            //// Create a new document from the generated XML (to test importing XML)
            AnimlDocument document2  = AnimlDocument.ReadFromString(docString);
            string        docString2 = document2.ToXml();

            Console.WriteLine("AnIML document from import:");
            Console.WriteLine("=========================");
            Console.WriteLine(docString2);
            Console.WriteLine();

            //// Compare the initial XML with the one after reading from the XML
            Console.WriteLine("AnIML documents are equal:");
            Console.WriteLine("==========================");
            Console.WriteLine(docString.Equals(docString2, StringComparison.Ordinal) ? "YES" : "NO");
            Console.WriteLine();


            //// Validate the AnIML document against the AnIML core schema
            Console.WriteLine("Validating document against the AnIML Core Schema:");
            Console.WriteLine("==================================================");

            AnimlDocumentValidator validator = AnimlDocumentValidator.CreateValidatorForAnimlDocumentString(docString);

            if (!validator.Validate())
            {
                Console.WriteLine("Validation failed.");
                validator.ValidationMessages.ForEach(Console.WriteLine);
            }
            else
            {
                Console.WriteLine("Validation succeeded.");
            }
        }