| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace System.Fire.Container {
- public partial class ContainerList {
- /// <summary>
- /// Create a new Data-Stack to store the data in
- /// </summary>
- /// <param name="FileName">Set a file name for the data</param>
- /// <returns>Returns the Stack-ID. If it failed to create a stack, it will return -1</returns>
- public int CreateStack(string FileName) {
- for (int i = 0; i < 256; i++) {
- if (this._stack[i] == null) {
- this._stack[i] = new ContainerStack(FileName);
- this._stack[i].IsDone = false;
- return i;
- }
- }
- return -1;
- }
- /// <summary>
- /// Create a new Data-Stack to store the data in
- /// </summary>
- /// <returns>Returns the Stack-ID. If it failed to create a stack, it will return -1</returns>
- public int CreateStack() {
- for (int i = 0; i < 256; i++) {
- if (this._stack[i] == null) {
- this._stack[i] = new ContainerStack();
- this._stack[i].IsDone = false;
- return i;
- }
- }
- return -1;
- }
- /// <summary>
- /// Close the Stack, set the file data and write the stack
- /// </summary>
- /// <param name="StackId">The Stack-ID</param>
- /// <returns>Returns the File-ID</returns>
- public int CloseStack(int StackId) {
- this._stack[StackId].IsDone = true;
- this.WriteStack(StackId);
- ContainerFile cf = new ContainerFile();
- byte[] chunks = this._stack[StackId].getStackPositions();
- cf.UploadDate = DateTime.Now;
- cf.FileInfoPos = this.WriteFileInfo(new FileInfoX(this._stack[StackId].FileName));
- cf.ChunkPos = this.WriteChunk(chunks);
- cf.ChunkLen = chunks.Length;
- cf.Size = this._stack[StackId].WrittenBytes;
- cf.MediaType = Mime.getMediaType(this._stack[StackId].FileName);
- this._stack[StackId] = null;
- int fi = this._files.Count();
- this._files.Add(cf);
- return fi;
- }
- /// <summary>
- /// Write one chunk from the stack into a container
- /// </summary>
- /// <param name="stackId">The Stack-ID</param>
- private void WriteStack(int stackId) {
- // Get best container
- this.WriteStack(this._stack[stackId]);
- }
- /// <summary>
- /// Write one chunk from the stack into a container
- /// </summary>
- /// <param name="stack">The Stack</param>
- private void WriteStack(ContainerStack stack) {
- Container c = this.GetBestContainer(stack);
- ushort pos = c.WriteChunk(stack.read(c.ChunkSize));
- /*System.Diagnostics.Debug.WriteLine("Writ: " +
- c.GroupId.ToString().PadLeft(3) + " | " +
- c.ContainerId.ToString().PadLeft(3) + " | " +
- pos.ToString().PadLeft(3) + " | "
- );*/
- stack.AddStackPosition(c, pos);
- }
- /// <summary>
- /// Writes all data from a stack into a container
- /// </summary>
- /// <param name="stackId">The Stack-ID</param>
- private void WriteAllStack(int stackId) {
- // Get best container
- this.WriteAllStack(this._stack[stackId]);
- }
- /// <summary>
- /// Writes all data from a stack into a container
- /// </summary>
- /// <param name="stack">The Stack</param>
- private void WriteAllStack(ContainerStack stack) {
- while (stack.Size > 0) {
- Container c = this.GetBestContainer(stack);
- ushort pos = c.WriteChunk(stack.read(c.ChunkSize));
- System.Diagnostics.Debug.WriteLine("Writ: " +
- c.GroupId.ToString().PadLeft(3) + " | " +
- c.ContainerId.ToString().PadLeft(3) + " | " +
- pos.ToString().PadLeft(3) + " | "
- );
- stack.AddStackPosition(c, pos);
- }
- }
- }
- }
|