Read() public method

public Read ( int length, FromLogCallback fromLog, FromSuccessorCallback fromSuccessor ) : void
length int
fromLog FromLogCallback
fromSuccessor FromSuccessorCallback
return void
Beispiel #1
0
        public static ICollection <DeltaOperation> Merge(
            IEnumerable <DeltaOperation> lastRevision,
            IEnumerable <DeltaOperation> priorRevision)
        {
            var result = new LinkedList <DeltaOperation>();

            using (var merger = new DeltaSimulator(lastRevision))
            {
                foreach (DeltaOperation operation in priorRevision)
                {
                    switch (operation.Command)
                    {
                    case DeltaCommand.WriteLog:
                        result.AddLast(operation);
                        break;

                    case DeltaCommand.WriteSuccessor:
                        merger.Seek(operation.Offset);
                        merger.Read(operation.Length,
                                    delegate(byte[] data, int offset, int count)
                        {
                            result.AddLast(DeltaOperation.WriteLog(data, offset, count));
                            return(count);
                        },
                                    delegate(int offset, int count)
                        {
                            result.AddLast(DeltaOperation.WriteSuccessor(offset, count));
                            return(count);
                        });
                        break;
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
 public static ICollection<DeltaOperation> Merge(
     IEnumerable<DeltaOperation> lastRevision,
     IEnumerable<DeltaOperation> priorRevision)
 {
     var result = new LinkedList<DeltaOperation>();
     using (var merger = new DeltaSimulator(lastRevision))
     {
         foreach (DeltaOperation operation in priorRevision)
         {
             switch (operation.Command)
             {
                 case DeltaCommand.WriteLog:
                     result.AddLast(operation);
                     break;
                 case DeltaCommand.WriteSuccessor:
                     merger.Seek(operation.Offset);
                     merger.Read(operation.Length,
                         delegate(byte[] data, int offset, int count)
                         {
                             result.AddLast(DeltaOperation.WriteLog(data, offset, count));
                             return count;
                         },
                         delegate(int offset, int count)
                         {
                             result.AddLast(DeltaOperation.WriteSuccessor(offset, count));
                             return count;
                         });
                     break;
             }
         }
     }
     return result;
 }
Beispiel #3
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int bytesRead = 0;

            simulator.Read(count,
                           delegate(byte[] opData, int opOffset, int opCount)
            {
                Buffer.BlockCopy(opData, opOffset, buffer, offset, opCount);
                offset    += opCount;
                count     -= opCount;
                bytesRead += opCount;
                return(opCount);
            },
                           delegate(int opOffset, int opCount)
            {
                baseStream.Seek(opOffset, SeekOrigin.Begin);
                var opBytesRead = baseStream.Read(buffer, offset, opCount);
                offset         += opBytesRead;
                count          -= opBytesRead;
                bytesRead      += opBytesRead;
                return(opBytesRead);
            });
            return(bytesRead);
        }