public ValueTask <SerializableClassifiedSpans> GetSemanticClassificationsAsync( PinnedSolutionInfo solutionInfo, DocumentId documentId, TextSpan span, ClassificationOptions options, StorageDatabase database, bool isFullyLoaded, CancellationToken cancellationToken) { return(RunServiceAsync(async cancellationToken => { var solution = await GetSolutionAsync(solutionInfo, cancellationToken).ConfigureAwait(false); var document = solution.GetDocument(documentId) ?? await solution.GetSourceGeneratedDocumentAsync(documentId, cancellationToken).ConfigureAwait(false); Contract.ThrowIfNull(document); using var _ = ArrayBuilder <ClassifiedSpan> .GetInstance(out var temp); await AbstractClassificationService.AddSemanticClassificationsInCurrentProcessAsync( document, span, options, temp, cancellationToken).ConfigureAwait(false); if (isFullyLoaded) { // Once fully loaded, there's no need for us to keep around any of the data we cached in-memory // during the time the solution was loading. lock (_cachedData) _cachedData.Clear(); // Enqueue this document into our work queue to fully classify and cache. _workQueue.AddWork((document, options, database)); } return SerializableClassifiedSpans.Dehydrate(temp.ToImmutable()); }, cancellationToken)); }
public StorageDatabaseUnitTest() { // _context = new DetectionSystemDbContext(new DbContextOptionsBuilder().UseSqlite("Data Source = test.db").Options); _context = new DetectionSystemDbContext(new DbContextOptionsBuilder().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options); _context.Database.EnsureCreated(); _storageDatabase = new StorageDatabase(_context); }
private PecanDocument <T> LoadDocument <T>(string id, string documentName = null, bool includeDeleted = false, bool expectFullJsonStringReturned = false) { this.Logger?.Trace(this.GetType().Name, $"Load document {id} of {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}"); PecanDocument <T> finalResult = null; if (IsAnonymousObject <T>()) { StorageDatabase <PecanDocument <object>, object> handle = this.GetDatabaseServiceHandle <object>(documentName); if (expectFullJsonStringReturned) { string result = handle.LoadJson(id, includeDeleted, expectFullJsonStringReturned); finalResult = new PecanDocument <T> { DocumentEntity = (T)(object)result }; } else { PecanDocument <object> result = handle.Load(id, includeDeleted, expectFullJsonStringReturned); finalResult = this.TrackDocument(id, documentName, result, false) as PecanDocument <T>; } } else { StorageDatabase <PecanDocument <T>, T> handle = this.GetDatabaseServiceHandle <T>(documentName); PecanDocument <T> result = handle.Load(id, includeDeleted); finalResult = this.TrackDocument(id, documentName, result, false); } return(finalResult); }
private static async Task <bool> TryGetCachedClassificationsAsync( Document document, TextSpan textSpan, ClassificationType type, RemoteHostClient client, StorageDatabase database, bool isFullyLoaded, ArrayBuilder <ClassifiedSpan> result, CancellationToken cancellationToken) { // Only try to get cached classifications if we're not fully loaded yet. if (isFullyLoaded) { return(false); } var(documentKey, checksum) = await SemanticClassificationCacheUtilities.GetDocumentKeyAndChecksumAsync( document, cancellationToken).ConfigureAwait(false); var cachedSpans = await client.TryInvokeAsync <IRemoteSemanticClassificationService, SerializableClassifiedSpans?>( document.Project, (service, solutionInfo, cancellationToken) => service.GetCachedClassificationsAsync( documentKey, textSpan, type, checksum, database, cancellationToken), cancellationToken).ConfigureAwait(false); // if the remote call fails do nothing (error has already been reported) if (!cachedSpans.HasValue || cachedSpans.Value == null) { return(false); } cachedSpans.Value.Rehydrate(result); return(true); }
public void DeleteForever <T>(string id, string documentName = null) { this.Logger?.Trace(this.GetType().Name, $"Delete document forever {documentName} with id {id} Supplied document name {documentName} - {this.GetContextDescription()}"); StorageDatabase <PecanDocument <T>, T> handle = this.GetDatabaseServiceHandle <T>(documentName); handle.DeleteForever(id); }
public IEnumerable <T> Query <T>(Func <IEnumerable <T>, IEnumerable <T> > query, string documentName = null) { this.Logger?.Trace(this.GetType().Name, $"Query document {documentName} Supplied document name {documentName} - {this.GetContextDescription()}"); StorageDatabase <PecanDocument <T>, T> handle = this.GetDatabaseServiceHandle <T>(documentName); return(handle.LoadAll(d => { return query(d.Select(x => x.DocumentEntity)); })); }
private StorageDatabase <PecanDocument <T>, T> GetDatabaseServiceHandle <T>(string documentName) { this.Logger?.Trace(this.GetType().Name, $"Get database handle. Supplied document name {documentName} - {this.GetContextDescription()}"); StorageDatabase <PecanDocument <T>, T> handle = null; handle = this.databaseService.Documents <PecanDocument <T>, T>(documentName); handle.InitializeDatabaseCacheIfNotReady(); return(handle); }
public string SaveFile(string filePath, string destinationFolderForFiles = null) { this.ThrowNotPossibleRemotelyExceptionIfNecessary(); this.Logger?.Trace(this.GetType().Name, $"Storing and saving file {filePath} possibly to destination {destinationFolderForFiles} - {this.GetContextDescription()}"); StorageDatabase <PecanDocument <FilesStorage>, FilesStorage> handle = this.GetDatabaseServiceHandle <FilesStorage>(null); string id = handle.GetNextId().Item1; FilesStorage obj = this.UpdateFile(id, filePath, destinationFolderForFiles); return(this.Save(obj, obj.Id)); }
public void TEST_no_caching() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); DatabaseService.DataBaseSettings.MaxResponseTime = TimeSpan.FromMinutes(5); for (int i = 0; i < 100; i++) { StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>(); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); History.LoadAll(true).ToList().ForEach( x => { History.Delete(x.Id); History.DeleteForever(x.Id); }); IEnumerable <Finance <object> > allx = fin.LoadAll(true); Finance <object> data = fin.Create(new Finance <object>()); IEnumerable <Finance <object> > allk = fin.LoadAll(true); IEnumerable <Finance <object> > allhhjjw = fin.LoadAll(true); data.FileContent = "bla"; IEnumerable <Finance <object> > allhhw = fin.LoadAll(true); fin.Update(data); IEnumerable <Finance <object> > allw = fin.LoadAll(true); History <object> h = History.Load(History.LoadAll(true).LastOrDefault().Id); data = fin.Load(data.Id); IEnumerable <Finance <object> > ally = fin.LoadAll(true); TestHelperMethods.AssertAwait( () => { IEnumerable <Finance <object> > all = fin.LoadAll(true); Assert.AreEqual(1, all.Count()); }); fin.Delete(data.Id); h = History.Load(History.LoadAll(true).Last().Id); DbStats stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name); fin.DeleteForever(data.Id); h = History.Load(History.LoadAll(true).LastOrDefault().Id); stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name); TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count())); } }
private PecanDocument <TAs> LoadDocument <T, TAs>(string id, string documentName = null, bool includeDeleted = false, bool expectFullJsonStringReturned = false) { this.Logger?.Trace(this.GetType().Name, $"Load document {id} of {typeof(T).Name} as {typeof(TAs).Name}. Supplied document name {documentName} - {this.GetContextDescription()}"); PecanDocument <TAs> finalResult = null; if (IsAnonymousObject <T>()) { StorageDatabase <PecanDocument <object>, object> handle = this.GetDatabaseServiceHandle <object>(documentName); if (expectFullJsonStringReturned) { string result = handle.LoadJson(id, includeDeleted, expectFullJsonStringReturned); finalResult = new PecanDocument <TAs> { DocumentEntity = (TAs)(object)result }; } else { var result = handle.Load <PecanDocument <TAs> >(id, includeDeleted); finalResult = result; } //todo as is not tracked finalResult = this.TrackDocument(id, documentName, result, false); } else { this.Logger?.Trace(this.GetType().Name, $"Loading document {id} of {typeof(T).Name} as {typeof(TAs).Name} . Supplied document name {documentName} - {this.GetContextDescription()}"); StorageDatabase <PecanDocument <T>, T> handle = this.GetDatabaseServiceHandle <T>(documentName); string result = handle.LoadJson(id, includeDeleted, expectFullJsonStringReturned); if (expectFullJsonStringReturned) { finalResult = new PecanDocument <TAs> { DocumentEntity = (TAs)(object)result } } ; else { finalResult = this.databaseService.DataBaseSettings.StorageMechanismMech.FileSystem.SerializationFactory.DeserializeObject <PecanDocument <TAs> >(result); } } return(finalResult); }
public IEnumerable <T> Search <T>(Predicate <string> predicate, Func <IEnumerable <T>, IEnumerable <T> > query = null, string documentName = null) { this.Logger?.Trace(this.GetType().Name, $"Search document {documentName} Supplied document name {documentName} - {this.GetContextDescription()}"); StorageDatabase <PecanDocument <T>, T> handle = this.GetDatabaseServiceHandle <T>(documentName); IEnumerable <PecanDocument <T> > result = handle.Search( predicate, d => { return(query?.Invoke(d.Select(x => x.DocumentEntity)).Select( x => new PecanDocument <T> { DocumentEntity = x }) ?? d); }); return(result.Select(x => x.DocumentEntity)); }
public StorageService() { lock (SqliteDatabase.lockobj) { if (Storage == null) { Storage = new StorageDatabase(); } } lock (StorageDatabaseAzure.lockobj) { if (AzureStorage == null) { AzureStorage = new StorageDatabaseAzure(); } } }
public string Save <T>(string documentName, T document, string id = null) { if (RunAsHttpClient) { var databaseName = PecanDatabaseUtilityObj.DetermineDatabaseName <PecanDocument <T>, T>(documentName); var data = JsonConvert.SerializeObject(document); var resultStr = RemoteAccess.MakeRequest <string>(RemoteServerAdrress, $"Save?data={data}&database={databaseName}"); return(resultStr); } this.Logger?.Trace(this.GetType().Name, $"STORING NEW Document with id {id} of {documentName} type {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}"); if (IsAnonymousObject <T>()) { this.Logger?.Trace(this.GetType().Name, $"STORING NEW Document determined to be anonymous with id {id} of {documentName} type {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}"); StorageDatabase <PecanDocument <object>, object> handle = this.GetDatabaseServiceHandle <object>(documentName); var data = new PecanDocument <object> { DocumentEntity = document.ToDynamic() }; PecanDocument <object> result = handle.Create(data, false, id); this.Logger?.Trace(this.GetType().Name, $"STORING NEW successfully obtained final Order id {result?.Id} after the storing Document with id {id} of {documentName} type {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}"); return(result.Id); } else { this.Logger?.Trace(this.GetType().Name, $"STORING NEW storing Document determined to be NOT anonymous with id {id} of {documentName} type {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}"); StorageDatabase <PecanDocument <T>, T> handle = this.GetDatabaseServiceHandle <T>(documentName); var data = new PecanDocument <T> { DocumentEntity = document }; PecanDocument <T> result = handle.Create(data, false, id); this.Logger?.Trace(this.GetType().Name, $"STORING NEW successfully obtained final Order id {result?.Id} after the storing Document with id {id} of {documentName} type {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}"); return(result.Id); } }
public MetadataInfoCreator( HostWorkspaceServices services, SolutionKey solutionKey, Checksum checksum, StorageDatabase database, PortableExecutableReference reference) { _services = services; _solutionKey = solutionKey; _checksum = checksum; _database = database; _reference = reference; _metadataReader = null; _allTypeDefinitions = new List <MetadataDefinition>(); _containsExtensionsMethod = false; _inheritanceMap = OrderPreservingMultiDictionary <string, string> .GetInstance(); _parentToChildren = OrderPreservingMultiDictionary <MetadataNode, MetadataNode> .GetInstance(); _extensionMethodToParameterTypeInfo = new MultiDictionary <MetadataNode, ParameterTypeInfo>(); _rootNode = MetadataNode.Allocate(name: ""); }
/// <summary> /// 注册库存数据库Session对象 /// </summary> private static void RegisterStroageDbSession() { string connectionString = ConfigurationManager.ConnectionStrings["StorageDbContext"].ToString(); if (String.IsNullOrEmpty(connectionString)) { throw new ApplicationException("数据库连接字符串不能为空!请检查!"); } IDbConnection connection = SqlConnectionFactory.CreateSqlConnection(DatabaseType.MySql, connectionString); MainContainerCached.Register <IStorageDatabase>(() => { var database = new StorageDatabase(connection); return(database); }); MainContainerCached.Register <IStorageDbSession, StorageDbSession>(); }
public void TestMethod1() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>(); IEnumerable <History <object> > h = History.LoadAll(true); IEnumerable <Finance <object> > f = fin.LoadAll(true); Finance <object> mod = fin.Create( new Finance <object> { FileName = "shdlkhslkdhlksd" }); h = History.LoadAll(true); IEnumerable <Finance <object> > f1 = fin.LoadAll(); DbStats t = SystemDbService.GetSystemStatistics(DatabaseService); DbStats q = SystemDbService.GetSystemStatistics(DatabaseService, x => x.LastOperation == "CREATE"); foreach (Finance <object> id in f1) { Finance <object> d = fin.Load(id.Id); fin.Delete(id.Id); fin.DeleteForever(id.Id); } h = History.LoadAll(true); f = fin.LoadAll(true); IEnumerable <History <object> > h1 = History.LoadAll(); foreach (History <object> id in h1) { History <object> d = History.Load(id.Id); History.Delete(id.Id); History.DeleteForever(id.Id); } h = History.LoadAll(true); f = fin.LoadAll(true); t = SystemDbService.GetSystemStatistics(DatabaseService); }
public void load_test_with_nocaching() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); DatabaseService.DataBaseSettings.MaxResponseTime = TimeSpan.FromMinutes(3); StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>(); fin.LoadAll(true).ToList().ForEach(x => fin.DeleteForever(x.Id)); History.LoadAll(true).ToList().ForEach(x => History.DeleteForever(x.Id)); int count = 1000; for (int i = 0; i < count; i++) { fin.Create(new Finance <object>()); } fin.Create(new Finance <object>(), true); TestHelperMethods.AssertAwait( () => { int ttt = fin.LoadAll(true).Count(); Assert.AreEqual(count + 1, ttt); }); List <Finance <object> > x1 = fin.LoadAll(true).Take(10).ToList(); List <Finance <object> > x2 = fin.LoadAll(true).Take(1000).ToList(); List <Finance <object> > x3 = fin.LoadAll(true).Take(1000).ToList(); IEnumerable <Finance <object> > tester = fin.LoadAll( finances => from finance in finances where finance.ETag != null select finance); fin.LoadAll(true).ToList().ForEach(x => fin.DeleteForever(x.Id)); History.LoadAll(true).ToList().ForEach(x => History.DeleteForever(x.Id)); //(3000); TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count())); }
public void TEST_serach() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); DatabaseService.DataBaseSettings.EnableCaching = true; StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); fin.LoadAll(true).ToList().ForEach( x => { fin.DeleteForever(x.Id); }); fin.Create( new Finance <object> { FileDescription = "yo", FileName = "wow" }); fin.Create( new Finance <object> { FileDescription = "yay", FileName = "way" }); IEnumerable <Finance <object> > all = fin.LoadAll(); Assert.AreEqual(2, all.Count()); IEnumerable <Finance <object> > all2 = fin.Search(s => s.Contains("yay")); Assert.AreEqual(1, all2.Count()); IEnumerable <Finance <object> > all3 = fin.Search(s => s.Contains("way")); Assert.AreEqual(1, all3.Count()); IEnumerable <Finance <object> > all4 = fin.Search(s => s.Contains("y")); Assert.AreEqual(2, all4.Count()); }
public void TEST_with_caching_inmemory() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); for (int i = 0; i < 100; i++) { DatabaseService.DataBaseSettings.EnableFasterCachingButWithLeakyUpdates = true; StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>(); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); History.LoadAll(true).ToList().ForEach( x => { History.Delete(x.Id); History.DeleteForever(x.Id); }); Finance <object> data = fin.Create(new Finance <object>()); data.FileContent = "bla"; fin.Update(data); History <object> h = History.Load(History.LoadAll(true).LastOrDefault().Id); data = fin.Load(data.Id); TestHelperMethods.AssertAwait(() => Assert.AreEqual(1, fin.LoadAll(true).Count())); fin.Delete(data.Id); h = History.Load(History.LoadAll(true).Last().Id); DbStats stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name); fin.DeleteForever(data.Id); h = History.Load(History.LoadAll(true).LastOrDefault().Id); stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name); TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count())); } }
private static Task <SpellChecker> LoadOrCreateSpellCheckerAsync( HostWorkspaceServices services, SolutionKey solutionKey, Checksum checksum, StorageDatabase database, string filePath, ImmutableArray <Node> sortedNodes) { var result = TryLoadOrCreateAsync( services, solutionKey, checksum, database, loadOnly: false, createAsync: () => CreateSpellCheckerAsync(checksum, sortedNodes), keySuffix: "_SpellChecker_" + filePath, tryReadObject: SpellChecker.TryReadFrom, cancellationToken: CancellationToken.None); Contract.ThrowIfNull(result, "Result should never be null as we passed 'loadOnly: false'."); return(result); }
private static async Task <SymbolTreeInfo> GetInfoForMetadataReferenceSlowAsync( HostWorkspaceServices services, SolutionKey solutionKey, PortableExecutableReference reference, Checksum checksum, StorageDatabase database, Metadata metadata, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); // Important: this captured async lazy may live a long time *without* computing the final results. As such, // it is important that it note capture any large state. For example, it should not hold onto a Solution // instance. var asyncLazy = s_metadataIdToInfo.GetValue( metadata.Id, id => new AsyncLazy <SymbolTreeInfo>( c => TryCreateMetadataSymbolTreeInfoAsync(services, solutionKey, reference, checksum, database, c), cacheResult: true)); return(await asyncLazy.GetValueAsync(cancellationToken).ConfigureAwait(false)); }
private static Task <SymbolTreeInfo> TryCreateMetadataSymbolTreeInfoAsync( HostWorkspaceServices services, SolutionKey solutionKey, PortableExecutableReference reference, Checksum checksum, StorageDatabase database, CancellationToken cancellationToken) { var filePath = reference.FilePath; var result = TryLoadOrCreateAsync( services, solutionKey, checksum, database, loadOnly: false, createAsync: () => CreateMetadataSymbolTreeInfoAsync(services, solutionKey, checksum, database, reference), keySuffix: "_Metadata_" + filePath, tryReadObject: reader => TryReadSymbolTreeInfo(reader, checksum, nodes => GetSpellCheckerAsync(services, solutionKey, checksum, database, filePath, nodes)), cancellationToken: cancellationToken); Contract.ThrowIfNull(result != null); return(result); }
private static async Task <T> TryLoadOrCreateAsync <T>( HostWorkspaceServices services, SolutionKey solutionKey, Checksum checksum, StorageDatabase database, bool loadOnly, Func <Task <T> > createAsync, string keySuffix, Func <ObjectReader, T> tryReadObject, CancellationToken cancellationToken) where T : class, IObjectWritable, IChecksummedObject { using (Logger.LogBlock(FunctionId.SymbolTreeInfo_TryLoadOrCreate, cancellationToken)) { if (checksum == null) { return(loadOnly ? null : await CreateWithLoggingAsync().ConfigureAwait(false)); } // Ok, we can use persistence. First try to load from the persistence service. var persistentStorageService = services.GetPersistentStorageService(database); var storage = await persistentStorageService.GetStorageAsync(solutionKey, checkBranchId : false, cancellationToken).ConfigureAwait(false); await using var _ = storage.ConfigureAwait(false); // Get the unique key to identify our data. var key = PrefixMetadataSymbolTreeInfo + keySuffix; using (var stream = await storage.ReadStreamAsync(key, checksum, cancellationToken).ConfigureAwait(false)) using (var reader = ObjectReader.TryGetReader(stream, cancellationToken: cancellationToken)) { if (reader != null) { // We have some previously persisted data. Attempt to read it back. // If we're able to, and the version of the persisted data matches // our version, then we can reuse this instance. var read = tryReadObject(reader); if (read != null) { // If we were able to read something in, it's checksum better // have matched the checksum we expected. Debug.Assert(read.Checksum == checksum); return(read); } } } cancellationToken.ThrowIfCancellationRequested(); // Couldn't read from the persistence service. If we've been asked to only load // data and not create new instances in their absence, then there's nothing left // to do at this point. if (loadOnly) { return(null); } // Now, try to create a new instance and write it to the persistence service. var result = await CreateWithLoggingAsync().ConfigureAwait(false); Contract.ThrowIfNull(result); using (var stream = SerializableBytes.CreateWritableStream()) { using (var writer = new ObjectWriter(stream, leaveOpen: true, cancellationToken)) { result.WriteTo(writer); } stream.Position = 0; await storage.WriteStreamAsync(key, stream, checksum, cancellationToken).ConfigureAwait(false); } return(result); } async Task <T> CreateWithLoggingAsync() { using (Logger.LogBlock(FunctionId.SymbolTreeInfo_Create, cancellationToken)) { return(await createAsync().ConfigureAwait(false)); } } }
private static Task <SymbolTreeInfo> CreateMetadataSymbolTreeInfoAsync( HostWorkspaceServices services, SolutionKey solutionKey, Checksum checksum, StorageDatabase database, PortableExecutableReference reference) { var creator = new MetadataInfoCreator(services, solutionKey, checksum, database, reference); return(Task.FromResult(creator.Create())); }
public static async Task <SyntaxTreeIndex?> LoadAsync( HostWorkspaceServices services, DocumentKey documentKey, Checksum?checksum, StorageDatabase database, StringTable stringTable, CancellationToken cancellationToken) { try { var persistentStorageService = services.GetPersistentStorageService(database); var storage = await persistentStorageService.GetStorageAsync(documentKey.Project.Solution, checkBranchId : false, cancellationToken).ConfigureAwait(false); await using var _ = storage.ConfigureAwait(false); // attempt to load from persisted state using var stream = await storage.ReadStreamAsync(documentKey, PersistenceName, checksum, cancellationToken).ConfigureAwait(false); using var reader = ObjectReader.TryGetReader(stream, cancellationToken: cancellationToken); if (reader != null) { return(ReadFrom(stringTable, reader, checksum)); } } catch (Exception e) when(IOUtilities.IsNormalIOException(e)) { // Storage APIs can throw arbitrary exceptions. } return(null); }
public static IChecksummedPersistentStorageService GetPersistentStorageService(this HostWorkspaceServices services, StorageDatabase database) { var configuration = services.GetRequiredService <IPersistentStorageConfiguration>(); switch (database) { case StorageDatabase.SQLite: return(services.GetService <ISQLiteStorageServiceFactory>()?.Create(configuration) ?? NoOpPersistentStorageService.GetOrThrow(configuration)); case StorageDatabase.CloudCache: return(services.GetService <ICloudCacheStorageServiceFactory>()?.Create(configuration) ?? NoOpPersistentStorageService.GetOrThrow(configuration)); default: return(NoOpPersistentStorageService.GetOrThrow(configuration)); } }
public StorageManager() { m_SavingPath = Application.dataPath + "/DesignData/StorageData.xml"; m_StorageDatabase = new StorageDatabase(); m_StorageDatabase.SetValue(m_SavingPath, MaxSlots); }
public void transaction() { var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null); DatabaseService.DataBaseSettings.MaxResponseTime = TimeSpan.FromMinutes(10); StorageDatabase <Finance <object>, object> fin = DatabaseService.Documents <Finance <object>, object>(); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count())); int total = 100; Task.Run( () => { DatabaseService.Transaction( handle => { for (int i = 0; i < total; i++) { Finance <object> ti = handle.GetDBRef <Finance <object>, object>().Create(new Finance <object>()); } return(true); }); }); IEnumerable <Finance <object> > t = fin.LoadAll(true); TestHelperMethods.AssertAwait(1000); fin.Create(new Finance <object>()); //(3000); Assert.AreEqual(total + 1, fin.LoadAll(true).Count()); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); Assert.AreEqual(0, fin.LoadAll(true).Count()); Task task = Task.Run( () => { for (int i = 0; i < total; i++) { Finance <object> ti = fin.Create(new Finance <object>()); } }); IEnumerable <Finance <object> > ttt = fin.LoadAll(true); TestHelperMethods.AssertAwait(1000); fin.Create(new Finance <object>()); // Assert.AreNotEqual(total + 1, fin.LoadAll(true).Count()); task.Wait(); //(3000); fin.LoadAll(true).ToList().ForEach( x => { fin.Delete(x.Id); fin.DeleteForever(x.Id); }); Assert.AreEqual(0, fin.LoadAll(true).Count()); StorageDatabase <History <object>, object> his = DatabaseService.Documents <History <object>, object>(); his.LoadAll(true).ToList().ForEach( x => { his.Delete(x.Id); his.DeleteForever(x.Id); }); }
public static IChecksummedPersistentStorageService GetPersistentStorageService(this HostWorkspaceServices services, StorageDatabase database) { var configuration = services.GetRequiredService <IPersistentStorageConfiguration>(); return(database switch { #if !DOTNET_BUILD_FROM_SOURCE StorageDatabase.SQLite => services.GetService <SQLitePersistentStorageService>() ?? NoOpPersistentStorageService.GetOrThrow(configuration), #endif StorageDatabase.CloudCache => services.GetService <ICloudCacheStorageService>() ?? NoOpPersistentStorageService.GetOrThrow(configuration), _ => NoOpPersistentStorageService.GetOrThrow(configuration), });