Пример #1
0
        protected void HeadPartition(Stream stream, List <ItemPartition> list)
        {
            try
            {
                var head = new ItemPartition()
                {
                    ItemType = PersistentItemType.Head,
                    Position = stream.Position
                };
                head.Size = Math.Min(this.HeadSize, stream.Length - head.Position);
                list.Add(head);

                var item = new ItemPartition()
                {
                    ItemType = PersistentItemType.Content,
                    Position = head.EndPosition
                };
                item.Size = stream.Length - item.Position;
                list.Add(item);
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
        protected void TailPartition(Stream stream, List <ItemPartition> list)
        {
            try
            {
                var tail = new ItemPartition()
                {
                    ItemType = PersistentItemType.Tail,
                    Position = stream.Length - this.TailSize,
                    Size     = this.TailSize
                };
                list.Add(tail);

                var item = new ItemPartition()
                {
                    ItemType = PersistentItemType.Content,
                    Position = stream.Position
                };
                item.Size = stream.Length - stream.Position - tail.Size;
                list.Add(item);
            }
            catch
            {
                throw;
            }
        }
Пример #3
0
        protected void AveragePartition(Stream stream, List <ItemPartition> list)
        {
            try
            {
                long nCount = (stream.Length - stream.Position) / this.Size;
                if (0 != (stream.Length - stream.Position) % this.Size)
                {
                    nCount++;
                }

                for (long i = 0; i < nCount; i++)
                {
                    var item = new ItemPartition()
                    {
                        ItemType = PersistentItemType.Content,
                        Position = stream.Position + i * this.Size
                    };
                    item.Size = Math.Min(this.Size, stream.Length - item.Position);

                    list.Add(item);
                }
            }
            catch
            {
                throw;
            }
        }
Пример #4
0
 /// <summary>
 /// Determinate how to save a ItemPartition.
 /// Subclass should override this method to meet its needs.
 /// </summary>
 /// <param name="partition"></param>
 /// <returns></returns>
 /// <see cref="Biu.Serialization.PersistenceDecision"/>
 /// <see cref="Biu.Serialization.ItemPartition"/>
 public virtual PersistenceDecision MakeSavingDecision(ItemPartition partition)
 {
     return(new PersistenceDecision()
     {
         Key = this.Keys.FirstOrDefault(),
         Formatter = this.Formatters.FirstOrDefault(),
         StoredType = PersistentItemStoredType.Stream,
         Significance = PersistentItemSignificance.Normal
     });
 }
Пример #5
0
        protected void HeadTailPartition(Stream stream, List <ItemPartition> list)
        {
            try
            {
                var head = new ItemPartition()
                {
                    ItemType = PersistentItemType.Head,
                    Position = stream.Position
                };
                head.Size = Math.Min(this.HeadSize, stream.Length - head.Position);
                list.Add(head);

                var tail = new ItemPartition()
                {
                    ItemType = PersistentItemType.Tail,
                    Position = stream.Length - this.TailSize,
                    Size     = this.TailSize
                };

                long nRemainingSize = stream.Length - stream.Position - head.Size - tail.Size;
                long nCount         = nRemainingSize / this.Size;
                if (0 != nRemainingSize % this.Size)
                {
                    nCount++;
                }

                for (long i = 0; i < nCount; i++)
                {
                    var item = new ItemPartition()
                    {
                        ItemType = PersistentItemType.Content,
                        Position = stream.Position + i * this.Size
                    };
                    item.Size = Math.Min(this.Size, nRemainingSize - item.Position);

                    list.Add(item);
                }

                list.Add(tail);
            }
            catch
            {
                throw;
            }
        }