Compare View

switch
from
...
to
 
Commits (3)
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
... ... @@ -288,12 +288,18 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS
288 288 public static class Functions
289 289 {
290 290 public const string CMD_PACKAGES = "-PACKAGES";
291   - public static class CreateBackupPackage
  291 + public const string CMD_DIR1 = "-DIR1";
  292 + public const string CMD_DIR2 = "-DIR2";
  293 + public static class CreateBackupPackage
292 294 {
293 295 public const string KEY = "CRE";
294 296 }
295   - }
296   - }
  297 + public static class CompareDirectories
  298 + {
  299 + public const string KEY = "COM";
  300 + }
  301 + }
  302 + }
297 303 public static class SQLDataBaseManager
298 304 {
299 305 public const string KEY = "SQL";
... ...
Vrh.Log4Pro.MaintenanceConsole/Manager - BackupPackageManager.cs
... ... @@ -22,6 +22,8 @@ using Vrh.XmlProcessing;
22 22 using VRH.Common;
23 23 using System.Xml.Linq;
24 24 using System.Text.RegularExpressions;
  25 +using System.Security.Cryptography;
  26 +using System.Numerics;
25 27  
26 28 namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS
27 29 {
... ... @@ -42,7 +44,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS
42 44  
43 45 var menufunctions = new Menu("Manage Backup Packages", "Select the management function!")
44 46 .AddMenuItem(new Menu.Item(CLP.Module.BackupPackageManager.Functions.CreateBackupPackage.KEY, "Create backup package", CreateBackupPackage,ep))
45   - .SetSelectionMode(Menu.SelectionMode.Single)
  47 + .AddMenuItem(new Menu.Item(CLP.Module.BackupPackageManager.Functions.CompareDirectories.KEY, "Compare directories", CompareDirectories, ep))
  48 + .SetSelectionMode(Menu.SelectionMode.Single)
46 49 .SetMenuHeaderDisplayer(BackupPackageListDisplayer);
47 50 menufunctions.ExecuteMenu(functionkey);
48 51 return o2;
... ... @@ -50,7 +53,213 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS
50 53 #endregion Execute
51 54  
52 55 #region First level Executors with UI
53   - private static object CreateBackupPackage(object parameter, object o)
  56 + internal static object CompareDirectories(object parameter, object o)
  57 + {
  58 + var config = parameter==null?null:((parameter as Menu.ExecutorParameter).GetConfig<BackupPackageManagerXmlProcessor>());
  59 + var args = parameter == null ? null : ((parameter as Menu.ExecutorParameter).Args);
  60 +
  61 + var dir1= CommandLine.GetCommandLineArgument(args, CLP.Module.BackupPackageManager.Functions.CMD_DIR1);
  62 + var dir2 = CommandLine.GetCommandLineArgument(args, CLP.Module.BackupPackageManager.Functions.CMD_DIR2);
  63 +
  64 +
  65 + string rootWORKING = ColorConsole.ReadLine("Enter path to WORKING INSTALLATION directory:", defaultvalue: dir1 ?? "", required: true); //@"C:\Path\To\Folder1";
  66 + string rootUPGRADE = ColorConsole.ReadLine("Enter path to UPGRADE INSTALLATION directory:", defaultvalue: dir1 ?? "", required: true); //@"C:\Path\To\Folder2";
  67 + string searchpatterncsvlist = ColorConsole.ReadLine("Enter search pattern (csv list):", defaultvalue: "*.dll,*.exe", required: true); //@"C:\Path\To\Folder2";
  68 +
  69 + rootWORKING = rootWORKING + @"\"; rootWORKING.Replace(@"/", @"\").Replace(@"\\", @"\");
  70 + rootUPGRADE = rootUPGRADE + @"\"; rootUPGRADE.Replace(@"/", @"\").Replace(@"\\", @"\");
  71 +
  72 + ColorConsole.WriteLine("Comparing folders...");
  73 + ColorConsole.WriteLine($" WORKING INSTALLATION: {rootWORKING}");
  74 + ColorConsole.WriteLine($" UPGRADE INSTALLATION: {rootUPGRADE}");
  75 + ColorConsole.WriteLine($" Search patterns: {searchpatterncsvlist}");
  76 + ColorConsole.WriteLine();
  77 +
  78 +
  79 + var folderWFiles = GetFilesWithRelativePaths(rootWORKING, searchpatterncsvlist);
  80 + var folder2Files = GetFilesWithRelativePaths(rootUPGRADE, searchpatterncsvlist);
  81 +
  82 +
  83 + var allfiles = new HashSet<string>(folderWFiles.Keys);
  84 + allfiles.UnionWith(folder2Files.Keys);
  85 +
  86 + var savedcursortop = Console.CursorTop;
  87 + Console.WriteLine();
  88 + var actualcursortop = Console.CursorTop;
  89 + var numberofprocessedfiles = 0;
  90 + var upgradefiles = new Dictionary<string, (CompareDirectoriesActions,string)>();
  91 + string previousdirectory = null;
  92 + foreach (var onefile in allfiles.OrderBy(p => Path.GetDirectoryName(p)))
  93 + {
  94 + numberofprocessedfiles++;
  95 + if (numberofprocessedfiles < 25)
  96 + {
  97 + actualcursortop = Console.CursorTop;
  98 + ColorConsole.SetCursorPosition(0, savedcursortop); ColorConsole.Write(onefile, suffix: new string(' ', 20));
  99 + ColorConsole.SetCursorPosition(0, actualcursortop);
  100 + }
  101 + bool inWORKFolder = folderWFiles.TryGetValue(onefile, out string file1);
  102 + bool inUPGRADEFolder = folder2Files.TryGetValue(onefile, out string file2);
  103 +
  104 + if (inWORKFolder && inUPGRADEFolder)
  105 + {
  106 + if (!FilesAreEqual(file1, file2, out string difftext))
  107 + {
  108 + string actualdirectory = Path.GetDirectoryName(onefile);
  109 + if (previousdirectory != actualdirectory)
  110 + {
  111 + ColorConsole.WriteLine(actualdirectory, ConsoleColor.DarkYellow);
  112 + previousdirectory = actualdirectory;
  113 + }
  114 + //ColorConsole.WriteLine($"DIFFERENT ({difftext}): {relativePath}", ConsoleColor.Yellow);
  115 + ColorConsole.WriteLine($"< {onefile} ({difftext}):", ConsoleColor.Yellow);
  116 + upgradefiles.Add(onefile, (CompareDirectoriesActions.CopyFROMUPGRADE, $"({difftext})"));
  117 + }
  118 + }
  119 + else if (inWORKFolder)
  120 + {
  121 + string actualdirectory = Path.GetDirectoryName(onefile);
  122 + if (previousdirectory != actualdirectory)
  123 + {
  124 + ColorConsole.WriteLine(actualdirectory, ConsoleColor.DarkYellow);
  125 + previousdirectory = actualdirectory;
  126 + }
  127 + //ColorConsole.WriteLine($"ONLY IN Folder1: {relativePath}", ConsoleColor.Yellow);
  128 + ColorConsole.WriteLine($"-- {onefile}", ConsoleColor.Yellow);
  129 + upgradefiles.Add(onefile, (CompareDirectoriesActions.DeleteINWORKING,""));
  130 + }
  131 + else if (inUPGRADEFolder)
  132 + {
  133 + string actualdirectory = Path.GetDirectoryName(onefile);
  134 + if (previousdirectory != actualdirectory)
  135 + {
  136 + ColorConsole.WriteLine(actualdirectory, ConsoleColor.DarkYellow);
  137 + previousdirectory = actualdirectory;
  138 + }
  139 + //ColorConsole.WriteLine($"ONLY IN Folder2: {relativePath}", ConsoleColor.Yellow);
  140 + ColorConsole.WriteLine($"<< {onefile}", ConsoleColor.Yellow);
  141 + upgradefiles.Add(onefile, (CompareDirectoriesActions.CopyFROMUPGRADE,"(new file)"));
  142 + }
  143 + }
  144 + ColorConsole.WriteLine();
  145 + ColorConsole.WriteLine("Do You want to upgrade WORKING INSTALLATION with UPGRADE INSTALLATION?");
  146 + ColorConsole.WriteLine(rootWORKING,prefix:" WORKING INSTALLATION root folder:");
  147 + ColorConsole.WriteLine(rootUPGRADE,prefix:" UPGRADE INSTALLATION root folder:");
  148 + string doupgradetxt = ColorConsole.ReadLine("Do upgrade?",validitylist: new List<string>{"yes","no","YES","NO","ask","ASK" }, defaultvalue: "no", required: true);
  149 + if (doupgradetxt.ToUpper() == "EX") return o;
  150 + if (doupgradetxt.ToUpper() == "YES" || doupgradetxt.ToUpper() == "ASK")
  151 + {
  152 + bool ask = doupgradetxt.ToUpper() == "ASK";
  153 + bool goontoall = false;
  154 + foreach (var uf in upgradefiles)
  155 + {
  156 + bool goon = true;
  157 + if (ask && !goontoall)
  158 + {
  159 + string actiontext = uf.Value.Item1 == CompareDirectoriesActions.CopyFROMUPGRADE ? "upgrade" : "remove";
  160 + ColorConsole.WriteLine($"Do You want to {actiontext} file in WORKING INSTALLATION?");
  161 + var validitylist = new List<string> { "yes", "no", "YES", "NO", "yestoall", "YESTOALL", };
  162 + string goontxt = ColorConsole.ReadLine(uf.Key,f:ConsoleColor.Yellow, prefix:" file:",suffix:uf.Value.Item2, validitylist:validitylist, defaultvalue: "no", required: true);
  163 + if (goontxt.ToUpper() == "EX") return o;
  164 + goon = goontxt.ToUpper() == "YES";
  165 + goontoall = goontxt.ToUpper() == "YESTOALL";
  166 + }
  167 + if (goon || goontoall)
  168 + {
  169 + if (uf.Value.Item1 == CompareDirectoriesActions.CopyFROMUPGRADE) { File.Copy(Path.Combine(rootUPGRADE, uf.Key), Path.Combine(rootWORKING, uf.Key), overwrite: true); }
  170 + else if (uf.Value.Item1 == CompareDirectoriesActions.DeleteINWORKING) { File.Delete(Path.Combine(rootWORKING, uf.Key)); }
  171 + }
  172 + }
  173 + }
  174 + return o;
  175 + }
  176 + private enum CompareDirectoriesActions { CopyFROMUPGRADE, DeleteINWORKING,}
  177 + private static Dictionary<string, string> GetFilesWithRelativePaths(string root,string searchpattern="*")
  178 + {
  179 + var searchpatternlist = searchpattern.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
  180 + List<string> files = new List<string>() { };
  181 + foreach (var sp in searchpatternlist)
  182 + {
  183 + files.AddRange(Directory.GetFiles(root, sp, SearchOption.AllDirectories));
  184 + }
  185 + var dict = new Dictionary<string, string>();
  186 + foreach (var fileAbsolutPath in files)
  187 + {
  188 + string relativePath = GetRelativePath(root, fileAbsolutPath);
  189 + dict[relativePath] = fileAbsolutPath;
  190 + }
  191 + return dict;
  192 + }
  193 + /// <summary>
  194 + /// Creates a relative path from one file or folder to another.
  195 + /// </summary>
  196 + /// <param name="fromPath">Contains the directory that defines the start of the relative path.</param>
  197 + /// <param name="toPath">Contains the path that defines the endpoint of the relative path.</param>
  198 + /// <returns>The relative path from the start directory to the end path or <c>toPath</c> if the paths are not related.</returns>
  199 + /// <exception cref="ArgumentNullException"></exception>
  200 + /// <exception cref="UriFormatException"></exception>
  201 + /// <exception cref="InvalidOperationException"></exception>
  202 + public static string GetRelativePath(String fromPath, String toPath)
  203 + {
  204 + if (String.IsNullOrEmpty(fromPath)) throw new ArgumentNullException("fromPath");
  205 + if (String.IsNullOrEmpty(toPath)) throw new ArgumentNullException("toPath");
  206 +
  207 + Uri fromUri = new Uri(fromPath);
  208 + Uri toUri = new Uri(toPath);
  209 +
  210 + if (fromUri.Scheme != toUri.Scheme) { return toPath; } // path can't be made relative.
  211 +
  212 + Uri relativeUri = fromUri.MakeRelativeUri(toUri);
  213 + String relativePath = Uri.UnescapeDataString(relativeUri.ToString());
  214 +
  215 + if (toUri.Scheme.Equals("file", StringComparison.InvariantCultureIgnoreCase))
  216 + {
  217 + relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
  218 + }
  219 +
  220 + return relativePath;
  221 + }
  222 + private static bool FilesAreEqual(string WORKINGfilePath, string UPGRADEfilePath,out string differencetext)
  223 + {
  224 + differencetext = null;
  225 + var fiW = new FileInfo(WORKINGfilePath);
  226 + var fiU = new FileInfo(UPGRADEfilePath);
  227 +
  228 + var fvW = FileVersionInfo.GetVersionInfo(WORKINGfilePath);
  229 + var fvU = FileVersionInfo.GetVersionInfo(UPGRADEfilePath);
  230 + var fvW1=GetVersionNumber(fvW, out string fvW2);
  231 + var fvU1 = GetVersionNumber(fvU, out string fvU2);
  232 + var fveresiondifftext = "";// $" {fvW1}<>{fvU1};{fvW2}<>{fvU2}";
  233 + var pvW1 = GetVersionNumber(fvW, out string pvW2,true);
  234 + var pvU1 = GetVersionNumber(fvU, out string pvU2,true);
  235 + var pveresiondifftext = "";// $" {pvW1}<>{pvU1};{pvW2}<>{pvU2}";
  236 + if (fvW.FileVersion != fvU.FileVersion) { string oldertext = fvW1 > fvU1 ? "DOWNGRADE":"UPGRADE"; differencetext = $"{oldertext} FileVersion: {fveresiondifftext} {fvW.FileVersion} <--> {fvU.FileVersion}"; return false; }
  237 + if (fvW.ProductVersion != fvU.ProductVersion) { string oldertext = pvW1 > pvU1 ? "DOWNGRADE" : "UPGRADE"; differencetext = $"{oldertext} ProductVersion: {pveresiondifftext} {fvW.ProductVersion} <--> {fvU.ProductVersion}"; return false; }
  238 + //if (fi1.CreationTime != fi2.CreationTime) return false;
  239 + //if (fi1.LastWriteTimeUtc != fi2.LastWriteTimeUtc) { differencetext = "LastWriteTimeUTC"; return false; }
  240 + if (fiW.Length != fiU.Length) { string oldertext = fiW.Length > fiU.Length?"DOWNSIZE":"UPSIZE"; differencetext = $"Length: {oldertext} {fiW.Length} <--> {fiU.Length}"; return false; }
  241 + using (var sha256 = SHA256.Create())
  242 + using (var stream1 = File.OpenRead(WORKINGfilePath))
  243 + using (var stream2 = File.OpenRead(UPGRADEfilePath))
  244 + {
  245 + var hash1 = sha256.ComputeHash(stream1);
  246 + var hash2 = sha256.ComputeHash(stream2);
  247 +
  248 + if (!hash1.SequenceEqual(hash2)) { differencetext = "Hash/Content"; return false; }
  249 + }
  250 + return true;
  251 + }
  252 + private static long GetVersionNumber(FileVersionInfo vi,out string vt,bool useproductversion=false)
  253 + {
  254 + vt = useproductversion
  255 + ? $"{vi.ProductMajorPart}.{vi.ProductMinorPart}.{vi.ProductBuildPart}.{vi.ProductPrivatePart}"
  256 + : $"{vi.FileMajorPart}.{vi.FileMinorPart}.{vi.FileBuildPart}.{vi.FilePrivatePart}";
  257 + long numberbase = 10000;
  258 + return useproductversion
  259 + ? vi.ProductMajorPart * numberbase * numberbase * numberbase + vi.ProductMinorPart * numberbase * numberbase + vi.ProductBuildPart * numberbase + vi.ProductPrivatePart
  260 + : vi.FileMajorPart * numberbase * numberbase * numberbase + vi.FileMinorPart * numberbase * numberbase + vi.FileBuildPart * numberbase + vi.FilePrivatePart;
  261 + }
  262 + private static object CreateBackupPackage(object parameter, object o)
54 263 {
55 264 var config = (parameter as Menu.ExecutorParameter).GetConfig< BackupPackageManagerXmlProcessor>();
56 265 var args = (parameter as Menu.ExecutorParameter).Args;
... ...
Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs
... ... @@ -33,6 +33,8 @@ using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
33 33 using System.Windows.Controls;
34 34 using Menu = Vrh.Log4Pro.MaintenanceConsole.MenuNS.Menu;
35 35 using static Vrh.Log4Pro.MaintenanceConsole.MenuNS.Menu;
  36 +using System.Security.AccessControl;
  37 +using System.Data;
36 38  
37 39 namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS
38 40 {
... ... @@ -1382,10 +1384,10 @@ GO
1382 1384 #endregion private method: DisplayDataBaseInfo
1383 1385 #endregion private methods
1384 1386 }
1385   - #endregion SQLDataBaseManager class
  1387 + #endregion SQLDataBaseManager class
1386 1388  
1387   - #region class SQLDataBaseManager
1388   - public static class SQLDataBaseManagerCore
  1389 + #region class SQLDataBaseManagerCore
  1390 + public static class SQLDataBaseManagerCore
1389 1391 {
1390 1392 /// <summary>
1391 1393 /// Egy adatbázis fizikai file-jainak mozgatása egy másik lokációba
... ... @@ -1539,14 +1541,26 @@ GO
1539 1541 finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); }
1540 1542 }
1541 1543  
1542   - /// <summary>
1543   - /// Create SQL DB backup
1544   - /// </summary>
1545   - /// <param name="sqld">az sql db-t leíró descriptor</param>
1546   - /// <param name="forcecreatezip"></param>
1547   - /// <param name="timestamp"></param>
1548   - /// <returns></returns>
1549   - public static string CreateBackup(SQLDataBase sqld,bool? forcecreatezip, DateTime? timestamp,bool emulate=false)
  1544 + private static void RunEXEOnRemoteComputer(string servername,string username, string password, string exefilename)
  1545 + {
  1546 + var processToRun = new[] { exefilename/*"notepad.exe"*/ };
  1547 + var connection = new ConnectionOptions();
  1548 + connection.Username = username;
  1549 + connection.Password = password;
  1550 + var wmiScope = new ManagementScope(String.Format(@"\\{0}\root\cimv2", servername), connection);
  1551 + var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
  1552 + wmiProcess.InvokeMethod("Create", processToRun);
  1553 + }
  1554 +
  1555 +
  1556 + /// <summary>
  1557 + /// Create SQL DB backup
  1558 + /// </summary>
  1559 + /// <param name="sqld">az sql db-t leíró descriptor</param>
  1560 + /// <param name="forcecreatezip"></param>
  1561 + /// <param name="timestamp"></param>
  1562 + /// <returns></returns>
  1563 + public static string CreateBackup(SQLDataBase sqld,bool? forcecreatezip, DateTime? timestamp,bool emulate=false)
1550 1564 {
1551 1565 string backupdirectorypath = sqld.Xml_BackupTargetDirectoryPath;
1552 1566 string tranzitdirectorypath = sqld.Xml_PrimaryDB_TranzitDirectoryPath;
... ... @@ -1599,57 +1613,32 @@ GO
1599 1613  
1600 1614 if (!emulate)
1601 1615 {
1602   - ColorConsole.WriteLine($"Database backup started...", ConsoleColor.DarkGreen);
1603   - if (File.Exists(backupFullName)) { File.Delete(backupFullName); }
1604   - var smoBackup = new Backup();
1605   - smoBackup.Database = dbname;
1606   - smoBackup.Action = BackupActionType.Database;
1607   - smoBackup.BackupSetName = smoBackup.Database + " Backup";
1608   - smoBackup.BackupSetDescription = $"Full Backup of {smoBackup.Database}";
1609   - smoBackup.MediaDescription = "Disk";
1610   - Console.WriteLine($"Backup set: {smoBackup.BackupSetName} ({smoBackup.BackupSetDescription}) to media: {smoBackup.MediaDescription}");
1611   - string dummystring = sqld.Xml_PrimaryDB_IsUseTranzit ? " REMOTE SQL SERVER!" : "";
1612   - Console.WriteLine($"Database name: {smoBackup.Database}{dummystring}");
1613   - Console.WriteLine($"Connection string: {sqld.SQLCS_Primary}");
1614   - smoBackup.Devices.AddDevice(sqld.Xml_PrimaryDB_IsUseTranzit ? tranzitFullName : backupFullName, DeviceType.File);
1615   - Console.WriteLine($"Backup full name:{backupFullName}");
1616   - if (sqld.Xml_PrimaryDB_IsUseTranzit)
1617   - {
1618   - Console.WriteLine($" ...will be created through tranzit: {tranzitFullName}");
1619   - }
1620   - smoBackup.PercentComplete += SmoBackupRestore_PercentComplete;
1621   - smoBackup.PercentCompleteNotification = 1;
  1616 + ColorConsole.WriteLine($"Database backup started...", ConsoleColor.DarkGreen);
  1617 + if (File.Exists(backupFullName)) { File.Delete(backupFullName); }
  1618 +
  1619 +
  1620 + Console.WriteLine($"Backup set: {dbname + " Backup"} (Full backup of {dbname}) to media: Disk");
  1621 + string dummystring = sqld.Xml_PrimaryDB_IsUseTranzit ? " REMOTE SQL SERVER!" : "";
  1622 + Console.WriteLine($"Database name: {dbname}{dummystring}");
  1623 + Console.WriteLine($"Connection string: {sqld.SQLCS_Primary}");
  1624 + Console.WriteLine($"Backup full name:{backupFullName}");
  1625 + if (sqld.Xml_PrimaryDB_IsUseTranzit) { Console.WriteLine($" ...will be created through through tranzit {tranzitFullName}"); }
  1626 +
  1627 + var result = BackupDatabase(sqld.Xml_PrimaryDB_IsUseTranzit ? tranzitFullName : backupFullName, sqld.SQLCS_Primary, sqld.Xml_BackupTimeout, SmoBackupRestore_PercentComplete);
  1628 +
  1629 + Console.WriteLine($"");
  1630 + Console.WriteLine("BACKUP " + (result.Success?"SUCCESS":"FAILURE") + ". " + result.Resulttext);
1622 1631  
1623   - Server sqlserver = null;
1624   - try
1625   - {
1626   - sqlserver = SQLServerConnect(sqld.SQLCS_Primary, "master"); if (sqlserver == null) { return null; }
1627   - sqlserver.ConnectionContext.StatementTimeout = sqld.Xml_BackupTimeout;
1628   - backupstarttime = DateTime.Now;
1629   - smoBackup.SqlBackupAsync(sqlserver);
1630   - smoBackup.Wait();
1631   - //smoBackup.Wait();
1632   - Console.WriteLine($"");
1633   - Console.WriteLine($"Backup completed. Backup time: {(int)(DateTime.Now.Subtract(backupstarttime).TotalSeconds)}sec.");
1634   - }
1635   - catch (Exception ex)
1636   - {
1637   - ColorConsole.WriteLine($"ERROR! Database backup failed. DB name:'{smoBackup.Database}'. BAK/ZIP file name:'{Path.GetFileName(returnfilename)}'", ConsoleColor.Red);
1638   - var errmsg = ""; while (ex != null) { errmsg += ";" + ex.Message;ex = ex.InnerException; }
1639   - ColorConsole.WriteLine(errmsg, ConsoleColor.Red);
1640   - return null;
1641   - }
1642   - finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); }
1643 1632 if (sqld.Xml_PrimaryDB_IsUseTranzit && File.Exists(tranzitFullName))
1644 1633 {
1645   - File.Move(tranzitFullName, backupFullName);
1646   - Console.WriteLine($"Moving backup file...");
1647   - Console.WriteLine($" ...from tranzit location: {tranzitFullName}");
1648   - Console.WriteLine($" ...to backup location: {backupFullName}");
  1634 + Console.WriteLine($"Moving backup file...");
  1635 + Console.WriteLine($" ...from tranzit location: {tranzitFullName}");
  1636 + Console.WriteLine($" ...to backup location: {backupFullName}");
  1637 + File.Move(tranzitFullName, backupFullName);
1649 1638 }
1650 1639 if (!File.Exists(backupFullName))
1651 1640 {
1652   - ColorConsole.WriteLine($"ERROR! Database backup failed. DB name:'{smoBackup.Database}'. BAK/ZIP file name:'{Path.GetFileName(returnfilename)}'", ConsoleColor.Red);
  1641 + ColorConsole.WriteLine($"ERROR! Database backup failed. DB name:'{dbname}'. BAK/ZIP file name:'{Path.GetFileName(returnfilename)}'", ConsoleColor.Red);
1653 1642 return null;
1654 1643 }
1655 1644 if (createzip)
... ... @@ -1661,12 +1650,76 @@ GO
1661 1650 File.Delete(backupFullName);
1662 1651 Console.WriteLine($"Zipping completed. Compressing time: {(int)(DateTime.Now.Subtract(startcompressing).TotalSeconds)}sec.");
1663 1652 }
1664   - ColorConsole.WriteLine($"SUCCESS! Database backup created. DB name:'{smoBackup.Database}'. BAK/ZIP file name:'{Path.GetFileName(returnfilename)}'", ConsoleColor.DarkGreen);
  1653 + ColorConsole.WriteLine($"SUCCESS! Database backup created. DB name:'{dbname}'. BAK/ZIP file name:'{Path.GetFileName(returnfilename)}'", ConsoleColor.DarkGreen);
