protected override void Dispose(bool disposing) { if (disposing) { NodeTypeDependency.Unsubscribe(Changed); } }
private void Changed(object sender, EventArgs <int> e) { if (NodeTypeDependency.IsChanged(e.Data, _nodeTypeId)) { OnChanged(null); } }
private static void RegisterSchema(SchemaEditor origSchema, SchemaEditor newSchema, SchemaWriter schemaWriter) { using (var op = SnTrace.Database.StartOperation("Write storage schema modifications.")) { // Ensure transaction encapsulation bool isLocalTransaction = !TransactionScope.IsActive; if (isLocalTransaction) { TransactionScope.Begin(); } try { List <PropertySet> modifiedPropertySets = new List <PropertySet>(); schemaWriter.Open(); WriteSchemaModifications(origSchema, newSchema, schemaWriter, modifiedPropertySets); foreach (PropertySet modifiedPropertySet in modifiedPropertySets) { NodeTypeDependency.FireChanged(modifiedPropertySet.Id); } schemaWriter.Close(); if (isLocalTransaction) { TransactionScope.Commit(); } ActiveSchema.Reset(); op.Successful = true; } catch (Exception ex) { SnLog.WriteException(ex, null, EventId.RepositoryRuntime); throw new SchemaEditorCommandException("Error during schema registration.", ex); } finally { IDisposable unmanagedWriter = schemaWriter as IDisposable; if (unmanagedWriter != null) { unmanagedWriter.Dispose(); } try { if (isLocalTransaction && TransactionScope.IsActive) { TransactionScope.Rollback(); } } catch (Exception ex2) { // This catch block will handle any errors that may have occurred // on the server that would cause the rollback to fail, such as // a closed connection (MSDN). const string msg = "Error during schema transaction rollback."; SnLog.WriteException(ex2, msg, EventId.RepositoryRuntime); throw new SchemaEditorCommandException(msg, ex2); } } } }
private string InsertCacheWithTypeDependency(Node node) { var cacheKey = "NodeData." + node.VersionId; var dependencies = new NodeTypeDependency(node.NodeTypeId); Cache.Insert(cacheKey, node.Data, dependencies); return(cacheKey); }
private static void RegisterSchema(SchemaEditor origSchema, SchemaEditor newSchema, SchemaWriter schemaWriter) { if (schemaWriter.CanWriteDifferences) { using (var op = SnTrace.Database.StartOperation("Write storage schema modifications.")) { try { var modifiedPropertySets = new List <PropertySet>(); schemaWriter.Open(); WriteSchemaModifications(origSchema, newSchema, schemaWriter, modifiedPropertySets); foreach (var modifiedPropertySet in modifiedPropertySets) { NodeTypeDependency.FireChanged(modifiedPropertySet.Id); } schemaWriter.Close(); ActiveSchema.Reset(); op.Successful = true; } catch (Exception ex) { SnLog.WriteException(ex, null, EventId.RepositoryRuntime); throw new SchemaEditorCommandException("Error during schema registration.", ex); } finally { if (schemaWriter is IDisposable unmanagedWriter) { unmanagedWriter.Dispose(); } } } } else { using (var op = SnTrace.Database.StartOperation("Update storage schema.")) { var modifiedPropertySetIds = GetModifiedPropertySetIds(origSchema, newSchema); schemaWriter.WriteSchemaAsync(newSchema.ToRepositorySchemaData()).GetAwaiter().GetResult(); ActiveSchema.Reset(); foreach (var id in modifiedPropertySetIds) { NodeTypeDependency.FireChanged(id); } op.Successful = true; } } }
public NodeTypeChangeMonitor(int nodeTypeId) { _nodeTypeId = nodeTypeId; try { NodeTypeDependency.Subscribe(Changed); } finally { InitializationComplete(); } }
protected static void FireChanged() { var nodeType = ActiveSchema.NodeTypes[typeof(T).Name]; // It is possible that the nodetype is not registered yet (for // example during initial import). if (nodeType != null) { NodeTypeDependency.FireChanged(nodeType.Id); } else { SnTrace.System.Write("TreeCache: Unknown content type: {0}.", typeof(T).Name); } }
public void Cache_Builtin_TypeDependency() { Test((builder) => { builder.UseCacheProvider(new SnMemoryCache()); }, () => { var cache = DistributedApplication.Cache; var root = CreateTestFolder(Repository.Root); // create node1 and cache it with it own NodeIdDependency var folder1 = CreateTestFolder(root, true); var file11 = CreateTestFile(folder1); var folder11 = CreateTestFolder(folder1); var file111 = CreateTestFile(folder11); cache.Reset(); var rootKey = InsertCacheWithTypeDependency(cache, root); var folder1Key = InsertCacheWithTypeDependency(cache, folder1); var file11Key = InsertCacheWithTypeDependency(cache, file11); var folder11Key = InsertCacheWithTypeDependency(cache, folder11); var file111Key = InsertCacheWithTypeDependency(cache, file111); // pre-check: all nodes are in the cache Assert.IsTrue(IsInCache(rootKey)); Assert.IsTrue(IsInCache(folder1Key)); Assert.IsTrue(IsInCache(file11Key)); Assert.IsTrue(IsInCache(folder11Key)); Assert.IsTrue(IsInCache(file111Key)); // TEST: Remove the folder type tree var before = WhatIsInTheCache(cache); foreach (var nodeType in NodeType.GetByName("Folder").GetAllTypes()) { NodeTypeDependency.FireChanged(nodeType.Id); } var after = WhatIsInTheCache(cache); // check: all folders are removed Assert.IsFalse(IsInCache(rootKey)); Assert.IsFalse(IsInCache(folder1Key)); Assert.IsTrue(IsInCache(file11Key)); Assert.IsFalse(IsInCache(folder11Key)); Assert.IsTrue(IsInCache(file111Key)); }); }
public void Cache_Builtin_TypeDependency() { Test2((services) => { services.AddSingleton <ISnCache, SnMemoryCache>(); }, () => { var root = CreateTestFolder(Repository.Root); // create node1 and cache it with it own NodeIdDependency var folder1 = CreateTestFolder(root, true); var file11 = CreateTestFile(folder1); var folder11 = CreateTestFolder(folder1); var file111 = CreateTestFile(folder11); Cache.Reset(); var rootKey = InsertCacheWithTypeDependency(root); var folder1Key = InsertCacheWithTypeDependency(folder1); var file11Key = InsertCacheWithTypeDependency(file11); var folder11Key = InsertCacheWithTypeDependency(folder11); var file111Key = InsertCacheWithTypeDependency(file111); // pre-check: all nodes are in the cache Assert.IsTrue(IsInCache(rootKey)); Assert.IsTrue(IsInCache(folder1Key)); Assert.IsTrue(IsInCache(file11Key)); Assert.IsTrue(IsInCache(folder11Key)); Assert.IsTrue(IsInCache(file111Key)); // TEST: Remove the folder type tree var before = WhatIsInTheCache(); foreach (var nodeType in NodeType.GetByName("Folder").GetAllTypes()) { NodeTypeDependency.FireChanged(nodeType.Id); } var after = WhatIsInTheCache(); // check: all folders are removed Assert.IsFalse(IsInCache(rootKey)); Assert.IsFalse(IsInCache(folder1Key)); Assert.IsTrue(IsInCache(file11Key)); Assert.IsFalse(IsInCache(folder11Key)); Assert.IsTrue(IsInCache(file111Key)); }); }
private static void RegisterSchema(SchemaEditor origSchema, SchemaEditor newSchema, SchemaWriter schemaWriter) { using (var traceOperation = Logger.TraceOperation("Write storage schema modifications.")) { // Ensure transaction encapsulation bool isLocalTransaction = !TransactionScope.IsActive; if (isLocalTransaction) { TransactionScope.Begin(); } try { List <PropertySet> modifiedPropertySets = new List <PropertySet>(); schemaWriter.Open(); WriteSchemaModifications(origSchema, newSchema, schemaWriter, modifiedPropertySets); foreach (PropertySet modifiedPropertySet in modifiedPropertySets) { NodeTypeDependency.FireChanged(modifiedPropertySet.Id); } schemaWriter.Close(); if (isLocalTransaction) { TransactionScope.Commit(); } ActiveSchema.Reset(); traceOperation.IsSuccessful = true; } finally { IDisposable unmanagedWriter = schemaWriter as IDisposable; if (unmanagedWriter != null) { unmanagedWriter.Dispose(); } if (isLocalTransaction && TransactionScope.IsActive) { TransactionScope.Rollback(); } } } }