public void Initialize()
        {
            int defaultMaxNumberOfItemsToIndexInSingleBatch     = Environment.Is64BitProcess ? 128 * 1024 : 16 * 1024;
            int defaultInitialNumberOfItemsToIndexInSingleBatch = Environment.Is64BitProcess ? 512 : 256;

            var ravenSettings = new StronglyTypedRavenSettings(Settings);

            ravenSettings.Setup(defaultMaxNumberOfItemsToIndexInSingleBatch, defaultInitialNumberOfItemsToIndexInSingleBatch);

            // Important! this value is synchronized with the max sessions number in esent
            // since we cannot have more requests in the system than we have sessions for them
            // and we also need to allow sessions for background operations and for multi get requests
            MaxConcurrentServerRequests = ravenSettings.MaxConcurrentServerRequests.Value;

            MaxConcurrentMultiGetRequests = ravenSettings.MaxConcurrentMultiGetRequests.Value;
            if (ConcurrentMultiGetRequests == null)
            {
                ConcurrentMultiGetRequests = new SemaphoreSlim(MaxConcurrentMultiGetRequests);
            }

            MemoryLimitForIndexingInMB = ravenSettings.MemoryLimitForIndexing.Value;

            EncryptionKeyBitsPreference = ravenSettings.EncryptionKeyBitsPreference.Value;
            // Core settings
            MaxPageSize = ravenSettings.MaxPageSize.Value;

            MemoryCacheLimitMegabytes = ravenSettings.MemoryCacheLimitMegabytes.Value;

            MemoryCacheExpiration = ravenSettings.MemoryCacheExpiration.Value;

            MemoryCacheLimitPercentage = ravenSettings.MemoryCacheLimitPercentage.Value;

            MemoryCacheLimitCheckInterval = ravenSettings.MemoryCacheLimitCheckInterval.Value;

            // Discovery
            DisableClusterDiscovery = ravenSettings.DisableClusterDiscovery.Value;

            // TODO: Validate the cluster name. Valid names are only valid chars in documents IDs.
            ClusterName = ravenSettings.ClusterName.Value;

            ServerName = ravenSettings.ServerName.Value;

            MaxStepsForScript = ravenSettings.MaxStepsForScript.Value;
            AdditionalStepsForScriptBasedOnDocumentSize = ravenSettings.AdditionalStepsForScriptBasedOnDocumentSize.Value;

            // Index settings
            MaxIndexingRunLatency        = ravenSettings.MaxIndexingRunLatency.Value;
            MaxIndexWritesBeforeRecreate = ravenSettings.MaxIndexWritesBeforeRecreate.Value;

            PreventAutomaticSuggestionCreation = ravenSettings.PreventAutomaticSuggestionCreation.Value;

            DisablePerformanceCounters = ravenSettings.DisablePerformanceCounters.Value;

            PrewarmFacetsOnIndexingMaxAge   = ravenSettings.PrewarmFacetsOnIndexingMaxAge.Value;
            PrewarmFacetsSyncronousWaitTime = ravenSettings.PrewarmFacetsSyncronousWaitTime.Value;

            MaxNumberOfItemsToIndexInSingleBatch = ravenSettings.MaxNumberOfItemsToIndexInSingleBatch.Value;
            FlushIndexToDiskSizeInMb             = ravenSettings.FlushIndexToDiskSizeInMb.Value;

            var initialNumberOfItemsToIndexInSingleBatch = Settings["Raven/InitialNumberOfItemsToIndexInSingleBatch"];

            if (initialNumberOfItemsToIndexInSingleBatch != null)
            {
                InitialNumberOfItemsToIndexInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToIndexInSingleBatch),
                                                                    MaxNumberOfItemsToIndexInSingleBatch);
            }
            else
            {
                InitialNumberOfItemsToIndexInSingleBatch = MaxNumberOfItemsToIndexInSingleBatch == ravenSettings.MaxNumberOfItemsToIndexInSingleBatch.Default ?
                                                           defaultInitialNumberOfItemsToIndexInSingleBatch :
                                                           Math.Max(16, Math.Min(MaxNumberOfItemsToIndexInSingleBatch / 256, defaultInitialNumberOfItemsToIndexInSingleBatch));
            }
            AvailableMemoryForRaisingIndexBatchSizeLimit = ravenSettings.AvailableMemoryForRaisingIndexBatchSizeLimit.Value;

            MaxNumberOfItemsToReduceInSingleBatch     = ravenSettings.MaxNumberOfItemsToReduceInSingleBatch.Value;
            InitialNumberOfItemsToReduceInSingleBatch = MaxNumberOfItemsToReduceInSingleBatch == ravenSettings.MaxNumberOfItemsToReduceInSingleBatch.Default ?
                                                        defaultInitialNumberOfItemsToIndexInSingleBatch / 2 :
                                                        Math.Max(16, Math.Min(MaxNumberOfItemsToIndexInSingleBatch / 256, defaultInitialNumberOfItemsToIndexInSingleBatch / 2));

            NumberOfItemsToExecuteReduceInSingleStep = ravenSettings.NumberOfItemsToExecuteReduceInSingleStep.Value;

            var initialNumberOfItemsToReduceInSingleBatch = Settings["Raven/InitialNumberOfItemsToReduceInSingleBatch"];

            if (initialNumberOfItemsToReduceInSingleBatch != null)
            {
                InitialNumberOfItemsToReduceInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToReduceInSingleBatch),
                                                                     MaxNumberOfItemsToReduceInSingleBatch);
            }

            MaxNumberOfParallelIndexTasks = ravenSettings.MaxNumberOfParallelIndexTasks.Value;

            NewIndexInMemoryMaxBytes = ravenSettings.NewIndexInMemoryMaxMb.Value;

            MaxIndexCommitPointStoreTimeInterval = ravenSettings.MaxIndexCommitPointStoreTimeInterval.Value;

            MinIndexingTimeIntervalToStoreCommitPoint = ravenSettings.MinIndexingTimeIntervalToStoreCommitPoint.Value;

            MaxNumberOfStoredCommitPoints = ravenSettings.MaxNumberOfStoredCommitPoints.Value;

            // Data settings
            RunInMemory = ravenSettings.RunInMemory.Value;

            if (string.IsNullOrEmpty(DefaultStorageTypeName))
            {
                DefaultStorageTypeName = Settings["Raven/StorageTypeName"] ?? Settings["Raven/StorageEngine"] ?? "esent";
            }

            CreateAutoIndexesForAdHocQueriesIfNeeded = ravenSettings.CreateAutoIndexesForAdHocQueriesIfNeeded.Value;

            DatbaseOperationTimeout = ravenSettings.DatbaseOperationTimeout.Value;

            TimeToWaitBeforeRunningIdleIndexes     = ravenSettings.TimeToWaitBeforeRunningIdleIndexes.Value;
            TimeToWaitBeforeMarkingAutoIndexAsIdle = ravenSettings.TimeToWaitBeforeMarkingAutoIndexAsIdle.Value;

            TimeToWaitBeforeMarkingIdleIndexAsAbandoned = ravenSettings.TimeToWaitBeforeMarkingIdleIndexAsAbandoned.Value;
            TimeToWaitBeforeRunningAbandonedIndexes     = ravenSettings.TimeToWaitBeforeRunningAbandonedIndexes.Value;

            ResetIndexOnUncleanShutdown = ravenSettings.ResetIndexOnUncleanShutdown.Value;
            DisableInMemoryIndexing     = ravenSettings.DisableInMemoryIndexing.Value;

            SetupTransactionMode();

            DataDirectory = ravenSettings.DataDir.Value;

            var indexStoragePathSettingValue = ravenSettings.IndexStoragePath.Value;

            if (string.IsNullOrEmpty(indexStoragePathSettingValue) == false)
            {
                IndexStoragePath = indexStoragePathSettingValue;
            }

            MaxRecentTouchesToRemember = ravenSettings.MaxRecentTouchesToRemember.Value;

            // HTTP settings
            HostName = ravenSettings.HostName.Value;

            if (string.IsNullOrEmpty(DatabaseName))             // we only use this for root database
            {
                Port   = PortUtil.GetPort(ravenSettings.Port.Value);
                UseSsl = ravenSettings.UseSsl.Value;
            }

            SetVirtualDirectory();

            HttpCompression = ravenSettings.HttpCompression.Value;

            AccessControlAllowOrigin    = ravenSettings.AccessControlAllowOrigin.Value;
            AccessControlMaxAge         = ravenSettings.AccessControlMaxAge.Value;
            AccessControlAllowMethods   = ravenSettings.AccessControlAllowMethods.Value;
            AccessControlRequestHeaders = ravenSettings.AccessControlRequestHeaders.Value;

            AnonymousUserAccessMode = GetAnonymousUserAccessMode();

            RedirectStudioUrl = ravenSettings.RedirectStudioUrl.Value;

            DisableDocumentPreFetchingForIndexing = ravenSettings.DisableDocumentPreFetchingForIndexing.Value;

            MaxNumberOfItemsToPreFetchForIndexing = ravenSettings.MaxNumberOfItemsToPreFetchForIndexing.Value;

            // Misc settings
            WebDir = ravenSettings.WebDir.Value;

            PluginsDirectory = ravenSettings.PluginsDirectory.Value.ToFullPath();

            CompiledIndexCacheDirectory = ravenSettings.CompiledIndexCacheDirectory.Value.ToFullPath();

            var taskSchedulerType = ravenSettings.TaskScheduler.Value;

            if (taskSchedulerType != null)
            {
                var type = Type.GetType(taskSchedulerType);
                CustomTaskScheduler = (TaskScheduler)Activator.CreateInstance(type);
            }

            AllowLocalAccessWithoutAuthorization = ravenSettings.AllowLocalAccessWithoutAuthorization.Value;

            FetchingDocumentsFromDiskTimeoutInSeconds = ravenSettings.FetchingDocumentsFromDiskTimeoutInSeconds.Value;
            MaximumSizeAllowedToFetchFromStorageInMb  = ravenSettings.MaximumSizeAllowedToFetchFromStorageInMb.Value;

            PostInit();
        }
        public void Initialize()
        {
            int defaultMaxNumberOfItemsToIndexInSingleBatch     = Environment.Is64BitProcess ? 128 * 1024 : 16 * 1024;
            int defaultInitialNumberOfItemsToIndexInSingleBatch = Environment.Is64BitProcess ? 512 : 256;

            var ravenSettings = new StronglyTypedRavenSettings(Settings);

            ravenSettings.Setup(defaultMaxNumberOfItemsToIndexInSingleBatch, defaultInitialNumberOfItemsToIndexInSingleBatch);

            // Core settings
            MaxPageSize = ravenSettings.MaxPageSize.Value;

            MemoryCacheLimitMegabytes = ravenSettings.MemoryCacheLimitMegabytes.Value;

            MemoryCacheExpiration = ravenSettings.MemoryCacheExpiration.Value;

            MemoryCacheLimitPercentage = ravenSettings.MemoryCacheLimitPercentage.Value;

            MemoryCacheLimitCheckInterval = ravenSettings.MemoryCacheLimitCheckInterval.Value;

            // Discovery
            DisableClusterDiscovery = ravenSettings.DisableClusterDiscovery.Value;

            // TODO: Validate the cluster name. Valid names are only valid chars in documents IDs.
            ClusterName = ravenSettings.ClusterName.Value;

            ServerName = ravenSettings.ServerName.Value;

            MaxStepsForScript = ravenSettings.MaxStepsForScript.Value;
            AdditionalStepsForScriptBasedOnDocumentSize = ravenSettings.AdditionalStepsForScriptBasedOnDocumentSize.Value;

            // Index settings
            MaxIndexingRunLatency        = ravenSettings.MaxIndexingRunLatency.Value;
            MaxIndexWritesBeforeRecreate = ravenSettings.MaxIndexWritesBeforeRecreate.Value;

            MaxNumberOfItemsToIndexInSingleBatch = ravenSettings.MaxNumberOfItemsToIndexInSingleBatch.Value;

            var initialNumberOfItemsToIndexInSingleBatch = Settings["Raven/InitialNumberOfItemsToIndexInSingleBatch"];

            if (initialNumberOfItemsToIndexInSingleBatch != null)
            {
                InitialNumberOfItemsToIndexInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToIndexInSingleBatch),
                                                                    MaxNumberOfItemsToIndexInSingleBatch);
            }
            else
            {
                InitialNumberOfItemsToIndexInSingleBatch = MaxNumberOfItemsToIndexInSingleBatch == ravenSettings.MaxNumberOfItemsToIndexInSingleBatch.Default ?
                                                           defaultInitialNumberOfItemsToIndexInSingleBatch :
                                                           Math.Max(16, Math.Min(MaxNumberOfItemsToIndexInSingleBatch / 256, defaultInitialNumberOfItemsToIndexInSingleBatch));
            }
            AvailableMemoryForRaisingIndexBatchSizeLimit = ravenSettings.AvailableMemoryForRaisingIndexBatchSizeLimit.Value;



            MaxNumberOfItemsToReduceInSingleBatch     = ravenSettings.MaxNumberOfItemsToReduceInSingleBatch.Value;
            InitialNumberOfItemsToReduceInSingleBatch = MaxNumberOfItemsToReduceInSingleBatch == ravenSettings.MaxNumberOfItemsToReduceInSingleBatch.Default ?
                                                        defaultInitialNumberOfItemsToIndexInSingleBatch / 2 :
                                                        Math.Max(16, Math.Min(MaxNumberOfItemsToIndexInSingleBatch / 256, defaultInitialNumberOfItemsToIndexInSingleBatch / 2));

            NumberOfItemsToExecuteReduceInSingleStep = ravenSettings.NumberOfItemsToExecuteReduceInSingleStep.Value;

            var initialNumberOfItemsToReduceInSingleBatch = Settings["Raven/InitialNumberOfItemsToReduceInSingleBatch"];

            if (initialNumberOfItemsToReduceInSingleBatch != null)
            {
                InitialNumberOfItemsToReduceInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToReduceInSingleBatch),
                                                                     MaxNumberOfItemsToReduceInSingleBatch);
            }

            MaxNumberOfParallelIndexTasks = ravenSettings.MaxNumberOfParallelIndexTasks.Value;

            NewIndexInMemoryMaxBytes = ravenSettings.NewIndexInMemoryMaxMb.Value;

            MaxIndexCommitPointStoreTimeInterval = ravenSettings.MaxIndexCommitPointStoreTimeInterval.Value;

            MinIndexingTimeIntervalToStoreCommitPoint = ravenSettings.MinIndexingTimeIntervalToStoreCommitPoint.Value;

            MaxNumberOfStoredCommitPoints = ravenSettings.MaxNumberOfStoredCommitPoints.Value;

            // Data settings
            RunInMemory = ravenSettings.RunInMemory.Value;

            if (string.IsNullOrEmpty(DefaultStorageTypeName))
            {
                DefaultStorageTypeName = Settings["Raven/StorageTypeName"] ?? Settings["Raven/StorageEngine"] ?? "esent";
            }

            CreateAutoIndexesForAdHocQueriesIfNeeded = ravenSettings.CreateAutoIndexesForAdHocQueriesIfNeeded.Value;

            TimeToWaitBeforeRunningIdleIndexes     = ravenSettings.TimeToWaitBeforeRunningIdleIndexes.Value;
            TimeToWaitBeforeMarkingAutoIndexAsIdle = ravenSettings.TimeToWaitBeforeMarkingAutoIndexAsIdle.Value;

            TimeToWaitBeforeMarkingIdleIndexAsAbandoned = ravenSettings.TimeToWaitBeforeMarkingIdleIndexAsAbandoned.Value;
            TimeToWaitBeforeRunningAbandonedIndexes     = ravenSettings.TimeToWaitBeforeRunningAbandonedIndexes.Value;

            ResetIndexOnUncleanShutdown = ravenSettings.ResetIndexOnUncleanShutdown.Value;

            SetupTransactionMode();

            DataDirectory = ravenSettings.DataDir.Value;

            var indexStoragePathSettingValue = ravenSettings.IndexStoragePath.Value;

            if (string.IsNullOrEmpty(indexStoragePathSettingValue) == false)
            {
                IndexStoragePath = indexStoragePathSettingValue;
            }

            // HTTP settings
            HostName = ravenSettings.HostName.Value;

            if (string.IsNullOrEmpty(DatabaseName))             // we only use this for root database
            {
                Port   = PortUtil.GetPort(ravenSettings.Port.Value);
                UseSsl = ravenSettings.UseSsl.Value;
            }

            SetVirtualDirectory();

            HttpCompression = ravenSettings.HttpCompression.Value;

            AccessControlAllowOrigin    = ravenSettings.AccessControlAllowOrigin.Value;
            AccessControlMaxAge         = ravenSettings.AccessControlMaxAge.Value;
            AccessControlAllowMethods   = ravenSettings.AccessControlAllowMethods.Value;
            AccessControlRequestHeaders = ravenSettings.AccessControlRequestHeaders.Value;

            AnonymousUserAccessMode = GetAnonymousUserAccessMode();

            RedirectStudioUrl = ravenSettings.RedirectStudioUrl.Value;

            DisableDocumentPreFetchingForIndexing = ravenSettings.DisableDocumentPreFetchingForIndexing.Value;

            MaxNumberOfItemsToPreFetchForIndexing = ravenSettings.MaxNumberOfItemsToPreFetchForIndexing.Value;

            // Misc settings
            WebDir = ravenSettings.WebDir.Value;

            PluginsDirectory = ravenSettings.PluginsDirectory.Value.ToFullPath();

            CompiledIndexCacheDirectory = ravenSettings.CompiledIndexCacheDirectory.Value.ToFullPath();

            var taskSchedulerType = ravenSettings.TaskScheduler.Value;

            if (taskSchedulerType != null)
            {
                var type = Type.GetType(taskSchedulerType);
                CustomTaskScheduler = (TaskScheduler)Activator.CreateInstance(type);
            }

            AllowLocalAccessWithoutAuthorization = ravenSettings.AllowLocalAccessWithoutAuthorization.Value;

            PostInit();
        }
        public void Initialize()
        {
            int defaultMaxNumberOfItemsToIndexInSingleBatch     = Environment.Is64BitProcess ? 128 * 1024 : 64 * 1024;
            int defaultInitialNumberOfItemsToIndexInSingleBatch = Environment.Is64BitProcess ? 512 : 256;

            var ravenSettings = new StronglyTypedRavenSettings(Settings);

            ravenSettings.Setup(defaultMaxNumberOfItemsToIndexInSingleBatch, defaultInitialNumberOfItemsToIndexInSingleBatch);

            // Core settings
            MaxPageSize = ravenSettings.MaxPageSize.Value;

            MemoryCacheLimitMegabytes = ravenSettings.MemoryCacheLimitMegabytes.Value;

            MemoryCacheExpiration = ravenSettings.MemoryCacheExpiration.Value;

            MemoryCacheLimitPercentage = ravenSettings.MemoryCacheLimitPercentage.Value;

            MemoryCacheLimitCheckInterval = ravenSettings.MemoryCacheLimitCheckInterval.Value;

            // Index settings
            MaxIndexingRunLatency = ravenSettings.MaxIndexingRunLatency.Value;

            MaxNumberOfItemsToIndexInSingleBatch = ravenSettings.MaxNumberOfItemsToIndexInSingleBatch.Value;

            var initialNumberOfItemsToIndexInSingleBatch = Settings["Raven/InitialNumberOfItemsToIndexInSingleBatch"];

            if (initialNumberOfItemsToIndexInSingleBatch != null)
            {
                InitialNumberOfItemsToIndexInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToIndexInSingleBatch),
                                                                    MaxNumberOfItemsToIndexInSingleBatch);
            }
            else
            {
                InitialNumberOfItemsToIndexInSingleBatch = MaxNumberOfItemsToIndexInSingleBatch == ravenSettings.MaxNumberOfItemsToIndexInSingleBatch.Default ?
                                                           defaultInitialNumberOfItemsToIndexInSingleBatch :
                                                           Math.Max(16, Math.Min(MaxNumberOfItemsToIndexInSingleBatch / 256, defaultInitialNumberOfItemsToIndexInSingleBatch));
            }
            AvailableMemoryForRaisingIndexBatchSizeLimit = ravenSettings.AvailableMemoryForRaisingIndexBatchSizeLimit.Value;



            MaxNumberOfItemsToReduceInSingleBatch     = ravenSettings.MaxNumberOfItemsToReduceInSingleBatch.Value;
            InitialNumberOfItemsToReduceInSingleBatch = MaxNumberOfItemsToReduceInSingleBatch == ravenSettings.MaxNumberOfItemsToReduceInSingleBatch.Default?
                                                        defaultInitialNumberOfItemsToIndexInSingleBatch / 2 :
                                                        Math.Max(16, Math.Min(MaxNumberOfItemsToIndexInSingleBatch / 256, defaultInitialNumberOfItemsToIndexInSingleBatch / 2));

            NumberOfItemsToExecuteReduceInSingleStep = ravenSettings.NumberOfItemsToExecuteReduceInSingleStep.Value;

            var initialNumberOfItemsToReduceInSingleBatch = Settings["Raven/InitialNumberOfItemsToReduceInSingleBatch"];

            if (initialNumberOfItemsToReduceInSingleBatch != null)
            {
                InitialNumberOfItemsToReduceInSingleBatch = Math.Min(int.Parse(initialNumberOfItemsToReduceInSingleBatch),
                                                                     MaxNumberOfItemsToReduceInSingleBatch);
            }

            MaxNumberOfParallelIndexTasks = ravenSettings.MaxNumberOfParallelIndexTasks.Value;

            TempIndexPromotionMinimumQueryCount = ravenSettings.TempIndexPromotionMinimumQueryCount.Value;

            TempIndexPromotionThreshold = ravenSettings.TempIndexPromotionThreshold.Value;

            TempIndexCleanupPeriod = ravenSettings.TempIndexCleanupPeriod.Value;

            TempIndexCleanupThreshold = ravenSettings.TempIndexCleanupThreshold.Value;

            TempIndexInMemoryMaxBytes = ravenSettings.TempIndexInMemoryMaxMb.Value;

            // Data settings
            RunInMemory = ravenSettings.RunInMemory.Value;

            if (string.IsNullOrEmpty(DefaultStorageTypeName))
            {
                DefaultStorageTypeName = Settings["Raven/StorageTypeName"] ?? Settings["Raven/StorageEngine"] ?? "esent";
            }

            CreateTemporaryIndexesForAdHocQueriesIfNeeded = ravenSettings.CreateTemporaryIndexesForAdHocQueriesIfNeeded.Value;

            ResetIndexOnUncleanShutdown = ravenSettings.ResetIndexOnUncleanShutdown.Value;

            SetupTransactionMode();

            DataDirectory = ravenSettings.DataDir.Value;

            var indexStoragePathSettingValue = ravenSettings.IndexStoragePath.Value;

            if (string.IsNullOrEmpty(indexStoragePathSettingValue) == false)
            {
                IndexStoragePath = indexStoragePathSettingValue;
            }

            // HTTP settings
            HostName = ravenSettings.HostName.Value;

            if (string.IsNullOrEmpty(DatabaseName))             // we only use this for root database
            {
                Port = PortUtil.GetPort(ravenSettings.Port.Value);
            }
            SetVirtualDirectory();

            HttpCompression = ravenSettings.HttpCompression.Value;

            AccessControlAllowOrigin    = ravenSettings.AccessControlAllowOrigin.Value;
            AccessControlMaxAge         = ravenSettings.AccessControlMaxAge.Value;
            AccessControlAllowMethods   = ravenSettings.AccessControlAllowMethods.Value;
            AccessControlRequestHeaders = ravenSettings.AccessControlRequestHeaders.Value;

            AnonymousUserAccessMode = GetAnonymousUserAccessMode();

            RedirectStudioUrl = ravenSettings.RedirectStudioUrl.Value;

            DisableDocumentPreFetchingForIndexing = ravenSettings.DisableDocumentPreFetchingForIndexing.Value;

            // Misc settings
            WebDir = ravenSettings.WebDir.Value;

            PluginsDirectory = ravenSettings.PluginsDirectory.Value.ToFullPath();

            var taskSchedulerType = ravenSettings.TaskScheduler.Value;

            if (taskSchedulerType != null)
            {
                var type = Type.GetType(taskSchedulerType);
                CustomTaskScheduler = (TaskScheduler)Activator.CreateInstance(type);
            }

            AllowLocalAccessWithoutAuthorization = ravenSettings.AllowLocalAccessWithoutAuthorization.Value;

            PostInit();
        }