/// <summary> Used to create the correct storage type </summary>
            internal override INodeStorage CreateStorage()
            {
                if (StorageType == StorageType.Custom)
                {
                    return(Check.NotNull(StorageSystem));
                }
                if (StorageType == StorageType.Memory)
                {
                    return(new BTreeMemoryStore());
                }

                bool exists = File.Exists(FileName);

                if (CreateFile == CreatePolicy.Always || (!exists && CreateFile == CreatePolicy.IfNeeded))
                {
                    return(BTreeFileStore.CreateNew(FileName, FileBlockSize, FileGrowthRate, ConcurrentWriters, FileOpenOptions));
                }

                InvalidConfigurationValueException.Assert(exists, "CreateFile", "The file does not exist and CreateFile is Never");
                return(new BTreeFileStore(FileName, FileBlockSize, FileGrowthRate, ConcurrentWriters, FileOpenOptions, ReadOnly));
            }
            /// <summary> Used to create the correct storage type </summary>
            internal override INodeStorage CreateStorage()
            {
                if (StorageType == StorageType.Custom)
                {
                    return(Check.NotNull(StorageSystem));
                }
                if (StorageType == StorageType.Memory)
                {
                    return(new BTreeMemoryStore());
                }

                InvalidConfigurationValueException.Assert(StorageType == StorageType.Disk, "StorageType", "Unknown value defined.");
                bool exists = File.Exists(FileName);

                if (exists && new FileInfo(FileName).Length == 0)
                {
                    exists = false;
                    File.Delete(FileName);
                }
                bool createNew = CreateFile == CreatePolicy.Always ||
                                 (exists == false && CreateFile == CreatePolicy.IfNeeded);

                if (!exists && !createNew)
                {
                    throw new InvalidConfigurationValueException("CreateFile", "The file does not exist and CreateFile is Never");
                }

                TransactedCompoundFile.Options foptions =
                    new TransactedCompoundFile.Options(FileName)
                {
                    BlockSize   = FileBlockSize,
                    FileOptions = FileOptions.None,
                    ReadOnly    = ReadOnly,
                    CreateNew   = createNew
                };

                switch (StoragePerformance)
                {
                case StoragePerformance.Fastest:
                {
                    SetStorageCache(true);
                    break;
                }

                case StoragePerformance.CommitToCache:
                {
                    foptions.FileOptions   = FileOptions.None;
                    foptions.CommitOnWrite = true;
                    break;
                }

                case StoragePerformance.CommitToDisk:
                {
                    foptions.FileOptions   = FileOptions.WriteThrough;
                    foptions.CommitOnWrite = true;
                    break;
                }

                case StoragePerformance.LogFileInCache:
                case StoragePerformance.LogFileNoCache:
                {
                    SetStorageCache(true);
                    if (LogFile == null)
                    {
                        _logFileName = _logFileName ?? Path.ChangeExtension(FileName, ".tlog");
                        SetLogFile(new TransactionLog <TKey, TValue>(
                                       new TransactionLogOptions <TKey, TValue>(_logFileName, KeySerializer, ValueSerializer)
                            {
                                FileOptions = StoragePerformance == StoragePerformance.LogFileNoCache
                                            ? FileOptions.WriteThrough : FileOptions.None,
                            }
                                       ));
                    }
                    break;
                }

                default:
                    throw new InvalidConfigurationValueException("DurabilityProtection", "The configuration option is not valid.");
                }

                return(new BTreeFileStoreV2(foptions));
            }