/// <summary>
        /// Creates a new instance of LightningEnvironment.
        /// </summary>
        /// <param name="directory">Directory for storing database files.</param>
        /// <param name="openFlags">Database open options.</param>
        /// <param name="accessMode">Unix file access privelegies (optional). Only makes sense on unix operationg systems.</param>
        public LightningEnvironment(string directory, EnvironmentOpenFlags openFlags = EnvironmentOpenFlags.None, UnixAccessMode accessMode = UnixAccessMode.Default)
        {
            if (String.IsNullOrWhiteSpace(directory))
                throw new ArgumentException("Invalid directory name");

            IntPtr handle = default(IntPtr);
            NativeMethods.Execute(lib => lib.mdb_env_create(out handle));

            _shouldDispose = true;
            
            _handle = handle;
            _accessMode = accessMode;

            this.Directory = directory;
            _openFlags = openFlags;

            if (LightningConfig.Environment.DefaultMapSize != LightningConfig.Environment.LibDefaultMapSize)
                this.MapSize = LightningConfig.Environment.DefaultMapSize;
            else
                _mapSize = LightningConfig.Environment.LibDefaultMapSize;

            if (LightningConfig.Environment.DefaultMaxDatabases != LightningConfig.Environment.LibDefaultMaxDatabases)
                this.MaxDatabases = LightningConfig.Environment.DefaultMaxDatabases;
            else
                _maxDbs = LightningConfig.Environment.LibDefaultMaxDatabases;

            _openedDatabases = new ConcurrentDictionary<string, LightningDatabase>();
            _databasesForReuse = new HashSet<uint>();

            ConverterStore = new ConverterStore();
            var defaultConverters = new DefaultConverters();
            defaultConverters.RegisterDefault(this);
        }
        /// <summary>
        /// Open the environment.
        /// </summary>
        public void Open(EnvironmentOpenFlags openFlags = EnvironmentOpenFlags.None, UnixAccessMode accessMode = UnixAccessMode.Default)
        {
            if (IsOpened)
            {
                throw new InvalidOperationException("Environment is already opened.");
            }

            if (!openFlags.HasFlag(EnvironmentOpenFlags.NoSubDir) && !Directory.Exists(Path))
            {
                Directory.CreateDirectory(Path);
            }

            if (openFlags.HasFlag(EnvironmentOpenFlags.NoSubDir) && !Directory.Exists(System.IO.Path.GetDirectoryName(Path)))
            {
                Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Path));
            }

            try
            {
                mdb_env_open(_handle, Path, openFlags, accessMode);
            }
            catch (Exception ex)
            {
                throw new LightningException($"Failed to open environment at path {Path}", ex);
            }

            IsOpened = true;
        }
        public LightningEnvironment(string directory, EnvironmentOpenFlags openFlags)
        {
            if (String.IsNullOrWhiteSpace(directory))
                throw new ArgumentException("Invalid directory name");

            IntPtr handle = default(IntPtr);
            Native.Execute(() => Native.mdb_env_create(out handle));

            _shouldDispose = true;
            
            _handle = handle;

            this.Directory = directory;
            _openFlags = openFlags;

            _mapSize = DefaultMapSize;
            _maxDbs = DefaultMaxDatabases;

            _openedDatabases = new ConcurrentDictionary<string, LightningDatabase>();
            _databasesForReuse = new HashSet<uint>();

            ConverterStore = new ConverterStore();
            var defaultConverters = new DefaultConverters();
            defaultConverters.RegisterDefault(this);
        }
        public LightningEnvironment(string directory, EnvironmentOpenFlags openFlags, UnixAccessMode accessMode = UnixAccessMode.Default)
        {
            if (String.IsNullOrWhiteSpace(directory))
                throw new ArgumentException("Invalid directory name");

            IntPtr handle = default(IntPtr);
            Native.Execute(lib => lib.mdb_env_create(out handle));

            _shouldDispose = true;
            
            _handle = handle;
            _accessMode = accessMode;

            this.Directory = directory;
            _openFlags = openFlags;

            _mapSize = DefaultMapSize;
            _maxDbs = DefaultMaxDatabases;

            _openedDatabases = new ConcurrentDictionary<string, LightningDatabase>();
            _databasesForReuse = new HashSet<uint>();

            ConverterStore = new ConverterStore();
            var defaultConverters = new DefaultConverters();
            defaultConverters.RegisterDefault(this);
        }
