/// <summary> /// Resets the <see cref="ReqIFLoaderService"/> by clearing <see cref="ReqIFData"/> and /// <see cref="sourceStream"/> /// </summary> public void Reset() { this.sourceStream = null; this.ReqIFData = null; this.externalObjectDataCache.Clear(); this.logger.LogDebug("loader service reset"); ReqIfChanged?.Invoke(this, null); }
/// <summary> /// Loads the <see cref="ReqIF"/> objects from the provided <see cref="Stream"/> /// and stores the result in the <see cref="ReqIFData"/> property. /// </summary> /// <param name="reqIFStream"> /// a <see cref="Stream"/> that contains <see cref="ReqIF"/> content /// </param> /// <param name="token"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns> /// an awaitable <see cref="Task"/> /// </returns> public async Task Load(Stream reqIFStream, CancellationToken token) { this.externalObjectDataCache.Clear(); this.sourceStream = new MemoryStream(); var deserializationStream = new MemoryStream(); this.logger.LogDebug("copying the reqif stream to the deserialization stream for deserialization"); reqIFStream.Seek(0, SeekOrigin.Begin); await reqIFStream.CopyToAsync(deserializationStream, 81920, token); if (deserializationStream.Position != 0) { deserializationStream.Seek(0, SeekOrigin.Begin); } this.logger.LogDebug("copying the reqif stream to the source stream for safe keeping"); reqIFStream.Seek(0, SeekOrigin.Begin); await reqIFStream.CopyToAsync(this.sourceStream, 81920, token); if (this.sourceStream.Position != 0) { this.sourceStream.Seek(0, SeekOrigin.Begin); } IEnumerable <ReqIF> result = null; var sw = Stopwatch.StartNew(); this.logger.LogDebug("starting deserialization"); result = await this.reqIfDeSerializer.DeserializeAsync(deserializationStream, token); this.logger.LogDebug("deserialization finished in {time} [ms]", sw.ElapsedMilliseconds); deserializationStream.Dispose(); this.ReqIFData = result; ReqIfChanged?.Invoke(this, this.ReqIFData); }