/// <summary> /// 删除归档数据 /// </summary> /// <param name="archive"></param> public void DropArchive(ArchiveState archive) { var catalogName = string.Format( "Archive{0}{1}_{2}", archive.Ontology.Ontology.Code, archive.ArchiveOn.ToString("yyyyMMdd"), archive.NumberId.ToString()); if (catalogName.Equals(this.GetEntityDb(archive.Ontology).Database.CatalogName, StringComparison.OrdinalIgnoreCase)) { throw new AnycmdException("归档库的数据库名不能与本体库相同"); } string sql = @"IF EXISTS ( SELECT 1 FROM master..sysdatabases WHERE name = '" + catalogName + @"' ) ALTER DATABASE " + catalogName + @" SET SINGLE_USER WITH ROLLBACK IMMEDIATE IF EXISTS ( SELECT 1 FROM master..sysdatabases WHERE name = '" + catalogName + @"' ) ALTER DATABASE " + catalogName + @" SET MULTI_USER IF EXISTS ( SELECT 1 FROM master..sysdatabases WHERE name = '" + catalogName + @"' ) DROP DATABASE " + catalogName + ""; this.GetEntityDb(archive.Ontology).ExecuteNonQuery(sql, null); }
public byte[] AddFile(ulong streamId, Stream file, HashType type = HashType.None) { EnsureMaximumState(ArchiveState.PushingFiles); if (_state == ArchiveState.Initial) { _outputFilter = DoOutputFiltering(_hashedStream); _state = ArchiveState.PushingFiles; } byte[] ret = null; _streamIds.Add(streamId); _streamSizes.Add(file.Length); Stream stream = file; HashAlgorithm hash = null; if (type != HashType.None) { hash = Hash.New(type); stream = new HashCalculatorInputFilter(stream, hash); } stream.CopyTo(_outputFilter); if (type != HashType.None) { stream.Dispose(); hash.FinishHashing(); ret = hash.Hash; } AnyFile = true; return ret; }
public DataTuple GetPlist( ArchiveState archive, OrderedElementSet selectElements, List <FilterData> filters, PagingInput pagingData) { return(this.GetPlistInfoItems( archive.Ontology, this.GetArchiveDb(archive.Ontology, archive), selectElements, filters, pagingData)); }
/// <summary> /// /// </summary> /// <param name="archive"></param> /// <param name="localEntityId"></param> /// <param name="selectElements"></param> /// <returns></returns> public InfoItem[] Get( ArchiveState archive, string localEntityId, OrderedElementSet selectElements) { var topTwo = GetTop2InfoItemSet(archive, new InfoItem[] { InfoItem.Create(archive.Ontology.IdElement, localEntityId) }, selectElements); if (topTwo.BothHasValue || topTwo.BothNoValue) { return(new InfoItem[0]); } else { return(topTwo.SingleInfoTuple); } }
public static ArchiveTr Create(ArchiveState archive) { return(new ArchiveTr(archive.AcDomain) { ArchiveOn = archive.ArchiveOn, CreateOn = archive.CreateOn, CreateBy = archive.CreateBy, CreateUserId = archive.CreateUserId, DataSource = archive.DataSource, Id = archive.Id, NumberId = archive.NumberId, OntologyId = archive.OntologyId, Title = archive.Title, UserId = archive.UserId }); }
private TowInfoTuple GetTop2InfoItemSet( ArchiveState archive, IEnumerable <InfoItem> infoIDs, OrderedElementSet selectElements) { return(GetTop2InfoItemSet(archive.Ontology, this.GetArchiveDb(archive.Ontology, archive), infoIDs, selectElements)); }
public static double CalculateProgress(int totalNumberOfMessages, int numberOfMessagesArchived, ArchiveState state) { double total = totalNumberOfMessages; switch (state) { case ArchiveState.ArchiveProgressing: return(numberOfMessagesArchived / total); case ArchiveState.ArchiveFinalizing: case ArchiveState.ArchiveCompleted: return(1.0); default: return(0.0); } }
public static ArchiveTr Create(ArchiveState archive) { return new ArchiveTr(archive.AcDomain) { ArchiveOn = archive.ArchiveOn, CreateOn = archive.CreateOn, CreateBy = archive.CreateBy, CreateUserId = archive.CreateUserId, DataSource = archive.DataSource, Id = archive.Id, NumberId = archive.NumberId, OntologyId = archive.OntologyId, Title = archive.Title, UserId = archive.UserId }; }
public void WriteFile(string filepath, bool compressNOTWORKING, ArchiveFile file, bool surpressErrors) { if (!_writing) { throw new Exception("Must call BeginWriting() before calling WriteFile()"); } if (!_indexTable.ContainsKey(filepath)) { if (!surpressErrors) { throw new FileNotFoundException("File with given path was not found in the releasemanifest"); } Console.WriteLine("Following file was not found in the releasemanifest: {0}", filepath); return; } if (!_fileTable.ContainsKey(filepath)) { if (!surpressErrors) { throw new FileNotFoundException("File with given path was not found in the file table"); } Console.WriteLine("Following file was not found: {0}", filepath); return; } var archive = _fileTable[filepath]; for (int i = 0; i < archive.Count; i++) { // Handle archive state creation if (!_archiveStates.ContainsKey(archive[i].FilePath)) { var state = new ArchiveState(); state.ArchivePath = archive[i].FilePath; state.OriginalLength = archive[i].DataLength; state.OriginalValues = new Dictionary <string, ArchiveFileInfo>(); _archiveStates[archive[i].FilePath] = state; } if (!_bufferTable.ContainsKey(archive[i].FilePath)) { _bufferTable[archive[i].FilePath] = new ArchiveWriteBuffer(); } _bufferTable[archive[i].FilePath].WriteData(filepath, file.Data); // Copy file info to the list of originals and then modify it if (!_archiveStates[archive[i].FilePath].OriginalValues.ContainsKey(filepath)) { _archiveStates[archive[i].FilePath].OriginalValues[filepath] = ArchiveFileInfo.Copy(archive[i].Files[filepath]); } } // Handle manifest changes _indexTable[filepath].Descriptor.CompressedSize = file.CompressedSize; _indexTable[filepath].Descriptor.DecompressedSize = file.UncompressedSize; }
private void EnsureMaximumState(ArchiveState maxState) { if ((int)_state > (int)maxState) throw new InvalidProgramState(); }
public DataTuple GetPlist( ArchiveState archive, OrderedElementSet selectElements, List<FilterData> filters, PagingInput pagingData) { return this.GetPlistInfoItems( archive.Ontology, this.GetArchiveDb(archive.Ontology, archive), selectElements, filters, pagingData); }
/// <summary> /// /// </summary> /// <param name="archive"></param> /// <param name="localEntityId"></param> /// <param name="selectElements"></param> /// <returns></returns> public InfoItem[] Get( ArchiveState archive, string localEntityId, OrderedElementSet selectElements) { var topTwo = GetTop2InfoItemSet(archive, new InfoItem[] { InfoItem.Create(archive.Ontology.IdElement, localEntityId) }, selectElements); if (topTwo.BothHasValue || topTwo.BothNoValue) { return new InfoItem[0]; } else { return topTwo.SingleInfoTuple; } }
public void AddFso(FileSystemObject fso) { EnsureMaximumState(ArchiveState.PushingFsos); if (_state == ArchiveState.Initial) { _initialFsoOffset = _hashedStream.BytesWritten; _outputFilter = DoOutputFiltering(_hashedStream); _state = ArchiveState.PushingFsos; } else if (_state == ArchiveState.PushingFiles) { _outputFilter.Flush(); _outputFilter.Dispose(); _initialFsoOffset = _hashedStream.BytesWritten; _outputFilter = DoOutputFiltering(_hashedStream); _state = ArchiveState.PushingFsos; } var x0 = _outputFilter.BytesWritten; Serializer.SerializeToStream(_outputFilter, fso); var x1 = _outputFilter.BytesWritten; _baseObjectEntrySizes.Add(x1 - x0); }
private void EnsureMinimumState(ArchiveState minState) { if ((int)_state < (int)minState) throw new InvalidProgramState(); }
private TowInfoTuple GetTop2InfoItemSet( ArchiveState archive, IEnumerable<InfoItem> infoIDs, OrderedElementSet selectElements) { return GetTop2InfoItemSet(archive.Ontology, this.GetArchiveDb(archive.Ontology, archive), infoIDs, selectElements); }
public void AddVersionManifest(VersionManifest versionManifest) { EnsureMinimumState(ArchiveState.PushingFsos); EnsureMaximumState(ArchiveState.PushingFsos); _outputFilter.Flush(); _outputFilter.Dispose(); _outputFilter = null; versionManifest.ArchiveMetadata = new ArchiveMetadata { EntrySizes = new List<long>(_baseObjectEntrySizes), StreamIds = new List<ulong>(_streamIds), StreamSizes = new List<long>(_streamSizes), //CompressionMethod = CompressionMethod, EntriesSizeInArchive = _hashedStream.BytesWritten - _initialFsoOffset, }; long manifestLength; using (var filter = DoOutputFiltering(_hashedStream, false)) { var x0 = _hashedStream.BytesWritten; Serializer.SerializeToStream(filter, versionManifest); filter.Flush(); var x1 = _hashedStream.BytesWritten; manifestLength = x1 - x0; } var bytes = BitConverter.GetBytes(manifestLength); _hashedStream.Write(bytes, 0, bytes.Length); _hashedStream.Dispose(); _hashedStream = null; _hash.FinishHashing(); bytes = _hash.Hash; _fileStream.Write(bytes, 0, bytes.Length); _fileStream.Flush(); _fileStream.Dispose(); _transaction.Commit(); _fileStream = null; _transaction.Dispose(); _transaction = null; _state = ArchiveState.Final; }