Ejemplo n.º 1
0
 public MongoConnectionInfo(ICollection <MongoServerAddress> servers, string username, string password, int poolSize, int timeout, int insertionRetries)
 {
     Servers          = servers;
     Username         = username;
     Password         = password;
     PoolSize         = poolSize;
     Timeout          = timeout;
     InsertionRetries = insertionRetries;
     ConnectionType   = MongoConnectionType.Undetermined;
 }
Ejemplo n.º 2
0
 public MongoConnectionInfo(MongoConnection mongoConfig)
 {
     Servers = new List <MongoServerAddress>();
     foreach (MongoServer mongoServer in mongoConfig.Servers)
     {
         Servers.Add(new MongoServerAddress(mongoServer.Server, mongoServer.Port));
     }
     Username         = mongoConfig.User.Username;
     Password         = mongoConfig.User.Password;
     PoolSize         = mongoConfig.PoolSize;
     Timeout          = mongoConfig.Timeout;
     InsertionRetries = mongoConfig.InsertionRetries;
     ConnectionType   = MongoConnectionType.Undetermined;
 }
Ejemplo n.º 3
0
        public IMongoClient GetClient()
        {
            if (client == null)
            {
                MongoUrl mongoUrl = BuildMongoUrl();
                try
                {
                    client = new MongoClient(mongoUrl);
                    Log.DebugFormat("Created MongoDB client for {0}", this);
                    ConnectionType = GetConnectionType();
                }
                catch (TimeoutException ex)
                {
                    throw MongoExceptionHelper.GetMongoException(ex);
                }
                catch (MongoException ex)
                {
                    throw MongoExceptionHelper.GetMongoException(ex);
                }
            }

            return(client);
        }
Ejemplo n.º 4
0
 public string ToUrl(MongoConnectionType connectionType) =>
 $"mongodb{(UseSrvRecord ? "+srv" : string.Empty)}://{(connectionType == MongoConnectionType.Command ? $"{Command.Username}:{Command.Password}" : $"{Query.Username}:{Query.Password}")}@{Server ?? throw new ArgumentNullException(nameof(Server))}/{Database ?? throw new ArgumentNullException(nameof(Database))}{(Options == null ? string.Empty : $"?{Options}")}";