Exemplo n.º 1
0
        /// <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();
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
        /// <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();
        }
Exemplo n.º 8
0
 /// <inheritdocs/>
 public abstract void Write(ChunkFileContext context, object instance);
Exemplo n.º 9
0
 /// <inheritdocs/>
 public abstract object Read(ChunkFileContext context);