1665 1654 }
1666 1655 return returnfilename;
1667 1656 }
1668 1657 private static DateTime backupstarttime;
1669   - private static void SmoBackupRestore_PercentComplete(object sender, PercentCompleteEventArgs e)
  1658 + private static (bool Success, string Resulttext, string Header) BackupDatabase(string backuptargetfilename, string sqlconnectionstringtodatabase, int BackupTimeout, PercentCompleteEventHandler pcEventHandler)
  1659 + {
  1660 + string DatabaseName = ServerConnectionPool.GetSqlConnection(sqlconnectionstringtodatabase).Database;
  1661 + string Header = $"Sql connection to database:{sqlconnectionstringtodatabase} Backup target:{backuptargetfilename}";
  1662 + string SUCCESSTEXT = "Done with SUCCESS; Time elapsed:{0}";
  1663 + string EXCEPTIONTEXT = "BACKUPEXCEPTION: {0}";
  1664 + string SERVERCONNECTIONFAILURETEXT = "SERVERCONNECTIONFAILURE";
  1665 + backupstarttime = DateTime.Now;
  1666 + bool mode = false;
  1667 + if (mode)
  1668 + {
  1669 + var SQLCtos = ServerConnectionPool.GetSqlConnection(sqlconnectionstringtodatabase, "master");
  1670 + string SqlConnectionStringToServer = SQLCtos.ConnectionString;
  1671 + DatabaseName = "[" + DatabaseName + "]";
  1672 + string SQLBackUp = @"BACKUP DATABASE " + DatabaseName + " TO DISK = N'" + backuptargetfilename + @"'";
  1673 + SqlConnection cnBk = new SqlConnection(SqlConnectionStringToServer);
  1674 + SqlCommand cmdBkUp = new SqlCommand(SQLBackUp, cnBk);
  1675 + cmdBkUp.CommandTimeout = BackupTimeout;
  1676 + Header = $"{SQLBackUp} {Header}";
  1677 + try
  1678 + {
  1679 + cnBk.Open();
  1680 + cmdBkUp.ExecuteNonQuery();
  1681 + return (true, string.Format(SUCCESSTEXT, DateTime.Now.Subtract(backupstarttime).TotalSeconds), Header);
  1682 + }
  1683 + catch (Exception ex)
  1684 + {
  1685 + var errmsg = ""; while (ex != null) { errmsg += ex.Message + ";"; ex = ex.InnerException; }
  1686 + return (false, string.Format(EXCEPTIONTEXT, errmsg), Header);
  1687 + }
  1688 + finally
  1689 + {
  1690 + if (cnBk.State == ConnectionState.Open) { cnBk.Close(); }
  1691 + }
  1692 + }
  1693 + else
  1694 + {
  1695 + var smoBackup = new Backup();
  1696 + smoBackup.Database = DatabaseName;
  1697 + smoBackup.Action = BackupActionType.Database;
  1698 + smoBackup.BackupSetName = smoBackup.Database + " Backup";
  1699 + smoBackup.BackupSetDescription = $"Full Backup of {smoBackup.Database}";
  1700 + smoBackup.MediaDescription = "Disk";
  1701 + smoBackup.Devices.AddDevice(backuptargetfilename, DeviceType.File);
  1702 + smoBackup.PercentComplete += pcEventHandler;
  1703 + smoBackup.PercentCompleteNotification = 1;
  1704 +
  1705 + Server sqlserver = null;
  1706 + try
  1707 + {
  1708 + sqlserver = SQLServerConnect(sqlconnectionstringtodatabase, "master"); if (sqlserver == null) { return (false, string.Format(SERVERCONNECTIONFAILURETEXT), Header); }
  1709 + sqlserver.ConnectionContext.StatementTimeout = BackupTimeout;
  1710 + smoBackup.SqlBackup(sqlserver);
  1711 + //smoBackup.SqlBackupAsync(sqlserver);smoBackup.Wait();
  1712 + return (true, string.Format(SUCCESSTEXT, DateTime.Now.Subtract(backupstarttime).TotalSeconds), Header);
  1713 + }
  1714 + catch (Exception ex)
  1715 + {
  1716 + var errmsg = ""; while (ex != null) { errmsg += ex.Message + ";"; ex = ex.InnerException; }
  1717 + return (false, string.Format(EXCEPTIONTEXT, errmsg), Header);
  1718 + }
  1719 + finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); }
  1720 + }
  1721 + }
  1722 + private static void SmoBackupRestore_PercentComplete(object sender, PercentCompleteEventArgs e)
