zhao
2021-06-24 02ca96debc6056275d58e55d97f7885a195542d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HH.WMS.Utils.ExcelLibrary.CompoundDocumentFormat
{
    public class SectorAllocation
    {
        CompoundDocument Document;
 
        int SecIDCapacity;
 
        public SectorAllocation(CompoundDocument document)
        {
            this.Document = document;
            this.SecIDCapacity = document.SectorSize / 4;
        }
 
        public int AllocateSector()
        {
            int newSectorID = Document.AllocateNewSector();
            LinkSectorID(newSectorID, SID.EOC);
            return newSectorID;
        }
 
        public void LinkSectorID(int sectorID, int newSectorID)
        {
            if (sectorID < 0)
            {
                throw new ArgumentOutOfRangeException("sectorID");
            }
            int SATSectorIndex = sectorID / SecIDCapacity;
            int SectorIndex = sectorID % SecIDCapacity;
 
            int SATSectorID = Document.MasterSectorAllocation.GetSATSectorID(SATSectorIndex);
            Document.WriteInSector(SATSectorID, SectorIndex * 4, newSectorID);
        }
 
        public int GetNextSectorID(int sectorID)
        {
            if (sectorID < 0)
            {
                throw new ArgumentOutOfRangeException("sectorID");
            }
            int SATSectorIndex = sectorID / SecIDCapacity;
            int SectorIndex = sectorID % SecIDCapacity;
 
            int SATSectorID = Document.MasterSectorAllocation.GetSATSectorID(SATSectorIndex);
            return Document.ReadInt32InSector(SATSectorID, SectorIndex * 4);
        }
 
        public List<int> GetSIDChain(int StartSID)
        {
            List<int> chain = new List<int>();
            int sid = StartSID;
            while (sid != SID.EOC)
            {
                chain.Add(sid);
                sid = GetNextSectorID(sid);
            }
            return chain;
        }
    }
}