Esempio n. 1
0
        /// <summary>Opens the directory with the given <paramref name="path"/>.
        /// If the directory does not exist, and if <paramref name="readOnly"/> is false, it is created. Otherwise, this method returns null.
        /// If the <paramref name="layer"/> is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
        /// </summary>
        /// <param name="directory">Parent directory</param>
        /// <param name="trans">Transaction used by the operation</param>
        /// <param name="path">Path to the directory to open or create</param>
        /// <param name="readOnly">If true, do not make any modifications to the database, and return null if the directory does not exist.</param>
        /// <param name="layer">Optional layer ID that is checked with the opened directory.</param>
        /// <returns></returns>
        public static Task <FdbDirectorySubspace> TryCreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, FdbDirectoryPath path, bool readOnly, Slice layer = default)
        {
            Contract.NotNull(directory, nameof(directory));
            Contract.NotNull(trans, nameof(trans));

            return(readOnly ? directory.TryOpenAsync(trans, path, layer) : directory.CreateOrOpenAsync(trans, path, layer));
        }
Esempio n. 2
0
        /// <summary>Opens the directory with the given <paramref name="path"/>.
        /// If the directory does not exist, it is created (creating parent directories if necessary).
        /// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
        /// </summary>
        public static Task <FdbDirectorySubspace> CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, FdbDirectoryPath path, Slice layer, CancellationToken ct)
        {
            Contract.NotNull(directory, nameof(directory));
            Contract.NotNull(db, nameof(db));

            return(db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, path, layer), ct));
        }
        /// <summary>Opens the directory with the given <paramref name="name"/>.
        /// If the directory does not exist, it is created (creating parent directories if necessary).
        /// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
        /// </summary>
        public static Task <FdbDirectorySubspace> CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken ct)
        {
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            if (db == null)
            {
                throw new ArgumentNullException(nameof(db));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, new [] { name }, Slice.Nil), ct));
        }
        /// <summary>Opens the directory with the given <paramref name="path"/>.
        /// If the directory does not exist, it is created (creating parent directories if necessary).
        /// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
        /// </summary>
        public static Task <FdbDirectorySubspace> CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable <string> path, Slice layer, CancellationToken ct)
        {
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            if (db == null)
            {
                throw new ArgumentNullException(nameof(db));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            return(db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, path, layer), ct));
        }
        /// <summary>Opens the directory with the given <paramref name="name"/>.
        /// If the directory does not exist, it is created (creating parent directories if necessary).
        /// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
        /// </summary>
        public static Task <FdbDirectorySubspace> CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, [NotNull] string name, Slice layer = default(Slice))
        {
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            if (trans == null)
            {
                throw new ArgumentNullException(nameof(trans));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(directory.CreateOrOpenAsync(trans, new[] { name }, layer));
        }
        // this helper class contain extension methods to help deal with IFdbDatabase vs IFdbTransaction

        #region CreateOrOpen...

        /// <summary>Opens the directory with the given <paramref name="path"/>.
        /// If the directory does not exist, it is created (creating parent directories if necessary).
        /// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
        /// </summary>
        public static Task <FdbDirectorySubspace> CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable <string> path, CancellationToken cancellationToken)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            return(db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, path, Slice.Nil), cancellationToken));
        }
        /// <summary>Opens the directory with the given <paramref name="path"/>.
        /// If the directory does not exist, and if <paramref name="readOnly"/> is false, it is created. Otherwise, this method returns null.
        /// If the <paramref name="layer"/> is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
        /// </summary>
        /// <param name="directory">Parent directory</param>
        /// <param name="trans">Transaction used by the operation</param>
        /// <param name="path">Path to the directory to open or create</param>
        /// <param name="readOnly">If true, do not make any modifications to the database, and return null if the directory does not exist.</param>
        /// <param name="layer">Optional layer ID that is checked with the opened directory.</param>
        /// <returns></returns>
        public static Task <FdbDirectorySubspace> TryCreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, [NotNull] IEnumerable <string> path, bool readOnly, Slice layer = default(Slice))
        {
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            if (trans == null)
            {
                throw new ArgumentNullException(nameof(trans));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (readOnly)
            {
                return(directory.TryOpenAsync(trans, path, layer));
            }
            else
            {
                return(directory.CreateOrOpenAsync(trans, path, layer));
            }
        }
Esempio n. 8
0
 /// <summary>Opens a subdirectory with the given path.
 /// If the subdirectory does not exist, it is created (creating intermediate subdirectories if necessary).
 /// If layer is specified, it is checked against the layer of an existing subdirectory or set as the layer of a new subdirectory.
 /// </summary>
 public Task <FdbDirectorySubspace> CreateOrOpenAsync([NotNull] string name, CancellationToken cancellationToken)
 {
     return(m_database.ReadWriteAsync((tr) => m_directory.CreateOrOpenAsync(tr, new [] { name }, Slice.Nil), cancellationToken));
 }