public static List <RptData> GetCollectionReport(MDTServer server, string DbName) { MongoClient client = new MongoClient(server.ConnectionString); var lst = new List <RptData>(); var DbCollections = MongoGeneralLogic.GetDatabaseCollections(server.ConnectionString, DbName); foreach (var item in DbCollections) { var collection = client.GetDatabase(DbName).GetCollection <BsonDocument>(item).Find(x => true).ToList(); string Size = ""; float bytesSizeF = collection.Sum(x => x.ToBson().Length); if (bytesSizeF < 1000) { Size = Math.Round(bytesSizeF, 2) + " Bytes"; } else if (bytesSizeF < 1000 * 1000) { Size = Math.Round(bytesSizeF / 1000, 2) + " KB"; } else if (bytesSizeF < 1000 * 1000 * 1000) { Size = Math.Round(bytesSizeF / 1000000, 2) + " MB"; } lst.Add(new RptData() { CollectionName = item, SizeStr = Size, Size = bytesSizeF, Count = collection.Count }); } return(lst.OrderByDescending(x => x.Size).ToList()); }
public static void ImportFromJson(MDTServer server, string DbName, List <string> Files, bool DropIfExist) { var tempPath = CreateTempDir(); var MongoPath = GetMongoPath(); foreach (var FilePath in Files) { var CollectionName = Path.GetFileNameWithoutExtension(FilePath); var NewPath = Path.Combine(tempPath, Path.GetFileName(FilePath)); if (DropIfExist) { DropCollection(server.ConnectionString, DbName, CollectionName); } File.Copy(FilePath, NewPath); string command = string.Format("--db {0} --collection {1} {2} --host \"{3}:{4}\"", DbName, CollectionName, NewPath, server.Server, server.Port); RuMongoProcess("mongoimport.exe", MongoPath, command); File.Delete(NewPath); } try { Directory.Delete(tempPath); } catch (Exception ex) { } }
public static void ExportToDump(MDTServer server, string dbName, string OutPutFile, List <string> Collections, out string log) { var MongoPath = GetMongoPath(); string Log = ""; //Prepare Directory //Create Temp Dir to export to var TempDir = CreateTempDir(); string command = string.Format("-d {0} -o {1} --host \"{2}:{3}\"", dbName, TempDir, server.Server, server.Port); RuMongoProcess("mongodump", MongoPath, command); string TempOutPutFile = TempDir + ".MDT"; ZipFile.CreateFromDirectory(Path.Combine(TempDir, dbName), TempOutPutFile); File.Move(TempOutPutFile, OutPutFile); try { Directory.Delete(TempDir, true); } catch { } log = Log; }
public FrmCollectionRpt(MDTServer server, string DbName) { InitializeComponent(); label1.Text = server + " - " + DbName; GrvReport.DataSource = MongoGeneralLogic.GetCollectionReport(server, DbName); }
MDTServer GetServer() { MDTServer server = new MDTServer() { AuthDb = TxtAuthDb.Text, Password = TxtPassword.Text, Port = (int)NumPort.Value, Server = TxtServer.Text, ConnectionAlias = TxtConnectionName.Text, UseAuth = RdAuth.Checked }; return(server); }
public static void ImportFromDump(MDTServer server, string DbName, string FilePath, bool DropIfExist) { //Unzip File To Temp var TempPath = CreateTempDir(); ZipFile.ExtractToDirectory(FilePath, TempPath); var MongoPath = GetMongoPath(); if (DropIfExist) { DropDataBase(server.ConnectionString, DbName); } string command = string.Format("-d {0} {1} --host \"{2}:{3}\"", DbName, TempPath, server.Server, server.Port); RuMongoProcess("mongorestore.exe", MongoPath, command); }
public static List <string> GetServerDataBases(MDTServer server) { List <string> result = new List <string>(); MongoClient client = new MongoClient(server.ConnectionString); MongoServer mongoserver = client.GetServer(); try { result = mongoserver.GetDatabaseNames().ToList(); } catch { } //MongoDatabase database = server.GetDatabase("RUF"); return(result); }
//public List<> #region Server Connection public static bool TryToConnectToServer(MDTServer server) { bool result = false; MongoClient client = new MongoClient(server.ConnectionString); MongoServer mongoserver = client.GetServer(); try { mongoserver.Connect(); result = true; } catch { } //MongoDatabase database = server.GetDatabase("RUF"); return(result); }
public ExportFrm(MDTServer server, string DbName, List<string> Collection) { InitializeComponent(); this.server = server; this.DbName = DbName; this.Text += " - " + DbName; var collections = MongoGeneralLogic.GetDatabaseCollections(server.ConnectionString, DbName); foreach (var item in collections) { bool ChekItem = !Collection.Any() || Collection.Contains(item); if (Collection.Any()) { CollectionChk.Items.Add(item, ChekItem); } else { CollectionChk.Items.Add(item, true); } } ChkAll.Checked = !Collection.Any(); }
void NewConnection(MDTServer server = null) { var c = new ConnectionsFrm(); if (server != null || c.ShowDialog() == DialogResult.OK) { var CurrentConnection = server ?? Session.CurrentConnections.Last(); var ConnectionDb = MongoGeneralLogic.GetServerDataBases(CurrentConnection); string ConnectionName = !string.IsNullOrEmpty(CurrentConnection.ConnectionAlias) ? CurrentConnection.ConnectionAlias : CurrentConnection.Server; ServerTreeNode connectionNode = new ServerTreeNode() { Text = ConnectionName, ImageIndex = 0, ServerConnectionString = CurrentConnection.ConnectionString, Server = CurrentConnection, ContextMenuStrip = ServerContextMenu, }; foreach (var db in ConnectionDb) { var dbTreeNode = new DbTreeNode() { Text = db, Name = "Db_" + db, ImageIndex = 1, ContextMenuStrip = DbContextMenu, DbName = db, Server = CurrentConnection, ServerConnectionString = CurrentConnection.ConnectionString }; dbTreeNode.Nodes.Add(""); connectionNode.Nodes.Add(dbTreeNode); } ConnectionTree.Nodes.Add(connectionNode); connectionNode.Expand(); } }
public ImportFromJsonFrm(string DbName, MDTServer server) : this(server) { this.TxtDbName.Text = DbName; }
public ImportFromJsonFrm(MDTServer server) { InitializeComponent(); this.server = server; }
public ImportDumpFrm(MDTServer server) { InitializeComponent(); this.server = server; }