1670 1723 {
1671 1724 ColorConsole.SetCursorPosition(0, Console.CursorTop);
1672 1725 ColorConsole.Write($"Completed: {e.Percent}%. {e.Message}. Backup time : {(int)(DateTime.Now.Subtract(backupstarttime).TotalSeconds)}sec.");
... ... @@ -2629,10 +2682,10 @@ GO
2629 2682 }
2630 2683 #endregion BackupSqlData
2631 2684 }
2632   - #endregion class SQLDataBaseManager
  2685 + #endregion class SQLDataBaseManagerCore
2633 2686  
2634   - #region SQLDataBaseManager class
2635   - public class SQLDataBaseManagerXmlProcessor : XmlParser
  2687 + #region SQLDataBaseManagerXmlProcessor class
  2688 + public class SQLDataBaseManagerXmlProcessor : XmlParser
2636 2689 {
2637 2690 #region fields
2638 2691 private List<SQLDataBase> _sqldatabaselist;
... ... @@ -2663,10 +2716,10 @@ GO
2663 2716 public List<SQLDataBase> GetDefinitionList() { return _sqldatabaselist; }
2664 2717 #endregion GetDefinitionList
2665 2718 }
2666   - #endregion SQLDataBaseManager class
  2719 + #endregion SQLDataBaseManagerXmlProcessor class
