Ejemplo n.º 1
0
        private async Task TransformFile(string file, string outPath)
        {
            var content = await File.ReadAllTextAsync(file);

            var currentMimeType = MimeTypeUtils.ProbeFhirMimeType(content);

            if (!currentMimeType.HasValue)
            {
                _logger.LogWarning("Can't determine mime-type of {0} -- Skipping", file);
                return;
            }

            string result  = null;
            var    newFile = _arguments.OutputIsDirectory ? Path.Combine(outPath, Path.GetFileName(file)) : outPath;

            _logger.LogInformation("Transform {0} --> {1}", file, newFile);
            if (_arguments.XslTransform != null)
            {
                result = TransformXslt(content, currentMimeType.Value);
            }
            else if (_arguments.JustTransform != null)
            {
                result = TransformJust(content, currentMimeType.Value);
            }

            result = GetContentAs(result, currentMimeType.Value);

            await File.WriteAllTextAsync(newFile, result);
        }
Ejemplo n.º 2
0
        public ResourceWrapper Parse(string content, FhirMimeType?type = null, bool permissiveParsing = false)
        {
            if (!type.HasValue)
            {
                type = MimeTypeUtils.ProbeFhirMimeType(content);
            }

            if (!type.HasValue)
            {
                return(null);
            }

            switch (Version)
            {
            case FhirVersion.R3:
                var settingsR3 = new ParserSettings {
                    PermissiveParsing = permissiveParsing
                };
                var resourceR3 = type == FhirMimeType.Json
                         ? new R3Serialization.FhirJsonParser(settingsR3).Parse <Resource>(content)
                        : new R3Serialization.FhirXmlParser(settingsR3).Parse <Resource>(content);
                return(new ResourceWrapper(resourceR3, FhirVersion.R3));

            case FhirVersion.R4:
                var settingsR4 = new ParserSettings {
                    PermissiveParsing = permissiveParsing
                };
                var resourceR4 = type == FhirMimeType.Json
                        ? new R4Serialization.FhirJsonParser(settingsR4).Parse <Resource>(content)
                        : new R4Serialization.FhirXmlParser(settingsR4).Parse <Resource>(content);
                return(new ResourceWrapper(resourceR4, FhirVersion.R4));

            default:
                return(default);
            }
        }