/// <summary> /// Contract specification. /// </summary> /// <param name="context">Must not be null.</param> /// <param name="instance">Must not be null.</param> void IFileChunkHandler.Write(ChunkFileContext context, object instance) { Contract.Requires(context != null); Contract.Requires(instance != null); throw new System.NotImplementedException(); }
/// <summary> /// Reads the current chunk and creates a runtime type for it, which is then returned. /// </summary> /// <param name="context">The context of the chunk file being read. Must not be null.</param> /// <returns>Returns null if there was no runtime type found for the current chunk.</returns> public override object Read(ChunkFileContext context) { Check.IfArgumentNull(context, nameof(context)); Check.IfArgumentNull(context.ChunkStack, nameof(context.ChunkStack)); Check.IfArgumentNull(context.ChunkStack.CurrentChunk, nameof(context.ChunkStack.CurrentChunk)); Check.IfArgumentNull(context.ChunkFile, nameof(context.ChunkFile)); Check.IfArgumentNull(context.ChunkFile.BaseStream, nameof(context.ChunkFile.BaseStream)); var reader = context.Services.GetService <FileChunkReader>(); var stream = context.ChunkFile.BaseStream; var chunk = context.ChunkStack.CurrentChunk; chunk.RuntimeInstance = reader.ReadRuntimeChunkType(stream, chunk.ChunkId); // extra check if type returned is correct for chunk. if (chunk.RuntimeInstance != null && !ChunkAttribute.GetChunkId(chunk.RuntimeInstance).MatchesWith(chunk.ChunkId.ToString())) { var msg = String.Format( CultureInfo.InvariantCulture, "The type '{0}' tagged with '{1}' was returned when '{2}' was requested.", chunk.RuntimeInstance.GetType(), ChunkAttribute.GetChunkId(chunk.RuntimeInstance), chunk.ChunkId); throw new ChunkFileException(msg); } return(chunk.RuntimeInstance); }
/// <inheritdocs/> public override void Write(ChunkFileContext context, object instance) { Check.IfArgumentNull(context, nameof(context)); Check.IfArgumentNull(instance, nameof(instance)); var writer = context.Services.GetService <FileChunkWriter>(); writer.WriteRuntimeChunkType(instance); }
public override void Write(ChunkFileContext context, object instance) { Check.IfArgumentNull(context, "context"); Check.IfArgumentNull(instance, "instance"); var writer = context.CompositionContainer.GetService <FileChunkWriter>(); writer.WriteRuntimeChunkType(instance); }
public FileChunkWriter(ChunkFileContext context) { Contract.Requires(context != null); Contract.Requires(context.CompositionContainer != null); Check.IfArgumentNull(context, "context"); Check.IfArgumentNull(context.CompositionContainer, "context.CompositionContainer"); context.CompositionContainer.ComposeParts(this); context.CompositionContainer.AddInstance(this); this.context = context; }
/// <summary> /// Constructs a new writer instance. /// </summary> /// <param name="context">Must not be null. Can be reused from a read operation.</param> public FileChunkWriter(ChunkFileContext context) : base(context) { Check.IfArgumentNull(context, nameof(context)); Check.IfArgumentNull(context.Services, nameof(context.Services)); _streamNavigator = context.Services.GetService <IStreamNavigator>(); _handlerMgr = context.Services.GetService <FileChunkHandlerManager>(); _stringWriter = context.Services.GetService <IStringWriter>(); _numberWriter = context.Services.GetService <INumberWriter>(); context.Services.AddService(GetType(), this); }
/// <summary> /// Contract specification. /// </summary> /// <param name="context">Must not be null.</param> /// <returns>No contract.</returns> object IFileChunkHandler.Read(ChunkFileContext context) { Contract.Requires(context != null); throw new System.NotImplementedException(); }
/// <inheritdocs/> public abstract void Write(ChunkFileContext context, object instance);
/// <inheritdocs/> public abstract object Read(ChunkFileContext context);