public void should_write_directly_to_data() { _fileSet = new FileSet( new IDataFile[] { new DataFile(_dataFileInfo1, _pageSize, _startUpLog) }, new ILogFile[] { new LogFile(_logFileInfo1, true, _startUpLog) }, _pagePoolFactory, _startUpLog); _fileSet.Write( null, Enumerable.Repeat( new PageUpdate { SequenceNumber = 0, PageNumber = 1, Offset = 20, Data = new byte[] { 5, 6, 7 } }, 1)); using (var page = _pagePool.Get(1)) { _fileSet.Read(page); Assert.AreEqual(5, page.Data[20]); Assert.AreEqual(6, page.Data[21]); Assert.AreEqual(7, page.Data[22]); } }
public void Setup() { _startupLog = SetupMock <IStartupLog>(); _errorLog = SetupMock <IErrorLog>(); _pagePoolFactory = SetupMock <IPagePoolFactory>(); _pagePool = _pagePoolFactory.Create(_pageSize); _logFileInfo1 = new FileInfo("C:\\temp\\test1.ldf"); _logFileInfo2 = new FileInfo("C:\\temp\\test2.ldf"); _dataFileInfo1 = new FileInfo("C:\\temp\\test1.mdf"); _dataFileInfo2 = new FileInfo("C:\\temp\\test2.mdf"); _fileSet = new FileSet( new IDataFile[] { new DataFile(_dataFileInfo1, _pageSize, _startupLog), new DataFile(_dataFileInfo2, _pageSize, _startupLog) }, new ILogFile[] { new LogFile(_logFileInfo1, true, _startupLog), new LogFile(_logFileInfo2, true, _startupLog) }, _pagePoolFactory, _startupLog); var databaseFactory = SetupMock <IDatabaseFactory>(); _database = databaseFactory.Open(null); var pageCache = new PageCache(_fileSet, _database, _pagePoolFactory, _startupLog, _errorLog); _pageStore = new PageStore(pageCache, _startupLog); }
public void should_write_within_transaction() { _fileSet = new FileSet( new IDataFile[] { new DataFile(_dataFileInfo1, _pageSize, _startUpLog) }, new ILogFile[] { new LogFile(_logFileInfo1, true, _startUpLog) }, _pagePoolFactory, _startUpLog); var databaseFactory = SetupMock <IDatabaseFactory>(); var pageStoreFactory = SetupMock <IPageStoreFactory>(); var pageStore = pageStoreFactory.Open(_fileSet); var database = databaseFactory.Open(pageStore); var transaction = database.BeginTransaction(null); _fileSet.Write( transaction, Enumerable.Repeat( new PageUpdate { SequenceNumber = 0, PageNumber = 1, Offset = 20, Data = new byte[] { 5, 6, 7 } }, 1)); // Before the transaction is committed the page should be in its // original state using (var originalPage = _pagePool.Get(1)) { _fileSet.Read(originalPage); Assert.AreEqual(0, originalPage.Data[20]); Assert.AreEqual(0, originalPage.Data[21]); Assert.AreEqual(0, originalPage.Data[22]); _fileSet.CommitTransaction(transaction).Wait(); _fileSet.FinalizeTransaction(transaction).Wait(); // After commiting and finalizing the transaction the page should be // changed in the data file using (var newPage = _pagePool.Get(1)) { _fileSet.Read(newPage); Assert.AreEqual(5, newPage.Data[20]); Assert.AreEqual(6, newPage.Data[21]); Assert.AreEqual(7, newPage.Data[22]); } // Anyone with a reference to the original page should not see any change Assert.AreEqual(0, originalPage.Data[20]); Assert.AreEqual(0, originalPage.Data[21]); Assert.AreEqual(0, originalPage.Data[22]); } }
/// <summary>The temporary ignore.</summary> /// <param name="fileSet">The file set.</param> /// <param name="contentItem">The content item.</param> /// <returns>The <see cref="bool"/>.</returns> public bool TemporaryIgnore(IFileSet fileSet, ContentItem contentItem) { return (this.Configuration != null && this.Configuration.Overrides != null && (this.Configuration.Overrides.ShouldIgnore(fileSet) || this.Configuration.Overrides.ShouldIgnore(contentItem))); }
public void Setup() { _startUpLog = SetupMock <IStartupLog>(); _errorLog = SetupMock <IErrorLog>(); _pagePoolFactory = SetupMock <IPagePoolFactory>(); _pagePool = _pagePoolFactory.Create(_pageSize); _dataFileInfo = new FileInfo("C:\\temp\\test.mdf"); _dataFile = new DataFile(_dataFileInfo, _pageSize, _startUpLog); _logFileInfo = new FileInfo("C:\\temp\\test.ldf"); _logFile = new LogFile(_logFileInfo, true, _startUpLog); _fileSet = new FileSet( new[] { _dataFile }, new[] { _logFile }, _pagePoolFactory, _startUpLog); var databaseFactory = SetupMock <IDatabaseFactory>(); _database = databaseFactory.Open(null); var pageCache = new PageCache(_fileSet, _database, _pagePoolFactory, _startUpLog, _errorLog); _pageStore = new PageStore(pageCache, _startUpLog); _accessorFactory = new AccessorFactory(); _accessor = _accessorFactory.SmallSequentialAccessor(_pageStore); }
public FileSetWatcher(IFileSet fileSet, IReporter reporter) { Ensure.NotNull(fileSet, nameof(fileSet)); _fileSet = fileSet; _fileWatcher = new FileWatcher(reporter); }
/// <summary>The should ignore outputs.</summary> /// <param name="fileSet">The file set.</param> /// <returns>The <see cref="bool"/>.</returns> private bool ShouldIgnoreOutputs(IFileSet fileSet) { return(this.outputs.Any() && !this.outputs.Any( output => fileSet.Output.IndexOf(output, StringComparison.OrdinalIgnoreCase) >= 0 && (output.IndexOf(".", StringComparison.OrdinalIgnoreCase) == -1 || fileSet.Output.Count(o => o == '.') > 1))); }
/// <summary>Makes the section cachable.</summary> /// <param name="varByFileSet">The var By File Set.</param> /// <param name="varBySettings">The settings to var by.</param> /// <param name="isSkipable">Determines if the cache is skipable.</param> /// <param name="infiniteWaitForLock">Should the lock wait infinitely (not use a timeout)</param> /// <returns>The <see cref="ICachableWebGreaseSection"/>.</returns> public ICachableWebGreaseSection MakeCachable(IFileSet varByFileSet, object varBySettings = null, bool isSkipable = false, bool infiniteWaitForLock = false) { this.cacheVarByFileSet = varByFileSet; this.cacheVarBySetting = varBySettings; this.cacheIsSkipable = isSkipable; this.cacheInfiniteWaitForLock = infiniteWaitForLock; return(this); }
public PageHeadCollection( IFileSet fileSet, IStartupLog startupLog, IErrorLog errorLog, IPagePool pagePool) { _pages = new Dictionary <ulong, PageHead>(); _fileSet = fileSet; _startupLog = startupLog; _errorLog = errorLog; _pagePool = pagePool; _cleanupThread = new Thread(() => { _startupLog.WriteLine("Stale page clean up thread starting"); while (!_disposing) { try { Thread.Sleep(50); // TODO: Delete pages that have not been touched for a while and // have no cached versions } catch (ThreadAbortException) { return; } catch (Exception ex) { _errorLog.WriteLine("Exception in page collection cleanup thread. " + ex.Message, ex); } } _startupLog.WriteLine("Stale page clean up thread exiting"); }) { IsBackground = true, Name = "Page collection cleanup", Priority = ThreadPriority.AboveNormal }; _cleanupThread.Start(); }
public PageCache( IFileSet fileSet, IDatabase database, IPagePoolFactory pagePoolFactory, IStartupLog startupLog, IErrorLog errorLog) { _startupLog = startupLog; _errorLog = errorLog; _fileSet = fileSet; _database = database; startupLog.WriteLine("Creating a new page cache for " + _fileSet); _pagePool = pagePoolFactory.Create(fileSet.PageSize); _pages = new PageHeadCollection(fileSet, startupLog, errorLog, _pagePool); _versions = new VersionHeadCollection(startupLog, errorLog, database); _transactions = new TransactionHeadCollection(startupLog, errorLog, _pagePool); }
public FileEntityEntry Entry(object entity) { if (_fileEntityEntry == null) { _fileEntityEntry = new FileEntityEntry(); } //TODO: //Update marker var type = entity.GetType(); Type fileSetType = null; IFileSet o = null; var props = this.GetType().GetProperties(); foreach (var prop in props) { fileSetType = prop.PropertyType; var propType = prop.PropertyType; if (propType.GenericTypeArguments.Length == 0) { continue; } var gen_type = propType.GenericTypeArguments[0]; var ret_type = gen_type.GetType(); if (gen_type == type) { o = prop.GetValue(this) as IFileSet; break; } } if (o != null) { var name = type.Name; var idPropInfo = type.GetProperty(type.Name + "Id"); if (idPropInfo == null) { idPropInfo = type.GetProperty("Id"); } if (idPropInfo == null) { throw new ArgumentException("Type " + name + " don't have any Id name"); } var id = idPropInfo.GetValue(entity); object itemFromSet = null; foreach (var item in o) { var idcmp = idPropInfo.GetValue(item); if (Comparer.Default.Compare(idcmp, id) == 0) { itemFromSet = item; break; } } //if (itemFromSet != null) //{ // fileSetType.GetMethod("Remove").Invoke(o, new object[] { itemFromSet }); // fileSetType.GetMethod("Add").Invoke(o, new object[] { entity }); //} } return(_fileEntityEntry); }
private static void PrintExcludes(IFileSet fileSet) { foreach (var item in fileSet.ExcludedDirectories) Console.WriteLine("Excluded directory: " + item); foreach (var item in fileSet.ExcludedFiles) Console.WriteLine("Excluded file: " + item); }
IPageStore IPageStoreFactory.Open(IFileSet fileSet) { return(new PageStore(_pageCache, _startUpLog)); }
public ApplyAttributes(IFileSet fileSet) { FileSet = fileSet; }
/// <summary>Initializes a new instance of the <see cref="WebGreaseSectionKey"/> class.</summary> /// <param name="context">The context.</param> /// <param name="category">The id.</param> /// <param name="cacheVarByContentItem">The cache var by content item.</param> /// <param name="cacheVarBySetting">The cache var by setting.</param> /// <param name="cacheVarByFileSet">The cache var by file set.</param> /// <param name="uniqueKey">The unique Key.</param> public WebGreaseSectionKey(IWebGreaseContext context, string category, ContentItem cacheVarByContentItem, object cacheVarBySetting, IFileSet cacheVarByFileSet, string uniqueKey = null) { this.Category = category; this.Value = uniqueKey; if (string.IsNullOrWhiteSpace(uniqueKey)) { var varyByFiles = new List <CacheVaryByFile>(); var varyBySettings = new List <string>(); if (cacheVarByContentItem != null) { varyByFiles.Add(CacheVaryByFile.FromFile(context, cacheVarByContentItem)); varyBySettings.Add(cacheVarByContentItem.ResourcePivotKeys.ToJson()); } if (cacheVarByFileSet != null) { varyBySettings.Add(cacheVarByFileSet.ToJson()); } if (context.Configuration.Overrides != null) { varyBySettings.Add(context.Configuration.Overrides.UniqueKey); } varyBySettings.Add(cacheVarBySetting.ToJson(true)); this.Value = CacheSectionFileVersionKey + Delimiter + category + Delimiter + string.Join(Delimiter, varyByFiles.Select(vbf => vbf.Hash).Concat(varyBySettings)); } }
/// <summary>The should ignore output extensions.</summary> /// <param name="fileSet">The file set.</param> /// <returns>The <see cref="bool"/>.</returns> private bool ShouldIgnoreOutputExtensions(IFileSet fileSet) { return(this.outputExtensions.Any() && !this.outputExtensions.Any(outputExtension => fileSet.Output.EndsWith(outputExtension, StringComparison.OrdinalIgnoreCase))); }
public void should_roll_back_uncommitted_transactions_on_restart() { _fileSet = new FileSet( new IDataFile[] { new DataFile(_dataFileInfo1, _pageSize, _startUpLog), new DataFile(_dataFileInfo2, _pageSize, _startUpLog) }, new ILogFile[] { new LogFile(_logFileInfo1, true, _startUpLog), new LogFile(_logFileInfo2, true, _startUpLog) }, _pagePoolFactory, _startUpLog); var databaseFactory = SetupMock <IDatabaseFactory>(); var pageStoreFactory = SetupMock <IPageStoreFactory>(); var pageStore = pageStoreFactory.Open(_fileSet); var database = databaseFactory.Open(pageStore); var transaction1 = database.BeginTransaction(null); _fileSet.Write( transaction1, new[] { new PageUpdate { SequenceNumber = 0, PageNumber = 1, Offset = 20, Data = new byte[] { 1, 2, 3 } } }); database.CommitTransaction(transaction1); var transaction2 = database.BeginTransaction(null); _fileSet.Write( transaction2, new[] { new PageUpdate { SequenceNumber = 0, PageNumber = 1, Offset = 25, Data = new byte[] { 4, 5, 6 } } }); database.CommitTransaction(transaction2); var transaction3 = database.BeginTransaction(null); _fileSet.Write( transaction3, new[] { new PageUpdate { SequenceNumber = 0, PageNumber = 1, Offset = 5, Data = new byte[] { 7, 8, 9 } }, new PageUpdate { SequenceNumber = 0, PageNumber = 1, Offset = 30, Data = new byte[] { 10, 11, 12 } } }); database.CommitTransaction(transaction3); // Before the transaction is committed the page should be in its original state using (var originalPage = _pagePool.Get(1)) { _fileSet.Read(originalPage); for (var i = 0; i < _pageSize; i++) { Assert.AreEqual(0, originalPage.Data[i]); } } // Commit transactions to the log files but do not update the data files _fileSet.CommitTransaction(transaction1).Wait(); _fileSet.CommitTransaction(transaction2).Wait(); _fileSet.CommitTransaction(transaction3).Wait(); // Shut down and close all the files _fileSet.Dispose(); // Reopen all of the files _fileSet = new FileSet( new IDataFile[] { new DataFile(_dataFileInfo1, _startUpLog), new DataFile(_dataFileInfo2, _startUpLog) }, new ILogFile[] { new LogFile(_logFileInfo1, false, _startUpLog), new LogFile(_logFileInfo2, false, _startUpLog) }, _pagePoolFactory, _startUpLog); // Roll back all transactions ulong[] mustRollBackVersions; ulong[] canRollForwardVersions; _fileSet.GetIncompleteTransactions(out mustRollBackVersions, out canRollForwardVersions); _fileSet.RollBack(mustRollBackVersions); _fileSet.RollBack(canRollForwardVersions); // After rolling back the page should be unchanged in the data file using (var newPage = _pagePool.Get(1)) { _fileSet.Read(newPage); for (var i = 0; i < _pageSize; i++) { Assert.AreEqual(0, newPage.Data[i]); } } // There should be no incomplete transactions now _fileSet.GetIncompleteTransactions(out mustRollBackVersions, out canRollForwardVersions); Assert.AreEqual(0, mustRollBackVersions.Length); Assert.AreEqual(0, canRollForwardVersions.Length); }
/// <summary>Determines if the fileset should be temporary ignored.</summary> /// <param name="fileSet">The file set.</param> /// <returns>The <see cref="bool"/>.</returns> public bool ShouldIgnore(IFileSet fileSet) { return(fileSet != null && !string.IsNullOrWhiteSpace(fileSet.Output) && (this.ShouldIgnoreOutputs(fileSet) || this.ShouldIgnoreOutputExtensions(fileSet))); }
IPageCache IPageCacheFactory.Create(IDatabase database, IFileSet fileSet) { return(new PageCache(fileSet, database, _pagePoolFactory, _startUpLog, _errorLog)); }
protected AbstractCopyToDirectory(IFileSet fileSet, string directoryFullName) { FileSet = fileSet; DirectoryFullName = directoryFullName; ToDirectory = new DirectoryInfo(directoryFullName); }
public MoveToDirectory(IFileSet fileSet, string directoryFullName) : base(fileSet, directoryFullName) { }
public void should_write_multiple_files_within_transaction() { _fileSet = new FileSet( new IDataFile[] { new DataFile(_dataFileInfo1, _pageSize, _startUpLog), new DataFile(_dataFileInfo2, _pageSize, _startUpLog) }, new ILogFile[] { new LogFile(_logFileInfo1, true, _startUpLog), new LogFile(_logFileInfo2, true, _startUpLog) }, _pagePoolFactory, _startUpLog); var databaseFactory = SetupMock <IDatabaseFactory>(); var pageStoreFactory = SetupMock <IPageStoreFactory>(); var pageStore = pageStoreFactory.Open(_fileSet); var database = databaseFactory.Open(pageStore); var transaction1 = database.BeginTransaction(null); var transaction2 = database.BeginTransaction(null); var transaction3 = database.BeginTransaction(null); _fileSet.Write( transaction1, new[] { new PageUpdate { SequenceNumber = 0, PageNumber = 1, Offset = 20, Data = new byte[] { 1, 2, 3 } } }); _fileSet.Write( transaction2, new[] { new PageUpdate { SequenceNumber = 0, PageNumber = 1, Offset = 25, Data = new byte[] { 4, 5, 6 } } }); _fileSet.Write( transaction3, new[] { new PageUpdate { SequenceNumber = 0, PageNumber = 1, Offset = 5, Data = new byte[] { 7, 8, 9 } }, new PageUpdate { SequenceNumber = 0, PageNumber = 1, Offset = 30, Data = new byte[] { 10, 11, 12 } } }); // Before the transaction is committed the page should be in its // original state using (var originalPage = _pagePool.Get(1)) { _fileSet.Read(originalPage); for (var i = 0; i < _pageSize; i++) { Assert.AreEqual(0, originalPage.Data[i]); } _fileSet.CommitTransaction(transaction1).Wait(); _fileSet.CommitTransaction(transaction2).Wait(); _fileSet.CommitTransaction(transaction3).Wait(); _fileSet.FinalizeTransaction(transaction1).Wait(); _fileSet.FinalizeTransaction(transaction2).Wait(); _fileSet.FinalizeTransaction(transaction3).Wait(); // After commiting and finalizing the transactions the page should be // changed in the data file using (var newPage = _pagePool.Get(1)) { _fileSet.Read(newPage); Assert.AreEqual(1, newPage.Data[20]); Assert.AreEqual(2, newPage.Data[21]); Assert.AreEqual(3, newPage.Data[22]); Assert.AreEqual(4, newPage.Data[25]); Assert.AreEqual(5, newPage.Data[26]); Assert.AreEqual(6, newPage.Data[27]); Assert.AreEqual(7, newPage.Data[5]); Assert.AreEqual(8, newPage.Data[6]); Assert.AreEqual(9, newPage.Data[7]); Assert.AreEqual(10, newPage.Data[30]); Assert.AreEqual(11, newPage.Data[31]); Assert.AreEqual(12, newPage.Data[32]); } // Anyone with a reference to the original page should not see any change for (var i = 0; i < _pageSize; i++) { Assert.AreEqual(0, originalPage.Data[i]); } } }
public MongoDbContext(string connectionString, string dbName) { var concreteType = this.GetType(); this.db = dbName; this.innerContext = new MongoDB.Driver.MongoClient(connectionString); var entitySets = new List <IEntitySet>(); var entitySetProperties = concreteType.GetProperties() .Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(IEntitySet <,>)); foreach (var prop in entitySetProperties) { var keyType = prop.PropertyType.GetGenericArguments()[0]; var entityType = prop.PropertyType.GetGenericArguments()[1]; var createEntitySetMethod = typeof(EntitySet <,>).MakeGenericType(new[] { keyType, entityType }) .GetConstructor( System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, new[] { typeof(MongoDbContext), typeof(string) }, null); var entitySet = createEntitySetMethod.Invoke(new object[] { this, this.db }); prop.SetValue(this, entitySet, new object[] { }); entitySets.Add(entitySet as IEntitySet); } this.entitySets = entitySets; var knownTypesResolverAttrs = concreteType.GetCustomAttributes(typeof(KnownDataTypesResolverAttribute)); foreach (KnownDataTypesResolverAttribute knownTypesResolverAttr in knownTypesResolverAttrs) { foreach (var type in knownTypesResolverAttr.TypesToUseForSearchingAssemblies) { var concreteEntityTypes = ContextUtils.FindInheritingTypes(type.Assembly, entitySets.Select(s => s.EntityType)); RegisterKnownTypes(concreteEntityTypes); } } var knownTypesAttrs = concreteType.GetCustomAttributes(typeof(KnownDataTypesAttribute)); foreach (KnownDataTypesAttribute knownTypesAttr in knownTypesAttrs) { RegisterKnownTypes(knownTypesAttr.Types); } var fileSetProperty = concreteType.GetProperties() .Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(IFileSet <>)) .SingleOrDefault(); if (fileSetProperty != null) { var keyType = fileSetProperty.PropertyType.GetGenericArguments()[0]; var createFileSetMethod = typeof(FileSet <>).MakeGenericType(new[] { keyType }) .GetConstructor( System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, new[] { typeof(MongoDbContext), typeof(string) }, null); var fileSet = createFileSetMethod.Invoke(new object[] { this, this.db }); fileSetProperty.SetValue(this, fileSet, new object[] { }); this.fileSet = fileSet as IFileSet; } }
public FileSetWatcher(IFileSet fileSet, ILogger logger) { _fileSet = fileSet; _fileWatcher = new FileWatcher(logger); }