示例#1
0
        private MongoConnection GetMongoServer(Models.MongoDBConnectionDetails connectionParameters)
        {
            MongoConnection         connection = new MongoConnection();
            MongoDBClientConnection mongoDBClientConnection = PrepareMongoClient(connectionParameters);

            try
            {
                connection.MongoDBServer = mongoDBClientConnection.MongoDBClient.GetServer();
                connection.MongoLogs     = mongoDBClientConnection.MongoLogs;
                connection.MongoDBServer.Connect();
                return(connection);
            }
            catch (Exception e)
            {
                throw new Exception(mongoDBClientConnection.MongoLogs, e);
            }
        }
 public JsonResult FormOne(Models.MongoDBConnectionDetails mongodbConnection)
 {
     try
     {
         CreateSSHTunnel(mongodbConnection, out string sSHLogs);
         MongoConnection mongoServer = GetMongoServer(mongodbConnection, out string mongoLogs);
         GetDatabases(mongoServer, out string databaseLogs);
         mongodbConnection.forwardedPortLocal.Stop();
         mongodbConnection.SshClient.Disconnect();
         return(Json(string.Concat(sSHLogs, mongoLogs, databaseLogs), JsonRequestBehavior.AllowGet));
         //return Json(string.Concat(string.Join(",",mongoServer.MongoDBServer.GetDatabaseNames().ToList()),"_________________", mongoServer.MongoLogs), JsonRequestBehavior.AllowGet);
     }
     catch (Exception e)
     {
         return(Json(string.Concat(string.IsNullOrEmpty(e.Message) ? "":e.Message, "**********", e.InnerException == null?"":e.InnerException.Message, JsonRequestBehavior.AllowGet)));
     }
 }
 private void GetDatabases(MongoConnection mongoConnection, out string logs)
 {
     logs = string.Empty;
     try
     {
         var databases = mongoConnection.MongoDBServer.GetDatabaseNames().ToList();
         logs += string.Format("\n Available databases in MongoDB Server:\n");
         foreach (string database in databases)
         {
             logs += string.Format(database + "\n");
         }
     }
     catch (Exception e)
     {
         logs += string.Format(e.Message);
     }
 }
        private MongoConnection GetMongoServer(Models.MongoDBConnectionDetails connectionParameters, out string logs)
        {
            logs = string.Empty;
            MongoConnection         connection = new MongoConnection();
            MongoDBClientConnection mongoDBClientConnection = PrepareMongoClient(connectionParameters);

            try
            {
                connection.MongoDBServer = mongoDBClientConnection.MongoDBClient.GetServer();
                connection.MongoDBServer.Connect();
                logs += string.Format("Connected with MongoDB Server \n");
            }
            catch (Exception e)
            {
                logs += string.Format(e.Message);
            }
            return(connection);
        }