/// <summary>
 /// Export using browse encoder
 /// </summary>
 /// <param name="endpoint"></param>
 /// <param name="diagnostics"></param>
 /// <param name="stream"></param>
 /// <param name="ct"></param>
 /// <returns></returns>
 private async Task BrowseEncodeModelAsync(EndpointModel endpoint,
                                           DiagnosticsModel diagnostics, Stream stream, CancellationToken ct)
 {
     using (var encoder = new BrowseStreamEncoder(_outer._client, endpoint,
                                                  stream, Encoding, diagnostics, _outer._logger, null)) {
         await encoder.EncodeAsync(ct);
     }
 }
        /// <inheritdoc/>
        public async Task ArchiveAsync(CancellationToken ct)
        {
            var diagnostics = new List <OperationResultModel>();

            // Write manifest

            // Write nodes
            IEnumerable <string> historyNodes = null;

            using (var stream = _archive.GetStream("_nodes", FileMode.CreateNew))
                using (var encoder = new BrowseStreamEncoder(_client, _endpoint, stream,
                                                             _contentType, null, _logger, _elevation)) {
                    await encoder.EncodeAsync(ct);

                    historyNodes = encoder.HistoryNodes;
                    diagnostics.AddRange(encoder.Diagnostics);
                }

            if (historyNodes != null)
            {
                foreach (var nodeId in historyNodes)
                {
                    using (var stream = _archive.GetStream("_history/" + nodeId,
                                                           FileMode.CreateNew))
                        using (var encoder = new HistoryStreamEncoder(_client, _endpoint,
                                                                      stream, _contentType, nodeId, _logger, _elevation,
                                                                      _startTime, _endTime, _maxValues)) {
                            await encoder.EncodeAsync(ct);

                            diagnostics.AddRange(encoder.Diagnostics);
                        }
                }
            }

            using (var stream = _archive.GetStream("_diagnostics", FileMode.CreateNew))
                using (var encoder = new ModelEncoder(stream, _contentType)) {
                    foreach (var operation in diagnostics)
                    {
                        encoder.WriteEncodeable(null, operation, operation.GetType());
                    }
                }
        }