// Begin data access methods for user objects public User GetUser() { try { _server.Ping(); return(_db.GetCollection <User>("Users").FindAll().ToList <User>().LastOrDefault()); } catch { return(null); } }
private static void Ping(MongoServer server) { try { server.Ping(); } catch (SocketException) { throw new QueueConfigurationException(); } }
public static bool ServerIsRunning(MongoServer server) { try { server.Ping(); } catch { return false; } return true; }
public static bool ServerIsRunning(MongoServer server) { try { server.Ping(); } catch { return(false); } return(true); }
//if the _mongoDB object is null we have not instantiated it and connected to the database static public bool IsConnected() { if (_mongoDB != null) { //there's a chance we lost th eocnnection but since no read/write occurred we ar enot aware yet so let's ping try { _mongoDB.Ping(); } catch { return(false); } } return(_mongoDB != null && _mongoDB.State == MongoServerState.Connected); }
/// <summary> /// Connects to the upstream MongoDB server and returns if successful. /// </summary> private static bool ConnectToUpstream( ) { try { upstream = MongoServer.Create( ); upstream.Connect( ); upstream.Ping( ); return true; } catch ( MongoConnectionException ) { return false; } }
public SearchHashForm(string collectionName = "HashForm", string dbName = "emdsdb", string hostIP = "localhost") { connectionString = String.Format("mongodb://{0}/?safe=true", hostIP); try { server = MongoServer.Create(connectionString); database = server.GetDatabase(dbName); collection = database.GetCollection<FormHash>(collectionName); server.Ping(); } catch { throw new Exception("Проблема подключением к монге"); } log = FileLogger.GetLogger(); }
public HealthCheckFacet SitecoreMongo() { var checkResult = new HealthCheckFacet { Name = "SitecoreMongo", Healthy = true, }; var client = new MongoClient(_config.MongoDbConnectionString); var server = new MongoServer(MongoServerSettings.FromClientSettings(client.Settings)); client.ListDatabases(CancellationToken.None);//get mongo to do something first, otherwise the server ping will fail the first time after the app starts server.Ping(); return(checkResult); }
public MongoRepository(string connectionString, string dbName, string collectionName) { ConnectionString = connectionString; DatabaseName = dbName; CollectionName = collectionName; try { server = MongoServer.Create(connectionString); database = server.GetDatabase(dbName, SafeMode.True); collection = database.GetCollection(collectionName); server.Ping(); } catch { throw new Exception("Проблема с сервером БД"); //return null; } }
public TrainLogRepository(string collectionName = "NeuralTrainLog", string dbName = "emdsdb", string connectionString = "mongodb://localhost/?safe=true") { CollectionName = collectionName; DbName = dbName; ConnectionString = String.Format("{0}/{1}", connectionString, dbName); try { var client = new MongoClient(ConnectionString); server = client.GetServer(); database = server.GetDatabase(dbName); collection = database.GetCollection(collectionName); server.Ping(); } catch { throw new Exception("Не удалось подключиться к MongoDB"); } }
private TrainLogger(string collectionName = "NeuralTrainLog", string dbName = "emdsdb", string connectionStringMongo = "mongodb://localhost/?safe=true") { IdSession = Guid.NewGuid(); isCreate = true; CollectionName = collectionName; DbName = dbName; AgeNumber = -1; connectionString = connectionStringMongo; try { server = MongoServer.Create(connectionString); database = server.GetDatabase(dbName); collection = database.GetCollection(collectionName); server.Ping(); } catch { throw new Exception("Не удалось подключиться к MongoDB"); } }
public bool CheckInstall(GlobalSettings s) { try { server.Ping(); if (!database.GetCollection <WritaPost>("Posts").Exists()) { InstallSet set = InstallHelper.GetInstall(); CreatePost(set.homepage); CreatePost(set.firstpost); database.GetCollection <WritaSettings>("Settings").Save(set.settings); //install. } return(true); } catch { return(false); } }
public void TestPing() { _server.Ping(); }
public void Ping() { _mongoServer.Ping(); }