Esempio n. 5
0
        /// <summary>
        /// Open the environment.
        /// </summary>
        public void Open(EnvironmentOpenFlags openFlags = EnvironmentOpenFlags.None, UnixAccessMode accessMode = UnixAccessMode.Default)
        {
            if (IsOpened)
            {
                throw new InvalidOperationException("Environment is already opened.");
            }

            if (!Directory.Exists(Path))
            {
                Directory.CreateDirectory(Path);
            }

            mdb_env_open(_handle, Path, openFlags, accessMode);

            IsOpened = true;
        }
Esempio n. 6
0
        public static LmdbEnv CreateDb(string folder, long size,
                                       EnvironmentOpenFlags flags = EnvironmentOpenFlags.None)
        {
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            var env = new LightningEnvironment(folder, new EnvironmentConfiguration()
            {
                MaxDatabases = 1,
                MapSize      = size,
                MaxReaders   = 1024 * 4
            });

            var readOnly = (flags & EnvironmentOpenFlags.ReadOnly) == EnvironmentOpenFlags.ReadOnly;



            env.Open(flags);

            LightningDatabase db;

            if (readOnly)
            {
                using (var tx = env.BeginTransaction(TransactionBeginFlags.ReadOnly)) {
                    db = tx.OpenDatabase();
                    tx.Commit();
                }
            }
            else
            {
                var config = new DatabaseConfiguration()
                {
                    Flags = DatabaseOpenFlags.Create
                };
                using (var tx = env.BeginTransaction()) {
                    db = tx.OpenDatabase(configuration: config);
                    tx.Commit();
                }
            }

            return(new LmdbEnv(db, env));
        }
Esempio n. 7
0
 public static int mdb_env_open(IntPtr env, string path, EnvironmentOpenFlags flags, UnixAccessMode mode)
 {
     return(check(LmdbMethods.mdb_env_open(env, path, flags, mode)));
 }
        /// <summary>
        /// Open the environment.
        /// </summary>
        public void Open(EnvironmentOpenFlags openFlags = EnvironmentOpenFlags.None, UnixAccessMode accessMode = UnixAccessMode.Default)
        {
            if(IsOpened)
                throw new InvalidOperationException("Environment is already opened.");

            if (!Directory.Exists(Path))
                Directory.CreateDirectory(Path);

            mdb_env_open(_handle, Path, openFlags, accessMode);

            IsOpened = true;
        }
 int INativeLibraryFacade.mdb_env_open(IntPtr env, string path, EnvironmentOpenFlags flags, int mode)
 {
     return FallbackLibraryFacade.mdb_env_open(env, path, flags, mode);
 }
 int INativeLibraryFacade.mdb_env_open(IntPtr env, string path, EnvironmentOpenFlags flags, UnixAccessMode mode)
 {
     return(Native64BitLibraryFacade.mdb_env_open(env, path, flags, mode));
 }
Esempio n. 11
0
 int INativeLibraryFacade.mdb_env_open(IntPtr env, string path, EnvironmentOpenFlags flags, UnixAccessMode mode)
 {
     return Native64BitLibraryFacade.mdb_env_open(env, path, flags, mode);
 }
Esempio n. 12
0
 private static extern int mdb_env_open(IntPtr env, string path, EnvironmentOpenFlags flags, int mode);
Esempio n. 13
0
 internal static extern int mdb_env_open(IntPtr env, string path, EnvironmentOpenFlags flags, UnixAccessMode mode);
Esempio n. 14
0
 public static int mdb_env_open(IntPtr env, string path, EnvironmentOpenFlags flags, UnixAccessMode mode)
 {
     return check(LmdbMethods.mdb_env_open(env, path, flags, mode));
 }
        /// <summary>
        /// Open the environment.
        /// </summary>
        public void Open(EnvironmentOpenFlags openFlags = EnvironmentOpenFlags.None, UnixAccessMode accessMode = UnixAccessMode.Default)
        {
            if(IsOpened)
                throw new InvalidOperationException("Environment is already opened.");

            if (!openFlags.HasFlag(EnvironmentOpenFlags.NoSubDir) && !Directory.Exists(Path))
                Directory.CreateDirectory(Path);

            try
            {
                mdb_env_open(_handle, Path, openFlags, accessMode);
            }
            catch(Exception ex)
            {
                throw new LightningException($"Failed to open environment at path {Path}", ex);
            }

            IsOpened = true;
        }
 int INativeLibraryFacade.mdb_env_open(IntPtr env, string path, EnvironmentOpenFlags flags, int mode)
 {
     return(FallbackLibraryFacade.mdb_env_open(env, path, flags, mode));
 }
Esempio n. 17
0
 public static extern int mdb_env_open(IntPtr env, string path, EnvironmentOpenFlags flags, int mode);