private static void LoadIndexType(IndexRecord record)
        {
            if (record.Page.Header.IndexId > 0)
            {
                record.IndexType = record.IndexType | IndexTypes.NonClustered;
            }
            else
            {
                record.IndexType = record.IndexType | IndexTypes.Clustered;
            }

            if (record.Page.Header.Level > 0)
            {
                record.IndexType = record.IndexType | IndexTypes.Node;
            }
            else
            {
                record.IndexType = record.IndexType | IndexTypes.Leaf;
            }

            if ((record.Structure as IndexStructure).Heap)
            {
                record.IndexType = record.IndexType | IndexTypes.Heap;
            }
            else
            {
                record.IndexType = record.IndexType | IndexTypes.TableClustered;
            }

            record.IncludeKey = (!(record.Structure as IndexStructure).Unique &&
                                 record.IsIndexType(IndexTypes.NonClustered)) ||
                                record.IsIndexType(IndexTypes.NonClusteredLeaf);
        }
Esempio n. 2
0
        private IndexRecord ReadIndexRecord(byte[] recordBuffer)
        {
            var record = new IndexRecord();

            record.ReadFrom(recordBuffer);
            return(record);
        }
        internal static void Load(IndexRecord record)
        {
            var varColStartIndex = 0;

            LoadIndexType(record);

            LoadStatusBits(record);

            if (record.HasNullBitmap)
            {
                LoadNullBitmap(record);

                varColStartIndex = 2 + record.NullBitmapSize;
            }

            if (record.HasVariableLengthColumns)
            {
                LoadColumnOffsetArray(record, varColStartIndex);
            }

            record.VariableLengthDataOffset = (ushort)(record.Page.Header.MinLen + sizeof(short) + varColStartIndex + (sizeof(short) * record.VariableLengthColumnCount));

            LoadColumnValues(record);

            if (record.IsIndexType(IndexTypes.Node) | record.Page.Header.IndexId == 1)
            {
                LoadDownPagePointer(record);
            }

            if (record.IsIndexType(IndexTypes.Heap) && (!(record.Structure as IndexStructure).Unique | record.IsIndexType(IndexTypes.Leaf)))
            {
                LoadRid(record);
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            IndexRecord record = new IndexRecord();
            record[0] = "马克-吐温";
            record[1] = "Crox出版公司";
            record[2] = "汤姆-索亚历险记";
            Console.WriteLine(record["Title"]);
            Console.WriteLine(record["Author"]);
            Console.WriteLine(record["Publisher"]);

            Console.ReadKey();


            /*
             属性与索引的比较:
             属性
             1.通过名称标识;
             2.通过简单名称来访问;
             3.可以用static来修饰;
             4.属性的get访问器没有参数;
             5.属性的set访问器包含隐式value参数;

            索引器
            1.通过参数列表进行标识;
            2.通过[]运算符来访问;
            3.不能用static来修饰;
            4.索引的get访问器具有与索引相同的参数列表;
            5.除了有value参数外,索引的set访问器还具有与索引相同的与参数列表;

             */
        }
Esempio n. 5
0
 static void Main(string[] args)
 {
     if (args.Length < 2 || !File.Exists(args[0]) || !Directory.Exists(args[1]))
     {
         printUsage();
         return;
     }
     string foldersListConfigFile = args[0];
     string destinationFolder = args[1];
     logFilePath = destinationFolder + @"/log.txt";
     indexRecord = new IndexRecord(destinationFolder);
     using (StreamReader reader = new StreamReader(foldersListConfigFile))
     {
         while (reader.Peek() >= 0)
         {
             string folder = reader.ReadLine();
             if (folder.StartsWith("-"))
                 notScanFolderList.Add(folder.Remove(0, 1));
             else
                 scanFolderList.Add(folder);
         }
     }
     foreach (string folder in scanFolderList)
     {
         Console.WriteLine("Start Scan Folder: " + folder);
         recordAllFileInfo(folder, destinationFolder);
     }
     indexRecord.scanCleanAndGenerateFileIDToDeleteList(destinationFolder + @"\delete");
     indexRecord.saveFileIDIndexedList();
     Console.WriteLine("Done! File Processed: {0}; Directory Processed: {1}; Directory Skipped: {2}; Error: {3}", processedFileCount, processedDirectoryCount, skippedDirectoryCount, errorCoult);
 }
Esempio n. 6
0
        /**
         * @return the value calculated for the position of the first DBCELL record for this sheet.
         * That value is1 found on the IndexRecord.
         */
        private static int GetDbCellRecordPos(InternalSheet sheet)
        {
            MyIndexRecordListener myIndexListener = new MyIndexRecordListener();

            sheet.VisitContainedRecords(myIndexListener, 0);
            IndexRecord indexRecord     = myIndexListener.GetIndexRecord();
            int         dbCellRecordPos = indexRecord.GetDbcellAt(0);

            return(dbCellRecordPos);
        }
        private void parseRecords()
        {
            Records = new IndexRecord[Header.SlotCnt];

            int cnt = 0;

            foreach (short recordOffset in SlotArray)
            {
                Records[cnt++] = new IndexRecord(ArrayHelper.SliceArray(RawBytes, recordOffset, RawBytes.Length - recordOffset), this);
            }
        }
Esempio n. 8
0
 public void VisitRecord(Record r)
 {
     if (r is IndexRecord)
     {
         if (_indexRecord != null)
         {
             throw new Exception("too many index records");
         }
         _indexRecord = (IndexRecord)r;
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Retrieve the map output of a single map task
        /// and send it to the merger.
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        private bool CopyMapOutput(TaskAttemptID mapTaskId)
        {
            // Figure out where the map task stored its output.
            Path mapOutputFileName = localMapFiles[mapTaskId].GetOutputFile();
            Path indexFileName     = mapOutputFileName.Suffix(".index");
            // Read its index to determine the location of our split
            // and its size.
            SpillRecord sr = new SpillRecord(indexFileName, job);
            IndexRecord ir = sr.GetIndex(reduce);
            long        compressedLength   = ir.partLength;
            long        decompressedLength = ir.rawLength;

            compressedLength   -= CryptoUtils.CryptoPadding(job);
            decompressedLength -= CryptoUtils.CryptoPadding(job);
            // Get the location for the map output - either in-memory or on-disk
            MapOutput <K, V> mapOutput = merger.Reserve(mapTaskId, decompressedLength, id);

            // Check if we can shuffle *now* ...
            if (mapOutput == null)
            {
                Log.Info("fetcher#" + id + " - MergeManager returned Status.WAIT ...");
                return(false);
            }
            // Go!
            Log.Info("localfetcher#" + id + " about to shuffle output of map " + mapOutput.GetMapId
                         () + " decomp: " + decompressedLength + " len: " + compressedLength + " to " + mapOutput
                     .GetDescription());
            // now read the file, seek to the appropriate section, and send it.
            FileSystem        localFs  = FileSystem.GetLocal(job).GetRaw();
            FSDataInputStream inStream = localFs.Open(mapOutputFileName);

            inStream = CryptoUtils.WrapIfNecessary(job, inStream);
            try
            {
                inStream.Seek(ir.startOffset + CryptoUtils.CryptoPadding(job));
                mapOutput.Shuffle(Localhost, inStream, compressedLength, decompressedLength, metrics
                                  , reporter);
            }
            finally
            {
                try
                {
                    inStream.Close();
                }
                catch (IOException ioe)
                {
                    Log.Warn("IOException closing inputstream from map output: " + ioe.ToString());
                }
            }
            scheduler.CopySucceeded(mapTaskId, Localhost, compressedLength, 0, 0, mapOutput);
            return(true);
        }
Esempio n. 10
0
        private static void LoadDownPagePointer(IndexRecord record)
        {
            //Last 6 bytes of the fixed slot
            var address = new byte[PageAddress.Size];

            var downPagePointerOffset = record.SlotOffset + record.Page.Header.MinLen - PageAddress.Size;

            Array.Copy(record.Page.PageData, downPagePointerOffset, address, 0, PageAddress.Size);

            record.DownPagePointer = new PageAddress(address);

            record.Mark("DownPagePointer", downPagePointerOffset, PageAddress.Size);
        }
Esempio n. 11
0
        private static void LoadStatusBits(IndexRecord record)
        {
            var statusA = record.Page.PageData[record.SlotOffset];

            record.StatusBitsA = new BitArray(new byte[] { statusA });

            record.Mark("StatusBitsADescription", record.SlotOffset, 1);

            record.RecordType = (RecordType)((statusA >> 1) & 7);

            record.HasNullBitmap            = record.StatusBitsA[4];
            record.HasVariableLengthColumns = record.StatusBitsA[5];
        }
Esempio n. 12
0
        private static void LoadColumnOffsetArray(IndexRecord record, int varColStartIndex)
        {
            var varColCountOffset = record.SlotOffset + record.Page.Header.MinLen + varColStartIndex;

            record.VariableLengthColumnCount = BitConverter.ToUInt16(record.Page.PageData, varColCountOffset);

            record.Mark("VariableLengthColumnCount", varColCountOffset, sizeof(short));

            // Load offset array of 2-byte ints indicating the end offset of each variable length field
            record.ColOffsetArray = GetOffsetArray(record.Page.PageData,
                                                   record.VariableLengthColumnCount,
                                                   record.SlotOffset + record.Page.Header.MinLen + sizeof(short) + varColStartIndex);

            record.Mark("ColOffsetArrayDescription", varColCountOffset + sizeof(short), record.VariableLengthColumnCount * sizeof(short));
        }
Esempio n. 13
0
        private void GetPolygonOfArea_MultiPatch(List <Utils.Polygon> polygons, IndexRecord rec)
        {
            //NOTE: at this point we ignore the type (outer ring, inner ring
            //this is not correct and should be implemented correctly
            //suggestion: Add a property Exclude to Framework.Data.Polygon

            _shpFileStream.Position = rec.Offset + 8 + 36; //skip bounding box and shapetype
            int numberOfPolygons = GetInt32(_shpFileStream, true);
            int numberOfPoints   = GetInt32(_shpFileStream, true);

            int[] pointIndexFirstPointPerPolygon = new int[numberOfPolygons];
            int[] partsTypePerPolygon            = new int[numberOfPolygons];
            for (int i = 0; i < numberOfPolygons; i++)
            {
                pointIndexFirstPointPerPolygon[i] = GetInt32(_shpFileStream, true);
            }
            for (int i = 0; i < numberOfPolygons; i++)
            {
                partsTypePerPolygon[i] = GetInt32(_shpFileStream, true);
            }
            for (int i = 0; i < numberOfPolygons; i++)
            {
                Utils.Polygon pg = new Utils.Polygon();
                int           pointCount;
                if (i < numberOfPolygons - 1)
                {
                    pointCount = pointIndexFirstPointPerPolygon[i + 1] - pointIndexFirstPointPerPolygon[i];
                }
                else
                {
                    pointCount = numberOfPoints - pointIndexFirstPointPerPolygon[i];
                }
                for (int p = 0; p < pointCount; p++)
                {
                    double x = GetDouble(_shpFileStream, true);
                    double y = GetDouble(_shpFileStream, true);
                    if (_coordType == CoordType.DutchGrid)
                    {
                        pg.AddLocation(Utils.Calculus.LocationFromRD(x, y));
                    }
                    else
                    {
                        pg.AddLocation(new Utils.Location(y, x));
                    }
                }
                polygons.Add(pg);
            }
        }
Esempio n. 14
0
        private void parseRecords()
        {
            Records = new IndexRecord[Header.SlotCnt];

            //var offsets = SlotArray.OrderBy(x => x).Select((o, i) => new {o, i}).ToArray();

            //var joinedOffsets = from o1 in offsets
            //                     join o2 in offsets on o1.i equals o2.i-1 into ps
            //                     from p in ps.DefaultIfEmpty()
            //                     select new { o1.i,o1.o, length = p?.o - o1.o };
            var idx = 0;

            foreach (var recordOffset in SlotArray)
            {
                Records[idx++] = new IndexRecord(ArrayHelper.SliceArray(RawBytes.ToArray(), recordOffset, RawBytes.Count - recordOffset), this);
            }
        }
Esempio n. 15
0
        public static IndexRecord[] RewriteWithIndexRebuild(
            SortedDictionary <int, object> data, IDbConnection dbConnection)
        {
            var descriptor = dbConnection.GetDescriptor();

            descriptor.RecordSize = GetObjectSize(data.First());
            var maxBlockRecordsCount = descriptor.BlockSize / descriptor.RecordSize;
            var blockRecordsCount    = (int)(maxBlockRecordsCount * (descriptor.FillFactor / 100.0));
            var blocksCount          = data.Count / blockRecordsCount;

            if (data.Count % blockRecordsCount > 0)
            {
                ++blocksCount;
            }
            var indexes   = new IndexRecord[blocksCount];
            var formatter = new BinaryFormatter();
            var fs        = dbConnection.GetDataFileStream();

            fs.SetLength(0);
            fs.Flush();
            using (var iter = data.GetEnumerator())
            {
                iter.MoveNext();
                for (int block = 0; block < blocksCount; ++block)
                {
                    fs.Position    = block * descriptor.BlockSize;
                    indexes[block] = new IndexRecord {
                        Key = iter.Current.Key, Block = block
                    };
                    for (int i = 0; i < blockRecordsCount; ++i)
                    {
                        formatter.Serialize(fs, iter.Current);
                        if (!iter.MoveNext())
                        {
                            break;
                        }
                    }
                    fs.Position = (block + 1) * descriptor.BlockSize - descriptor.LinkSize;
                    formatter.Serialize(fs, -1);
                }
            }
            descriptor.DataBlocksCount = blocksCount;
            descriptor.IndexRecordSize = GetObjectSize(indexes[0]);
            descriptor.OverloadSize    = 0;
            return(indexes);
        }
Esempio n. 16
0
        public static void CreateVolumeWithPendingFileCreation(string path, long size, int bytesPerCluster, string volumeLabel, string fileName, byte[] fileData)
        {
            VirtualHardDisk disk = VirtualHardDisk.CreateFixedDisk(path, size);

            disk.ExclusiveLock();
            Partition         partition         = NTFSFormatTests.CreatePrimaryPartition(disk);
            NTFSVolume        volume            = NTFSVolumeCreator.Format(partition, bytesPerCluster, volumeLabel);
            long              segmentNumber     = MasterFileTable.FirstUserSegmentNumber;
            FileNameRecord    fileNameRecord    = new FileNameRecord(MasterFileTable.RootDirSegmentReference, fileName, false, DateTime.Now);
            FileRecordSegment fileRecordSegment = CreateFileRecordSegment(segmentNumber, fileNameRecord, fileData);

            ulong dataStreamOffset = (ulong)(segmentNumber * volume.BytesPerFileRecordSegment);

            byte[] redoData = fileRecordSegment.GetBytes(volume.BytesPerFileRecordSegment, volume.MinorVersion, false);
            MftSegmentReference mftFileReference = new MftSegmentReference(0, 1);
            AttributeRecord     mftDataRecord    = volume.GetFileRecord(mftFileReference).GetAttributeRecord(AttributeType.Data, String.Empty);
            AttributeRecord     mftBitmapRecord  = volume.GetFileRecord(mftFileReference).GetAttributeRecord(AttributeType.Bitmap, String.Empty);
            uint transactionID = volume.LogClient.AllocateTransactionID();

            volume.LogClient.WriteLogRecord(mftFileReference, mftDataRecord, dataStreamOffset, volume.BytesPerFileRecordSegment, NTFSLogOperation.InitializeFileRecordSegment, redoData, NTFSLogOperation.Noop, new byte[0], transactionID);
            long        bitmapVCN          = segmentNumber / (volume.BytesPerCluster * 8);
            int         bitOffsetInCluster = (int)(segmentNumber % (volume.BytesPerCluster * 8));
            BitmapRange bitmapRange        = new BitmapRange((uint)bitOffsetInCluster, 1);
            ulong       bitmapStreamOffset = (ulong)(bitmapVCN * volume.BytesPerCluster);

            volume.LogClient.WriteLogRecord(mftFileReference, mftBitmapRecord, bitmapStreamOffset, volume.BytesPerCluster, NTFSLogOperation.SetBitsInNonResidentBitMap, bitmapRange.GetBytes(), NTFSLogOperation.Noop, new byte[0], transactionID);

            FileRecord parentDirectoryRecord = volume.GetFileRecord(MasterFileTable.RootDirSegmentReference);
            IndexData  parentDirectoryIndex  = new IndexData(volume, parentDirectoryRecord, AttributeType.FileName);

            byte[]      fileNameRecordBytes   = fileNameRecord.GetBytes();
            long        leafRecordVBN         = 0;
            IndexRecord leafRecord            = parentDirectoryIndex.ReadIndexRecord(leafRecordVBN);
            ulong       indexAllocationOffset = (ulong)parentDirectoryIndex.ConvertToDataOffset(leafRecordVBN);
            int         insertIndex           = CollationHelper.FindIndexForSortedInsert(leafRecord.IndexEntries, fileNameRecordBytes, CollationRule.Filename);
            int         insertOffset          = leafRecord.GetEntryOffset(volume.BytesPerIndexRecord, insertIndex);

            AttributeRecord rootDirIndexAllocation = volume.GetFileRecord(MasterFileTable.RootDirSegmentReference).GetAttributeRecord(AttributeType.IndexAllocation, IndexHelper.GetIndexName(AttributeType.FileName));
            IndexEntry      indexEntry             = new IndexEntry(fileRecordSegment.SegmentReference, fileNameRecord.GetBytes());

            volume.LogClient.WriteLogRecord(MasterFileTable.RootDirSegmentReference, rootDirIndexAllocation, indexAllocationOffset, volume.BytesPerIndexRecord, 0, insertOffset, NTFSLogOperation.AddIndexEntryToAllocationBuffer, indexEntry.GetBytes(), NTFSLogOperation.Noop, new byte[0], transactionID, false);

            volume.LogClient.WriteForgetTransactionRecord(transactionID, true);
            disk.ReleaseLock();
        }
Esempio n. 17
0
        private static void LoadRid(IndexRecord record)
        {
            int ridOffset;
            var ridAddress = new byte[8];

            if (record.IsIndexType(IndexTypes.Leaf))
            {
                ridOffset = record.SlotOffset + record.Page.Header.MinLen - 8;
            }
            else
            {
                ridOffset = record.SlotOffset + record.Page.Header.MinLen - 14;
            }

            Array.Copy(record.Page.PageData, ridOffset, ridAddress, 0, RowIdentifier.Size);

            record.Rid = new RowIdentifier(ridAddress);

            record.Mark("Rid", ridOffset, RowIdentifier.Size);
        }
Esempio n. 18
0
        private void GetPolygonOfArea_Polygon(List <Utils.Polygon> polygons, IndexRecord rec)
        {
            _shpFileStream.Position = rec.Offset + 8 + 36; //skip bounding box and shapetype
            int numberOfPolygons = GetInt32(_shpFileStream, true);
            int numberOfPoints   = GetInt32(_shpFileStream, true);

            int[] pointIndexFirstPointPerPolygon = new int[numberOfPolygons];
            for (int i = 0; i < numberOfPolygons; i++)
            {
                pointIndexFirstPointPerPolygon[i] = GetInt32(_shpFileStream, true);
            }
            for (int i = 0; i < numberOfPolygons; i++)
            {
                Utils.Polygon pg = new Utils.Polygon();
                int           pointCount;
                if (i < numberOfPolygons - 1)
                {
                    pointCount = pointIndexFirstPointPerPolygon[i + 1] - pointIndexFirstPointPerPolygon[i];
                }
                else
                {
                    pointCount = numberOfPoints - pointIndexFirstPointPerPolygon[i];
                }
                for (int p = 0; p < pointCount; p++)
                {
                    double x = GetDouble(_shpFileStream, true);
                    double y = GetDouble(_shpFileStream, true);
                    if (_coordType == CoordType.DutchGrid)
                    {
                        pg.AddLocation(Utils.Calculus.LocationFromRD(x, y));
                    }
                    else
                    {
                        pg.AddLocation(new Utils.Location(y, x));
                    }
                }
                polygons.Add(pg);
            }
        }
Esempio n. 19
0
        public IndexRecord CreateIndexRecord(int indexRecordOffset, int sizeOfInitialSheetRecords, int offsetDefaultColWidth)
        {
            IndexRecord result = new IndexRecord();

            result.FirstRow               = firstrow;
            result.LastRowAdd1            = lastrow + 1;
            result.PosOfDefColWidthRecord = offsetDefaultColWidth;
            // Calculate the size of the records from the end of the BOF
            // and up to the RowRecordsAggregate...

            // Add the references to the DBCells in the IndexRecord (one for each block)
            // Note: The offsets are relative to the Workbook BOF. Assume that this is
            // 0 for now.....

            int blockCount = RowBlockCount;
            // Calculate the size of this IndexRecord
            int indexRecSize = IndexRecord.GetRecordSizeForBlockCount(blockCount);

            int currentOffset = indexRecordOffset + indexRecSize + sizeOfInitialSheetRecords;

            for (int block = 0; block < blockCount; block++)
            {
                // each row-block has a DBCELL record.
                // The offset of each DBCELL record needs to be updated in the INDEX record

                // account for row records in this row-block
                currentOffset += GetRowBlockSize(block);
                // account for cell value records after those
                currentOffset += _valuesAgg.GetRowCellBlockSize(
                    GetStartRowNumberForBlock(block), GetEndRowNumberForBlock(block));

                // currentOffset is now the location of the DBCELL record for this row-block
                result.AddDbcell(currentOffset);
                // Add space required to write the DBCELL record (whose reference was just added).
                currentOffset += (8 + (GetRowCountForBlock(block) * 2));
            }
            return(result);
        }
Esempio n. 20
0
        private static void LoadNullBitmap(IndexRecord record)
        {
            record.NullBitmapSize = (short)((record.Structure.Columns.Count - 1) / 8 + 1);

            var columnCountPosition = record.SlotOffset + record.Page.Header.MinLen;

            record.ColumnCount = BitConverter.ToInt16(record.Page.PageData, columnCountPosition);

            record.Mark("ColumnCount", columnCountPosition, sizeof(short));

            var nullBitmapBytes = new byte[record.NullBitmapSize];

            var nullBitmapPosition = record.SlotOffset + record.Page.Header.MinLen + sizeof(short);

            Array.Copy(record.Page.PageData,
                       nullBitmapPosition,
                       nullBitmapBytes,
                       0,
                       record.NullBitmapSize);

            record.NullBitmap = new BitArray(nullBitmapBytes);

            record.Mark("NullBitmapDescription", nullBitmapPosition, record.NullBitmapSize);
        }
Esempio n. 21
0
        private void GetPolygonOfArea(List <Framework.Data.Polygon> polygons, IndexRecord rec)
        {
            switch (rec.ShapeType)
            {
            case ShapeType.Polygon:
                GetPolygonOfArea_Polygon(polygons, rec);
                break;

            case ShapeType.PolygonM:
                GetPolygonOfArea_PolygonM(polygons, rec);
                break;

            case ShapeType.PolygonZ:
                GetPolygonOfArea_PolygonZ(polygons, rec);
                break;

            case ShapeType.MultiPatch:
                GetPolygonOfArea_MultiPatch(polygons, rec);
                break;

            default:
                break;
            }
        }
Esempio n. 22
0
        /**
         * Writes out this sheet.  First writes out the standard sheet
         * information then writes out each row in turn.
         * Once all the rows have been written out, it retrospectively adjusts
         * the offset references in the file
         *
         * @exception IOException
         */
        public void write()
        {
            Assert.verify(rows != null);

            // This worksheet consists of just one chart, so write it and return
            if (chartOnly)
                {
                drawingWriter.write(outputFile);
                return;
                }

            BOFRecord bof = new BOFRecord(BOFRecord.sheet);
            outputFile.write(bof);

            // Compute the number of blocks of 32 rows that will be needed
            int numBlocks = numRows / 32;
            if (numRows - numBlocks * 32 != 0)
                numBlocks++;

            int indexPos = outputFile.getPos();

            // Write the index record out now in order to serve as a place holder
            // The bof passed in is the bof of the workbook, not this sheet
            IndexRecord indexRecord = new IndexRecord(0, numRows, numBlocks);
            outputFile.write(indexRecord);

            if (settings.getAutomaticFormulaCalculation())
                {
                CalcModeRecord cmr = new CalcModeRecord(CalcModeRecord.automatic);
                outputFile.write(cmr);
                }
            else
                {
                CalcModeRecord cmr = new CalcModeRecord(CalcModeRecord.manual);
                outputFile.write(cmr);
                }

            CalcCountRecord ccr = new CalcCountRecord(0x64);
            outputFile.write(ccr);

            RefModeRecord rmr = new RefModeRecord();
            outputFile.write(rmr);

            IterationRecord itr = new IterationRecord(false);
            outputFile.write(itr);

            DeltaRecord dtr = new DeltaRecord(0.001);
            outputFile.write(dtr);

            SaveRecalcRecord srr = new SaveRecalcRecord(settings.getRecalculateFormulasBeforeSave());
            outputFile.write(srr);

            PrintHeadersRecord phr = new PrintHeadersRecord(settings.getPrintHeaders());
            outputFile.write(phr);

            PrintGridLinesRecord pglr = new PrintGridLinesRecord(settings.getPrintGridLines());
            outputFile.write(pglr);

            GridSetRecord gsr = new GridSetRecord(true);
            outputFile.write(gsr);

            GuttersRecord gutr = new GuttersRecord();
            gutr.setMaxColumnOutline(maxColumnOutlineLevel + 1);
            gutr.setMaxRowOutline(maxRowOutlineLevel + 1);

            outputFile.write(gutr);

            DefaultRowHeightRecord drhr = new DefaultRowHeightRecord
             (settings.getDefaultRowHeight(),
              settings.getDefaultRowHeight() !=
                        SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT);
            outputFile.write(drhr);

            if (maxRowOutlineLevel > 0)
                workspaceOptions.setRowOutlines(true);

            if (maxColumnOutlineLevel > 0)
                workspaceOptions.setColumnOutlines(true);

            workspaceOptions.setFitToPages(settings.getFitToPages());
            outputFile.write(workspaceOptions);

            if (rowBreaks.Count > 0)
                {
                int[] rb = new int[rowBreaks.Count];
                for (int i = 0; i < rb.Length; i++)
                    rb[i] = (int)rowBreaks[i];

                HorizontalPageBreaksRecord hpbr = new HorizontalPageBreaksRecord(rb);
                outputFile.write(hpbr);
                }

            if (columnBreaks.Count > 0)
                {
                int[] rb = new int[columnBreaks.Count];

                for (int i = 0; i < rb.Length; i++)
                    rb[i] = (int)columnBreaks[i];

                VerticalPageBreaksRecord hpbr = new VerticalPageBreaksRecord(rb);
                outputFile.write(hpbr);
                }

            HeaderRecord header = new HeaderRecord(settings.getHeader().ToString());
            outputFile.write(header);

            FooterRecord footer = new FooterRecord(settings.getFooter().ToString());
            outputFile.write(footer);

            HorizontalCentreRecord hcr = new HorizontalCentreRecord(settings.isHorizontalCentre());
            outputFile.write(hcr);

            VerticalCentreRecord vcr = new VerticalCentreRecord(settings.isVerticalCentre());
            outputFile.write(vcr);

            // Write out the margins if they don't equal the default
            if (settings.getLeftMargin() != settings.getDefaultWidthMargin())
                {
                MarginRecord mr = new LeftMarginRecord(settings.getLeftMargin());
                outputFile.write(mr);
                }

            if (settings.getRightMargin() != settings.getDefaultWidthMargin())
                {
                MarginRecord mr = new RightMarginRecord(settings.getRightMargin());
                outputFile.write(mr);
                }

            if (settings.getTopMargin() != settings.getDefaultHeightMargin())
                {
                MarginRecord mr = new TopMarginRecord(settings.getTopMargin());
                outputFile.write(mr);
                }

            if (settings.getBottomMargin() != settings.getDefaultHeightMargin())
                {
                MarginRecord mr = new BottomMarginRecord(settings.getBottomMargin());
                outputFile.write(mr);
                }

            if (plsRecord != null)
                outputFile.write(plsRecord);

            SetupRecord setup = new SetupRecord(settings);
            outputFile.write(setup);

            if (settings.isProtected())
                {
                ProtectRecord pr = new ProtectRecord(settings.isProtected());
                outputFile.write(pr);

                ScenarioProtectRecord spr = new ScenarioProtectRecord(settings.isProtected());
                outputFile.write(spr);

                ObjectProtectRecord opr = new ObjectProtectRecord(settings.isProtected());
                outputFile.write(opr);

                if (settings.getPassword() != null)
                    {
                    PasswordRecord pw = new PasswordRecord(settings.getPassword());
                    outputFile.write(pw);
                    }
                else if (settings.getPasswordHash() != 0)
                    {
                    PasswordRecord pw = new PasswordRecord(settings.getPasswordHash());
                    outputFile.write(pw);
                    }
                }

            indexRecord.setDataStartPosition(outputFile.getPos());
            DefaultColumnWidth dcw = new DefaultColumnWidth(settings.getDefaultColumnWidth());
            outputFile.write(dcw);

            // Get a handle to the normal styles
            WritableCellFormat normalStyle = sheet.getWorkbook().getStyles().getNormalStyle();
            WritableCellFormat defaultDateFormat = sheet.getWorkbook().getStyles().getDefaultDateFormat();

            // Write out all the column formats
            foreach (ColumnInfoRecord cir in columnFormats)
                {
                // Writing out the column info with index 0x100 causes excel to crash
                if (cir.getColumn() < 0x100)
                    outputFile.write(cir);

                XFRecord xfr = cir.getCellFormat();

                if (xfr != normalStyle && cir.getColumn() < 0x100)
                    {
                    // Make this the format for every cell in the column
                    Cell[] cells = getColumn(cir.getColumn());

                    for (int i = 0; i < cells.Length; i++)
                        {
                        if (cells[i] != null &&
                            (cells[i].getCellFormat() == normalStyle ||
                             cells[i].getCellFormat() == defaultDateFormat))
                            {
                            // The cell has no overriding format specified, so
                            // set it to the column default
                            ((WritableCell)cells[i]).setCellFormat(xfr);
                            }
                        }
                    }
                }

            // Write out the auto filter
            if (autoFilter != null)
                autoFilter.write(outputFile);

            DimensionRecord dr = new DimensionRecord(numRows, numCols);
            outputFile.write(dr);

            // Write out all the rows, in blocks of 32
            for (int block = 0; block < numBlocks; block++)
                {
                DBCellRecord dbcell = new DBCellRecord(outputFile.getPos());

                int blockRows = System.Math.Min(32, numRows - block * 32);
                bool firstRow = true;

                // First write out all the row records
                for (int i = block * 32; i < block * 32 + blockRows; i++)
                    {
                    if (rows[i] != null)
                        {
                        rows[i].write(outputFile);
                        if (firstRow)
                            {
                            dbcell.setCellOffset(outputFile.getPos());
                            firstRow = false;
                            }
                        }
                    }

                // Now write out all the cells
                for (int i = block * 32; i < block * 32 + blockRows; i++)
                    {
                    if (rows[i] != null)
                        {
                        dbcell.addCellRowPosition(outputFile.getPos());
                        rows[i].writeCells(outputFile);
                        }
                    }

                // Now set the current file position in the index record
                indexRecord.addBlockPosition(outputFile.getPos());

                // Set the position of the file pointer and write out the DBCell
                // record
                dbcell.setPosition(outputFile.getPos());
                outputFile.write(dbcell);
                }

            // Do the drawings and charts if enabled
            if (!workbookSettings.getDrawingsDisabled())
                drawingWriter.write(outputFile);

            Window2Record w2r = new Window2Record(settings);
            outputFile.write(w2r);

            // Handle the frozen panes
            if (settings.getHorizontalFreeze() != 0 || settings.getVerticalFreeze() != 0)
                {
                PaneRecord pr = new PaneRecord(settings.getHorizontalFreeze(),settings.getVerticalFreeze());
                outputFile.write(pr);

                // Handle the selection record.  First, there will always be a top left
                SelectionRecord sr = new SelectionRecord(SelectionRecord.upperLeft, 0, 0);
                outputFile.write(sr);

                // Top right
                if (settings.getHorizontalFreeze() != 0)
                    {
                    sr = new SelectionRecord(SelectionRecord.upperRight, settings.getHorizontalFreeze(), 0);
                    outputFile.write(sr);
                    }

                // Bottom left
                if (settings.getVerticalFreeze() != 0)
                    {
                    sr = new SelectionRecord(SelectionRecord.lowerLeft, 0, settings.getVerticalFreeze());
                    outputFile.write(sr);
                    }

                // Bottom right
                if (settings.getHorizontalFreeze() != 0 &&
                    settings.getVerticalFreeze() != 0)
                    {
                    sr = new SelectionRecord(SelectionRecord.lowerRight,settings.getHorizontalFreeze(),settings.getVerticalFreeze());
                    outputFile.write(sr);
                    }

                Weird1Record w1r = new Weird1Record();
                outputFile.write(w1r);
                }
            else
                {
                // No frozen panes - just write out the selection record for the
                // whole sheet
                SelectionRecord sr = new SelectionRecord(SelectionRecord.upperLeft, 0, 0);
                outputFile.write(sr);
                }

            // Handle the zoom factor
            if (settings.getZoomFactor() != 100)
                {
                SCLRecord sclr = new SCLRecord(settings.getZoomFactor());
                outputFile.write(sclr);
                }

            // Now write out all the merged cells
            mergedCells.write(outputFile);

            // Write out all the hyperlinks
            foreach (WritableHyperlink hlr in hyperlinks)
                outputFile.write(hlr);

            if (buttonPropertySet != null)
                outputFile.write(buttonPropertySet);

            // Write out the data validations
            if (dataValidation != null || validatedCells.Count > 0)
                writeDataValidation();

            // Write out the conditional formats
            if (conditionalFormats != null && conditionalFormats.Count > 0)
                {
                foreach (ConditionalFormat cf in conditionalFormats)
                    cf.write(outputFile);
                }

            EOFRecord eof = new EOFRecord();
            outputFile.write(eof);

            // Now the various cross reference offsets have been calculated,
            // retrospectively set the values in the output file
            outputFile.setData(indexRecord.getData(), indexPos + 4);
        }
Esempio n. 23
0
        internal Worksheet(Workbook wb, BoundSheetRecord sheet, SortedList <long, Biff> records)
            : base(wb)
        {
            _name = sheet.Name;

            int idx = records.IndexOfKey((long)sheet.BofPos);

            _hyperlinks = new HyperLinkCollection(wb);

            for (int i = idx + 1; i < records.Count; ++i)
            {
                Biff biff = records.Values[i];
                if (biff is HyperLinkRecord)
                {
                    _hyperlinks.Add((HyperLinkRecord)biff);
                }
                else if (biff is EofRecord)
                {
                    break;
                }
            }

            BofRecord bof = (BofRecord)records.Values[idx++];

            Biff seeker = records.Values[idx++];

            while (!(seeker is IndexRecord))
            {
                seeker = records.Values[idx++];
            }

            IndexRecord index = (IndexRecord)seeker;

            _rows = new RowCollection(wb);
            foreach (uint indexPos in index.Rows)
            {
                long         dbCellPos = indexPos;
                int          dbCellIdx = records.IndexOfKey(dbCellPos);
                DbCellRecord dbCell    = (DbCellRecord)records[dbCellPos];

                if (dbCell.RowOffset > 0)
                {
                    long rowPos   = dbCellPos - dbCell.RowOffset;
                    int  recIndex = records.IndexOfKey(rowPos);
                    Debug.Assert(recIndex != -1);

                    Biff record = records.Values[recIndex++];
                    while (record is RowRecord)
                    {
                        RowRecord row        = (RowRecord)record;
                        Row       currentRow = new Row(Workbook, row);
                        _rows.Add(row.RowNumber, currentRow);

                        record = records.Values[recIndex++];
                    }

                    while (recIndex <= dbCellIdx)
                    {
                        if (!(record is CellRecord))
                        {
                            record = records.Values[recIndex++];
                            continue;
                        }

                        CellRecord thecell    = (CellRecord)record;
                        Row        currentRow = _rows[thecell.Row];

                        if (thecell is SingleColCellRecord)
                        {
                            SingleColCellRecord cell = (SingleColCellRecord)thecell;
                            object val = cell.Value;

                            Cell newCell = new Cell(Workbook, val);
                            if (cell is RowColXfCellRecord)
                            {
                                RowColXfCellRecord xfCell = (RowColXfCellRecord)cell;

                                Style style = Workbook.Styles[xfCell.Xf];
                                Debug.Assert(style != null);
                                newCell.Style = style;
                            }
                            currentRow.Cells.Add((byte)cell.Col, newCell);
                        }
                        else
                        {
                            MultipleColCellRecord cells = (MultipleColCellRecord)thecell;
                            for (ushort i = cells.FirstCol; i <= cells.LastCol; ++i)
                            {
                                object val = cells.GetValue(i);
                                if (val != null)
                                {
                                    Cell newCell = null;
                                    if (val is RkRec)
                                    {
                                        RkRec rk = (RkRec)val;

                                        newCell = new Cell(Workbook, rk.Value);
                                        Style style = Workbook.Styles[rk.Xf];
                                        Debug.Assert(style != null);
                                        newCell.Style = style;
                                    }
                                    else
                                    {
                                        newCell = new Cell(Workbook, val);
                                    }

                                    currentRow.Cells.Add((byte)i, newCell);
                                }
                            }
                        }

                        record = records.Values[recIndex++];
                    }
                }
            }
        }
Esempio n. 24
0
 private void GetPolygonOfArea_PolygonZ(List <Framework.Data.Polygon> polygons, IndexRecord rec)
 {
     //extra Z information is after the Polygon info, so..
     GetPolygonOfArea_Polygon(polygons, rec);
 }
Esempio n. 25
0
        public bool Initialize(string dbfNameFieldName, CoordType coordType, Framework.Data.AreaType areaType, string namePrefix, string dbfEncoding)
        {
            bool result = false;

            try
            {
                _coordType     = coordType;
                _shpFileStream = File.OpenRead(_shpFilename);
                _areaType      = areaType;
                _dbfEncoding   = dbfEncoding;
                int FileCode = GetInt32(_shpFileStream, false);
                if (FileCode == 9994)
                {
                    _shpFileStream.Position = 24;
                    _shpFileSize            = GetInt32(_shpFileStream, false);
                    _shpVersion             = GetInt32(_shpFileStream, true);
                    _shpShapeType           = (ShapeType)GetInt32(_shpFileStream, true);
                    _shpXMin = GetDouble(_shpFileStream, true);
                    _shpYMin = GetDouble(_shpFileStream, true);
                    _shpXMax = GetDouble(_shpFileStream, true);
                    _shpYMax = GetDouble(_shpFileStream, true);

                    using (FileStream fs = File.OpenRead(string.Format("{0}shx", _shpFilename.Substring(0, _shpFilename.Length - 3))))
                    {
                        FileCode = GetInt32(fs, false);
                        if (FileCode == 9994)
                        {
                            fs.Position = 24;
                            int shxFileSize = GetInt32(fs, false);
                            int shxVersion  = GetInt32(fs, true);

                            int intRecordCount = ((shxFileSize * 2) - 100) / 8;
                            fs.Position   = 100;
                            _indexRecords = new IndexRecord[intRecordCount];
                            for (int i = 0; i < intRecordCount; i++)
                            {
                                _indexRecords[i] = new IndexRecord()
                                {
                                    Offset = GetInt32(fs, false) * 2, ContentLength = GetInt32(fs, false) * 2
                                };
                            }
                            for (int i = 0; i < intRecordCount; i++)
                            {
                                IndexRecord ir = _indexRecords[i];
                                _shpFileStream.Position = ir.Offset + 8;
                                ir.ShapeType            = (ShapeType)GetInt32(_shpFileStream, true);
                                if (ir.ShapeType == ShapeType.NullShape)
                                {
                                    ir.ShapeType = _shpShapeType;
                                }
                                switch (ir.ShapeType)
                                {
                                case ShapeType.Polygon:
                                case ShapeType.PolygonZ:
                                case ShapeType.PolygonM:
                                case ShapeType.MultiPatch:
                                    ir.XMin   = GetDouble(_shpFileStream, true);
                                    ir.YMin   = GetDouble(_shpFileStream, true);
                                    ir.XMax   = GetDouble(_shpFileStream, true);
                                    ir.YMax   = GetDouble(_shpFileStream, true);
                                    ir.Ignore = false;
                                    break;

                                default:
                                    ir.Ignore = true;
                                    break;
                                }
                            }
                            using (DotNetDBF.DBFReader dbf = new DotNetDBF.DBFReader(string.Format("{0}dbf", _shpFilename.Substring(0, _shpFilename.Length - 3)), _dbfEncoding))
                            {
                                var fields = dbf.Fields;
                                dbf.SetSelectFields(new string[] { dbfNameFieldName });
                                var rec   = dbf.NextRecord();
                                int index = 0;
                                while (rec != null)
                                {
                                    if (!_indexRecords[index].Ignore)
                                    {
                                        _indexRecords[index].Name = string.Format("{0}{1}", namePrefix, rec[0]);
                                    }
                                    else
                                    {
                                        _indexRecords[index].Name = null;
                                    }
                                    index++;
                                    if (index < _indexRecords.Length)
                                    {
                                        rec = dbf.NextRecord();
                                    }
                                    else
                                    {
                                        rec = null;
                                    }
                                }
                            }

                            // all ok, check if we need to convert the coords to WGS84, the internal coord system
                            if (_coordType == CoordType.DutchGrid)
                            {
                                Utils.Calculus.LatLonFromRD(_shpXMin, _shpYMin, out _shpYMin, out _shpXMin);
                                Utils.Calculus.LatLonFromRD(_shpXMax, _shpYMax, out _shpYMax, out _shpXMax);

                                double lat;
                                double lon;
                                for (int i = 0; i < intRecordCount; i++)
                                {
                                    IndexRecord ir = _indexRecords[i];
                                    Utils.Calculus.LatLonFromRD(ir.XMin, ir.YMin, out lat, out lon);
                                    ir.YMin = lat;
                                    ir.XMin = lon;
                                    Utils.Calculus.LatLonFromRD(ir.XMax, ir.YMax, out lat, out lon);
                                    ir.YMax = lat;
                                    ir.XMax = lon;
                                }
                            }

                            var areaNames = (from a in _indexRecords select a.Name).Distinct();
                            foreach (var name in areaNames)
                            {
                                var records = from r in _indexRecords where r.Name == name select r;
                                Framework.Data.AreaInfo ai = new Framework.Data.AreaInfo();
                                ai.ID       = ai;
                                ai.Level    = areaType;
                                ai.MaxLat   = records.Max(x => x.YMax);
                                ai.MaxLon   = records.Max(x => x.XMax);
                                ai.MinLat   = records.Min(x => x.YMin);
                                ai.MinLon   = records.Min(x => x.XMin);
                                ai.Name     = name;
                                ai.ParentID = null; //not supported
                                _areaInfos.Add(ai);
                            }

                            result = true;
                        }
                    }
                }
            }
            catch
            {
            }
            return(result);
        }
Esempio n. 26
0
        private void GetPolygonOfArea_MultiPatch(List<Framework.Data.Polygon> polygons, IndexRecord rec)
        {
            //NOTE: at this point we ignore the type (outer ring, inner ring
            //this is not correct and should be implemented correctly
            //suggestion: Add a property Exclude to Framework.Data.Polygon

            _shpFileStream.Position = rec.Offset + 8 + 36; //skip bounding box and shapetype
            int numberOfPolygons = GetInt32(_shpFileStream, true);
            int numberOfPoints = GetInt32(_shpFileStream, true);
            int[] pointIndexFirstPointPerPolygon = new int[numberOfPolygons];
            int[] partsTypePerPolygon = new int[numberOfPolygons];
            for (int i = 0; i < numberOfPolygons; i++)
            {
                pointIndexFirstPointPerPolygon[i] = GetInt32(_shpFileStream, true);
            }
            for (int i = 0; i < numberOfPolygons; i++)
            {
                partsTypePerPolygon[i] = GetInt32(_shpFileStream, true);
            }
            for (int i = 0; i < numberOfPolygons; i++)
            {
                Framework.Data.Polygon pg = new Framework.Data.Polygon();
                int pointCount;
                if (i < numberOfPolygons - 1)
                {
                    pointCount = pointIndexFirstPointPerPolygon[i + 1] - pointIndexFirstPointPerPolygon[i];
                }
                else
                {
                    pointCount = numberOfPoints - pointIndexFirstPointPerPolygon[i];
                }
                for (int p = 0; p < pointCount; p++)
                {
                    double x = GetDouble(_shpFileStream, true);
                    double y = GetDouble(_shpFileStream, true);
                    if (_coordType == CoordType.DutchGrid)
                    {
                        pg.AddLocation(Utils.Calculus.LocationFromRD(x, y));
                    }
                    else
                    {
                        pg.AddLocation(new Framework.Data.Location(y, x));
                    }
                }
                polygons.Add(pg);
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Loads a record
        /// </summary>
        /// <param name="offset">The offset.</param>
        private void LoadRecord(ushort offset)
        {
            Record record = null;

            switch (Page.Header.PageType)
            {
            case PageType.Data:

                Structure tableStructure = new TableStructure(Page.Header.AllocationUnitId, Page.Database);

                if (Page.CompressionType == CompressionType.None)
                {
                    record = new DataRecord(Page, offset, tableStructure);
                }
                else
                {
                    record = new CompressedDataRecord(Page, offset, tableStructure);
                }

                allocationViewer.Visible = false;
                markerKeyTable.Visible   = true;
                break;

            case PageType.Index:

                Structure indexStructure = new IndexStructure(Page.Header.AllocationUnitId, Page.Database);

                record = new IndexRecord(Page, offset, indexStructure);

                allocationViewer.Visible = false;
                markerKeyTable.Visible   = true;
                break;

            case PageType.Iam:
            case PageType.Gam:
            case PageType.Sgam:
            case PageType.Bcm:
            case PageType.Dcm:

                allocationViewer.SetAllocationPage(Page.Header.PageAddress,
                                                   Page.Database.Name,
                                                   ConnectionString,
                                                   (Page.Header.PageType == PageType.Iam));

                markerKeyTable.Visible   = false;
                allocationViewer.Visible = true;
                break;

            case PageType.Pfs:

                allocationViewer.SetPfsPage(Page.Header.PageAddress,
                                            Page.Database.Name,
                                            ConnectionString);

                markerKeyTable.Visible   = false;
                allocationViewer.Visible = true;
                break;

            case PageType.Lob3:
            case PageType.Lob4:

                record = new BlobRecord(Page, offset);

                allocationViewer.Visible = false;
                markerKeyTable.Visible   = true;
                break;
            }

            if (record != null)
            {
                var markers = MarkerBuilder.BuildMarkers((Markable)record);

                hexViewer.AddMarkers(markers);

                markerKeyTable.SetMarkers(markers);

                hexViewer.ScrollToOffset(offset);

                offsetTableToolStripTextBox.Text = string.Format("{0:0000}", offset);
            }
        }
Esempio n. 28
0
 private void GetPolygonOfArea_Polygon(List<Framework.Data.Polygon> polygons, IndexRecord rec)
 {
     _shpFileStream.Position = rec.Offset + 8 + 36; //skip bounding box and shapetype
     int numberOfPolygons = GetInt32(_shpFileStream, true);
     int numberOfPoints = GetInt32(_shpFileStream, true);
     int[] pointIndexFirstPointPerPolygon = new int[numberOfPolygons];
     for (int i = 0; i < numberOfPolygons; i++)
     {
         pointIndexFirstPointPerPolygon[i] = GetInt32(_shpFileStream, true);
     }
     for (int i = 0; i < numberOfPolygons; i++)
     {
         Framework.Data.Polygon pg = new Framework.Data.Polygon();
         int pointCount;
         if (i < numberOfPolygons - 1)
         {
             pointCount = pointIndexFirstPointPerPolygon[i + 1] - pointIndexFirstPointPerPolygon[i];
         }
         else
         {
             pointCount = numberOfPoints - pointIndexFirstPointPerPolygon[i];
         }
         for (int p = 0; p < pointCount; p++)
         {
             double x = GetDouble(_shpFileStream, true);
             double y = GetDouble(_shpFileStream, true);
             if (_coordType == CoordType.DutchGrid)
             {
                 pg.AddLocation(Utils.Calculus.LocationFromRD(x,y));
             }
             else
             {
                 pg.AddLocation(new Framework.Data.Location(y, x));
             }
         }
         polygons.Add(pg);
     }
 }
Esempio n. 29
0
        private Maybe <DataRecord> FindDataRecord(
            NID[] nodePath,
            HID nodeId,
            TKey keyToFind,
            int bthKeySize,
            int bthDataSize,
            int currentDepth)
        {
            var node =
                heapOnNodeReader.GetHeapItem(nodePath, nodeId);

            if (currentDepth > 0)
            {
                var items = node.Slice(bthKeySize + 4);

                var previousIndexRecord = (IndexRecord)null;

                for (var i = 0; i < items.Length; i++)
                {
                    var key = items[i].Take(bthKeySize);
                    var hid = HID.OfValue(items[i].Take(bthKeySize, 4));

                    if (keyToFind.CompareTo(keyDecoder.Decode(key)) < 0)
                    {
                        return
                            (FindDataRecord(
                                 nodePath,
                                 nodeId,
                                 keyToFind,
                                 bthKeySize,
                                 bthDataSize,
                                 currentDepth - 1));
                    }

                    previousIndexRecord = new IndexRecord(key, hid);
                }

                if (keyToFind.CompareTo(keyDecoder.Decode(previousIndexRecord.Key)) > 0)
                {
                    return
                        (FindDataRecord(
                             nodePath,
                             nodeId,
                             keyToFind,
                             bthKeySize,
                             bthDataSize,
                             currentDepth - 1));
                }
            }
            else
            {
                var items = node.Slice(bthKeySize + bthDataSize);

                for (var i = 0; i < items.Length; i++)
                {
                    var key  = items[i].Take(bthKeySize);
                    var data = items[i].Take(bthKeySize, bthDataSize);

                    var decodedKey = keyDecoder.Decode(key);

                    if (keyToFind.CompareTo(decodedKey) == 0)
                    {
                        return(Maybe <DataRecord> .OfValue(new DataRecord(key, data)));
                    }
                }
            }

            return(Maybe <DataRecord> .NoValue());
        }
Esempio n. 30
0
        public bool Initialize(string dbfNameFieldName, CoordType coordType, Framework.Data.AreaType areaType, string namePrefix)
        {
            bool result = false;
            try
            {
                _coordType = coordType;
                _shpFileStream = File.OpenRead(_shpFilename);
                _areaType = areaType;
                int FileCode = GetInt32(_shpFileStream, false);
                if (FileCode==9994)
                {
                    _shpFileStream.Position = 24;
                    _shpFileSize = GetInt32(_shpFileStream, false);
                    _shpVersion = GetInt32(_shpFileStream, true);
                    _shpShapeType = (ShapeType)GetInt32(_shpFileStream, true);
                    _shpXMin = GetDouble(_shpFileStream, true);
                    _shpYMin = GetDouble(_shpFileStream, true);
                    _shpXMax = GetDouble(_shpFileStream, true);
                    _shpYMax = GetDouble(_shpFileStream, true);

                    using (FileStream fs = File.OpenRead(string.Format("{0}shx", _shpFilename.Substring(0, _shpFilename.Length - 3))))
                    {
                        FileCode = GetInt32(fs, false);
                        if (FileCode == 9994)
                        {
                            fs.Position = 24;
                            int shxFileSize = GetInt32(fs, false);
                            int shxVersion = GetInt32(fs, true);

                            int intRecordCount = ((shxFileSize * 2) - 100) / 8;
                            fs.Position = 100;
                            _indexRecords = new IndexRecord[intRecordCount];
                            for (int i = 0; i < intRecordCount; i++)
                            {
                                _indexRecords[i] = new IndexRecord() { Offset = GetInt32(fs, false) * 2, ContentLength = GetInt32(fs, false) * 2 };
                            }
                            for (int i = 0; i < intRecordCount; i++)
                            {
                                IndexRecord ir = _indexRecords[i];
                                _shpFileStream.Position = ir.Offset + 8;
                                ir.ShapeType = (ShapeType)GetInt32(_shpFileStream, true);
                                if (ir.ShapeType == ShapeType.NullShape)
                                {
                                    ir.ShapeType = _shpShapeType;
                                }
                                switch (ir.ShapeType)
                                {
                                    case ShapeType.Polygon:
                                    case ShapeType.PolygonZ:
                                    case ShapeType.PolygonM:
                                    case ShapeType.MultiPatch:
                                        ir.XMin = GetDouble(_shpFileStream, true);
                                        ir.YMin = GetDouble(_shpFileStream, true);
                                        ir.XMax = GetDouble(_shpFileStream, true);
                                        ir.YMax = GetDouble(_shpFileStream, true);
                                        ir.Ignore = false;
                                        break;
                                    default:
                                        ir.Ignore = true;
                                        break;
                                }
                            }
                            using (DotNetDBF.DBFReader dbf = new DotNetDBF.DBFReader(string.Format("{0}dbf", _shpFilename.Substring(0, _shpFilename.Length - 3))))
                            {
                                var fields = dbf.Fields;
                                dbf.SetSelectFields(new string[]{dbfNameFieldName});
                                var rec = dbf.NextRecord();
                                int index = 0;
                                while (rec != null)
                                {
                                    if (!_indexRecords[index].Ignore)
                                    {
                                        _indexRecords[index].Name = string.Format("{0}{1}",namePrefix,rec[0]);
                                        if (_indexRecords[index].Name == "Fryslân" || _indexRecords[index].Name == "Frysl�n")
                                        {
                                            _indexRecords[index].Name = "Friesland";
                                        }
                                        else
                                        {
                                            _indexRecords[index].Name = _indexRecords[index].Name.Replace("�", "â");
                                        }
                                    }
                                    else
                                    {
                                        _indexRecords[index].Name = null;
                                    }
                                    index++;
                                    if (index < _indexRecords.Length)
                                    {
                                        rec = dbf.NextRecord();
                                    }
                                    else
                                    {
                                        rec = null;
                                    }
                                }
                            }

                            // all ok, check if we need to convert the coords to WGS84, the internal coord system
                            if (_coordType == CoordType.DutchGrid)
                            {
                                Utils.Calculus.LatLonFromRD(_shpXMin, _shpYMin, out _shpYMin, out _shpXMin);
                                Utils.Calculus.LatLonFromRD(_shpXMax, _shpYMax, out _shpYMax, out _shpXMax);

                                double lat;
                                double lon;
                                for (int i = 0; i < intRecordCount; i++)
                                {
                                    IndexRecord ir = _indexRecords[i];
                                    Utils.Calculus.LatLonFromRD(ir.XMin, ir.YMin, out lat, out lon);
                                    ir.YMin = lat;
                                    ir.XMin = lon;
                                    Utils.Calculus.LatLonFromRD(ir.XMax, ir.YMax, out lat, out lon);
                                    ir.YMax = lat;
                                    ir.XMax = lon;
                                }
                            }

                            var areaNames = (from a in _indexRecords select a.Name).Distinct();
                            foreach (var name in areaNames)
                            {
                                var records = from r in _indexRecords where r.Name == name select r;
                                Framework.Data.AreaInfo ai = new Framework.Data.AreaInfo();
                                ai.ID = ai;
                                ai.Level = areaType;
                                ai.MaxLat = records.Max(x => x.YMax);
                                ai.MaxLon = records.Max(x => x.XMax);
                                ai.MinLat = records.Min(x => x.YMin);
                                ai.MinLon = records.Min(x => x.XMin);
                                ai.Name = name;
                                ai.ParentID = null; //not supported
                                _areaInfos.Add(ai);
                            }

                            result = true;
                        }
                    }
                }
            }
            catch
            {
            }
            return result;
        }
Esempio n. 31
0
        private Biff GetCorrectRecord(GenericBiff record, Stream stream, SstRecord sst)
        {
            Biff ret = record;

            switch (record.Id)
            {
            case (ushort)RecordType.Bof:
                BofRecord bof = new BofRecord(record);
                if (bof.Version < 0x0600)
                {
                    throw new Exception("Versions below Excel 97/2000 are currently not supported.");
                }

                ret = bof;
                break;

            case (ushort)RecordType.Boundsheet:
                ret = new BoundSheetRecord(record);
                break;

            case (ushort)RecordType.Index:
                ret = new IndexRecord(record);
                break;

            case (ushort)RecordType.DbCell:
                ret = new DbCellRecord(record);
                break;

            case (ushort)RecordType.Row:
                ret = new RowRecord(record);
                break;

            case (ushort)RecordType.Continue:
                ret = new ContinueRecord(record);
                break;

            case (ushort)RecordType.Blank:
                ret = new BlankRecord(record);
                break;

            case (ushort)RecordType.BoolErr:
                ret = new BoolErrRecord(record);
                break;

            case (ushort)RecordType.Formula:
                ret = new FormulaRecord(record, stream);
                break;

            case (ushort)RecordType.Label:
                ret = new LabelRecord(record);
                break;

            case (ushort)RecordType.LabelSst:
                ret = new LabelSstRecord(record, sst);
                break;

            case (ushort)RecordType.MulBlank:
                ret = new MulBlankRecord(record);
                break;

            case (ushort)RecordType.MulRk:
                ret = new MulRkRecord(record);
                break;

            case (ushort)RecordType.String:
                ret = new StringValueRecord(record);
                break;

            case (ushort)RecordType.Xf:
                ret = new XfRecord(record);
                break;

            case (ushort)RecordType.Rk:
                ret = new RkRecord(record);
                break;

            case (ushort)RecordType.Number:
                ret = new NumberRecord(record);
                break;

            case (ushort)RecordType.Array:
                ret = new ArrayRecord(record);
                break;

            case (ushort)RecordType.ShrFmla:
                ret = new SharedFormulaRecord(record);
                break;

            case (ushort)RecordType.Table:
                ret = new TableRecord(record);
                break;

            case (ushort)RecordType.Sst:
                ret = new SstRecord(record, stream);
                break;

            case (ushort)RecordType.Eof:
                ret = new EofRecord(record);
                break;

            case (ushort)RecordType.Font:
                ret = new FontRecord(record);
                break;

            case (ushort)RecordType.Format:
                ret = new Net.SourceForge.Koogra.Excel.Records.FormatRecord(record);
                break;

            case (ushort)RecordType.Palette:
                ret = new PaletteRecord(record);
                break;

            case (ushort)RecordType.Hyperlink:
                ret = new HyperLinkRecord(record);
                break;
            }

            return(ret);
        }
Esempio n. 32
0
        private static void LoadColumnValues(IndexRecord record)
        {
            RecordField field;

            var columnValues = new List <RecordField>();

            var index = 0;

            foreach (IndexColumn indexCol in (record.Structure as IndexStructure).Columns)
            {
                var processKeyColumn      = !indexCol.Key || (record.IncludeKey && indexCol.Key);
                var processIncludesColumn = !indexCol.IncludedColumn || (indexCol.IncludedColumn && record.IsIndexType(IndexTypes.Leaf));

                if (processKeyColumn & processIncludesColumn)
                {
                    field = new RecordField(indexCol);

                    var    length        = 0;
                    var    offset        = 0;
                    byte[] data          = null;
                    var    variableIndex = 0;

                    if (indexCol.LeafOffset >= 0)
                    {
                        // Fixed length field
                        offset = indexCol.LeafOffset;
                        length = indexCol.DataLength;
                        data   = new byte[length];

                        Array.Copy(record.Page.PageData, indexCol.LeafOffset + record.SlotOffset, data, 0, length);
                    }
                    else if (record.HasVariableLengthColumns)
                    {
                        //Variable length field
                        variableIndex = (indexCol.LeafOffset * -1) - 1;

                        if (variableIndex == 0)
                        {
                            offset = record.VariableLengthDataOffset;
                        }
                        else
                        {
                            offset = record.ColOffsetArray[variableIndex - 1];
                        }

                        if (variableIndex >= record.ColOffsetArray.Length)
                        {
                            length = 0;
                        }
                        else
                        {
                            length = record.ColOffsetArray[variableIndex] - offset;
                        }

                        data = new byte[length];

                        Array.Copy(record.Page.PageData, offset + record.SlotOffset, data, 0, length);
                    }

                    field.Offset         = offset;
                    field.Length         = length;
                    field.Data           = data;
                    field.VariableOffset = variableIndex;

                    field.Mark("Value", record.SlotOffset + field.Offset, field.Length);


                    record.Mark("FieldsArray", field.Name, index);

                    index++;

                    columnValues.Add(field);
                }
            }

            record.Fields.AddRange(columnValues);
        }
Esempio n. 33
0
 private void GetPolygonOfArea_PolygonM(List <Utils.Polygon> polygons, IndexRecord rec)
 {
     //extra M information is after the Polygon info, so..
     GetPolygonOfArea_Polygon(polygons, rec);
 }
Esempio n. 34
0
 public virtual T Visit(IndexRecord record)
 {
     return(default(T));
 }
Esempio n. 35
0
 private void GetPolygonOfArea_PolygonZ(List<Framework.Data.Polygon> polygons, IndexRecord rec)
 {
     //extra Z information is after the Polygon info, so..
     GetPolygonOfArea_Polygon(polygons, rec);
 }
Esempio n. 36
0
 private void GetPolygonOfArea(List<Framework.Data.Polygon> polygons, IndexRecord rec)
 {
     switch (rec.ShapeType)
     {
         case ShapeType.Polygon:
             GetPolygonOfArea_Polygon(polygons, rec);
             break;
         case ShapeType.PolygonM:
             GetPolygonOfArea_PolygonM(polygons, rec);
             break;
         case ShapeType.PolygonZ:
             GetPolygonOfArea_PolygonZ(polygons, rec);
             break;
         case ShapeType.MultiPatch:
             GetPolygonOfArea_MultiPatch(polygons, rec);
             break;
         default:
             break;
     }
 }
Esempio n. 37
0
 private void GetPolygonOfArea_PolygonM(List<Core.Data.Polygon> polygons, IndexRecord rec)
 {
     //extra M information is after the Polygon info, so..
     GetPolygonOfArea_Polygon(polygons, rec);
 }