public StorageDatabase <TDocumentWithObject, TObjectOnly> Documents <TDocumentWithObject, TObjectOnly>(string directoryName = null) where TDocumentWithObject : IStandardDocument <TObjectOnly> { string key = TypeOfWrapper.TypeOf(typeof(StorageDatabase <TDocumentWithObject, TObjectOnly>)).FullName + "+" + directoryName; this.Logger?.Trace(this.GetType().Name, $"Accessing database storage with key {key} for directory name {directoryName} . Documment with object : {typeof(TDocumentWithObject).Name}, Object type only : {typeof(TObjectOnly).Name}"); if (!this.cache.ContainsKey(key)) { lock (this.padlock) { if (!this.cache.ContainsKey(key)) { var val = new StorageDatabase <TDocumentWithObject, TObjectOnly>( this.DataBaseSettings.AkkaCommonStorageMechanism, directoryName, this, this.Logger); this.cache[key] = val; } } } return(this.cache[key] as StorageDatabase <TDocumentWithObject, TObjectOnly>); }
public static DbStats GetSystemStatistics(DatabaseService DatabaseService, Func <SystemDb <object>, bool> query = null, string documentName = "") { var dbStats = new DbStats(); StorageDatabase <SystemDb <object>, object> sys = DatabaseService.Documents <SystemDb <object>, object>(null); var docs = new List <SystemDb <object> >(); foreach (string s in sys.LoadAllIdsIncludingDeletedDocuments()) { docs.Add(sys.Load(s)); } docs = docs.Where( x => x.DocumentName.ToLower() != documentName.ToLower() && true || x.DocumentName.ToLower() == documentName.ToLower() ).ToList(); if (query != null) { docs = docs.Where(query).ToList(); } int HistoryCount = docs.Count(x => x.DocumentName == TypeOfWrapper.TypeOf(typeof(History <>)).Name); dbStats.TotalDocumentCount = docs.Count - HistoryCount; dbStats.DeletedDocumentCount = docs.Count(x => x.Deleted); dbStats.HistoryDocumentCount = HistoryCount; return(dbStats); }
public static void UpdateDocumentHistory <TDocumentWithObject, TObjectOnly>(TDocumentWithObject original, TDocumentWithObject dbObject, IStorageMechanism storageMechanism, string databaseName, DatabaseService DatabaseService) where TDocumentWithObject : IStandardDocument <TObjectOnly> { if (TypeOfWrapper.TypeOf(typeof(TDocumentWithObject)).Name == TypeOfWrapper.TypeOf(typeof(History <>)).Name || TypeOfWrapper.TypeOf(typeof(TDocumentWithObject)).Name == TypeOfWrapper.TypeOf(typeof(SystemDb <>)).Name || original?.Id == null) { return; } List <PropertyCompareResult> compares = Compare <TDocumentWithObject, TObjectOnly>(original, dbObject); using (StorageDatabase <History <object>, object> history = DatabaseService.DatabaseAccessRegardlessOfTransaction <History <object>, object>(storageMechanism, null)) { history.CreateAll( compares.Select( x => new History <object> { OldValue = x.OldValue, NewValue = x.NewValue, DocumentName = x.DocumentName, DateTime = x.DateTime, Name = x.Name }).ToList()); } }
internal StorageDatabase <TDocumentWithObject, TObjectOnly> DatabaseAccessRegardlessOfTransaction <TDocumentWithObject, TObjectOnly>(IStorageMechanism storageMechanism, string directoryName) where TDocumentWithObject : IStandardDocument <TObjectOnly> { string key = TypeOfWrapper.TypeOf(typeof(StorageDatabase <TDocumentWithObject, TObjectOnly>)).FullName + "+" + directoryName; this.Logger?.Trace(this.GetType().Name, $"Accessing database storage outside the usual pipeline with key {key} for directory name {directoryName} with storage mechanism {storageMechanism?.GetType().Name}. Documment with object : {typeof(TDocumentWithObject).Name}, Object type only : {typeof(TObjectOnly).Name}"); if (!this.cacheForTransactionScenarios.ContainsKey(key)) { lock (this.padlock2) { if (!this.cacheForTransactionScenarios.ContainsKey(key)) { var val = new StorageDatabase <TDocumentWithObject, TObjectOnly>( storageMechanism, directoryName, this, this.Logger); this.cacheForTransactionScenarios[key] = val; } } } return(this.cacheForTransactionScenarios[key] as StorageDatabase <TDocumentWithObject, TObjectOnly>); }