Beispiel #1
0
        public void ConvertServiceModelAndStripSchemaFromDataBindingName()
        {
            // XSD to Json Schema
            XsdToJsonSchema xsdToJsonSchemaConverter = new XsdToJsonSchema(new XmlTextReader("Common/xsd/ServiceModel.xsd"), TestLogger.Create <XsdToJsonSchema>());
            JsonSchema      schemaJsonSchema         = xsdToJsonSchemaConverter.AsJsonSchema();

            JsonSchemaToInstanceModelGenerator converter = new JsonSchemaToInstanceModelGenerator("TestOrg", "ServiceModel", schemaJsonSchema);
            ServiceMetadata serviceMetadata = converter.GetServiceMetadata();

            string actualDatabinding = serviceMetadata.Elements["Skjema.Skattyterinforgrp5801.Kontaktgrp5803.KontaktpersonPoststeddatadef10442.value"].DataBindingName;

            Assert.Equal("skattyterinforgrp5801.kontaktgrp5803.kontaktpersonPoststeddatadef10442.value", actualDatabinding);
        }
        public ActionResult Upload(string org, string service, IFormFile thefile)
        {
            if (thefile == null)
            {
                throw new ApplicationException("Cannot upload empty file");
            }

            string mainFileName = ContentDispositionHeaderValue.Parse(new StringSegment(thefile.ContentDisposition)).FileName.ToString();

            MemoryStream xsdMemoryStream = new MemoryStream();

            thefile.OpenReadStream().CopyTo(xsdMemoryStream);
            xsdMemoryStream.Position = 0;
            XmlReader reader = XmlReader.Create(xsdMemoryStream, new XmlReaderSettings {
                IgnoreWhitespace = true
            });

            XDocument mainXsd = XDocument.Load(reader, LoadOptions.None);

            ServiceMetadata serviceMetadata = null;

            bool useOldParser = false;

            if (useOldParser)
            {
                var seresParser = new SeresXsdParser(_repository);
                serviceMetadata = seresParser.ParseXsdToServiceMetadata(org, service, mainXsd, null);
            }
            else
            {
                xsdMemoryStream.Position = 0;
                reader = XmlReader.Create(xsdMemoryStream, new XmlReaderSettings {
                    IgnoreWhitespace = true
                });

                XsdToJsonSchema xsdToJsonSchemaConverter = new XsdToJsonSchema(reader, _loggerFactory.CreateLogger <XsdToJsonSchema>());
                JsonSchema      schemaJsonSchema         = xsdToJsonSchemaConverter.AsJsonSchema();

                JsonSchemaToInstanceModelGenerator converter = new JsonSchemaToInstanceModelGenerator(org, service, schemaJsonSchema);
                serviceMetadata = converter.GetServiceMetadata();

                HandleTexts(org, service, converter.GetTexts());
            }

            if (_repository.CreateModel(org, service, serviceMetadata, mainXsd))
            {
                return(RedirectToAction("Index", new { org, service }));
            }

            return(Json(false));
        }
Beispiel #3
0
        public void TextGenerationOk()
        {
            var schemaText = File.ReadAllText("Common/jsd/service-model.schema.json");
            var schemaJson = JsonValue.Parse(schemaText);
            var schema     = new JsonSerializer().Deserialize <JsonSchema>(schemaJson);

            JsonSchemaToInstanceModelGenerator converter = new JsonSchemaToInstanceModelGenerator("TestOrg", "ServiceModel", schema);

            ServiceMetadata serviceMetadata = converter.GetServiceMetadata();

            Assert.NotNull(serviceMetadata);

            // get a chosen text identifier
            string placeholder = serviceMetadata.Elements["Skjema.Skattyterinforgrp5801.klagefristgrp5804.KlageUtloptKlagefristBegrunnelsedatadef25456.value"].Texts["PlaceHolder"];

            Assert.Equal("25456.KlageUtloptKlagefristBegrunnelsedatadef25456.PlaceHolder", placeholder);
        }