2667 2720  
2668   - #region SQLDataBase class
2669   - public class SQLDataBase : XmlLinqBase
  2721 + #region SQLDataBase class
  2722 + public class SQLDataBase : XmlLinqBase
2670 2723 {
2671 2724 #region fields
2672 2725 public bool Valid = true;
... ...
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
... ... @@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
32 32 // You can specify all the values or you can default the Build and Revision Numbers
33 33 // by using the '*' as shown below:
34 34 // [assembly: AssemblyVersion("1.0.*")]
35   -[assembly: AssemblyVersion("1.33.0.0")]
36   -[assembly: AssemblyFileVersion("1.33.0.0")]
  35 +[assembly: AssemblyVersion("1.34.2.0")]
  36 +[assembly: AssemblyFileVersion("1.34.2.0")]
... ...
Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj
... ... @@ -347,23 +347,23 @@
347 347 <Reference Include="Microsoft.CSharp" />
348 348 <Reference Include="System.Data" />
349 349 <Reference Include="System.Xml" />
350   - <Reference Include="VRH.Common, Version=4.1.1.0, Culture=neutral, processorArchitecture=MSIL">
351   - <HintPath>..\packages\VRH.Common.4.1.1\lib\net462\VRH.Common.dll</HintPath>
  350 + <Reference Include="VRH.Common, Version=4.1.4.0, Culture=neutral, processorArchitecture=MSIL">
  351 + <HintPath>..\packages\VRH.Common.4.1.4\lib\net462\VRH.Common.dll</HintPath>
352 352 </Reference>
353   - <Reference Include="VRH.Common.COM, Version=4.1.0.0, Culture=neutral, processorArchitecture=MSIL">
354   - <HintPath>..\packages\VRH.Common.4.1.1\lib\net462\VRH.Common.COM.dll</HintPath>
  353 + <Reference Include="VRH.Common.COM, Version=4.1.3.0, Culture=neutral, processorArchitecture=MSIL">
  354 + <HintPath>..\packages\VRH.Common.4.1.4\lib\net462\VRH.Common.COM.dll</HintPath>
355 355 </Reference>
356   - <Reference Include="VRH.Common.EF, Version=4.1.0.0, Culture=neutral, processorArchitecture=MSIL">
357   - <HintPath>..\packages\VRH.Common.4.1.1\lib\net462\VRH.Common.EF.dll</HintPath>
  356 + <Reference Include="VRH.Common.EF, Version=4.1.3.0, Culture=neutral, processorArchitecture=MSIL">
  357 + <HintPath>..\packages\VRH.Common.4.1.4\lib\net462\VRH.Common.EF.dll</HintPath>
358 358 </Reference>
359   - <Reference Include="VRH.Common.Log4ProIS, Version=4.1.1.0, Culture=neutral, processorArchitecture=MSIL">
360   - <HintPath>..\packages\VRH.Common.4.1.1\lib\net462\VRH.Common.Log4ProIS.dll</HintPath>
  359 + <Reference Include="VRH.Common.Log4ProIS, Version=4.1.4.0, Culture=neutral, processorArchitecture=MSIL">
  360 + <HintPath>..\packages\VRH.Common.4.1.4\lib\net462\VRH.Common.Log4ProIS.dll</HintPath>
361 361 </Reference>
362 362 <Reference Include="Vrh.Web.Providers, Version=2.0.2.0, Culture=neutral, processorArchitecture=MSIL">
363 363 <HintPath>..\packages\VRH.Web.Providers.2.0.2\lib\net452\Vrh.Web.Providers.dll</HintPath>
364 364 </Reference>
365   - <Reference Include="Vrh.XmlProcessing, Version=2.8.0.0, Culture=neutral, processorArchitecture=MSIL">
366   - <HintPath>..\packages\Vrh.XmlProcessing.2.8.0\lib\net45\Vrh.XmlProcessing.dll</HintPath>
  365 + <Reference Include="Vrh.XmlProcessing, Version=2.9.5.0, Culture=neutral, processorArchitecture=MSIL">
  366 + <HintPath>..\packages\Vrh.XmlProcessing.2.9.5\lib\net462\Vrh.XmlProcessing.dll</HintPath>
367 367 </Reference>
368 368 <Reference Include="WindowsBase" />
369 369 </ItemGroup>
... ...
Vrh.Log4Pro.MaintenanceConsole/packages.config
... ... @@ -73,7 +73,7 @@
73 73 <package id="System.Threading.Timer" version="4.0.1" targetFramework="net472" />
74 74 <package id="System.Xml.ReaderWriter" version="4.0.11" targetFramework="net472" />
75 75 <package id="System.Xml.XDocument" version="4.0.11" targetFramework="net472" />
76   - <package id="VRH.Common" version="4.1.1" targetFramework="net472" />
  76 + <package id="VRH.Common" version="4.1.4" targetFramework="net472" />
77 77 <package id="VRH.Web.Providers" version="2.0.2" targetFramework="net472" />
78   - <package id="Vrh.XmlProcessing" version="2.8.0" targetFramework="net472" />
  78 + <package id="Vrh.XmlProcessing" version="2.9.5" targetFramework="net472" />
79 79 </packages>
80 80 \ No newline at end of file
... ...