Exemplo n.º 1
0
        /// <summary>
        /// Method to create the database collection associated with the specified model type using
        /// the current configuration settings.
        /// </summary>
        /// <returns></returns>
        public static async Task <bool> CreateCollectionAsync <T>(IDocumentDBConfiguration configuration)
        {
            string collectionName = ModelUtility.GetPluralizedModelName <T>();

            using (var client = NewDocumentClient(configuration))
            {
                string             collectionsFeed = GetCollectionsFeed(configuration);
                DocumentCollection collection      = client.CreateDocumentCollectionQuery(collectionsFeed)
                                                     .Where(c => c.Id == collectionName)
                                                     .AsEnumerable()
                                                     .FirstOrDefault();
                if (collection == null)
                {
                    collection = await client.CreateDocumentCollectionAsync(
                        collectionsFeed,
                        new DocumentCollection { Id = collectionName });

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemplo n.º 2
0
 public DocumentDBRepositoryBase(IDocumentDBConfiguration configuration)
 {
     Configuration = configuration;
     DatabaseName  = configuration.DataBase;
     Client        = new MongoClient($"mongodb://{Configuration.UserName}:{Configuration.Password}@{Configuration.Host}?ssl=true");
     Database      = Client.GetDatabase(DatabaseName);
     Collection    = Database.GetCollection <TEntity>(CollectionName);
 }
Exemplo n.º 3
0
        internal static DocumentClient NewDocumentClient(IDocumentDBConfiguration configuration)
        {
            Uri uri;

            if (!Uri.TryCreate(configuration.AccountUri, UriKind.Absolute, out uri))
            {
                uri = new Uri("http://invalid_uri");
            }
            return(new DocumentClient(uri, configuration.AccountKey));
        }
 public DocumentDBRepositoryBase(IDocumentDBConfiguration configuration)
 {
     Configuration = configuration;
     DatabaseName  = configuration.DataBase;
     if (string.IsNullOrEmpty(configuration.UserName) && string.IsNullOrEmpty(configuration.Password))
     {
         Client = new MongoClient($"mongodb://{Configuration.Host}?ssl=false");
     }
     else
     {
         Client = new MongoClient($"mongodb://{Configuration.UserName}:{Configuration.Password}@{Configuration.Host}?ssl={configuration.SSL}");
     }
     Database   = Client.GetDatabase(DatabaseName);
     Collection = Database.GetCollection <TEntity>(CollectionName);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Method to create the database as specified by the configuration's document database name.
        /// </summary>
        /// <returns></returns>
        public static async Task <bool> CreateDatabaseAsync(IDocumentDBConfiguration configuration)
        {
            using (var client = NewDocumentClient(configuration))
            {
                var database = client.CreateDatabaseQuery()
                               .Where(d => configuration.DatabaseName.Equals(d.Id))
                               .AsEnumerable()
                               .FirstOrDefault();
                if (database == null)
                {
                    database = await client.CreateDatabaseAsync(new Database()
                    {
                        Id = configuration.DatabaseName
                    });

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Get a string for the collection feed based on configuration setting for the database name.
 /// </summary>
 /// <returns></returns>
 internal static string GetCollectionsFeed(IDocumentDBConfiguration configuration)
 {
     return($"dbs/{configuration.DatabaseName}/");
 }
Exemplo n.º 7
0
 // TODO: Refactor to use DocumentDB SDK's UriFactory to construct URI's
 internal static string GetDocumentLink <T>(string id, IDocumentDBConfiguration configuration) where T : IModel
 {
     return($"{GetDocumentFeed<T>(configuration)}/docs/{id}");
 }
Exemplo n.º 8
0
 /// <summary>
 /// Get a string for a document feed based on configuration setting for the database name and the
 /// type of the model in the collection
 /// </summary>
 /// <returns></returns>
 internal static string GetDocumentFeed <T>(IDocumentDBConfiguration configuration) where T : IModel
 {
     return($"{GetCollectionsFeed(configuration)}colls/{ModelUtility.GetPluralizedModelName<T>()}");
 }
Exemplo n.º 9
0
 public FamilyRepository(IDocumentDBConfiguration configuration) : base(configuration)
 {
 }
Exemplo n.º 10
0
 public Repository(IDocumentDBConfiguration configuration)
 {
     Configuration = configuration;
     Context       = DocumentDBUtility.NewDocumentClient(configuration);
 }