public override int Upload(BinaryReader aReader, int aSlfFileId) { int _count = 0; foreach (Ja2Data.SlfFile.Record _file in this.FFiles) { try { aReader.BaseStream.Position = _file.Offset; SlfRecordHeader _recHeader = base.CreateSlfRecordHeader(_file); this.FHeaders.Add(_recHeader); SlfRecordJsd _newJsdRecord = this.LoadJsd(aReader.BaseStream); _newJsdRecord.SlfFileId = aSlfFileId; _newJsdRecord.SlfRecordHeader = _recHeader; FJsdRecords.Add(_newJsdRecord); this.AddRecordsToDataSet(); _count += this.SaveChanges(); } catch (Exception _exc) { string _excMess = String.Format("Uploading file {0} exception\n", _file.FileName); throw new Exception(_excMess, _exc); } } return(_count); }
private Ja2Data.SlfFile.Record DownloadJsdRecord(long aJsdRecordId) { Ja2DataEntities _context = new Ja2DataEntities(); SlfRecordJsd _jsdRec = _context.SlfRecordJsd.First(x => x.SlfRecordJsdId == aJsdRecordId); Ja2Data.SlfFile.Record _jsdFile = this.DownloadJsdRecord(_jsdRec); _context = null; return(_jsdFile); }
private SlfRecordJsd LoadJsd(Stream aInput) { SlfRecordJsd _jsdRecord = new SlfRecordJsd(); Ja2Data.JsdFile _jsdFile = Ja2Data.JsdFile.Load(aInput); this.FJsdFileIsHiDefinition = _jsdFile.IsHighDefenition; this.FProfileXSize = Ja2Data.JsdTile.GetProfileXSize(this.FJsdFileIsHiDefinition); this.FProfileYSize = Ja2Data.JsdTile.GetProfileYSize(this.FJsdFileIsHiDefinition); this.FJsdTileCell = new List <JsdTileCell>(this.FStrCount * FProfileXSize * FProfileYSize); _jsdRecord.ID = _jsdFile.FormatId; _jsdRecord.NumberOfImageTileLocsStored = _jsdFile.NumberOfImageTileLocsStored; _jsdRecord.NumberOfStructuresStored = _jsdFile.NumberOfStructuresStored; _jsdRecord.NumberOfStructuresAndOrImages = _jsdFile.NumberOfElements; _jsdRecord.StructureDataSize = _jsdFile.StructureDataSize; _jsdRecord.Unused = _jsdFile.Unused; _jsdRecord.UserId = this.FUserId; _jsdRecord.DateCreated = DateTime.Now; var _flags = this.FJsdFlags.Where(x => (x.Mask & (byte)_jsdFile.Flags) != 0); foreach (Flag _flag in _flags) { JsdRecordHeaderFlag _recFlag = new JsdRecordHeaderFlag(); _recFlag.FlagId = (byte)_flag.Id; _recFlag.SlfRecordJsd = _jsdRecord; this.FJsdHeaderFlags.Add(_recFlag); } if (_jsdFile.Auxilarity.Length > 0) { JsdAuxData _auxData = this.LoadJsdAux(_jsdFile.Auxilarity, _jsdFile.TileLocData); _auxData.SlfRecordJsd = _jsdRecord; this.FJsdAuxData.Add(_auxData); } if (_jsdFile.Structs.Length > 0) { foreach (Ja2Data.JsdStruct _struct in _jsdFile.Structs) { JsdStructure _structRec = this.LoadStructure(_struct); _structRec.SlfRecordJsd = _jsdRecord; this.FJsdStructures.Add(_structRec); } } return(_jsdRecord); }
private Ja2Data.SlfFile.Record DownloadJsdRecord(SlfRecordJsd aJsdRecord) { this.FJsdCells = new List <JsdCell>(100 * aJsdRecord.NumberOfStructuresStored); string _queryString = @"Select T.JsdTileId, C.RowNumber, C.CellNumber, Value from JsdTileCell C inner join JsdTile T on C.JsdTileId = T.JsdTileId inner join JsdStructure S on S.JsdStructureId = T.JsdStructureId inner join SlfRecordJsd SRJ on SRJ.SlfRecordJsdId = S.SlfRecordJsdId where SRJ.SlfRecordJsdId = @JsdFileId" ; DbRawSqlQuery _query = this.FContext.Database.SqlQuery(typeof(JsdCell), _queryString, new SqlParameter("@JsdFileId", aJsdRecord.SlfRecordJsdId)); var _enum = _query.GetEnumerator(); while (_enum.MoveNext()) { this.FJsdCells.Add(((JsdCell)_enum.Current)); } Ja2Data.SlfFile.Record.Header _header = this.DownloadSlfRecordHeader(aJsdRecord.SlfRecordHeader); Ja2Data.SlfFile.Record _jsdRec = new Ja2Data.SlfFile.Record(_header); _jsdRec.Data = new byte[_header.uiLength]; int _flags = 0; foreach (JsdRecordHeaderFlag _flag in aJsdRecord.JsdRecordHeaderFlag) { _flags |= _flag.JsdHeaderFlags.Mask.Value; } Ja2Data.JsdFile.Header _jsdHeader = new Ja2Data.JsdFile.Header( aJsdRecord.ID, (ushort)aJsdRecord.NumberOfStructuresAndOrImages, (ushort)aJsdRecord.NumberOfStructuresStored, (ushort)aJsdRecord.StructureDataSize, (byte)_flags, aJsdRecord.Unused, (ushort)aJsdRecord.NumberOfImageTileLocsStored ); Ja2Data.JsdFile _jsdFile = new Ja2Data.JsdFile(_jsdHeader); if (aJsdRecord.JsdAuxData.Count > 0) { JsdAuxData _jsdAuxData = aJsdRecord.JsdAuxData.First(); if (aJsdRecord.NumberOfImageTileLocsStored > 0) { Array.Copy(_jsdAuxData.TileLocationData, _jsdFile.TileLocData, _jsdFile.TileLocData.Length); } int i = 0; foreach (AuxDataJsdAux _aux in _jsdAuxData.AuxDataJsdAux) { _jsdFile.Auxilarity[i] = this.DownloadAuxObjectData(_aux.AuxObjectData); i++; } } if (aJsdRecord.JsdStructure.Count > 0) { int i = 0; foreach (JsdStructure _struct in aJsdRecord.JsdStructure) { _jsdFile.Structs[i] = this.DownloadJsdStructure(_struct, _jsdFile.IsHighDefenition); i++; } } using (MemoryStream _ms = new MemoryStream(_jsdRec.Data)) { _jsdFile.Save(_ms); } return(_jsdRec); }