private bool DeleteIdentifierLocations(EsentStorage.Key key, CancellationToken cancellationToken) { using (var accessor = _esentStorage.GetIdentifierLocationTableAccessor()) { accessor.Delete(key, cancellationToken); return(accessor.ApplyChanges()); } }
private bool WriteStream(EsentStorage.Key key, int nameId, Stream stream, object unused1, CancellationToken cancellationToken) { using (var accessor = GetAccessor(key)) using (var esentStream = accessor.GetWriteStream(key, nameId)) { WriteToStream(stream, esentStream, cancellationToken); return(accessor.ApplyChanges()); } }
private bool TryGetProjectKey(Project project, out EsentStorage.Key key) { key = default(EsentStorage.Key); if (!TryGetProjectId(project, out var projectId, out var projectNameId)) { return(false); } key = new EsentStorage.Key(projectId, projectNameId); return(true); }
private bool TryGetProjectAndDocumentKey(Document document, out EsentStorage.Key key) { key = default(EsentStorage.Key); if (!TryGetProjectId(document.Project, out var projectId, out var projectNameId) || !TryGetUniqueFileId(document.FilePath, out var documentId)) { return(false); } key = new EsentStorage.Key(projectId, projectNameId, documentId); return(true); }
private Stream ReadStream(EsentStorage.Key key, int nameId, object unused1, object unused2, CancellationToken cancellationToken) { using (var accessor = GetAccessor(key)) using (var esentStream = accessor.GetReadStream(key, nameId)) { if (esentStream == null) { return(null); } // this will copy over esent stream and let it go. return(SerializableBytes.CreateReadableStream(esentStream, cancellationToken)); } }
private VersionStamp GetIdentifierSetVersion(EsentStorage.Key key) { if (!PersistenceEnabled) { return(VersionStamp.Default); } if (!TryGetIdentifierSetVersionId(out var identifierId)) { return(VersionStamp.Default); } // TODO: verify that project is in solution associated with the storage return(EsentExceptionWrapper(key, identifierId, GetIdentifierSetVersion, CancellationToken.None)); }
private VersionStamp GetIdentifierSetVersion(EsentStorage.Key key, int identifierId, object unused1, object unused2, CancellationToken cancellationToken) { using (var accessor = _esentStorage.GetIdentifierLocationTableAccessor()) using (var stream = accessor.GetReadStream(key, identifierId)) { if (stream == null) { return(VersionStamp.Default); } using (var reader = new StreamObjectReader(stream)) { return(VersionStamp.ReadFrom(reader)); } } }
private bool TrySaveIdentifierSetVersion( EsentStorage.IdentifierLocationTableAccessor accessor, EsentStorage.Key key, VersionStamp version) { if (!TryGetIdentifierSetVersionId(out var identifierId)) { return(false); } accessor.PrepareBatchOneInsert(); using (var stream = accessor.GetWriteStream(key, identifierId)) using (var writer = new ObjectWriter(stream)) { version.WriteTo(writer); } accessor.FinishBatchOneInsert(); return(true); }
private bool ReadIdentifierPositions(EsentStorage.Key key, int identifierId, List <int> positions, object unused, CancellationToken cancellationToken) { using (var accessor = _esentStorage.GetIdentifierLocationTableAccessor()) using (var stream = accessor.GetReadStream(key, identifierId)) { if (stream == null) { // no such identifier exist. return(true); } using (var reader = new StreamObjectReader(stream)) { var formatVersion = reader.ReadString(); if (formatVersion != IdentifierSetSerializationVersion) { return(false); } return(ReadFrom(reader, positions, cancellationToken)); } } }
private EsentStorage.ProjectDocumentTableAccessor GetAccessor(EsentStorage.Key key) { return(key.DocumentIdOpt.HasValue ? _esentStorage.GetDocumentTableAccessor() : (EsentStorage.ProjectDocumentTableAccessor)_esentStorage.GetProjectTableAccessor()); }
private bool WriteIdentifierLocations(EsentStorage.Key key, Document document, VersionStamp version, SyntaxNode root, CancellationToken cancellationToken) { // delete any existing data if (!DeleteIdentifierLocations(key, cancellationToken)) { return(false); } var identifierMap = SharedPools.StringIgnoreCaseDictionary <int>().AllocateAndClear(); Dictionary <string, List <int> > map = null; try { map = CreateIdentifierLocations(document, root, cancellationToken); // okay, write new data using (var accessor = _esentStorage.GetIdentifierLocationTableAccessor()) { // make sure I have all identifier ready before starting big insertion int identifierId; foreach (var identifier in map.Keys) { if (!TryGetUniqueIdentifierId(identifier, out identifierId)) { return(false); } identifierMap[identifier] = identifierId; } // save whole map var uncommittedCount = 0; foreach (var kv in map) { cancellationToken.ThrowIfCancellationRequested(); var identifier = kv.Key; var positions = kv.Value; if ((uncommittedCount + positions.Count) > FlushThreshold) { accessor.Flush(); uncommittedCount = 0; } accessor.PrepareBatchOneInsert(); identifierId = identifierMap[identifier]; using (var stream = accessor.GetWriteStream(key, identifierId)) using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken)) { writer.WriteString(IdentifierSetSerializationVersion); WriteList(writer, positions); } accessor.FinishBatchOneInsert(); uncommittedCount += positions.Count; } // save special identifier that indicates version for this document if (!TrySaveIdentifierSetVersion(accessor, key, version)) { return(false); } return(accessor.ApplyChanges()); } } finally { SharedPools.StringIgnoreCaseDictionary <int>().ClearAndFree(identifierMap); Free(map); } }