From b2db361984b7f6833d24eb4c574ec3513d8b7633 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 9 Aug 2018 13:52:40 +0300 Subject: Removed APPLICATION_VERSIONS & EMBEDDED_SOFTWARE_VERSIONS TABLES. Added TANGO_VERSIONS. Working on PPC machine setup. --- .../MachineSetup/MachineSetupManager.cs | 41 ++-------------------- 1 file changed, 3 insertions(+), 38 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs index dc5164465..64500b454 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -81,7 +81,7 @@ namespace Tango.PPC.Common.MachineSetup //Download software package. var tempFile = TemporaryManager.CreateFile(".zip"); - UpdatingPackagesStatus = "Downloading application package..."; + UpdatingPackagesStatus = "Downloading software package..."; int fileSize = 0; UpdatingPackagesProgress = 0; @@ -100,48 +100,13 @@ namespace Tango.PPC.Common.MachineSetup LogManager.Log("Connecting to FTP site: " + setup_response.FtpAddress); ftp.ConnectAsync().Wait(); LogManager.Log("Retrieving download size..."); - fileSize = (int)ftp.GetFileSize(setup_response.ApplicationFtpFilePath); + fileSize = (int)ftp.GetFileSize(setup_response.FilePath); LogManager.Log("Download size: " + fileSize + " bytes."); LogManager.Log("Starting download..."); - ftp.DownloadAsync(fs, setup_response.ApplicationFtpFilePath).Wait(); + ftp.DownloadAsync(fs, setup_response.FilePath).Wait(); } } - //Extract software package. - ZipFile.ExtractToDirectory(tempFile, software_package_folder); - - //Download embedded package. - tempFile = TemporaryManager.CreateFile(".zip"); - - UpdatingPackagesStatus = "Downloading embedded package..."; - - fileSize = 0; - UpdatingPackagesProgress = 0; - - using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) => - { - InvokeUINow(() => - { - Thread.Sleep(10); - UpdatingPackagesProgress = ((double)current / (double)fileSize) * 100d; - }); - })) - { - using (FtpClient ftp = new FtpClient(setup_response.FtpAddress, setup_response.UserName, setup_response.Password)) - { - LogManager.Log("Connecting to FTP site: " + setup_response.FtpAddress); - ftp.ConnectAsync().Wait(); - LogManager.Log("Retrieving download size..."); - fileSize = (int)ftp.GetFileSize(setup_response.EmbeddedFtpFilePath); - LogManager.Log("Download size: " + fileSize + " bytes."); - LogManager.Log("Starting download..."); - ftp.DownloadAsync(fs, setup_response.EmbeddedFtpFilePath).Wait(); - } - } - - //Extract embedded package. - ZipFile.ExtractToDirectory(tempFile, embedded_package_folder); - //Synchronize database String remote_address = setup_response.DbAddress; -- cgit v1.3.1 From 690e3aa537a830e2f7c11aee03502124a0e612cf Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 9 Aug 2018 19:05:10 +0300 Subject: Working on PPC machine setup. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 1835008 -> 1835008 bytes .../MachineSetup/IMachineSetupManager.cs | 4 +- .../MachineSetup/MachineSetupManager.cs | 133 ++++++++------------- .../MachineSetup/MachineSetupSteps.cs | 2 +- .../PPC/Tango.PPC.UI/Views/MachineSetupView.xaml | 8 +- .../Visual_Studio/Tango.SQLExaminer/DbManager.cs | 14 +++ .../ExaminerSequenceConfigurationRunner.cs | 21 +++- .../SQLExaminer/Configurations/OverrideData.xml | Bin 78698 -> 76282 bytes .../Web/Tango.MachineService/Web.config | 4 +- 10 files changed, 88 insertions(+), 98 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 533bfb0ee..2abcb4b5b 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 5c9924eb0..5ad54eddd 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs index 52fc5acd1..096431d63 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs @@ -10,8 +10,8 @@ namespace Tango.PPC.Common.MachineSetup { MachineSetupSteps CurrentStep { get; } event EventHandler ProgressLog; - double UpdatingPackagesProgress { get; } - String UpdatingPackagesStatus { get; } + double DownloadingPackagesProgress { get; } + String DownloadingPackagesStatus { get; } event EventHandler ProgressStep; Task Setup(String serialNumber, String hostAddress); } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs index 64500b454..72c6da515 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -30,21 +30,24 @@ namespace Tango.PPC.Common.MachineSetup get { return _currentStep; } set { - _currentStep = value; - RaisePropertyChangedAuto(); - ProgressStep?.Invoke(this, _currentStep); + if (_currentStep != value) + { + _currentStep = value; + RaisePropertyChangedAuto(); + ProgressStep?.Invoke(this, _currentStep); + } } } private double _downloadProgress; - public double UpdatingPackagesProgress + public double DownloadingPackagesProgress { get { return _downloadProgress; } private set { _downloadProgress = value; RaisePropertyChangedAuto(); } } private String _updatingPackagesStatus; - public String UpdatingPackagesStatus + public String DownloadingPackagesStatus { get { return _updatingPackagesStatus; } set { _updatingPackagesStatus = value; RaisePropertyChangedAuto(); } @@ -56,9 +59,9 @@ namespace Tango.PPC.Common.MachineSetup { //Connect to machine service and get matching packages for this machine. - CurrentStep = MachineSetupSteps.UpdatingPackages; - UpdatingPackagesProgress = 0; - UpdatingPackagesStatus = "Connecting to machine service..."; + CurrentStep = MachineSetupSteps.DownloadingPackage; + DownloadingPackagesProgress = 0; + DownloadingPackagesStatus = "Connecting to machine service..."; MachineSetupRequest request = new MachineSetupRequest(); request.SerialNumber = serialNumber; @@ -74,24 +77,20 @@ namespace Tango.PPC.Common.MachineSetup var _newPackageTempFolder = TemporaryManager.CreateFolder(); _newPackageTempFolder.Persist = true; - var software_package_folder = _newPackageTempFolder.CreateFolder(); - var embedded_package_folder = _newPackageTempFolder.CreateFolder(); - - //Download software package. var tempFile = TemporaryManager.CreateFile(".zip"); - UpdatingPackagesStatus = "Downloading software package..."; + DownloadingPackagesStatus = "Downloading software package..."; int fileSize = 0; - UpdatingPackagesProgress = 0; + DownloadingPackagesProgress = 0; using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) => { InvokeUINow(() => { Thread.Sleep(10); - UpdatingPackagesProgress = ((double)current / (double)fileSize) * 100d; + DownloadingPackagesProgress = ((double)current / (double)fileSize) * 100d; }); })) { @@ -107,96 +106,60 @@ namespace Tango.PPC.Common.MachineSetup } } - //Synchronize database - String remote_address = setup_response.DbAddress; + //Extract software package. + ZipFile.ExtractToDirectory(tempFile, _newPackageTempFolder); + + //Synchronize database CurrentStep = MachineSetupSteps.SynchronizingSchema; String db_name = "Tango"; - String localAddress = SettingsManager.Default.GetOrCreate().DataBaseSource; - - var tempFolder = TemporaryManager.Default.CreateFolder("Machine Setup"); - String report_file = tempFolder.CreateImaginaryFile(".xml"); - String config_file = tempFolder.CreateImaginaryFile(".xml"); + String remote_address = setup_response.DbAddress; DbManager db = new DbManager(new SqlConnection(String.Format("Server={0};Integrated security=SSPI", localAddress))); - if (!db.Exists("Tango")) + if (!db.Exists(db_name)) { throw new InvalidProgramException("Database tango does not exists."); } - //Create schema configuration - ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.Schema); - - builder. - SetSourceServer(remote_address, db_name). - SetTargetServer(localAddress, db_name). - Synchronize(); - - //Synchronize Source schema with Target schema - - var process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Schema); - process.Progress += (x, msg) => - { - ProgressLog?.Invoke(this, msg); - }; - var result = process.Execute().Result; - - //Synchronization was successful - if (result.ExitCode != ExaminerProcessExitCode.Success) - { - throw new InvalidProgramException("Error while trying to synchronize database schema."); - } - - CurrentStep = MachineSetupSteps.SynchronizingData; - - //Create override data configuration - builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.OverrideData); + db.ClearDb(db_name); //TODO: This is not working! - builder. - SetSourceServer(remote_address, db_name). - SetTargetServer(localAddress, db_name). - Synchronize(); + ExaminerSequenceConfigurationRunner runner = new ExaminerSequenceConfigurationRunner( + Path.Combine(_newPackageTempFolder, "Synchronization Scripts", "config.xml"), + Path.Combine(_newPackageTempFolder, "Synchronization Scripts"), + new ExaminerSequenceDataSource() + { + Address = remote_address, + DataBaseName = db_name, + IntegratedSecurity = true, + }, + new ExaminerSequenceDataSource() + { + Address = localAddress, + DataBaseName = db_name, + IntegratedSecurity = true, + }, serialNumber); - process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data); - process.Progress += (x, msg) => + runner.Log += (x, msg) => { - ProgressLog?.Invoke(this, msg); + ProgressLog.Invoke(this, msg); }; - result = process.Execute().Result; - - //Synchronization was successful - if (result.ExitCode != ExaminerProcessExitCode.Success) - { - throw new InvalidProgramException("Error while trying to synchronize data."); - } - - CurrentStep = MachineSetupSteps.SynchronizingMachineConfiguration; - //Provision Target - builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.ProvisionMachine); - - builder. - SetSourceServer(remote_address, db_name). - SetTargetServer(localAddress, db_name). - SetMachineSerialNumber(serialNumber). - Synchronize(); - - - process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data); - process.Progress += (x, msg) => + runner.ScriptExecuting += (x, item) => { - ProgressLog?.Invoke(this, msg); + if (item.Type == ExaminerSequenceItemType.Data && item.RequiresSerialNumber) + { + CurrentStep = MachineSetupSteps.SynchronizingMachineConfiguration; + } + else if (item.Type == ExaminerSequenceItemType.Data) + { + CurrentStep = MachineSetupSteps.SynchronizingData; + } }; - result = process.Execute().Result; - //Synchronization was successful - if (result.ExitCode != ExaminerProcessExitCode.Success) - { - throw new InvalidProgramException("Error while trying to synchronize database schema."); - } + runner.Run().Wait(); }); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs index 1262eb248..3db1eb4b0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs @@ -10,7 +10,7 @@ namespace Tango.PPC.Common.MachineSetup public enum MachineSetupSteps { [Description("Downloading Package")] - UpdatingPackages, + DownloadingPackage, [Description("Synchronizing Schema")] SynchronizingSchema, [Description("Synchronizing Data")] diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml index 521da0e35..e300d95aa 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml @@ -65,15 +65,15 @@ - Downloading package... - + + - - Setup completed successfully. Machine is ready! + + Setup completed successfully. Machine is ready! START diff --git a/Software/Visual_Studio/Tango.SQLExaminer/DbManager.cs b/Software/Visual_Studio/Tango.SQLExaminer/DbManager.cs index 21c6af4b8..fb783c928 100644 --- a/Software/Visual_Studio/Tango.SQLExaminer/DbManager.cs +++ b/Software/Visual_Studio/Tango.SQLExaminer/DbManager.cs @@ -110,5 +110,19 @@ namespace Tango.SQLExaminer File.Delete(backupPath); } + + public void ClearDb(String name) + { + EnsureOpen(); + + SqlCommand cmd = new SqlCommand("EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'", _connection); + cmd.ExecuteNonQuery(); + + cmd = new SqlCommand("EXEC sp_MSForEachTable 'DELETE FROM ?'", _connection); + cmd.ExecuteNonQuery(); + + cmd = new SqlCommand("EXEC sp_MSForEachTable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL'", _connection); + cmd.ExecuteNonQuery(); + } } } diff --git a/Software/Visual_Studio/Tango.SQLExaminer/ExaminerSequenceConfigurationRunner.cs b/Software/Visual_Studio/Tango.SQLExaminer/ExaminerSequenceConfigurationRunner.cs index f6a5b31c2..b9ee986bc 100644 --- a/Software/Visual_Studio/Tango.SQLExaminer/ExaminerSequenceConfigurationRunner.cs +++ b/Software/Visual_Studio/Tango.SQLExaminer/ExaminerSequenceConfigurationRunner.cs @@ -22,6 +22,8 @@ namespace Tango.SQLExaminer public String ScriptsFolder { get; private set; } + public ExaminerSequenceConfiguration Configuration { get; private set; } + public ExaminerSequenceConfigurationRunner(String sequenceFile, String scriptsFolder, ExaminerSequenceDataSource source, ExaminerSequenceDataSource target, String machineSerialNumber) { SequenceFile = sequenceFile; @@ -29,21 +31,32 @@ namespace Tango.SQLExaminer Source = source; Target = target; MachineSerialNumber = machineSerialNumber; + Configuration = ExaminerSequenceConfiguration.FromFile(sequenceFile); } public Task Run() { return Task.Factory.StartNew(() => { - ExaminerSequenceConfiguration sequence = ExaminerSequenceConfiguration.FromFile(SequenceFile); + ExaminerSequenceConfiguration sequence = Configuration; - foreach (var item in sequence.Items) + foreach (var item in sequence.Items.OrderBy(x => x.Index)) { ScriptExecuting?.Invoke(this, item); ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(Path.Combine(ScriptsFolder, item.FileName)); - builder.SetSourceServer(Source.Address, Source.DataBaseName, Source.IntegratedSecurity, Source.UserName, Source.Password); - builder.SetTargetServer(Target.Address, Target.DataBaseName, Target.IntegratedSecurity, Target.UserName, Target.Password); + + + if (item.Direction == ExaminerSequenceItemDirection.SourceToTarget) + { + builder.SetSourceServer(Source.Address, Source.DataBaseName, Source.IntegratedSecurity, Source.UserName, Source.Password); + builder.SetTargetServer(Target.Address, Target.DataBaseName, Target.IntegratedSecurity, Target.UserName, Target.Password); + } + else + { + builder.SetSourceServer(Target.Address, Target.DataBaseName, Target.IntegratedSecurity, Target.UserName, Target.Password); + builder.SetTargetServer(Source.Address, Source.DataBaseName, Source.IntegratedSecurity, Source.UserName, Source.Password); + } if (item.RequiresSerialNumber) { diff --git a/Software/Visual_Studio/Tango.SQLExaminer/SQLExaminer/Configurations/OverrideData.xml b/Software/Visual_Studio/Tango.SQLExaminer/SQLExaminer/Configurations/OverrideData.xml index 3ec2890f9..9e5e41c23 100644 Binary files a/Software/Visual_Studio/Tango.SQLExaminer/SQLExaminer/Configurations/OverrideData.xml and b/Software/Visual_Studio/Tango.SQLExaminer/SQLExaminer/Configurations/OverrideData.xml differ diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index 4185b4e7b..ca05ae5e0 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -14,8 +14,8 @@ - - + + -- cgit v1.3.1 From 18fc4053deb06af6643f28a6bb4fd66c6a9a93e0 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 12 Aug 2018 19:00:36 +0300 Subject: Implemented temporary DB user login for machine service machine setup. Implemented Tango updater! Implemented support for software update on machine setup. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 1835008 -> 1835008 bytes .../Synchronization/MachineSetupResponse.proto | 10 +- .../Tango.MachineStudio.Updater/MainWindow.xaml | 2 +- .../Application/IPPCApplicationManager.cs | 11 +- .../Application/SetupRequiredEventArgs.cs | 23 -- .../PPC/Tango.PPC.Common/ApplicationStates.cs | 16 ++ .../MachineSetup/IMachineSetupManager.cs | 2 +- .../MachineSetup/MachineSetupManager.cs | 38 ++- .../MachineSetup/MachineSetupResult.cs | 2 +- .../PPC/Tango.PPC.Common/PPCSettings.cs | 4 +- .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 4 +- .../PPC/Tango.PPC.Publisher/MainWindowVM.cs | 6 + .../Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs | 10 + .../PPC/Tango.PPC.UI/MainWindow.xaml.cs | 2 +- .../PPCApplication/DefaultPPCApplicationManager.cs | 41 ++-- .../PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs | 33 +-- .../Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs | 33 +-- .../PPC/Tango.PPC.UI/Views/MachineSetupView.xaml | 2 +- .../Visual_Studio/PPC/Tango.PPC.Updater/App.config | 6 + .../Visual_Studio/PPC/Tango.PPC.Updater/App.xaml | 9 + .../PPC/Tango.PPC.Updater/App.xaml.cs | 24 ++ .../PPC/Tango.PPC.Updater/Images/package.png | Bin 0 -> 2250 bytes .../PPC/Tango.PPC.Updater/MainWindow.xaml | 17 ++ .../PPC/Tango.PPC.Updater/MainWindow.xaml.cs | 169 ++++++++++++++ .../Tango.PPC.Updater/Properties/AssemblyInfo.cs | 55 +++++ .../Properties/Resources.Designer.cs | 71 ++++++ .../Tango.PPC.Updater/Properties/Resources.resx | 117 ++++++++++ .../Properties/Settings.Designer.cs | 30 +++ .../Tango.PPC.Updater/Properties/Settings.settings | 7 + .../PPC/Tango.PPC.Updater/Tango.PPC.Updater.csproj | 102 ++++++++ .../Visual_Studio/Tango.Core/DB/DbCredentials.cs | 14 ++ Software/Visual_Studio/Tango.Core/DB/DbManager.cs | 256 +++++++++++++++++++++ .../Visual_Studio/Tango.Core/Tango.Core.csproj | 4 +- .../Synchronization/MachineSetupResponse.cs | 187 +++++++++------ .../Visual_Studio/Tango.SQLExaminer/DbManager.cs | 128 ----------- .../Tango.SQLExaminer/Tango.SQLExaminer.csproj | 1 - .../Tango.UnitTesting/SQLExaminer_TST.cs | 3 +- Software/Visual_Studio/Tango.sln | 55 ++++- .../Controllers/SynchronizationController.cs | 33 ++- .../Web/Tango.MachineService/Web.config | 4 +- 41 files changed, 1198 insertions(+), 333 deletions(-) delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Application/SetupRequiredEventArgs.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/ApplicationStates.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Updater/App.config create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Updater/App.xaml create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Updater/App.xaml.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Updater/Images/package.png create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Resources.Designer.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Resources.resx create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Settings.Designer.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Settings.settings create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Updater/Tango.PPC.Updater.csproj create mode 100644 Software/Visual_Studio/Tango.Core/DB/DbCredentials.cs create mode 100644 Software/Visual_Studio/Tango.Core/DB/DbManager.cs delete mode 100644 Software/Visual_Studio/Tango.SQLExaminer/DbManager.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 2abcb4b5b..5a9504bd5 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 5ad54eddd..264c75faf 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/PMR/Messages/Synchronization/MachineSetupResponse.proto b/Software/PMR/Messages/Synchronization/MachineSetupResponse.proto index 8b16e264b..fa525dcac 100644 --- a/Software/PMR/Messages/Synchronization/MachineSetupResponse.proto +++ b/Software/PMR/Messages/Synchronization/MachineSetupResponse.proto @@ -6,11 +6,13 @@ option java_package = "com.twine.tango.pmr.synchronization"; message MachineSetupResponse { string Version = 1; - string FilePath = 2; - string FtpAddress = 3; - string UserName = 4; - string Password = 5; + string FtpAddress = 2; + string FtpFilePath = 3; + string FtpUserName = 4; + string FtpPassword = 5; string DbAddress = 6; + string DbUserName = 7; + string DbPassword = 8; } \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml index a8d428650..e254d289b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/MainWindow.xaml @@ -29,7 +29,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs index e1d06034f..aba2d2fcd 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs @@ -38,7 +38,7 @@ namespace Tango.PPC.Common.Application /// /// Occurs when machine setup is required. /// - event EventHandler SetupRequired; + event EventHandler SetupRequired; /// /// Gets a value indicating whether the application is shutting down. @@ -51,8 +51,13 @@ namespace Tango.PPC.Common.Application void ShutDown(); /// - /// Gets the application version. + /// Gets the machine studio application version. /// - String Version { get; } + Version Version { get; } + + /// + /// Gets the build date. + /// + String BuildDate { get; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/SetupRequiredEventArgs.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/SetupRequiredEventArgs.cs deleted file mode 100644 index 9a545d781..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/SetupRequiredEventArgs.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.PPC.Common.Application -{ - public class SetupRequiredEventArgs : EventArgs - { - private Action _continueAction; - - public SetupRequiredEventArgs(Action continueAction) - { - _continueAction = continueAction; - } - - public void Continue() - { - _continueAction?.Invoke(); - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/ApplicationStates.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/ApplicationStates.cs new file mode 100644 index 000000000..3b4dbf4f7 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/ApplicationStates.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common +{ + public enum ApplicationStates + { + PreSetup = 0, + SemiSetup = 1, + Default = 2, + Updating = 3, + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs index 096431d63..8856bcfd4 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs @@ -13,6 +13,6 @@ namespace Tango.PPC.Common.MachineSetup double DownloadingPackagesProgress { get; } String DownloadingPackagesStatus { get; } event EventHandler ProgressStep; - Task Setup(String serialNumber, String hostAddress); + Task Setup(String serialNumber, String hostAddress); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs index 72c6da515..01f828c3f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -11,8 +11,10 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Tango.Core; +using Tango.Core.DB; using Tango.Core.IO; using Tango.PMR.Synchronization; +using Tango.PPC.Common.Application; using Tango.Settings; using Tango.SQLExaminer; using Tango.Transport.Web; @@ -21,6 +23,8 @@ namespace Tango.PPC.Common.MachineSetup { public class MachineSetupManager : ExtendedObject, IMachineSetupManager { + private IPPCApplicationManager _applicationManager; + public event EventHandler ProgressLog; public event EventHandler ProgressStep; @@ -53,9 +57,14 @@ namespace Tango.PPC.Common.MachineSetup set { _updatingPackagesStatus = value; RaisePropertyChangedAuto(); } } - public Task Setup(string serialNumber, string machineServiceAddress) + public MachineSetupManager(IPPCApplicationManager applicationManager) { - return Task.Factory.StartNew(() => + _applicationManager = applicationManager; + } + + public Task Setup(string serialNumber, string machineServiceAddress) + { + return Task.Factory.StartNew(() => { //Connect to machine service and get matching packages for this machine. @@ -94,15 +103,15 @@ namespace Tango.PPC.Common.MachineSetup }); })) { - using (FtpClient ftp = new FtpClient(setup_response.FtpAddress, setup_response.UserName, setup_response.Password)) + using (FtpClient ftp = new FtpClient(setup_response.FtpAddress, setup_response.FtpUserName, setup_response.FtpPassword)) { LogManager.Log("Connecting to FTP site: " + setup_response.FtpAddress); ftp.ConnectAsync().Wait(); LogManager.Log("Retrieving download size..."); - fileSize = (int)ftp.GetFileSize(setup_response.FilePath); + fileSize = (int)ftp.GetFileSize(setup_response.FtpFilePath); LogManager.Log("Download size: " + fileSize + " bytes."); LogManager.Log("Starting download..."); - ftp.DownloadAsync(fs, setup_response.FilePath).Wait(); + ftp.DownloadAsync(fs, setup_response.FtpFilePath).Wait(); } } @@ -117,14 +126,16 @@ namespace Tango.PPC.Common.MachineSetup String localAddress = SettingsManager.Default.GetOrCreate().DataBaseSource; String remote_address = setup_response.DbAddress; - DbManager db = new DbManager(new SqlConnection(String.Format("Server={0};Integrated security=SSPI", localAddress))); + DbManager db = DbManager.FromAddressAndName(localAddress, db_name); if (!db.Exists(db_name)) { throw new InvalidProgramException("Database tango does not exists."); } - db.ClearDb(db_name); //TODO: This is not working! + db.ClearDb(); + + db.Dispose(); ExaminerSequenceConfigurationRunner runner = new ExaminerSequenceConfigurationRunner( Path.Combine(_newPackageTempFolder, "Synchronization Scripts", "config.xml"), @@ -133,7 +144,9 @@ namespace Tango.PPC.Common.MachineSetup { Address = remote_address, DataBaseName = db_name, - IntegratedSecurity = true, + IntegratedSecurity = false, + UserName = setup_response.DbUserName, + Password = setup_response.DbPassword, }, new ExaminerSequenceDataSource() { @@ -142,12 +155,12 @@ namespace Tango.PPC.Common.MachineSetup IntegratedSecurity = true, }, serialNumber); - runner.Log += (x, msg) => + runner.Log += (x, msg) => { ProgressLog.Invoke(this, msg); }; - runner.ScriptExecuting += (x, item) => + runner.ScriptExecuting += (x, item) => { if (item.Type == ExaminerSequenceItemType.Data && item.RequiresSerialNumber) { @@ -160,6 +173,11 @@ namespace Tango.PPC.Common.MachineSetup }; runner.Run().Wait(); + + return new MachineSetupResult() + { + UpdatePackagePath = _newPackageTempFolder, + }; }); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupResult.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupResult.cs index 5887a6d34..c459ddf50 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupResult.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupResult.cs @@ -8,6 +8,6 @@ namespace Tango.PPC.Common.MachineSetup { public class MachineSetupResult { - public bool Completed { get; set; } + public String UpdatePackagePath { get; set; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs index aecf93a0d..2b87e89bb 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs @@ -26,9 +26,9 @@ namespace Tango.PPC.Common public List LoggingCategories { get; set; } /// - /// Gets or sets a value indicating whether this instance has setup. + /// Gets or sets the state of the application. /// - public bool HasSetup { get; set; } + public ApplicationStates ApplicationState { get; set; } /// /// Gets the update service address. diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index aeb478a36..1214093b9 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -102,7 +102,7 @@ GlobalVersionInfo.cs - + @@ -280,7 +280,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindowVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindowVM.cs index 6a0f92966..d429c8935 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindowVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindowVM.cs @@ -28,7 +28,13 @@ namespace Tango.PPC.Publisher public class MainWindowVM : ViewModel { private IPPCUpdateService _client; + +#if DEBUG + private String _appPath = AppDomain.CurrentDomain.BaseDirectory + "..\\..\\Debug\\PPC"; +#else private String _appPath = AppDomain.CurrentDomain.BaseDirectory + "..\\..\\Release\\PPC"; +#endif + private BasicHashGenerator _hashGenerator; private List _machineVersions; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs index f33ca1c42..4187967dc 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Configuration; using System.Data; +using System.Diagnostics; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -20,6 +21,7 @@ namespace Tango.PPC.UI /// public partial class App : Application { + public static String[] StartupArgs { get; private set; } private LogManager LogManager = LogManager.Default; /// @@ -28,6 +30,14 @@ namespace Tango.PPC.UI /// A that contains the event data. protected override void OnStartup(StartupEventArgs e) { + //If no debugger is attached and the argument --debug was passed launch the debugger + if (e.Args.Contains("-debug") && !Debugger.IsAttached) + { + Debugger.Launch(); + } + + StartupArgs = e.Args; + LogManager.RegisterLogger(new VSOutputLogger()); LogManager.RegisterLogger(new FileLogger()); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs index 181c05145..ca26b7761 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs @@ -37,7 +37,7 @@ namespace Tango.PPC.UI WindowStyle = WindowStyle.None; ResizeMode = ResizeMode.NoResize; WindowStartupLocation = WindowStartupLocation.Manual; - Topmost = false; // sure? + Topmost = true; // sure? var screens = System.Windows.Forms.Screen.AllScreens; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index e75a0616c..f2fba05fe 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -53,11 +53,11 @@ namespace Tango.PPC.UI.PPCApplication /// Gets the application version. /// /// - public string Version + public Version Version { get { - throw new NotImplementedException(); + return AssemblyHelper.GetCurrentAssemblyVersion(); } } @@ -102,32 +102,26 @@ namespace Tango.PPC.UI.PPCApplication settings.Save(); } - if (settings.HasSetup) + if (App.StartupArgs.Contains("-update_ok")) + { + settings.ApplicationState = ApplicationStates.Default; + settings.Save(); + } + + if (settings.ApplicationState == ApplicationStates.Default) { ObservablesEntitiesAdapter.Instance.Initialize(); } }); - if (settings.HasSetup) + if (settings.ApplicationState == ApplicationStates.PreSetup || settings.ApplicationState == ApplicationStates.SemiSetup) { - PostSetup(); + SetupRequired?.Invoke(this, new EventArgs()); } else { - SetupRequiredEventArgs args = new SetupRequiredEventArgs(() => - { - Task.Factory.StartNew(() => - { - ObservablesEntitiesAdapter.Instance.Initialize(); - - InvokeUI(() => - { - PostSetup(); - }); - }); - }); - SetupRequired?.Invoke(this, args); + PostSetup(); } }; } @@ -198,7 +192,16 @@ namespace Tango.PPC.UI.PPCApplication } public event EventHandler Ready; - public event EventHandler SetupRequired; + public event EventHandler SetupRequired; public event EventHandler ContentRendered; + + public String BuildDate + { + get + { + return AssemblyHelper.GetCurrentAssemblyBuildDate().ToShortDateString(); + } + } + } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs index 2a76ba80f..77767d588 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs @@ -26,12 +26,8 @@ namespace Tango.PPC.UI.ViewModels /// Represents the PPC loading splash screen view model. /// /// - public class LoadingViewVM : PPCViewModel, INavigationObjectReceiver + public class LoadingViewVM : PPCViewModel { - private bool _setup; - private SetupRequiredEventArgs _setupArgs; - private bool _post_setup; - /// /// Gets or sets the module loader. /// @@ -55,42 +51,17 @@ namespace Tango.PPC.UI.ViewModels { if (!DesignMode) { - applicationManager.SetupRequired += ApplicationManager_SetupRequired; Task.Delay(1000).ContinueWith((x) => { IsLoading = true; }); } } - private void ApplicationManager_SetupRequired(object sender, SetupRequiredEventArgs e) - { - _setupArgs = e; - _setup = true; - NavigationManager.NavigateTo(NavigationView.MachineSetupView); - } - /// /// Called when the application has been started. /// public override void OnApplicationStarted() { IsLoading = false; - - if (!_setup || _post_setup) - { - NavigationManager.NavigateTo(NavigationView.LoginView); - } - } - - public async void OnNavigatedToWithObject(MachineSetupResult machineSetupResult) - { - if (machineSetupResult.Completed) - { - _post_setup = true; - _setup = false; - IsLoading = true; - - await Task.Delay(500); - _setupArgs.Continue(); - } + NavigationManager.NavigateTo(NavigationView.LoginView); } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs index 7b4016341..2877d52b3 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; using System.Data.SqlClient; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Core.Commands; +using Tango.Core.Helpers; using Tango.PPC.Common; using Tango.PPC.Common.Application; using Tango.PPC.Common.MachineSetup; @@ -27,9 +29,7 @@ namespace Tango.PPC.UI.ViewModels Failed, } - private bool _postSetp; - - private SetupRequiredEventArgs _setupRequiredEventArgs; + private MachineSetupResult _setup_result; public IMachineSetupManager MachineSetupManager { get; set; } @@ -80,24 +80,9 @@ namespace Tango.PPC.UI.ViewModels applicationManager.SetupRequired += ApplicationManager_SetupRequired; } - private void ApplicationManager_SetupRequired(object sender, SetupRequiredEventArgs e) - { - _setupRequiredEventArgs = e; - } - - public override void OnApplicationStarted() - { - base.OnApplicationStarted(); - - if (_postSetp) - { - NavigationManager.NavigateTo(Common.Navigation.NavigationView.LoginView); - } - } - - public override void OnNavigatedTo() + private void ApplicationManager_SetupRequired(object sender, EventArgs e) { - base.OnNavigatedTo(); + NavigationManager.NavigateTo(NavigationView.MachineSetupView); } private void AppendLog(String msg) @@ -117,9 +102,8 @@ namespace Tango.PPC.UI.ViewModels try { - await MachineSetupManager.Setup(SerialNumber, HostAddress); - Settings.HasSetup = true; - _postSetp = true; + _setup_result = await MachineSetupManager.Setup(SerialNumber, HostAddress); + Settings.ApplicationState = ApplicationStates.SemiSetup; Settings.Save(); State = MachineSetupStates.Completed; } @@ -132,7 +116,8 @@ namespace Tango.PPC.UI.ViewModels private void CompleteSetup() { - NavigationManager.NavigateWithObject(NavigationView.LoadingView, new MachineSetupResult() { Completed = true }); + Process.Start(AssemblyHelper.GetCurrentAssemblyFolder() + "\\Tango.PPC.Updater.exe", _setup_result.UpdatePackagePath); + Environment.Exit(0); } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml index e300d95aa..9ff98ce52 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml @@ -37,7 +37,7 @@ SERIAL NUMBER - HOST ADDRESS + MACHINE SERVICE ADDRESS INSTALL diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/App.config b/Software/Visual_Studio/PPC/Tango.PPC.Updater/App.config new file mode 100644 index 000000000..8324aa6ff --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/App.xaml b/Software/Visual_Studio/PPC/Tango.PPC.Updater/App.xaml new file mode 100644 index 000000000..35893782c --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/App.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.Updater/App.xaml.cs new file mode 100644 index 000000000..bf390b97d --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/App.xaml.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace Tango.PPC.Updater +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + public static String[] StartupArgs { get; private set; } + + protected override void OnStartup(StartupEventArgs e) + { + StartupArgs = e.Args; + base.OnStartup(e); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/Images/package.png b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Images/package.png new file mode 100644 index 000000000..46446c02f Binary files /dev/null and b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Images/package.png differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml b/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml new file mode 100644 index 000000000..77a87d224 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml.cs new file mode 100644 index 000000000..a1c68bd78 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/MainWindow.xaml.cs @@ -0,0 +1,169 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Threading; + +namespace Tango.PPC.Updater +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + private String _appPath = AppDomain.CurrentDomain.BaseDirectory; + private String _msProcessName = "Tango.PPC.UI"; + private String _sourceFolder = App.StartupArgs.FirstOrDefault(); + + public MainWindow() + { + if (!Directory.Exists(_sourceFolder)) + { + ShowError("This update utility can only be executed by the main Tango."); + Environment.Exit(0); + } + + InitializeComponent(); + + WindowStyle = WindowStyle.None; + ResizeMode = ResizeMode.NoResize; + WindowStartupLocation = WindowStartupLocation.Manual; + Topmost = true; // sure? + + var screens = System.Windows.Forms.Screen.AllScreens; + + //Search for the vertical touch monitor. + var touch_screen = screens.Where(x => x.Bounds.Height > x.Bounds.Width).Last(); + + if (touch_screen != null) + { + Left = touch_screen.Bounds.Left; + Top = touch_screen.Bounds.Top; + Width = touch_screen.Bounds.Width; + Height = touch_screen.Bounds.Height; + } + + ContentRendered += MainWindow_ContentRendered; + } + + private void MainWindow_ContentRendered(object sender, EventArgs e) + { + Update(); + } + + private void Update() + { + EnsureTangoIsDown(); + ReplaceFiles(); + StartTango(); + Environment.Exit(0); + } + + private void StartTango() + { + txtStatus.Text = "Update completed. Starting application..."; + DoEvents(); + Thread.Sleep(1000); + + Process p = new Process(); + p.StartInfo.FileName = _appPath + "\\" + _msProcessName + ".exe"; + p.StartInfo.LoadUserProfile = true; + p.StartInfo.UseShellExecute = true; + p.StartInfo.Arguments = "-update_ok"; + p.Start(); + } + + private void ReplaceFiles() + { + int maxProgress = Directory.GetFiles(_sourceFolder, "*.*", SearchOption.AllDirectories).Length; + int progress = 0; + + foreach (string dirPath in Directory.GetDirectories(_sourceFolder, "*", SearchOption.AllDirectories)) + { + try + { + Directory.CreateDirectory(dirPath.Replace(_sourceFolder, _appPath)); + } + catch (Exception ex) + { + ShowError("Could not create directory " + Path.GetFileName(dirPath) + Environment.NewLine + ex.Message); + } + } + + foreach (string newPath in Directory.GetFiles(_sourceFolder, "*.*", SearchOption.AllDirectories)) + { + try + { + txtStatus.Text = "Copying file " + Path.GetFileName(newPath); + DoEvents(); + + File.Copy(newPath, newPath.Replace(_sourceFolder, _appPath), true); + + prog.Maximum = maxProgress; + prog.Value = progress++; + DoEvents(); + + Thread.Sleep(30); + } + catch (Exception ex) + { + if (!newPath.ToLower().Contains("updater.exe")) + { + ShowError("Could not create file " + Path.GetFileName(newPath) + Environment.NewLine + ex.Message); + } + } + } + } + + private void EnsureTangoIsDown() + { + Process appProcess = null; + + int tries = 0; + + do + { + appProcess = Process.GetProcessesByName(_msProcessName).FirstOrDefault(); + + if (appProcess != null) + { + tries++; + appProcess.Kill(); + Thread.Sleep(1000); + } + + if (tries > 10) + { + ShowError("The main Tango process seems to in a frozen state. Please restart your computer and try again."); + Environment.Exit(0); + } + + } while (appProcess != null); + } + + /// + /// Forces UI rendering. + /// + private void DoEvents() + { + Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { })); + } + + private void ShowError(String error) + { + MessageBox.Show(error, "Tango Update", MessageBoxButton.OK, MessageBoxImage.Error); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/AssemblyInfo.cs b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..499122342 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tango.PPC.Updater")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.PPC.Updater")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// 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.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Resources.Designer.cs b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Resources.Designer.cs new file mode 100644 index 000000000..8b92f59d7 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.PPC.Updater.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tango.PPC.Updater.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Resources.resx b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Settings.Designer.cs b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Settings.Designer.cs new file mode 100644 index 000000000..58f5a764e --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.PPC.Updater.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Settings.settings b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Settings.settings new file mode 100644 index 000000000..033d7a5e9 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Updater/Tango.PPC.Updater.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Tango.PPC.Updater.csproj new file mode 100644 index 000000000..41b03e807 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Updater/Tango.PPC.Updater.csproj @@ -0,0 +1,102 @@ + + + + + Debug + AnyCPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F} + WinExe + Tango.PPC.Updater + Tango.PPC.Updater + v4.6 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + + + AnyCPU + true + full + false + ..\..\Build\Debug\PPC\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + ..\..\Build\Release\PPC\ + TRACE + prompt + 4 + + + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Core/DB/DbCredentials.cs b/Software/Visual_Studio/Tango.Core/DB/DbCredentials.cs new file mode 100644 index 000000000..5962a9cc6 --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/DB/DbCredentials.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Core.DB +{ + public class DbCredentials + { + public String UserName { get; set; } + public String Password { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Core/DB/DbManager.cs b/Software/Visual_Studio/Tango.Core/DB/DbManager.cs new file mode 100644 index 000000000..2365dafdd --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/DB/DbManager.cs @@ -0,0 +1,256 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Core.DB +{ + public class DbManager : IDisposable + { + private static Random random = new Random(); + private SqlConnection _connection; + + #region Constructors + + private DbManager(SqlConnection connection) + { + _connection = connection; + _connection.Open(); + } + + public static DbManager FromConnection(SqlConnection connection) + { + return new DbManager(connection); + } + + public static DbManager FromConnectionString(String connectionString) + { + return new DbManager(new SqlConnection(connectionString)); + } + + public static DbManager FromAddress(String address) + { + return new DbManager(new SqlConnection(String.Format("Server={0};Integrated security=SSPI", address))); + } + + public static DbManager FromAddressAndName(String address, String database) + { + return new DbManager(new SqlConnection(String.Format("Server={0};Integrated security=SSPI;Initial Catalog={1}", address, database))); + } + + public static DbManager FromCredentials(String address, String database, String userName, String password) + { + return new DbManager(new SqlConnection(String.Format("Server={0};Initial Catalog={1};Id={2};Password={3}", address, database, userName, password))); + } + + #endregion + + #region Private Methods + + private string GetRandomString(int length) + { + const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + return "TEMP_" + new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()); + } + + #endregion + + #region Public Methods + + public void Create(String name) + { + String command = String.Format("CREATE DATABASE {0}", name); + SqlCommand cmd = new SqlCommand(command, _connection); + cmd.ExecuteNonQuery(); + } + + public bool Exists(String name) + { + try + { + String command = String.Format("SELECT database_id FROM sys.databases WHERE Name = '{0}'", name); + SqlCommand cmd = new SqlCommand(command, _connection); + object resultObj = cmd.ExecuteScalar(); + + int databaseID = 0; + + if (resultObj != null) + { + int.TryParse(resultObj.ToString(), out databaseID); + } + + return (databaseID > 0); + } + catch (Exception e) + { + return false; + } + } + + public void Delete(String name) + { + String command = String.Format("DROP DATABASE {0}", name); + SqlCommand cmd = new SqlCommand(command, _connection); + cmd.ExecuteNonQuery(); + } + + public void SetOffline(String name) + { + String command = String.Format("ALTER DATABASE {0} SET OFFLINE WITH ROLLBACK IMMEDIATE", name); + SqlCommand cmd = new SqlCommand(command, _connection); + cmd.ExecuteNonQuery(); + } + + public void SetOnline(String name) + { + String command = String.Format("ALTER DATABASE {0} SET ONLINE", name); + SqlCommand cmd = new SqlCommand(command, _connection); + cmd.ExecuteNonQuery(); + } + + public void CloneDB(String sourceDb, String backupPath, String targetDb, String targetMdf, String targetLdf) + { + String command = String.Format("BACKUP DATABASE {0} TO DISK = '{1}' WITH INIT", sourceDb, backupPath); + SqlCommand cmd = new SqlCommand(command, _connection); + cmd.ExecuteNonQuery(); + + command = String.Format("RESTORE FILELISTONLY FROM DISK='{0}'", backupPath); + cmd = new SqlCommand(command, _connection); + + List logical_names = new List(); + + using (var reader = cmd.ExecuteReader()) + { + while (reader.Read()) + { + logical_names.Add(reader.GetString(reader.GetOrdinal("LogicalName"))); + } + } + + command = String.Format("RESTORE DATABASE {0} FROM DISK='{1}' WITH MOVE '{2}' TO '{3}', MOVE '{4}' TO '{5}'", targetDb, backupPath, logical_names[0], targetMdf, logical_names[1], targetLdf); + cmd = new SqlCommand(command, _connection); + cmd.ExecuteNonQuery(); + + File.Delete(backupPath); + } + + public void ClearDb() + { + if (!_connection.ConnectionString.ToLower().Contains("initial catalog")) + { + throw new InvalidOperationException("Clear db can only be used when 'initial catalog' is specified at the connection string."); + } + + SqlCommand cmd = new SqlCommand("EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'", _connection); + cmd.ExecuteNonQuery(); + + cmd = new SqlCommand("EXEC sp_MSForEachTable 'DELETE FROM ?'", _connection); + cmd.ExecuteNonQuery(); + + cmd = new SqlCommand("EXEC sp_MSForEachTable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL'", _connection); + cmd.ExecuteNonQuery(); + } + + public void CreateLoginAndUser(String userName, String password, String database) + { + + SqlCommand cmd = new SqlCommand(String.Format( + + @" + +CREATE LOGIN {0} +WITH +PASSWORD = '{1}', +DEFAULT_DATABASE=[{2}], +CHECK_EXPIRATION=OFF, +CHECK_POLICY=OFF + +USE {2} +CREATE USER {0} FOR LOGIN {0} + +EXEC sp_addrolemember 'db_datareader', '{0}'; + +", userName, password, database), + + _connection); + cmd.ExecuteNonQuery(); + } + + public void DeleteLoginAndUser(String userName, String database) + { + SqlCommand cmd = new SqlCommand(String.Format( + + @" + +USE {1} + +DECLARE @loginNameToDrop sysname +DECLARE @userNameToDrop sysname +SET @loginNameToDrop = '{0}'; +SET @userNameToDrop = '{0}'; + +DECLARE sessionsToKill CURSOR FAST_FORWARD FOR + SELECT session_id + FROM sys.dm_exec_sessions + WHERE login_name = @loginNameToDrop +OPEN sessionsToKill + +DECLARE @sessionId INT +DECLARE @statement NVARCHAR(200) + +FETCH NEXT FROM sessionsToKill INTO @sessionId + +WHILE @@FETCH_STATUS = 0 +BEGIN + PRINT 'Killing session ' + CAST(@sessionId AS NVARCHAR(20)) + ' for login ' + @loginNameToDrop + + SET @statement = 'KILL ' + CAST(@sessionId AS NVARCHAR(20)) + EXEC sp_executesql @statement + + FETCH NEXT FROM sessionsToKill INTO @sessionId +END + +CLOSE sessionsToKill +DEALLOCATE sessionsToKill + +PRINT 'Dropping user ' + @userNameToDrop +SET @statement = 'DROP USER [' + @userNameToDrop + ']' +EXEC sp_executesql @statement + +PRINT 'Dropping login ' + @loginNameToDrop +SET @statement = 'DROP LOGIN [' + @loginNameToDrop + ']' +EXEC sp_executesql @statement + +", userName, database), + + _connection); + cmd.ExecuteNonQuery(); + } + + public DbCredentials CreateRandomLoginAndUser(String database) + { + DbCredentials cred = new DbCredentials() + { + UserName = GetRandomString(36), + Password = GetRandomString(36) + }; + + CreateLoginAndUser(cred.UserName, cred.Password, database); + return cred; + } + + #endregion + + #region IDisposable + + public void Dispose() + { + _connection.Dispose(); + } + + #endregion + } +} diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index ee5864518..6dcaf2505 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -73,6 +73,8 @@ + + @@ -151,7 +153,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.PMR/Synchronization/MachineSetupResponse.cs b/Software/Visual_Studio/Tango.PMR/Synchronization/MachineSetupResponse.cs index 0618c947e..7d86ea948 100644 --- a/Software/Visual_Studio/Tango.PMR/Synchronization/MachineSetupResponse.cs +++ b/Software/Visual_Studio/Tango.PMR/Synchronization/MachineSetupResponse.cs @@ -23,15 +23,16 @@ namespace Tango.PMR.Synchronization { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( "ChpNYWNoaW5lU2V0dXBSZXNwb25zZS5wcm90bxIZVGFuZ28uUE1SLlN5bmNo", - "cm9uaXphdGlvbiKEAQoUTWFjaGluZVNldHVwUmVzcG9uc2USDwoHVmVyc2lv", - "bhgBIAEoCRIQCghGaWxlUGF0aBgCIAEoCRISCgpGdHBBZGRyZXNzGAMgASgJ", - "EhAKCFVzZXJOYW1lGAQgASgJEhAKCFBhc3N3b3JkGAUgASgJEhEKCURiQWRk", - "cmVzcxgGIAEoCUIlCiNjb20udHdpbmUudGFuZ28ucG1yLnN5bmNocm9uaXph", - "dGlvbmIGcHJvdG8z")); + "cm9uaXphdGlvbiK1AQoUTWFjaGluZVNldHVwUmVzcG9uc2USDwoHVmVyc2lv", + "bhgBIAEoCRISCgpGdHBBZGRyZXNzGAIgASgJEhMKC0Z0cEZpbGVQYXRoGAMg", + "ASgJEhMKC0Z0cFVzZXJOYW1lGAQgASgJEhMKC0Z0cFBhc3N3b3JkGAUgASgJ", + "EhEKCURiQWRkcmVzcxgGIAEoCRISCgpEYlVzZXJOYW1lGAcgASgJEhIKCkRi", + "UGFzc3dvcmQYCCABKAlCJQojY29tLnR3aW5lLnRhbmdvLnBtci5zeW5jaHJv", + "bml6YXRpb25iBnByb3RvMw==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Synchronization.MachineSetupResponse), global::Tango.PMR.Synchronization.MachineSetupResponse.Parser, new[]{ "Version", "FilePath", "FtpAddress", "UserName", "Password", "DbAddress" }, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Synchronization.MachineSetupResponse), global::Tango.PMR.Synchronization.MachineSetupResponse.Parser, new[]{ "Version", "FtpAddress", "FtpFilePath", "FtpUserName", "FtpPassword", "DbAddress", "DbUserName", "DbPassword" }, null, null, null) })); } #endregion @@ -63,11 +64,13 @@ namespace Tango.PMR.Synchronization { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public MachineSetupResponse(MachineSetupResponse other) : this() { version_ = other.version_; - filePath_ = other.filePath_; ftpAddress_ = other.ftpAddress_; - userName_ = other.userName_; - password_ = other.password_; + ftpFilePath_ = other.ftpFilePath_; + ftpUserName_ = other.ftpUserName_; + ftpPassword_ = other.ftpPassword_; dbAddress_ = other.dbAddress_; + dbUserName_ = other.dbUserName_; + dbPassword_ = other.dbPassword_; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -86,19 +89,8 @@ namespace Tango.PMR.Synchronization { } } - /// Field number for the "FilePath" field. - public const int FilePathFieldNumber = 2; - private string filePath_ = ""; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public string FilePath { - get { return filePath_; } - set { - filePath_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - /// Field number for the "FtpAddress" field. - public const int FtpAddressFieldNumber = 3; + public const int FtpAddressFieldNumber = 2; private string ftpAddress_ = ""; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public string FtpAddress { @@ -108,25 +100,36 @@ namespace Tango.PMR.Synchronization { } } - /// Field number for the "UserName" field. - public const int UserNameFieldNumber = 4; - private string userName_ = ""; + /// Field number for the "FtpFilePath" field. + public const int FtpFilePathFieldNumber = 3; + private string ftpFilePath_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string FtpFilePath { + get { return ftpFilePath_; } + set { + ftpFilePath_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "FtpUserName" field. + public const int FtpUserNameFieldNumber = 4; + private string ftpUserName_ = ""; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public string UserName { - get { return userName_; } + public string FtpUserName { + get { return ftpUserName_; } set { - userName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + ftpUserName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); } } - /// Field number for the "Password" field. - public const int PasswordFieldNumber = 5; - private string password_ = ""; + /// Field number for the "FtpPassword" field. + public const int FtpPasswordFieldNumber = 5; + private string ftpPassword_ = ""; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public string Password { - get { return password_; } + public string FtpPassword { + get { return ftpPassword_; } set { - password_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + ftpPassword_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); } } @@ -141,6 +144,28 @@ namespace Tango.PMR.Synchronization { } } + /// Field number for the "DbUserName" field. + public const int DbUserNameFieldNumber = 7; + private string dbUserName_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string DbUserName { + get { return dbUserName_; } + set { + dbUserName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "DbPassword" field. + public const int DbPasswordFieldNumber = 8; + private string dbPassword_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string DbPassword { + get { return dbPassword_; } + set { + dbPassword_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { return Equals(other as MachineSetupResponse); @@ -155,11 +180,13 @@ namespace Tango.PMR.Synchronization { return true; } if (Version != other.Version) return false; - if (FilePath != other.FilePath) return false; if (FtpAddress != other.FtpAddress) return false; - if (UserName != other.UserName) return false; - if (Password != other.Password) return false; + if (FtpFilePath != other.FtpFilePath) return false; + if (FtpUserName != other.FtpUserName) return false; + if (FtpPassword != other.FtpPassword) return false; if (DbAddress != other.DbAddress) return false; + if (DbUserName != other.DbUserName) return false; + if (DbPassword != other.DbPassword) return false; return true; } @@ -167,11 +194,13 @@ namespace Tango.PMR.Synchronization { public override int GetHashCode() { int hash = 1; if (Version.Length != 0) hash ^= Version.GetHashCode(); - if (FilePath.Length != 0) hash ^= FilePath.GetHashCode(); if (FtpAddress.Length != 0) hash ^= FtpAddress.GetHashCode(); - if (UserName.Length != 0) hash ^= UserName.GetHashCode(); - if (Password.Length != 0) hash ^= Password.GetHashCode(); + if (FtpFilePath.Length != 0) hash ^= FtpFilePath.GetHashCode(); + if (FtpUserName.Length != 0) hash ^= FtpUserName.GetHashCode(); + if (FtpPassword.Length != 0) hash ^= FtpPassword.GetHashCode(); if (DbAddress.Length != 0) hash ^= DbAddress.GetHashCode(); + if (DbUserName.Length != 0) hash ^= DbUserName.GetHashCode(); + if (DbPassword.Length != 0) hash ^= DbPassword.GetHashCode(); return hash; } @@ -186,26 +215,34 @@ namespace Tango.PMR.Synchronization { output.WriteRawTag(10); output.WriteString(Version); } - if (FilePath.Length != 0) { + if (FtpAddress.Length != 0) { output.WriteRawTag(18); - output.WriteString(FilePath); + output.WriteString(FtpAddress); } - if (FtpAddress.Length != 0) { + if (FtpFilePath.Length != 0) { output.WriteRawTag(26); - output.WriteString(FtpAddress); + output.WriteString(FtpFilePath); } - if (UserName.Length != 0) { + if (FtpUserName.Length != 0) { output.WriteRawTag(34); - output.WriteString(UserName); + output.WriteString(FtpUserName); } - if (Password.Length != 0) { + if (FtpPassword.Length != 0) { output.WriteRawTag(42); - output.WriteString(Password); + output.WriteString(FtpPassword); } if (DbAddress.Length != 0) { output.WriteRawTag(50); output.WriteString(DbAddress); } + if (DbUserName.Length != 0) { + output.WriteRawTag(58); + output.WriteString(DbUserName); + } + if (DbPassword.Length != 0) { + output.WriteRawTag(66); + output.WriteString(DbPassword); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -214,21 +251,27 @@ namespace Tango.PMR.Synchronization { if (Version.Length != 0) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Version); } - if (FilePath.Length != 0) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(FilePath); - } if (FtpAddress.Length != 0) { size += 1 + pb::CodedOutputStream.ComputeStringSize(FtpAddress); } - if (UserName.Length != 0) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(UserName); + if (FtpFilePath.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(FtpFilePath); + } + if (FtpUserName.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(FtpUserName); } - if (Password.Length != 0) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Password); + if (FtpPassword.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(FtpPassword); } if (DbAddress.Length != 0) { size += 1 + pb::CodedOutputStream.ComputeStringSize(DbAddress); } + if (DbUserName.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(DbUserName); + } + if (DbPassword.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(DbPassword); + } return size; } @@ -240,21 +283,27 @@ namespace Tango.PMR.Synchronization { if (other.Version.Length != 0) { Version = other.Version; } - if (other.FilePath.Length != 0) { - FilePath = other.FilePath; - } if (other.FtpAddress.Length != 0) { FtpAddress = other.FtpAddress; } - if (other.UserName.Length != 0) { - UserName = other.UserName; + if (other.FtpFilePath.Length != 0) { + FtpFilePath = other.FtpFilePath; + } + if (other.FtpUserName.Length != 0) { + FtpUserName = other.FtpUserName; } - if (other.Password.Length != 0) { - Password = other.Password; + if (other.FtpPassword.Length != 0) { + FtpPassword = other.FtpPassword; } if (other.DbAddress.Length != 0) { DbAddress = other.DbAddress; } + if (other.DbUserName.Length != 0) { + DbUserName = other.DbUserName; + } + if (other.DbPassword.Length != 0) { + DbPassword = other.DbPassword; + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -270,25 +319,33 @@ namespace Tango.PMR.Synchronization { break; } case 18: { - FilePath = input.ReadString(); + FtpAddress = input.ReadString(); break; } case 26: { - FtpAddress = input.ReadString(); + FtpFilePath = input.ReadString(); break; } case 34: { - UserName = input.ReadString(); + FtpUserName = input.ReadString(); break; } case 42: { - Password = input.ReadString(); + FtpPassword = input.ReadString(); break; } case 50: { DbAddress = input.ReadString(); break; } + case 58: { + DbUserName = input.ReadString(); + break; + } + case 66: { + DbPassword = input.ReadString(); + break; + } } } } diff --git a/Software/Visual_Studio/Tango.SQLExaminer/DbManager.cs b/Software/Visual_Studio/Tango.SQLExaminer/DbManager.cs deleted file mode 100644 index fb783c928..000000000 --- a/Software/Visual_Studio/Tango.SQLExaminer/DbManager.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data.SqlClient; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.SQLExaminer -{ - public class DbManager - { - private SqlConnection _connection; - private bool _opened; - - public DbManager(SqlConnection connection) - { - _connection = connection; - } - - private void EnsureOpen() - { - if (!_opened) - { - _connection.Open(); - _opened = true; - } - } - - public void Create(String name) - { - EnsureOpen(); - String command = String.Format("CREATE DATABASE {0}", name); - SqlCommand cmd = new SqlCommand(command, _connection); - cmd.ExecuteNonQuery(); - } - - public bool Exists(String name) - { - try - { - EnsureOpen(); - String command = String.Format("SELECT database_id FROM sys.databases WHERE Name = '{0}'", name); - SqlCommand cmd = new SqlCommand(command, _connection); - object resultObj = cmd.ExecuteScalar(); - - int databaseID = 0; - - if (resultObj != null) - { - int.TryParse(resultObj.ToString(), out databaseID); - } - - return (databaseID > 0); - } - catch (Exception e) - { - return false; - } - } - - public void Delete(String name) - { - EnsureOpen(); - String command = String.Format("DROP DATABASE {0}", name); - SqlCommand cmd = new SqlCommand(command, _connection); - cmd.ExecuteNonQuery(); - } - - public void SetOffline(String name) - { - EnsureOpen(); - String command = String.Format("ALTER DATABASE {0} SET OFFLINE WITH ROLLBACK IMMEDIATE", name); - SqlCommand cmd = new SqlCommand(command, _connection); - cmd.ExecuteNonQuery(); - } - - public void SetOnline(String name) - { - EnsureOpen(); - String command = String.Format("ALTER DATABASE {0} SET ONLINE", name); - SqlCommand cmd = new SqlCommand(command, _connection); - cmd.ExecuteNonQuery(); - } - - public void CloneDB(String sourceDb, String backupPath, String targetDb, String targetMdf, String targetLdf) - { - EnsureOpen(); - - String command = String.Format("BACKUP DATABASE {0} TO DISK = '{1}' WITH INIT", sourceDb, backupPath); - SqlCommand cmd = new SqlCommand(command, _connection); - cmd.ExecuteNonQuery(); - - command = String.Format("RESTORE FILELISTONLY FROM DISK='{0}'", backupPath); - cmd = new SqlCommand(command, _connection); - - List logical_names = new List(); - - using (var reader = cmd.ExecuteReader()) - { - while (reader.Read()) - { - logical_names.Add(reader.GetString(reader.GetOrdinal("LogicalName"))); - } - } - - command = String.Format("RESTORE DATABASE {0} FROM DISK='{1}' WITH MOVE '{2}' TO '{3}', MOVE '{4}' TO '{5}'", targetDb, backupPath, logical_names[0], targetMdf, logical_names[1], targetLdf); - cmd = new SqlCommand(command, _connection); - cmd.ExecuteNonQuery(); - - File.Delete(backupPath); - } - - public void ClearDb(String name) - { - EnsureOpen(); - - SqlCommand cmd = new SqlCommand("EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'", _connection); - cmd.ExecuteNonQuery(); - - cmd = new SqlCommand("EXEC sp_MSForEachTable 'DELETE FROM ?'", _connection); - cmd.ExecuteNonQuery(); - - cmd = new SqlCommand("EXEC sp_MSForEachTable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL'", _connection); - cmd.ExecuteNonQuery(); - } - } -} diff --git a/Software/Visual_Studio/Tango.SQLExaminer/Tango.SQLExaminer.csproj b/Software/Visual_Studio/Tango.SQLExaminer/Tango.SQLExaminer.csproj index 12d8cf088..261794b0e 100644 --- a/Software/Visual_Studio/Tango.SQLExaminer/Tango.SQLExaminer.csproj +++ b/Software/Visual_Studio/Tango.SQLExaminer/Tango.SQLExaminer.csproj @@ -52,7 +52,6 @@ - diff --git a/Software/Visual_Studio/Tango.UnitTesting/SQLExaminer_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/SQLExaminer_TST.cs index 980dd7a27..5ab70938c 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/SQLExaminer_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/SQLExaminer_TST.cs @@ -9,6 +9,7 @@ using System.Text; using System.Threading.Tasks; using Tango.BL; using Tango.BL.Entities; +using Tango.Core.DB; using Tango.Core.IO; using Tango.SQLExaminer; @@ -183,7 +184,7 @@ namespace Tango.UnitTesting String source_db = "Source_DB_Test"; String target_db = "Target_DB_Test"; - DbManager db = new DbManager(new SqlConnection("Server=localhost\\SQLEXPRESS;Integrated security=SSPI")); + DbManager db = DbManager.FromAddress("localhost\\SQLEXPRESS"); Assert.IsTrue(db.Exists("Tango"), "Database Tango does not exists."); if (db.Exists(source_db)) diff --git a/Software/Visual_Studio/Tango.sln b/Software/Visual_Studio/Tango.sln index f9dbd0f39..aa5e89dd3 100644 --- a/Software/Visual_Studio/Tango.sln +++ b/Software/Visual_Studio/Tango.sln @@ -218,6 +218,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.PPC.Publisher", "PPC\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.PPC.UpdateService", "PPC\Tango.PPC.UpdateService\Tango.PPC.UpdateService.csproj", "{01C3EF89-6A17-4D70-A71F-0395A212F2F8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.PPC.Updater", "PPC\Tango.PPC.Updater\Tango.PPC.Updater.csproj", "{D0E71A4D-9EEA-4F07-983F-EEB4416C587F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution AppVeyor|Any CPU = AppVeyor|Any CPU @@ -3817,6 +3819,46 @@ Global {01C3EF89-6A17-4D70-A71F-0395A212F2F8}.Release|x64.Build.0 = Release|Any CPU {01C3EF89-6A17-4D70-A71F-0395A212F2F8}.Release|x86.ActiveCfg = Release|Any CPU {01C3EF89-6A17-4D70-A71F-0395A212F2F8}.Release|x86.Build.0 = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.AppVeyor|Any CPU.ActiveCfg = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.AppVeyor|Any CPU.Build.0 = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.AppVeyor|ARM.ActiveCfg = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.AppVeyor|ARM.Build.0 = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.AppVeyor|ARM64.ActiveCfg = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.AppVeyor|ARM64.Build.0 = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.AppVeyor|x64.ActiveCfg = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.AppVeyor|x64.Build.0 = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.AppVeyor|x86.ActiveCfg = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.AppVeyor|x86.Build.0 = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Debug|ARM.ActiveCfg = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Debug|ARM.Build.0 = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Debug|ARM64.Build.0 = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Debug|x64.ActiveCfg = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Debug|x64.Build.0 = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Debug|x86.ActiveCfg = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Debug|x86.Build.0 = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.DefaultBuild|Any CPU.ActiveCfg = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.DefaultBuild|Any CPU.Build.0 = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.DefaultBuild|ARM.ActiveCfg = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.DefaultBuild|ARM.Build.0 = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.DefaultBuild|ARM64.ActiveCfg = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.DefaultBuild|ARM64.Build.0 = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.DefaultBuild|x64.ActiveCfg = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.DefaultBuild|x64.Build.0 = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.DefaultBuild|x86.ActiveCfg = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.DefaultBuild|x86.Build.0 = Debug|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Release|Any CPU.Build.0 = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Release|ARM.ActiveCfg = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Release|ARM.Build.0 = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Release|ARM64.ActiveCfg = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Release|ARM64.Build.0 = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Release|x64.ActiveCfg = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Release|x64.Build.0 = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Release|x86.ActiveCfg = Release|Any CPU + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -3883,14 +3925,15 @@ Global {91B70E9B-66A7-4873-AE10-400E71CF404F} = {0048447D-1D94-4E60-9DAD-7349C777CB4E} {FABA6A2B-C7EA-4C58-A125-150FA5B4C72F} = {C81ED1A3-D18C-4D80-A8F5-061994A14A60} {01C3EF89-6A17-4D70-A71F-0395A212F2F8} = {C81ED1A3-D18C-4D80-A8F5-061994A14A60} + {D0E71A4D-9EEA-4F07-983F-EEB4416C587F} = {C81ED1A3-D18C-4D80-A8F5-061994A14A60} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {7986F7F4-A86A-4994-B1B6-0988D7F057B6} - BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear - BuildVersion_UpdateAssemblyVersion = True - BuildVersion_UpdateFileVersion = False - BuildVersion_StartDate = 2000/1/1 - BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs BuildVersion_UseGlobalSettings = False + BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs + BuildVersion_StartDate = 2000/1/1 + BuildVersion_UpdateFileVersion = False + BuildVersion_UpdateAssemblyVersion = True + BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear + SolutionGuid = {7986F7F4-A86A-4994-B1B6-0988D7F057B6} EndGlobalSection EndGlobal diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs index c377afb97..46308fa6f 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Web.Hosting; using System.Web.Http; using Tango.BL; +using Tango.Core.DB; using Tango.Core.Helpers; using Tango.Core.IO; using Tango.PMR.Stubs; @@ -90,12 +91,30 @@ namespace Tango.MachineService.Controllers var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); response.Version = latest_machine_version.Version; - response.FilePath = latest_machine_version.FtpFilePath; - response.DbAddress = GetRemoteServerAddress(); response.FtpAddress = GetFtpAddress(); - response.UserName = GetFtpUserName(); - response.Password = GetFtpPassword(); + response.FtpFilePath = latest_machine_version.FtpFilePath; + response.FtpUserName = GetFtpUserName(); + response.FtpPassword = GetFtpPassword(); + + DbCredentials credentials = new DbCredentials(); + + using (DbManager manager = DbManager.FromAddressAndName(GetDbAddress(), "Tango")) + { + credentials = manager.CreateRandomLoginAndUser("Tango"); + + Task.Delay(TimeSpan.FromMinutes(1)).ContinueWith((x) => + { + using (DbManager m = DbManager.FromAddressAndName(GetDbAddress(), "Tango")) + { + m.DeleteLoginAndUser(credentials.UserName, "Tango"); + } + }); + } + + response.DbAddress = GetDbAddress(); + response.DbUserName = credentials.UserName; + response.DbPassword = credentials.Password; } } catch (Exception ex) @@ -118,9 +137,9 @@ namespace Tango.MachineService.Controllers return ConfigurationManager.AppSettings["LocalServerAddress"].ToString(); } - private String GetRemoteServerAddress() + private String GetDbAddress() { - return ConfigurationManager.AppSettings["RemoteServerAddress"].ToString(); + return ConfigurationManager.AppSettings["DbAddress"].ToString(); } private String GetFtpAddress() @@ -136,7 +155,7 @@ namespace Tango.MachineService.Controllers private String GetFtpPassword() { return ConfigurationManager.AppSettings["FtpPassword"].ToString(); - } + } #endregion } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index ca05ae5e0..d116dc437 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -15,10 +15,12 @@ - + + +