diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - BackupPackageManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - BackupPackageManager.cs index 4f56f18..cc9253d 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - BackupPackageManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - BackupPackageManager.cs @@ -87,7 +87,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS Console.WriteLine(); var actualcursortop = Console.CursorTop; var numberofprocessedfiles = 0; - var upgradefiles = new Dictionary(); + var upgradefiles = new Dictionary(); string previousdirectory = null; foreach (var onefile in allfiles.OrderBy(p => Path.GetDirectoryName(p))) { @@ -113,7 +113,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS } //ColorConsole.WriteLine($"DIFFERENT ({difftext}): {relativePath}", ConsoleColor.Yellow); ColorConsole.WriteLine($"< {onefile} ({difftext}):", ConsoleColor.Yellow); - upgradefiles.Add(onefile, CompareDirectoriesActions.CopyFROMUPGRADE); + upgradefiles.Add(onefile, (CompareDirectoriesActions.CopyFROMUPGRADE, $"({difftext})")); } } else if (inWORKFolder) @@ -126,7 +126,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS } //ColorConsole.WriteLine($"ONLY IN Folder1: {relativePath}", ConsoleColor.Yellow); ColorConsole.WriteLine($"-- {onefile}", ConsoleColor.Yellow); - upgradefiles.Add(onefile, CompareDirectoriesActions.DeleteINWORKING); + upgradefiles.Add(onefile, (CompareDirectoriesActions.DeleteINWORKING,"")); } else if (inUPGRADEFolder) { @@ -138,17 +138,37 @@ namespace Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS } //ColorConsole.WriteLine($"ONLY IN Folder2: {relativePath}", ConsoleColor.Yellow); ColorConsole.WriteLine($"<< {onefile}", ConsoleColor.Yellow); - upgradefiles.Add(onefile, CompareDirectoriesActions.CopyFROMUPGRADE); + upgradefiles.Add(onefile, (CompareDirectoriesActions.CopyFROMUPGRADE,"(new file)")); } } ColorConsole.WriteLine(); - string movefiles = ColorConsole.ReadLine("Do You want to upgrade WORKING INSTALLATION with UPGRADE INSTALLATION:",validitylist: new List{"yes","no","YES","NO", }, defaultvalue: "no", required: true); //@"C:\Path\To\Folder1"; - if (movefiles.ToUpper() == "YES") + ColorConsole.WriteLine("Do You want to upgrade WORKING INSTALLATION with UPGRADE INSTALLATION?"); + ColorConsole.WriteLine(rootWORKING,prefix:" WORKING INSTALLATION root folder:"); + ColorConsole.WriteLine(rootUPGRADE,prefix:" UPGRADE INSTALLATION root folder:"); + string doupgradetxt = ColorConsole.ReadLine("Do upgrade?",validitylist: new List{"yes","no","YES","NO","ask","ASK" }, defaultvalue: "no", required: true); + if (doupgradetxt.ToUpper() == "EX") return o; + if (doupgradetxt.ToUpper() == "YES" || doupgradetxt.ToUpper() == "ASK") { - foreach (var uf in upgradefiles) + bool ask = doupgradetxt.ToUpper() == "ASK"; + bool goontoall = false; + foreach (var uf in upgradefiles) { - if (uf.Value == CompareDirectoriesActions.CopyFROMUPGRADE) { File.Copy(Path.Combine(rootUPGRADE, uf.Key), Path.Combine(rootWORKING, uf.Key)); } - else if (uf.Value == CompareDirectoriesActions.DeleteINWORKING) { File.Delete(Path.Combine(rootWORKING,uf.Key)); } + bool goon = true; + if (ask && !goontoall) + { + string actiontext = uf.Value.Item1 == CompareDirectoriesActions.CopyFROMUPGRADE ? "upgrade" : "remove"; + ColorConsole.WriteLine($"Do You want to {actiontext} file in WORKING INSTALLATION?"); + var validitylist = new List { "yes", "no", "YES", "NO", "yestoall", "YESTOALL", }; + string goontxt = ColorConsole.ReadLine(uf.Key,f:ConsoleColor.Yellow, prefix:" file:",suffix:uf.Value.Item2, validitylist:validitylist, defaultvalue: "no", required: true); + if (goontxt.ToUpper() == "EX") return o; + goon = goontxt.ToUpper() == "YES"; + goontoall = goontxt.ToUpper() == "YESTOALL"; + } + if (goon || goontoall) + { + if (uf.Value.Item1 == CompareDirectoriesActions.CopyFROMUPGRADE) { File.Copy(Path.Combine(rootUPGRADE, uf.Key), Path.Combine(rootWORKING, uf.Key), overwrite: true); } + else if (uf.Value.Item1 == CompareDirectoriesActions.DeleteINWORKING) { File.Delete(Path.Combine(rootWORKING, uf.Key)); } + } } } return o; diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs index f876b3b..bfbe023 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs @@ -33,6 +33,8 @@ using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder; using System.Windows.Controls; using Menu = Vrh.Log4Pro.MaintenanceConsole.MenuNS.Menu; using static Vrh.Log4Pro.MaintenanceConsole.MenuNS.Menu; +using System.Security.AccessControl; +using System.Data; namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS { @@ -1382,10 +1384,10 @@ GO #endregion private method: DisplayDataBaseInfo #endregion private methods } - #endregion SQLDataBaseManager class + #endregion SQLDataBaseManager class - #region class SQLDataBaseManager - public static class SQLDataBaseManagerCore + #region class SQLDataBaseManagerCore + public static class SQLDataBaseManagerCore { /// /// Egy adatbázis fizikai file-jainak mozgatása egy másik lokációba @@ -1539,14 +1541,26 @@ GO finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } } - /// - /// Create SQL DB backup - /// - /// az sql db-t leíró descriptor - /// - /// - /// - public static string CreateBackup(SQLDataBase sqld,bool? forcecreatezip, DateTime? timestamp,bool emulate=false) + private static void RunEXEOnRemoteComputer(string servername,string username, string password, string exefilename) + { + var processToRun = new[] { exefilename/*"notepad.exe"*/ }; + var connection = new ConnectionOptions(); + connection.Username = username; + connection.Password = password; + var wmiScope = new ManagementScope(String.Format(@"\\{0}\root\cimv2", servername), connection); + var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions()); + wmiProcess.InvokeMethod("Create", processToRun); + } + + + /// + /// Create SQL DB backup + /// + /// az sql db-t leíró descriptor + /// + /// + /// + public static string CreateBackup(SQLDataBase sqld,bool? forcecreatezip, DateTime? timestamp,bool emulate=false) { string backupdirectorypath = sqld.Xml_BackupTargetDirectoryPath; string tranzitdirectorypath = sqld.Xml_PrimaryDB_TranzitDirectoryPath; @@ -1599,57 +1613,32 @@ GO if (!emulate) { - ColorConsole.WriteLine($"Database backup started...", ConsoleColor.DarkGreen); - if (File.Exists(backupFullName)) { File.Delete(backupFullName); } - var smoBackup = new Backup(); - smoBackup.Database = dbname; - smoBackup.Action = BackupActionType.Database; - smoBackup.BackupSetName = smoBackup.Database + " Backup"; - smoBackup.BackupSetDescription = $"Full Backup of {smoBackup.Database}"; - smoBackup.MediaDescription = "Disk"; - Console.WriteLine($"Backup set: {smoBackup.BackupSetName} ({smoBackup.BackupSetDescription}) to media: {smoBackup.MediaDescription}"); - string dummystring = sqld.Xml_PrimaryDB_IsUseTranzit ? " REMOTE SQL SERVER!" : ""; - Console.WriteLine($"Database name: {smoBackup.Database}{dummystring}"); - Console.WriteLine($"Connection string: {sqld.SQLCS_Primary}"); - smoBackup.Devices.AddDevice(sqld.Xml_PrimaryDB_IsUseTranzit ? tranzitFullName : backupFullName, DeviceType.File); - Console.WriteLine($"Backup full name:{backupFullName}"); - if (sqld.Xml_PrimaryDB_IsUseTranzit) - { - Console.WriteLine($" ...will be created through tranzit: {tranzitFullName}"); - } - smoBackup.PercentComplete += SmoBackupRestore_PercentComplete; - smoBackup.PercentCompleteNotification = 1; + ColorConsole.WriteLine($"Database backup started...", ConsoleColor.DarkGreen); + if (File.Exists(backupFullName)) { File.Delete(backupFullName); } + + + Console.WriteLine($"Backup set: {dbname + " Backup"} (Full backup of {dbname}) to media: Disk"); + string dummystring = sqld.Xml_PrimaryDB_IsUseTranzit ? " REMOTE SQL SERVER!" : ""; + Console.WriteLine($"Database name: {dbname}{dummystring}"); + Console.WriteLine($"Connection string: {sqld.SQLCS_Primary}"); + Console.WriteLine($"Backup full name:{backupFullName}"); + if (sqld.Xml_PrimaryDB_IsUseTranzit) { Console.WriteLine($" ...will be created through through tranzit {tranzitFullName}"); } + + var result = BackupDatabase(sqld.Xml_PrimaryDB_IsUseTranzit ? tranzitFullName : backupFullName, sqld.SQLCS_Primary, sqld.Xml_BackupTimeout, SmoBackupRestore_PercentComplete); + + Console.WriteLine($""); + Console.WriteLine("BACKUP " + (result.Success?"SUCCESS":"FAILURE") + ". " + result.Resulttext); - Server sqlserver = null; - try - { - sqlserver = SQLServerConnect(sqld.SQLCS_Primary, "master"); if (sqlserver == null) { return null; } - sqlserver.ConnectionContext.StatementTimeout = sqld.Xml_BackupTimeout; - backupstarttime = DateTime.Now; - smoBackup.SqlBackupAsync(sqlserver); - smoBackup.Wait(); - //smoBackup.Wait(); - Console.WriteLine($""); - Console.WriteLine($"Backup completed. Backup time: {(int)(DateTime.Now.Subtract(backupstarttime).TotalSeconds)}sec."); - } - catch (Exception ex) - { - ColorConsole.WriteLine($"ERROR! Database backup failed. DB name:'{smoBackup.Database}'. BAK/ZIP file name:'{Path.GetFileName(returnfilename)}'", ConsoleColor.Red); - var errmsg = ""; while (ex != null) { errmsg += ";" + ex.Message;ex = ex.InnerException; } - ColorConsole.WriteLine(errmsg, ConsoleColor.Red); - return null; - } - finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } if (sqld.Xml_PrimaryDB_IsUseTranzit && File.Exists(tranzitFullName)) { - File.Move(tranzitFullName, backupFullName); - Console.WriteLine($"Moving backup file..."); - Console.WriteLine($" ...from tranzit location: {tranzitFullName}"); - Console.WriteLine($" ...to backup location: {backupFullName}"); + Console.WriteLine($"Moving backup file..."); + Console.WriteLine($" ...from tranzit location: {tranzitFullName}"); + Console.WriteLine($" ...to backup location: {backupFullName}"); + File.Move(tranzitFullName, backupFullName); } if (!File.Exists(backupFullName)) { - ColorConsole.WriteLine($"ERROR! Database backup failed. DB name:'{smoBackup.Database}'. BAK/ZIP file name:'{Path.GetFileName(returnfilename)}'", ConsoleColor.Red); + ColorConsole.WriteLine($"ERROR! Database backup failed. DB name:'{dbname}'. BAK/ZIP file name:'{Path.GetFileName(returnfilename)}'", ConsoleColor.Red); return null; } if (createzip) @@ -1661,12 +1650,76 @@ GO File.Delete(backupFullName); Console.WriteLine($"Zipping completed. Compressing time: {(int)(DateTime.Now.Subtract(startcompressing).TotalSeconds)}sec."); } - ColorConsole.WriteLine($"SUCCESS! Database backup created. DB name:'{smoBackup.Database}'. BAK/ZIP file name:'{Path.GetFileName(returnfilename)}'", ConsoleColor.DarkGreen); + ColorConsole.WriteLine($"SUCCESS! Database backup created. DB name:'{dbname}'. BAK/ZIP file name:'{Path.GetFileName(returnfilename)}'", ConsoleColor.DarkGreen); } return returnfilename; } private static DateTime backupstarttime; - private static void SmoBackupRestore_PercentComplete(object sender, PercentCompleteEventArgs e) + private static (bool Success, string Resulttext, string Header) BackupDatabase(string backuptargetfilename, string sqlconnectionstringtodatabase, int BackupTimeout, PercentCompleteEventHandler pcEventHandler) + { + string DatabaseName = ServerConnectionPool.GetSqlConnection(sqlconnectionstringtodatabase).Database; + string Header = $"Sql connection to database:{sqlconnectionstringtodatabase} Backup target:{backuptargetfilename}"; + string SUCCESSTEXT = "Done with SUCCESS; Time elapsed:{0}"; + string EXCEPTIONTEXT = "BACKUPEXCEPTION: {0}"; + string SERVERCONNECTIONFAILURETEXT = "SERVERCONNECTIONFAILURE"; + backupstarttime = DateTime.Now; + bool mode = false; + if (mode) + { + var SQLCtos = ServerConnectionPool.GetSqlConnection(sqlconnectionstringtodatabase, "master"); + string SqlConnectionStringToServer = SQLCtos.ConnectionString; + DatabaseName = "[" + DatabaseName + "]"; + string SQLBackUp = @"BACKUP DATABASE " + DatabaseName + " TO DISK = N'" + backuptargetfilename + @"'"; + SqlConnection cnBk = new SqlConnection(SqlConnectionStringToServer); + SqlCommand cmdBkUp = new SqlCommand(SQLBackUp, cnBk); + cmdBkUp.CommandTimeout = BackupTimeout; + Header = $"{SQLBackUp} {Header}"; + try + { + cnBk.Open(); + cmdBkUp.ExecuteNonQuery(); + return (true, string.Format(SUCCESSTEXT, DateTime.Now.Subtract(backupstarttime).TotalSeconds), Header); + } + catch (Exception ex) + { + var errmsg = ""; while (ex != null) { errmsg += ex.Message + ";"; ex = ex.InnerException; } + return (false, string.Format(EXCEPTIONTEXT, errmsg), Header); + } + finally + { + if (cnBk.State == ConnectionState.Open) { cnBk.Close(); } + } + } + else + { + var smoBackup = new Backup(); + smoBackup.Database = DatabaseName; + smoBackup.Action = BackupActionType.Database; + smoBackup.BackupSetName = smoBackup.Database + " Backup"; + smoBackup.BackupSetDescription = $"Full Backup of {smoBackup.Database}"; + smoBackup.MediaDescription = "Disk"; + smoBackup.Devices.AddDevice(backuptargetfilename, DeviceType.File); + smoBackup.PercentComplete += pcEventHandler; + smoBackup.PercentCompleteNotification = 1; + + Server sqlserver = null; + try + { + sqlserver = SQLServerConnect(sqlconnectionstringtodatabase, "master"); if (sqlserver == null) { return (false, string.Format(SERVERCONNECTIONFAILURETEXT), Header); } + sqlserver.ConnectionContext.StatementTimeout = BackupTimeout; + smoBackup.SqlBackup(sqlserver); + //smoBackup.SqlBackupAsync(sqlserver);smoBackup.Wait(); + return (true, string.Format(SUCCESSTEXT, DateTime.Now.Subtract(backupstarttime).TotalSeconds), Header); + } + catch (Exception ex) + { + var errmsg = ""; while (ex != null) { errmsg += ex.Message + ";"; ex = ex.InnerException; } + return (false, string.Format(EXCEPTIONTEXT, errmsg), Header); + } + finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } + } + } + private static void SmoBackupRestore_PercentComplete(object sender, PercentCompleteEventArgs e) { ColorConsole.SetCursorPosition(0, Console.CursorTop); ColorConsole.Write($"Completed: {e.Percent}%. {e.Message}. Backup time : {(int)(DateTime.Now.Subtract(backupstarttime).TotalSeconds)}sec."); @@ -2629,10 +2682,10 @@ GO } #endregion BackupSqlData } - #endregion class SQLDataBaseManager + #endregion class SQLDataBaseManagerCore - #region SQLDataBaseManager class - public class SQLDataBaseManagerXmlProcessor : XmlParser + #region SQLDataBaseManagerXmlProcessor class + public class SQLDataBaseManagerXmlProcessor : XmlParser { #region fields private List _sqldatabaselist; @@ -2663,10 +2716,10 @@ GO public List GetDefinitionList() { return _sqldatabaselist; } #endregion GetDefinitionList } - #endregion SQLDataBaseManager class + #endregion SQLDataBaseManagerXmlProcessor class - #region SQLDataBase class - public class SQLDataBase : XmlLinqBase + #region SQLDataBase class + public class SQLDataBase : XmlLinqBase { #region fields public bool Valid = true; diff --git a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs index 6e80d34..9d2c1e1 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.34.1.0")] -[assembly: AssemblyFileVersion("1.34.1.0")] +[assembly: AssemblyVersion("1.34.2.0")] +[assembly: AssemblyFileVersion("1.34.2.0")] diff --git a/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj b/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj index eba8e72..a7ddadd 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj +++ b/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj @@ -347,23 +347,23 @@ - - ..\packages\VRH.Common.4.1.1\lib\net462\VRH.Common.dll + + ..\packages\VRH.Common.4.1.4\lib\net462\VRH.Common.dll - - ..\packages\VRH.Common.4.1.1\lib\net462\VRH.Common.COM.dll + + ..\packages\VRH.Common.4.1.4\lib\net462\VRH.Common.COM.dll - - ..\packages\VRH.Common.4.1.1\lib\net462\VRH.Common.EF.dll + + ..\packages\VRH.Common.4.1.4\lib\net462\VRH.Common.EF.dll - - ..\packages\VRH.Common.4.1.1\lib\net462\VRH.Common.Log4ProIS.dll + + ..\packages\VRH.Common.4.1.4\lib\net462\VRH.Common.Log4ProIS.dll ..\packages\VRH.Web.Providers.2.0.2\lib\net452\Vrh.Web.Providers.dll - - ..\packages\Vrh.XmlProcessing.2.8.0\lib\net45\Vrh.XmlProcessing.dll + + ..\packages\Vrh.XmlProcessing.2.9.5\lib\net462\Vrh.XmlProcessing.dll diff --git a/Vrh.Log4Pro.MaintenanceConsole/packages.config b/Vrh.Log4Pro.MaintenanceConsole/packages.config index 53a7da2..d12081e 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/packages.config +++ b/Vrh.Log4Pro.MaintenanceConsole/packages.config @@ -73,7 +73,7 @@ - + - + \ No newline at end of file -- libgit2 0.21.2