示例#1
0
文件: Program.cs 项目: wangn6/rep2
 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);
 }
示例#2
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);
 }
示例#3
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);
            }
        }
示例#4
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);
     }
 }
示例#5
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;
     }
 }
示例#6
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;
        }
示例#7
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);
 }
        /**
         * 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);
        }