private static int GetBlockSize(NuCacheSettings settings) { var blockSize = 4096; var appSetting = settings.BTreeBlockSize; if (!appSetting.HasValue) { return(blockSize); } blockSize = appSetting.Value; var bit = 0; for (var i = blockSize; i != 1; i >>= 1) { bit++; } if (1 << bit != blockSize) { throw new ConfigurationException($"Invalid block size value \"{blockSize}\": must be a power of two."); } if (blockSize < 512 || blockSize > 65536) { throw new ConfigurationException($"Invalid block size value \"{blockSize}\": must be >= 512 and <= 65536."); } return(blockSize); }
protected virtual void ComposeSettings() { var contentSettings = new ContentSettings(); var coreDebugSettings = new CoreDebugSettings(); var globalSettings = new GlobalSettings(); var nuCacheSettings = new NuCacheSettings(); var requestHandlerSettings = new RequestHandlerSettings(); var userPasswordConfigurationSettings = new UserPasswordConfigurationSettings(); var webRoutingSettings = new WebRoutingSettings(); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(coreDebugSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(globalSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(nuCacheSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(requestHandlerSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(webRoutingSettings)); }
protected override IPublishedSnapshotService CreatePublishedSnapshotService(GlobalSettings globalSettings = null) { var options = new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }; var publishedSnapshotAccessor = new UmbracoContextPublishedSnapshotAccessor(Current.UmbracoContextAccessor); var runtimeStateMock = new Mock <IRuntimeState>(); runtimeStateMock.Setup(x => x.Level).Returns(() => RuntimeLevel.Run); var contentTypeFactory = Factory.GetRequiredService <IPublishedContentTypeFactory>(); var documentRepository = Mock.Of <IDocumentRepository>(); var mediaRepository = Mock.Of <IMediaRepository>(); var memberRepository = Mock.Of <IMemberRepository>(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); var typeFinder = TestHelper.GetTypeFinder(); var nuCacheSettings = new NuCacheSettings(); var lifetime = new Mock <IUmbracoApplicationLifetime>(); var repository = new NuCacheContentRepository(ScopeProvider, AppCaches.Disabled, Mock.Of <ILogger <NuCacheContentRepository> >(), memberRepository, documentRepository, mediaRepository, Mock.Of <IShortStringHelper>(), new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider(ShortStringHelper) })); var snapshotService = new PublishedSnapshotService( options, null, ServiceContext, contentTypeFactory, publishedSnapshotAccessor, Mock.Of <IVariationContextAccessor>(), base.ProfilingLogger, NullLoggerFactory.Instance, ScopeProvider, new NuCacheContentService(repository, ScopeProvider, NullLoggerFactory.Instance, Mock.Of <IEventMessagesFactory>()), DefaultCultureAccessor, Microsoft.Extensions.Options.Options.Create(globalSettings ?? new GlobalSettings()), Factory.GetRequiredService <IEntityXmlSerializer>(), new NoopPublishedModelFactory(), hostingEnvironment, Microsoft.Extensions.Options.Options.Create(nuCacheSettings)); return(snapshotService); }
public PublishedSnapshotService( PublishedSnapshotServiceOptions options, ISyncBootStateAccessor syncBootStateAccessor, IMainDom mainDom, ServiceContext serviceContext, IPublishedContentTypeFactory publishedContentTypeFactory, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IProfilingLogger profilingLogger, ILoggerFactory loggerFactory, IScopeProvider scopeProvider, INuCacheContentService publishedContentService, IDefaultCultureAccessor defaultCultureAccessor, IOptions <GlobalSettings> globalSettings, IPublishedModelFactory publishedModelFactory, IHostingEnvironment hostingEnvironment, IOptions <NuCacheSettings> config, ContentDataSerializer contentDataSerializer) { _options = options; _syncBootStateAccessor = syncBootStateAccessor; _mainDom = mainDom; _serviceContext = serviceContext; _publishedContentTypeFactory = publishedContentTypeFactory; _publishedSnapshotAccessor = publishedSnapshotAccessor; _variationContextAccessor = variationContextAccessor; _profilingLogger = profilingLogger; _loggerFactory = loggerFactory; _logger = _loggerFactory.CreateLogger <PublishedSnapshotService>(); _scopeProvider = scopeProvider; _publishedContentService = publishedContentService; _defaultCultureAccessor = defaultCultureAccessor; _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; _contentDataSerializer = contentDataSerializer; _config = config.Value; _publishedModelFactory = publishedModelFactory; }
public static BPlusTree <int, ContentNodeKit> GetTree(string filepath, bool exists, NuCacheSettings settings, ContentDataSerializer?contentDataSerializer = null) { var keySerializer = new PrimitiveSerializer(); var valueSerializer = new ContentNodeKitSerializer(contentDataSerializer); var options = new BPlusTree <int, ContentNodeKit> .OptionsV2(keySerializer, valueSerializer) { CreateFile = exists ? CreatePolicy.IfNeeded : CreatePolicy.Always, FileName = filepath, // read or write but do *not* keep in memory CachePolicy = CachePolicy.None, // default is 4096, min 2^9 = 512, max 2^16 = 64K FileBlockSize = GetBlockSize(settings), //HACK: Forces FileOptions to be WriteThrough here: https://github.com/mamift/CSharpTest.Net.Collections/blob/9f93733b3af7ee0e2de353e822ff54d908209b0b/src/CSharpTest.Net.Collections/IO/TransactedCompoundFile.cs#L316-L327, // as the reflection uses otherwise will failed in .NET Core as the "_handle" field in FileStream is renamed to "_fileHandle". StoragePerformance = StoragePerformance.CommitToDisk, // other options? }; var tree = new BPlusTree <int, ContentNodeKit>(options); // anything? //btree. return(tree); }
private void Init() { var factory = Mock.Of <IServiceProvider>(); Current.Factory = factory; var publishedModelFactory = new NoopPublishedModelFactory(); Mock.Get(factory).Setup(x => x.GetService(typeof(IPublishedModelFactory))).Returns(publishedModelFactory); Mock.Get(factory).Setup(x => x.GetService(typeof(IPublishedValueFallback))).Returns(new NoopPublishedValueFallback()); // create a content node kit var kit = new ContentNodeKit { ContentTypeId = 2, Node = new ContentNode(1, Guid.NewGuid(), 0, "-1,1", 0, -1, DateTime.Now, 0), DraftData = new ContentData { Name = "It Works2!", Published = false, TemplateId = 0, VersionId = 2, VersionDate = DateTime.Now, WriterId = 0, Properties = new Dictionary <string, PropertyData[]> { { "prop", new[] { new PropertyData { Culture = "", Segment = "", Value = "val2" }, new PropertyData { Culture = "fr-FR", Segment = "", Value = "val-fr2" }, new PropertyData { Culture = "en-UK", Segment = "", Value = "val-uk2" }, new PropertyData { Culture = "dk-DA", Segment = "", Value = "val-da2" }, new PropertyData { Culture = "de-DE", Segment = "", Value = "val-de2" } } } }, CultureInfos = new Dictionary <string, CultureVariation> { // draft data = everything, and IsDraft indicates what's edited { "fr-FR", new CultureVariation { Name = "name-fr2", IsDraft = true, Date = new DateTime(2018, 01, 03, 01, 00, 00) } }, { "en-UK", new CultureVariation { Name = "name-uk2", IsDraft = true, Date = new DateTime(2018, 01, 04, 01, 00, 00) } }, { "dk-DA", new CultureVariation { Name = "name-da2", IsDraft = true, Date = new DateTime(2018, 01, 05, 01, 00, 00) } }, { "de-DE", new CultureVariation { Name = "name-de1", IsDraft = false, Date = new DateTime(2018, 01, 02, 01, 00, 00) } } } }, PublishedData = new ContentData { Name = "It Works1!", Published = true, TemplateId = 0, VersionId = 1, VersionDate = DateTime.Now, WriterId = 0, Properties = new Dictionary <string, PropertyData[]> { { "prop", new[] { new PropertyData { Culture = "", Segment = "", Value = "val1" }, new PropertyData { Culture = "fr-FR", Segment = "", Value = "val-fr1" }, new PropertyData { Culture = "en-UK", Segment = "", Value = "val-uk1" } } } }, CultureInfos = new Dictionary <string, CultureVariation> { // published data = only what's actually published, and IsDraft has to be false { "fr-FR", new CultureVariation { Name = "name-fr1", IsDraft = false, Date = new DateTime(2018, 01, 01, 01, 00, 00) } }, { "en-UK", new CultureVariation { Name = "name-uk1", IsDraft = false, Date = new DateTime(2018, 01, 02, 01, 00, 00) } }, { "de-DE", new CultureVariation { Name = "name-de1", IsDraft = false, Date = new DateTime(2018, 01, 02, 01, 00, 00) } } } } }; // create a data source for NuCache var dataSource = new TestDataSource(kit); _contentNestedDataSerializerFactory = new JsonContentNestedDataSerializerFactory(); var runtime = Mock.Of <IRuntimeState>(); Mock.Get(runtime).Setup(x => x.Level).Returns(RuntimeLevel.Run); var serializer = new ConfigurationEditorJsonSerializer(); // create data types, property types and content types var dataType = new DataType(new VoidEditor("Editor", Mock.Of <IDataValueEditorFactory>()), serializer) { Id = 3 }; var dataTypes = new[] { dataType }; _propertyType = new PropertyType(TestHelper.ShortStringHelper, "Umbraco.Void.Editor", ValueStorageType.Nvarchar) { Alias = "prop", DataTypeId = 3, Variations = ContentVariation.Culture }; _contentType = new ContentType(TestHelper.ShortStringHelper, -1) { Id = 2, Alias = "alias-ct", Variations = ContentVariation.Culture }; _contentType.AddPropertyType(_propertyType); var contentTypes = new[] { _contentType }; var contentTypeService = new Mock <IContentTypeService>(); contentTypeService.Setup(x => x.GetAll()).Returns(contentTypes); contentTypeService.Setup(x => x.GetAll(It.IsAny <int[]>())).Returns(contentTypes); var mediaTypeService = new Mock <IMediaTypeService>(); mediaTypeService.Setup(x => x.GetAll()).Returns(Enumerable.Empty <IMediaType>()); mediaTypeService.Setup(x => x.GetAll(It.IsAny <int[]>())).Returns(Enumerable.Empty <IMediaType>()); var contentTypeServiceBaseFactory = new Mock <IContentTypeBaseServiceProvider>(); contentTypeServiceBaseFactory.Setup(x => x.For(It.IsAny <IContentBase>())).Returns(contentTypeService.Object); var dataTypeService = Mock.Of <IDataTypeService>(); Mock.Get(dataTypeService).Setup(x => x.GetAll()).Returns(dataTypes); // create a service context var serviceContext = ServiceContext.CreatePartial( dataTypeService: dataTypeService, memberTypeService: Mock.Of <IMemberTypeService>(), memberService: Mock.Of <IMemberService>(), contentTypeService: contentTypeService.Object, mediaTypeService: mediaTypeService.Object, localizationService: Mock.Of <ILocalizationService>(), domainService: Mock.Of <IDomainService>() ); // create a scope provider var scopeProvider = Mock.Of <IScopeProvider>(); Mock.Get(scopeProvider) .Setup(x => x.CreateScope( It.IsAny <IsolationLevel>(), It.IsAny <RepositoryCacheMode>(), It.IsAny <IEventDispatcher>(), It.IsAny <bool?>(), It.IsAny <bool>(), It.IsAny <bool>())) .Returns(Mock.Of <IScope>); // create a published content type factory var contentTypeFactory = new PublishedContentTypeFactory( publishedModelFactory, new PropertyValueConverterCollection(Array.Empty <IPropertyValueConverter>()), dataTypeService); // create a variation accessor _variationAccesor = new TestVariationContextAccessor(); var typeFinder = TestHelper.GetTypeFinder(); var globalSettings = new GlobalSettings(); var nuCacheSettings = new NuCacheSettings(); // at last, create the complete NuCache snapshot service! var options = new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }; _snapshotService = new PublishedSnapshotService( options, null, serviceContext, contentTypeFactory, new TestPublishedSnapshotAccessor(), _variationAccesor, Mock.Of <IProfilingLogger>(), NullLoggerFactory.Instance, scopeProvider, dataSource, new TestDefaultCultureAccessor(), Microsoft.Extensions.Options.Options.Create(globalSettings), Mock.Of <IEntityXmlSerializer>(), publishedModelFactory, TestHelper.GetHostingEnvironment(), Microsoft.Extensions.Options.Options.Create(nuCacheSettings), _contentNestedDataSerializerFactory); // invariant is the current default _variationAccesor.VariationContext = new VariationContext(); Mock.Get(factory).Setup(x => x.GetService(typeof(IVariationContextAccessor))).Returns(_variationAccesor); }