Beispiel #1
0
        Cursor <TSchema> GetNext()
        {
            int nextIndex = _index + 1;

            if (_entityResult.TryGetEntity(nextIndex, out TSchema entity))
            {
                _next = new EntityResultCursor <TSchema>(_context, _entityResult, nextIndex, entity);
            }

            _nextComputed = true;

            return(_next);
        }
Beispiel #2
0
        public async Task <FormatResult <TSchema> > FormatAsync(Stream output, EntityResult <TSchema> input)
        {
            using (var writer = new StreamWriter(output))
            {
                for (int i = 0;; i++)
                {
                    TSchema entity;
                    if (!input.TryGetEntity(i, out entity))
                    {
                        break;
                    }

                    HL7Segment segment = entity as HL7Segment;
                    if (segment == null)
                    {
                        throw new MacheteSchemaException($"The entity is not an HL7 segment: {TypeCache.GetShortName(entity.GetType())}");
                    }

                    if (i > 0)
                    {
                        await writer.WriteAsync(_settings.SegmentSeparator);
                    }

                    IEntityFormatter entityFormatter;
                    if (_schema.TryGetEntityFormatter(entity, out entityFormatter))
                    {
                        var context = new StringBuilderFormatContext();
                        context.AddSettings(_settings);

                        entityFormatter.Format(context, entity);

                        await writer.WriteAsync(context.ToString()).ConfigureAwait(false);
                    }
                    else
                    {
                        throw new MacheteSchemaException($"The entity type was not found: {TypeCache.GetShortName(entity.GetType())}");
                    }
                }
            }

            return(new HL7FormatResult <TSchema>());
        }