Commit eca09089d58abbe11831e57b10ca4902934d3697
1 parent
fc8a064b
v1.27.1.0
Showing
3 changed files
with
81 additions
and
21 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs
| @@ -747,24 +747,54 @@ GO | @@ -747,24 +747,54 @@ GO | ||
| 747 | SQLDataBase sqld = p.Parameters as SQLDataBase; | 747 | SQLDataBase sqld = p.Parameters as SQLDataBase; |
| 748 | try | 748 | try |
| 749 | { | 749 | { |
| 750 | - ColorConsole.WriteLine(prefix: $"Enter the dbname, the userid/password (for the user in favour you want to drop the DB). Format:", bracket: "()", text: "[DBNAME][,USERNAME[,PASSWORD]]:", f: ConsoleColor.Yellow); | ||
| 751 | - ColorConsole.WriteLine(prefix: " ", text: "[DBNAME]", bracket: "[]", suffix: $":name of the DB to delete, default:{sqld.DBName}", f: ConsoleColor.Yellow); | ||
| 752 | - ColorConsole.WriteLine(prefix: " ", text: "[USERNAME,PASSWORD empty]", bracket: "[]", suffix: $":use windows authentication with current user", f: ConsoleColor.Yellow); | ||
| 753 | - ColorConsole.WriteLine(prefix: " ", text: "USERNAME", bracket: "[]", suffix: $":use windows authentication with this user", f: ConsoleColor.Yellow); | ||
| 754 | - ColorConsole.WriteLine(prefix: " ", text: "USERNAME,PASSWORD", bracket: "[]", suffix: $":use sql server authentication with this user and password.", f: ConsoleColor.Yellow); | 750 | + ColorConsole.WriteLine(prefix: $"Enter the userid/password (for the user in favour you want to drop the DB). Format:", bracket: "()", text: "[USERID[,PASSWORD]]:", f: ConsoleColor.Yellow); |
| 751 | + ColorConsole.WriteLine(prefix: " ", text: "[USERID,PASSWORD empty]", bracket: "[]", suffix: $":use windows authentication with current user", f: ConsoleColor.Yellow); | ||
| 752 | + ColorConsole.WriteLine(prefix: " ", text: "USERID", bracket: "[]", suffix: $":use windows authentication with this user", f: ConsoleColor.Yellow); | ||
| 753 | + ColorConsole.WriteLine(prefix: " ", text: "USERID,PASSWORD", bracket: "[]", suffix: $":use sql server authentication with this user and password.", f: ConsoleColor.Yellow); | ||
| 755 | var parameters = ColorConsole.ReadLine($"EX=exit.", ConsoleColor.Yellow, suffix: " --> "); | 754 | var parameters = ColorConsole.ReadLine($"EX=exit.", ConsoleColor.Yellow, suffix: " --> "); |
| 756 | if (parameters.ToUpper() == "EX") { continue; } | 755 | if (parameters.ToUpper() == "EX") { continue; } |
| 757 | - | ||
| 758 | string userid = null; | 756 | string userid = null; |
| 759 | string password = null; | 757 | string password = null; |
| 758 | + if (!string.IsNullOrWhiteSpace(parameters)) | ||
| 759 | + { | ||
| 760 | + var parlst = parameters.Split(new char[] { ',' }); | ||
| 761 | + userid = parlst[0]; | ||
| 762 | + if (parlst.Count() > 1) { password = parameters.Split(new char[] { ',' })[1]; } | ||
| 763 | + } | ||
| 764 | + | ||
| 765 | + ColorConsole.WriteLine(prefix: $"Enter the regex mask for the name of the DBs to list. Format:", bracket: "()", text: "[REGEXMASK]:", f: ConsoleColor.Yellow); | ||
| 766 | + ColorConsole.WriteLine(prefix: " ", text: "[REGEXMASK]", bracket: "[]", suffix: $":regex mask for the name of the DBs to list, default:.*", f: ConsoleColor.Yellow); | ||
| 767 | + parameters = ColorConsole.ReadLine($"EX=exit.", ConsoleColor.Yellow, suffix: " --> "); | ||
| 768 | + if (parameters.ToUpper() == "EX") { continue; } | ||
| 769 | + string dbnamemask = null; | ||
| 770 | + if (!string.IsNullOrWhiteSpace(parameters)) | ||
| 771 | + { | ||
| 772 | + var parlst = parameters.Split(new char[] { ',' }); | ||
| 773 | + dbnamemask = parlst[0]; | ||
| 774 | + } | ||
| 775 | + if (string.IsNullOrWhiteSpace(dbnamemask)) { dbnamemask = ""; } | ||
| 776 | + | ||
| 777 | + var dbdescriptordict = SQLDataBaseManagerCore.GetDatabases(sqld.SQLCS, dbnamemask, userid, password); | ||
| 778 | + ColorConsole.WriteLine(text: "Available DBs", f: ConsoleColor.Yellow,suffix: $" (name masked with:'{dbnamemask}')"); | ||
| 779 | + foreach (var (dbdescriptor,ix) in dbdescriptordict.Select((text,ix)=> (text, ix))) | ||
| 780 | + { | ||
| 781 | + ColorConsole.WriteLine(prefix: $"#{ix}: ", bracket: "[]", text: dbdescriptor.Key, f: ConsoleColor.Yellow,suffix:dbdescriptor.Value); | ||
| 782 | + } | ||
| 783 | + ColorConsole.WriteLine(); | ||
| 784 | + | ||
| 785 | + ColorConsole.WriteLine(prefix: $"Enter the name of the DB you want to drop. Format:", bracket: "()", text: "[DBNAME]:", f: ConsoleColor.Yellow); | ||
| 786 | + ColorConsole.WriteLine(prefix: " ", text: "[DBNAME]", bracket: "[]", suffix: $":name of the DB to delete, default:{sqld.DBName}", f: ConsoleColor.Yellow); | ||
| 787 | + parameters = ColorConsole.ReadLine($"EX=exit.", ConsoleColor.Yellow, suffix: " --> "); | ||
| 788 | + if (parameters.ToUpper() == "EX") { continue; } | ||
| 789 | + | ||
| 760 | string dbname = null; | 790 | string dbname = null; |
| 761 | if (!string.IsNullOrWhiteSpace(parameters)) | 791 | if (!string.IsNullOrWhiteSpace(parameters)) |
| 762 | { | 792 | { |
| 763 | - dbname = parameters.Split(new char[] { ',' })[0]; | ||
| 764 | - if (parameters.IndexOf(',') >= 1) { userid = parameters.Split(new char[] { ',' })[1]; } | ||
| 765 | - if (parameters.IndexOf(',') >= 0) { password = parameters.Split(new char[] { ',' })[2]; } | 793 | + var parlst = parameters.Split(new char[] { ',' }); |
| 794 | + dbname = parlst[0]; | ||
| 766 | } | 795 | } |
| 767 | if (string.IsNullOrWhiteSpace(dbname)) { dbname = sqld.DBName; } | 796 | if (string.IsNullOrWhiteSpace(dbname)) { dbname = sqld.DBName; } |
| 797 | + | ||
| 768 | ColorConsole.WriteLine($"Dropping DB..."); | 798 | ColorConsole.WriteLine($"Dropping DB..."); |
| 769 | ColorConsole.WriteLine(prefix: " connection string to server:", text: sqld.SQLCS, bracket: "[]", f: ConsoleColor.Yellow); | 799 | ColorConsole.WriteLine(prefix: " connection string to server:", text: sqld.SQLCS, bracket: "[]", f: ConsoleColor.Yellow); |
| 770 | ColorConsole.WriteLine(prefix: " DB name to drop:", text: dbname, bracket: "[]", f: ConsoleColor.Yellow); | 800 | ColorConsole.WriteLine(prefix: " DB name to drop:", text: dbname, bracket: "[]", f: ConsoleColor.Yellow); |
| @@ -896,12 +926,12 @@ GO | @@ -896,12 +926,12 @@ GO | ||
| 896 | ColorConsole.Write($"{st.Xml_Description}", ConsoleColor.Black, ConsoleColor.White); | 926 | ColorConsole.Write($"{st.Xml_Description}", ConsoleColor.Black, ConsoleColor.White); |
| 897 | var statuscolor = st.Status == SQLDataBaseManagerCore.SQLDBStatus.NoAccess ? ConsoleColor.Red:ConsoleColor.Green; | 927 | var statuscolor = st.Status == SQLDataBaseManagerCore.SQLDBStatus.NoAccess ? ConsoleColor.Red:ConsoleColor.Green; |
| 898 | ColorConsole.Write(st.Status.ToString(), statuscolor, bracket: "[]", prefix: " ", suffix: ". "); | 928 | ColorConsole.Write(st.Status.ToString(), statuscolor, bracket: "[]", prefix: " ", suffix: ". "); |
| 929 | + ColorConsole.Write(st.DBName, statuscolor, bracket: "[]", prefix: "Database ", suffix: ". "); | ||
| 930 | + ColorConsole.Write(st.DataSource, statuscolor, bracket: "[]", prefix: "from server ", suffix: ". "); | ||
| 899 | if (st.Status != SQLDataBaseManagerCore.SQLDBStatus.NoAccess) | 931 | if (st.Status != SQLDataBaseManagerCore.SQLDBStatus.NoAccess) |
| 900 | { | 932 | { |
| 901 | - ColorConsole.Write(st.DBName, statuscolor, bracket: "[]", prefix: "Database ", suffix: ". "); | ||
| 902 | - ColorConsole.Write(st.DataSource, statuscolor, bracket: "[]", prefix: "from server ", suffix: ". "); | ||
| 903 | - if (st.Xml_IsRemoteDB) { ColorConsole.Write("REMOTE", ConsoleColor.Cyan, bracket: "[]", prefix: "", suffix: ""); } | ||
| 904 | } | 933 | } |
| 934 | + if (st.Xml_IsRemoteDB) { ColorConsole.Write("REMOTE", ConsoleColor.Cyan, bracket: "[]", prefix: "", suffix: ""); } | ||
| 905 | ColorConsole.WriteLine(); | 935 | ColorConsole.WriteLine(); |
| 906 | return " "; | 936 | return " "; |
| 907 | } | 937 | } |
| @@ -1381,12 +1411,41 @@ GO | @@ -1381,12 +1411,41 @@ GO | ||
| 1381 | if (sqlserver.Databases.Contains(databasename)) | 1411 | if (sqlserver.Databases.Contains(databasename)) |
| 1382 | { | 1412 | { |
| 1383 | GetExclusiveUse(databasename, sqlserver, sc); | 1413 | GetExclusiveUse(databasename, sqlserver, sc); |
| 1384 | - sqlserver.Databases[databasename].Drop(); | 1414 | + var db = (sqlserver.Databases[databasename]); |
| 1415 | + db.Drop(); | ||
| 1385 | return true; | 1416 | return true; |
| 1386 | } | 1417 | } |
| 1387 | else { throw new ApplicationException($"Specified DB '{databasename}' does not exist!"); } | 1418 | else { throw new ApplicationException($"Specified DB '{databasename}' does not exist!"); } |
| 1388 | } | 1419 | } |
| 1389 | - catch (Exception ex) { ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); return false; } | 1420 | + catch (Exception ex) { ColorConsole.WriteLine(ex.MessageNested(nameof(DropDatabase)), ConsoleColor.Red); return false; } |
| 1421 | + finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } | ||
| 1422 | + } | ||
| 1423 | + public static Dictionary<string, string> GetDatabases(string cs, string databasenamemask, string userid, string password) | ||
| 1424 | + { | ||
| 1425 | + Server sqlserver = null; | ||
| 1426 | + Dictionary<string, string> ReturnDict = new Dictionary<string, string>(); | ||
| 1427 | + try | ||
| 1428 | + { | ||
| 1429 | + var sc = GetSqlConnection(cs, dbname: null, userid: userid, userpassword: password); | ||
| 1430 | + sqlserver = SQLServerConnect(sc); if (sqlserver == null) return null; | ||
| 1431 | + | ||
| 1432 | + foreach (Database db in sqlserver.Databases) | ||
| 1433 | + { | ||
| 1434 | + if (!Regex.Match(db.Name, databasenamemask).Success) continue; | ||
| 1435 | + string dbname=""; try { dbname = db.Name; } catch { }; | ||
| 1436 | + if (string.IsNullOrWhiteSpace(dbname) || dbname=="?") continue; | ||
| 1437 | + var dbver = ""; try { dbver = $"v{db.Version};"; } catch { }; | ||
| 1438 | + var dbowner = ""; try { dbowner = $"owner:{db.Owner};"; } catch { }; | ||
| 1439 | + var dbsize = ""; try { dbsize = $"size:{db.Size}MB;"; } catch { }; | ||
| 1440 | + var dbfree = ""; try { dbfree = $"free:{db.SpaceAvailable}MB;"; } catch { }; | ||
| 1441 | + var dbstate = ""; try { dbstate = $"state:{db.State};"; } catch { }; | ||
| 1442 | + var dbstatus = ""; try { dbstatus = $"status:{db.Status};"; } catch { }; | ||
| 1443 | + var dbstr = $"{dbver}{dbowner}{dbsize}{dbfree}{dbstate}{dbstatus}"; | ||
| 1444 | + ReturnDict.Add(dbname,dbstr); | ||
| 1445 | + } | ||
| 1446 | + return ReturnDict; | ||
| 1447 | + } | ||
| 1448 | + catch (Exception ex) { ColorConsole.WriteLine(ex.MessageNested(nameof(GetDatabases)), ConsoleColor.Red); return null; } | ||
| 1390 | finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } | 1449 | finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } |
| 1391 | } | 1450 | } |
| 1392 | public static void GetExclusiveUse(string databasename,Server sqlserver,SqlConnection sc) | 1451 | public static void GetExclusiveUse(string databasename,Server sqlserver,SqlConnection sc) |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
| @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; | ||
| 32 | // You can specify all the values or you can default the Build and Revision Numbers | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
| 33 | // by using the '*' as shown below: | 33 | // by using the '*' as shown below: |
| 34 | // [assembly: AssemblyVersion("1.0.*")] | 34 | // [assembly: AssemblyVersion("1.0.*")] |
| 35 | -[assembly: AssemblyVersion("1.27.0.0")] | ||
| 36 | -[assembly: AssemblyFileVersion("1.27.0.0")] | 35 | +[assembly: AssemblyVersion("1.27.1.0")] |
| 36 | +[assembly: AssemblyFileVersion("1.27.1.0")] |
Vrh.Log4Pro.MaintenanceConsole/Tools.cs
| @@ -502,23 +502,24 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | @@ -502,23 +502,24 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | ||
| 502 | /// Az exception és belső exceptionjeinek összefűzése | 502 | /// Az exception és belső exceptionjeinek összefűzése |
| 503 | /// </summary> | 503 | /// </summary> |
| 504 | /// <param name="ex"></param> | 504 | /// <param name="ex"></param> |
| 505 | + /// <param name="header"></param> | ||
| 505 | /// <returns></returns> | 506 | /// <returns></returns> |
| 506 | - public static string MessageNested(this Exception ex) | 507 | + public static string MessageNested(this Exception ex, string header=null) |
| 507 | { | 508 | { |
| 508 | - string rexmsg = ""; | 509 | + string rexmsg = (!string.IsNullOrWhiteSpace(header)?(header+">>>: "):"")+ ""; |
| 509 | string indent = ""; | 510 | string indent = ""; |
| 510 | const string indentof1level = " "; | 511 | const string indentof1level = " "; |
| 511 | Exception excl = ex; | 512 | Exception excl = ex; |
| 512 | while (excl != null) | 513 | while (excl != null) |
| 513 | { | 514 | { |
| 514 | - if (!string.IsNullOrWhiteSpace(ex.Message)) | ||
| 515 | - { | 515 | + if (!string.IsNullOrWhiteSpace(ex.Message)) |
| 516 | + { | ||
| 516 | rexmsg += indent + excl.Message; | 517 | rexmsg += indent + excl.Message; |
| 517 | indent += (indent == "" ? "\n" : "") + indentof1level; | 518 | indent += (indent == "" ? "\n" : "") + indentof1level; |
| 518 | } | 519 | } |
| 519 | excl = excl.InnerException; | 520 | excl = excl.InnerException; |
| 520 | } | 521 | } |
| 521 | - return rexmsg.Replace("\n\n","\n"); | 522 | + return rexmsg.Replace("\n\n", "\n"); |
| 522 | } | 523 | } |
| 523 | } | 524 | } |
| 524 | 525 |