/// <summary>Export the passed FHIR version into the specified directory.</summary>
        /// <param name="info">           The information.</param>
        /// <param name="serverInfo">     Information describing the server.</param>
        /// <param name="options">        Options for controlling the operation.</param>
        /// <param name="exportDirectory">Directory to write files.</param>
        void ILanguage.Export(
            FhirVersionInfo info,
            FhirServerInfo serverInfo,
            ExporterOptions options,
            string exportDirectory)
        {
            // set internal vars so we don't pass them to every function
            // this is ugly, but the interface patterns get bad quickly because we need the type map to copy the FHIR info
            _info    = info;
            _options = options;

            // create a filename for writing (single file for now)
            string filename = Path.Combine(exportDirectory, $"R{info.MajorVersion}.txt");

            using (FileStream stream = new FileStream(filename, FileMode.Create))
                using (ExportStreamWriter writer = new ExportStreamWriter(stream))
                {
                    _writer = writer;

                    WriteHeader();

                    WritePrimitiveTypes(_info.PrimitiveTypes.Values);
                    WriteComplexes(_info.ComplexTypes.Values, "Complex Types");
                    WriteComplexes(_info.Resources.Values, "Resources");

                    WriteOperations(_info.SystemOperations.Values, true, "System Operations");
                    WriteSearchParameters(_info.AllResourceParameters.Values, "All Resource Parameters");
                    WriteSearchParameters(_info.SearchResultParameters.Values, "Search Result Parameters");
                    WriteSearchParameters(_info.AllInteractionParameters.Values, "All Interaction Parameters");

                    WriteValueSets(_info.ValueSetsByUrl.Values, "Value Sets");

                    WriteFooter();
                }
        }
Exemple #2
0
        /// <summary>Writes an indented comment.</summary>
        /// <param name="writer">The writer to write the comment to.</param>
        /// <param name="value">The value.</param>
        /// <param name="isSummary">(Optional) True if is summary, false if not.</param>
        /// <param name="singleLine">(Optional) True if this is a short comment using a single line comment prefix. Implies isSummary = false.</param>
        public static void WriteIndentedComment(ExportStreamWriter writer, string value, bool isSummary = true, bool singleLine = false)
        {
            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            if (singleLine)
            {
                isSummary = false;
            }

            if (isSummary)
            {
                writer.WriteLineIndented("/// <summary>");
            }

            string comment = value.Replace('\r', '\n').Replace("\r\n", "\n").Replace("\n\n", "\n")
                             .Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;");

            string[] lines = comment.Split('\n');
            foreach (string line in lines)
            {
                writer.WriteIndented(singleLine ? "// " : "/// ");
                writer.WriteLine(line);
            }

            if (isSummary)
            {
                writer.WriteLineIndented("/// </summary>");
            }
        }
Exemple #3
0
        /// <summary>Closes the scope.</summary>
        /// <param name="writer">          The writer to write the comment to.</param>
        /// <param name="includeSemicolon">(Optional) True to include, false to exclude the semicolon.</param>
        /// <param name="suppressNewline"> (Optional) True to suppress, false to allow the newline.</param>
        public static void CloseScope(ExportStreamWriter writer, bool includeSemicolon = false, bool suppressNewline = false)
        {
            writer.DecreaseIndent();

            if (includeSemicolon)
            {
                writer.WriteLineIndented("};");
            }
            else
            {
                writer.WriteLineIndented("}");
            }

            if (!suppressNewline)
            {
                writer.WriteLine(string.Empty);
            }
        }
        /// <summary>Export the passed FHIR version into the specified directory.</summary>
        /// <param name="info">           The information.</param>
        /// <param name="serverInfo">     Information describing the server.</param>
        /// <param name="options">        Options for controlling the operation.</param>
        /// <param name="exportDirectory">Directory to write files.</param>
        void ILanguage.Export(
            FhirVersionInfo info,
            FhirServerInfo serverInfo,
            ExporterOptions options,
            string exportDirectory)
        {
            // set internal vars so we don't pass them to every function
            // this is ugly, but the interface patterns get bad quickly because we need the type map to copy the FHIR info
            _info    = info;
            _options = options;

            _exportedCodes = new HashSet <string>();

            if (options.OptionalClassTypesToExport.Contains(ExporterOptions.FhirExportClassType.Enum))
            {
                _exportEnums = true;
            }
            else
            {
                _exportEnums = false;
            }

            // create a filename for writing (single file for now)
            string filename = Path.Combine(exportDirectory, $"R{info.MajorVersion}.ts");

            using (FileStream stream = new FileStream(filename, FileMode.Create))
                using (ExportStreamWriter writer = new ExportStreamWriter(stream))
                {
                    _writer = writer;

                    WriteHeader();

                    WriteComplexes(_info.ComplexTypes.Values, false);
                    WriteComplexes(_info.Resources.Values, true);

                    if (_exportEnums)
                    {
                        WriteValueSets(_info.ValueSetsByUrl.Values);
                    }

                    WriteFooter();
                }
        }
Exemple #5
0
        /// <summary>Export the passed FHIR version into the specified directory.</summary>
        /// <param name="info">           The information.</param>
        /// <param name="serverInfo">     Information describing the server.</param>
        /// <param name="options">        Options for controlling the operation.</param>
        /// <param name="exportDirectory">Directory to write files.</param>
        void ILanguage.Export(
            FhirVersionInfo info,
            FhirServerInfo serverInfo,
            ExporterOptions options,
            string exportDirectory)
        {
            // set internal vars so we don't pass them to every function
            // this is ugly, but the interface patterns get bad quickly because we need the type map to copy the FHIR info
            _info    = info;
            _options = options;

            if (options.OptionalClassTypesToExport.Contains(ExporterOptions.FhirExportClassType.Enum))
            {
                _exportEnums = true;
            }
            else
            {
                _exportEnums = false;
            }

            if ((options.LanguageOptions != null) && (options.LanguageOptions.Count > 0))
            {
                foreach (KeyValuePair <string, string> kvp in options.LanguageOptions)
                {
                    string key = kvp.Key.ToUpperInvariant();

                    switch (key)
                    {
                    case "NAMESPACE":
                        _namespace = kvp.Value;
                        break;
                    }
                }
            }

            _exportedResourceNamesAndTypes = new Dictionary <string, string>();
            _exportedCodes = new HashSet <string>();

            // create a filename for writing (single file for now)
            string filename = Path.Combine(exportDirectory, $"R{info.MajorVersion}.cs");

            using (FileStream stream = new FileStream(filename, FileMode.Create))
                using (ExportStreamWriter writer = new ExportStreamWriter(stream))
                {
                    _writer = writer;

                    WriteHeader();

                    // open namespace
                    _writer.WriteLineIndented($"namespace {_namespace}");
                    _writer.WriteLineIndented("{");
                    _writer.IncreaseIndent();

                    WriteComplexes(_info.ComplexTypes.Values, false);
                    WriteComplexes(_info.Resources.Values, true);

                    if (_exportEnums)
                    {
                        WriteValueSets(_info.ValueSetsByUrl.Values);
                    }

                    WritePolymorphicHelpers();

                    // close namespace
                    _writer.DecreaseIndent();
                    _writer.WriteLineIndented("}");

                    WriteFooter();
                }
        }
Exemple #6
0
 /// <summary>Opens the scope.</summary>
 /// <param name="writer">The writer to write the comment to.</param>
 public static void OpenScope(ExportStreamWriter writer)
 {
     writer.WriteLineIndented("{");
     writer.IncreaseIndent();
 }