From 57ae9d131e898a35061507bc8497bcf648cf00d1 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 8 Aug 2018 13:35:27 +0300 Subject: Working on machine setup ! --- .../MachineSetup/MachineSetupSteps.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs new file mode 100644 index 000000000..53a7780ec --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.MachineSetup +{ + public enum MachineSetupSteps + { + [Description("Synchronizing Schema")] + SynchronizingSchema, + [Description("Synchronizing Data")] + SynchronizingData, + [Description("Configuring Machine")] + SynchronizingMachineConfiguration + } +} -- cgit v1.3.1 From 9c5f5c1351c78536b54df2c90742efae19f00b59 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 8 Aug 2018 17:28:34 +0300 Subject: Working on PPC machine setup ! --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 1835008 -> 1835008 bytes .../Synchronization/MachineSetupRequest.proto | 9 + .../Synchronization/MachineSetupResponse.proto | 19 ++ .../Views/DBViews/ApplicationVersionView.xaml | 2 +- .../Views/DBViews/EmbeddedSoftwareVersionView.xaml | 2 +- .../Tango.MachineStudio.Common.csproj | 3 +- .../Update/FileStreamWrapper.cs | 56 ---- .../Tango.MachineStudio.Publisher/MainWindowVM.cs | 1 + .../MachineSetup/MachineSetupManager.cs | 110 ++++++- .../MachineSetup/MachineSetupSteps.cs | 2 + .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 9 +- .../PPC/Tango.PPC.Common/packages.config | 1 + Software/Visual_Studio/PPC/Tango.PPC.UI/App.config | 4 - .../Tango.BL/Entities/ApplicationVersion.cs | 48 ++- .../Tango.BL/Entities/EmbeddedSoftwareVersion.cs | 48 ++- .../Tango.Core/IO/FileStreamWrapper.cs | 56 ++++ .../Visual_Studio/Tango.Core/Tango.Core.csproj | 3 +- .../Tango.DAL.Remote/DB/APPLICATION_VERSIONS.cs | 4 +- .../DB/EMBEDDED_SOFTWARE_VERSIONS.cs | 4 +- .../Tango.DAL.Remote/DB/RemoteADO.Designer.cs | 2 +- .../Tango.DAL.Remote/DB/RemoteADO.edmx | 20 +- .../Tango.DAL.Remote/DB/RemoteADO.edmx.diagram | 132 ++++---- .../Synchronization/MachineSetupRequest.cs | 160 +++++++++ .../Synchronization/MachineSetupResponse.cs | 360 +++++++++++++++++++++ .../Tango.Transport/Tango.Transport.csproj | 4 +- .../Tango.Transport/Web/ITransportWebClient.cs | 14 + .../Tango.Transport/Web/ProtoWebClient.cs | 42 +++ Software/Visual_Studio/Tango.sln | 12 +- .../Tango.MachineService/App_Start/WebApiConfig.cs | 7 +- .../Controllers/SynchronizationController.cs | 80 +++++ .../Web/Tango.MachineService/ProtoBufFormatter.cs | 25 +- .../Tango.MachineService.csproj | 7 +- .../Web/Tango.MachineService/Web.config | 6 + 34 files changed, 1082 insertions(+), 170 deletions(-) create mode 100644 Software/PMR/Messages/Synchronization/MachineSetupRequest.proto create mode 100644 Software/PMR/Messages/Synchronization/MachineSetupResponse.proto delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/FileStreamWrapper.cs create mode 100644 Software/Visual_Studio/Tango.Core/IO/FileStreamWrapper.cs create mode 100644 Software/Visual_Studio/Tango.PMR/Synchronization/MachineSetupRequest.cs create mode 100644 Software/Visual_Studio/Tango.PMR/Synchronization/MachineSetupResponse.cs create mode 100644 Software/Visual_Studio/Tango.Transport/Web/ITransportWebClient.cs create mode 100644 Software/Visual_Studio/Tango.Transport/Web/ProtoWebClient.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index ff6024fa8..d0bc9e1de 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 43d0b72c2..fdb0761f2 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/PMR/Messages/Synchronization/MachineSetupRequest.proto b/Software/PMR/Messages/Synchronization/MachineSetupRequest.proto new file mode 100644 index 000000000..578e3a194 --- /dev/null +++ b/Software/PMR/Messages/Synchronization/MachineSetupRequest.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package Tango.PMR.Synchronization; +option java_package = "com.twine.tango.pmr.synchronization"; + +message MachineSetupRequest +{ + string SerialNumber = 1; +} \ No newline at end of file diff --git a/Software/PMR/Messages/Synchronization/MachineSetupResponse.proto b/Software/PMR/Messages/Synchronization/MachineSetupResponse.proto new file mode 100644 index 000000000..6ea748c93 --- /dev/null +++ b/Software/PMR/Messages/Synchronization/MachineSetupResponse.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package Tango.PMR.Synchronization; +option java_package = "com.twine.tango.pmr.synchronization"; + +message MachineSetupResponse +{ + string ApplicationVersion = 1; + string ApplicationFtpFilePath = 2; + + string EmbeddedVersion = 3; + string EmbeddedFtpFilePath = 4; + + string FtpAddress = 5; + string UserName = 6; + string Password = 7; + + string DbAddress = 8; +} \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/DBViews/ApplicationVersionView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/DBViews/ApplicationVersionView.xaml index c5e33f3fa..05c0b48e0 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/DBViews/ApplicationVersionView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/DBViews/ApplicationVersionView.xaml @@ -17,7 +17,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/DBViews/EmbeddedSoftwareVersionView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/DBViews/EmbeddedSoftwareVersionView.xaml index 279c15c84..43d9ab0eb 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/DBViews/EmbeddedSoftwareVersionView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/DBViews/EmbeddedSoftwareVersionView.xaml @@ -17,7 +17,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 26517c82b..ef8d57885 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -116,7 +116,6 @@ - @@ -294,7 +293,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/FileStreamWrapper.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/FileStreamWrapper.cs deleted file mode 100644 index 83fbdf7ea..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/FileStreamWrapper.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.MachineStudio.Common.Update -{ - /// - /// Represents a FileStream Wrapper dedicated for delivering Read/Write progress callbacks. - /// - /// - public class FileStreamWrapper : FileStream - { - private Action _callback; - - /// - /// Initializes a new instance of the class. - /// - /// Name of the file. - /// The mode. - /// The callback. - public FileStreamWrapper(String fileName, FileMode mode, Action callback) : base(fileName, mode) - { - _callback = callback; - } - - /// - /// Writes a block of bytes to the file stream. - /// - /// The buffer containing data to write to the stream. - /// The zero-based byte offset in from which to begin copying bytes to the stream. - /// The maximum number of bytes to write. - public override void Write(byte[] array, int offset, int count) - { - _callback?.Invoke(Length); - base.Write(array, offset, count); - } - - /// - /// Reads a block of bytes from the stream and writes the data in a given buffer. - /// - /// When this method returns, contains the specified byte array with the values between and ( + - 1 replaced by the bytes read from the current source. - /// The byte offset in at which the read bytes will be placed. - /// The maximum number of bytes to read. - /// - /// The total number of bytes read into the buffer. This might be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached. - /// - public override int Read(byte[] array, int offset, int count) - { - _callback?.Invoke(Position); - return base.Read(array, offset, count); - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/MainWindowVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/MainWindowVM.cs index 8d2d617f0..b2c5c4918 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/MainWindowVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/MainWindowVM.cs @@ -14,6 +14,7 @@ using System.Windows; using Tango.Core.Commands; using Tango.Core.Cryptography; using Tango.Core.Helpers; +using Tango.Core.IO; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Update; using Tango.Settings; 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 51c906019..f469fb799 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -1,13 +1,21 @@ -using System; +using FluentFTP; +using System; using System.Collections.Generic; using System.Data.SqlClient; +using System.IO; +using System.IO.Compression; using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; using System.Text; +using System.Threading; using System.Threading.Tasks; using Tango.Core; using Tango.Core.IO; +using Tango.PMR.Synchronization; using Tango.Settings; using Tango.SQLExaminer; +using Tango.Transport.Web; namespace Tango.PPC.Common.MachineSetup { @@ -28,10 +36,102 @@ namespace Tango.PPC.Common.MachineSetup } } - public Task Setup(string serialNumber, string hostAddress) + private double _downloadProgress; + public double DownloadProgress + { + get { return _downloadProgress; } + set { _downloadProgress = value; RaisePropertyChangedAuto(); } + } + + public Task Setup(string serialNumber, string machineServiceAddress) { return Task.Factory.StartNew(() => { + + //Connect to machine service and get matching packages for this machine. + CurrentStep = MachineSetupSteps.DownloadingPackage; + + MachineSetupRequest request = new MachineSetupRequest(); + request.SerialNumber = serialNumber; + + MachineSetupResponse setup_response = null; + + using (var http = new ProtoWebClient()) + { + setup_response = http.Post(machineServiceAddress + "/api/Synchronization/MachineSetup", request).Result; + } + + //Create temporary folders for packages. + 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"); + + int fileSize = 0; + DownloadProgress = 0; + + using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) => + { + InvokeUINow(() => + { + Thread.Sleep(10); + DownloadProgress = ((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.ApplicationFtpFilePath); + LogManager.Log("Download size: " + fileSize + " bytes."); + LogManager.Log("Starting download..."); + ftp.DownloadAsync(fs, setup_response.ApplicationFtpFilePath).Wait(); + } + } + + //Extract software package. + ZipFile.ExtractToDirectory(tempFile, software_package_folder); + + //Download embedded package. + tempFile = TemporaryManager.CreateFile(".zip"); + + fileSize = 0; + DownloadProgress = 0; + + using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) => + { + InvokeUINow(() => + { + Thread.Sleep(10); + DownloadProgress = ((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; + CurrentStep = MachineSetupSteps.SynchronizingSchema; String db_name = "Tango"; @@ -53,7 +153,7 @@ namespace Tango.PPC.Common.MachineSetup ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.Schema); builder. - SetSourceServer(hostAddress, db_name). + SetSourceServer(remote_address, db_name). SetTargetServer(localAddress, db_name). Synchronize(); @@ -78,7 +178,7 @@ namespace Tango.PPC.Common.MachineSetup builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.OverrideData); builder. - SetSourceServer(hostAddress, db_name). + SetSourceServer(remote_address, db_name). SetTargetServer(localAddress, db_name). Synchronize(); @@ -101,7 +201,7 @@ namespace Tango.PPC.Common.MachineSetup builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.ProvisionMachine); builder. - SetSourceServer(hostAddress, db_name). + SetSourceServer(remote_address, db_name). SetTargetServer(localAddress, db_name). SetMachineSerialNumber(serialNumber). Synchronize(); 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 53a7780ec..3db1eb4b0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs @@ -9,6 +9,8 @@ namespace Tango.PPC.Common.MachineSetup { public enum MachineSetupSteps { + [Description("Downloading Package")] + DownloadingPackage, [Description("Synchronizing Schema")] SynchronizingSchema, [Description("Synchronizing Data")] 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 0e2f3302c..5c90a8818 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 @@ -54,6 +54,9 @@ ..\..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll + + ..\..\packages\FluentFTP.19.1.2\lib\net45\FluentFTP.dll + ..\..\packages\FontAwesome.WPF.4.7.0.9\lib\net40\FontAwesome.WPF.dll @@ -76,6 +79,10 @@ True + + + + @@ -266,7 +273,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/packages.config b/Software/Visual_Studio/PPC/Tango.PPC.Common/packages.config index 1cd27f563..c90a10a58 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/packages.config +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/packages.config @@ -1,6 +1,7 @@  + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.config b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.config index ab5bb1006..10e543617 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.config +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.config @@ -37,10 +37,6 @@ - - - - diff --git a/Software/Visual_Studio/Tango.BL/Entities/ApplicationVersion.cs b/Software/Visual_Studio/Tango.BL/Entities/ApplicationVersion.cs index bdaa3ebef..3d876eb81 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/ApplicationVersion.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/ApplicationVersion.cs @@ -24,7 +24,7 @@ namespace Tango.BL.Entities public partial class ApplicationVersion : ObservableEntity { - protected Double _version; + protected String _version; /// /// Gets or sets the applicationversion version. @@ -32,7 +32,7 @@ namespace Tango.BL.Entities [Column("VERSION")] - public Double Version + public String Version { get { @@ -68,6 +68,50 @@ namespace Tango.BL.Entities } + protected String _ftpfilepath; + + /// + /// Gets or sets the applicationversion ftp file path. + /// + + [Column("FTP_FILE_PATH")] + + public String FtpFilePath + { + get + { + return _ftpfilepath; + } + + set + { + _ftpfilepath = value; RaisePropertyChanged(nameof(FtpFilePath)); + } + + } + + protected String _comments; + + /// + /// Gets or sets the applicationversion comments. + /// + + [Column("COMMENTS")] + + public String Comments + { + get + { + return _comments; + } + + set + { + _comments = value; RaisePropertyChanged(nameof(Comments)); + } + + } + protected ObservableCollection _configurations; /// diff --git a/Software/Visual_Studio/Tango.BL/Entities/EmbeddedSoftwareVersion.cs b/Software/Visual_Studio/Tango.BL/Entities/EmbeddedSoftwareVersion.cs index 115887346..31c95375d 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/EmbeddedSoftwareVersion.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/EmbeddedSoftwareVersion.cs @@ -24,7 +24,7 @@ namespace Tango.BL.Entities public partial class EmbeddedSoftwareVersion : ObservableEntity { - protected Double _version; + protected String _version; /// /// Gets or sets the embeddedsoftwareversion version. @@ -32,7 +32,7 @@ namespace Tango.BL.Entities [Column("VERSION")] - public Double Version + public String Version { get { @@ -68,6 +68,50 @@ namespace Tango.BL.Entities } + protected String _ftpfilepath; + + /// + /// Gets or sets the embeddedsoftwareversion ftp file path. + /// + + [Column("FTP_FILE_PATH")] + + public String FtpFilePath + { + get + { + return _ftpfilepath; + } + + set + { + _ftpfilepath = value; RaisePropertyChanged(nameof(FtpFilePath)); + } + + } + + protected String _comments; + + /// + /// Gets or sets the embeddedsoftwareversion comments. + /// + + [Column("COMMENTS")] + + public String Comments + { + get + { + return _comments; + } + + set + { + _comments = value; RaisePropertyChanged(nameof(Comments)); + } + + } + protected ObservableCollection _configurations; /// diff --git a/Software/Visual_Studio/Tango.Core/IO/FileStreamWrapper.cs b/Software/Visual_Studio/Tango.Core/IO/FileStreamWrapper.cs new file mode 100644 index 000000000..681f00919 --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/IO/FileStreamWrapper.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Core.IO +{ + /// + /// Represents a FileStream Wrapper dedicated for delivering Read/Write progress callbacks. + /// + /// + public class FileStreamWrapper : FileStream + { + private Action _callback; + + /// + /// Initializes a new instance of the class. + /// + /// Name of the file. + /// The mode. + /// The callback. + public FileStreamWrapper(String fileName, FileMode mode, Action callback) : base(fileName, mode) + { + _callback = callback; + } + + /// + /// Writes a block of bytes to the file stream. + /// + /// The buffer containing data to write to the stream. + /// The zero-based byte offset in from which to begin copying bytes to the stream. + /// The maximum number of bytes to write. + public override void Write(byte[] array, int offset, int count) + { + _callback?.Invoke(Length); + base.Write(array, offset, count); + } + + /// + /// Reads a block of bytes from the stream and writes the data in a given buffer. + /// + /// When this method returns, contains the specified byte array with the values between and ( + - 1 replaced by the bytes read from the current source. + /// The byte offset in at which the read bytes will be placed. + /// The maximum number of bytes to read. + /// + /// The total number of bytes read into the buffer. This might be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached. + /// + public override int Read(byte[] array, int offset, int count) + { + _callback?.Invoke(Position); + return base.Read(array, offset, count); + } + } +} diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index a0c54ef89..ee5864518 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -105,6 +105,7 @@ + @@ -150,7 +151,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/APPLICATION_VERSIONS.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/APPLICATION_VERSIONS.cs index 620be2da0..4bc38ca98 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/APPLICATION_VERSIONS.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/APPLICATION_VERSIONS.cs @@ -23,8 +23,10 @@ namespace Tango.DAL.Remote.DB public int ID { get; set; } public string GUID { get; set; } public System.DateTime LAST_UPDATED { get; set; } - public double VERSION { get; set; } + public string VERSION { get; set; } public string NAME { get; set; } + public string FTP_FILE_PATH { get; set; } + public string COMMENTS { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection CONFIGURATIONS { get; set; } diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/EMBEDDED_SOFTWARE_VERSIONS.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/EMBEDDED_SOFTWARE_VERSIONS.cs index 6ae24f6a7..7243e300a 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/EMBEDDED_SOFTWARE_VERSIONS.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/EMBEDDED_SOFTWARE_VERSIONS.cs @@ -23,8 +23,10 @@ namespace Tango.DAL.Remote.DB public int ID { get; set; } public string GUID { get; set; } public System.DateTime LAST_UPDATED { get; set; } - public double VERSION { get; set; } + public string VERSION { get; set; } public string NAME { get; set; } + public string FTP_FILE_PATH { get; set; } + public string COMMENTS { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection CONFIGURATIONS { get; set; } diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.Designer.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.Designer.cs index d26e67908..17bc2683d 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.Designer.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.Designer.cs @@ -1,4 +1,4 @@ -// T4 code generation is enabled for model 'C:\DATA\Development\Tango\Software\Visual_Studio\Tango.DAL.Remote\DB\RemoteADO.edmx'. +// T4 code generation is enabled for model 'D:\Development\Tango\Software\Visual_Studio\Tango.DAL.Remote\DB\RemoteADO.edmx'. // To enable legacy code generation, change the value of the 'Code Generation Strategy' designer // property to 'Legacy ObjectContext'. This property is available in the Properties Window when the model // is open in the designer. diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx index 1dbcca618..37bad1838 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx @@ -69,8 +69,10 @@ - + + + @@ -256,8 +258,10 @@ - + + + @@ -3034,8 +3038,10 @@ - + + + @@ -3253,8 +3259,10 @@ - + + + @@ -5329,6 +5337,8 @@ + + @@ -5528,6 +5538,8 @@ + + diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram index e85538862..801e44e43 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram @@ -5,81 +5,81 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - + + + diff --git a/Software/Visual_Studio/Tango.PMR/Synchronization/MachineSetupRequest.cs b/Software/Visual_Studio/Tango.PMR/Synchronization/MachineSetupRequest.cs new file mode 100644 index 000000000..d332f5bf8 --- /dev/null +++ b/Software/Visual_Studio/Tango.PMR/Synchronization/MachineSetupRequest.cs @@ -0,0 +1,160 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: MachineSetupRequest.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.Synchronization { + + /// Holder for reflection information generated from MachineSetupRequest.proto + public static partial class MachineSetupRequestReflection { + + #region Descriptor + /// File descriptor for MachineSetupRequest.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static MachineSetupRequestReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChlNYWNoaW5lU2V0dXBSZXF1ZXN0LnByb3RvEhlUYW5nby5QTVIuU3luY2hy", + "b25pemF0aW9uIisKE01hY2hpbmVTZXR1cFJlcXVlc3QSFAoMU2VyaWFsTnVt", + "YmVyGAEgASgJQiUKI2NvbS50d2luZS50YW5nby5wbXIuc3luY2hyb25pemF0", + "aW9uYgZwcm90bzM=")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Synchronization.MachineSetupRequest), global::Tango.PMR.Synchronization.MachineSetupRequest.Parser, new[]{ "SerialNumber" }, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class MachineSetupRequest : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MachineSetupRequest()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Tango.PMR.Synchronization.MachineSetupRequestReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MachineSetupRequest() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MachineSetupRequest(MachineSetupRequest other) : this() { + serialNumber_ = other.serialNumber_; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MachineSetupRequest Clone() { + return new MachineSetupRequest(this); + } + + /// Field number for the "SerialNumber" field. + public const int SerialNumberFieldNumber = 1; + private string serialNumber_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string SerialNumber { + get { return serialNumber_; } + set { + serialNumber_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as MachineSetupRequest); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(MachineSetupRequest other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (SerialNumber != other.SerialNumber) return false; + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (SerialNumber.Length != 0) hash ^= SerialNumber.GetHashCode(); + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (SerialNumber.Length != 0) { + output.WriteRawTag(10); + output.WriteString(SerialNumber); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (SerialNumber.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(SerialNumber); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(MachineSetupRequest other) { + if (other == null) { + return; + } + if (other.SerialNumber.Length != 0) { + SerialNumber = other.SerialNumber; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 10: { + SerialNumber = input.ReadString(); + break; + } + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual_Studio/Tango.PMR/Synchronization/MachineSetupResponse.cs b/Software/Visual_Studio/Tango.PMR/Synchronization/MachineSetupResponse.cs new file mode 100644 index 000000000..02d312aa1 --- /dev/null +++ b/Software/Visual_Studio/Tango.PMR/Synchronization/MachineSetupResponse.cs @@ -0,0 +1,360 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: MachineSetupResponse.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.Synchronization { + + /// Holder for reflection information generated from MachineSetupResponse.proto + public static partial class MachineSetupResponseReflection { + + #region Descriptor + /// File descriptor for MachineSetupResponse.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static MachineSetupResponseReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChpNYWNoaW5lU2V0dXBSZXNwb25zZS5wcm90bxIZVGFuZ28uUE1SLlN5bmNo", + "cm9uaXphdGlvbiLTAQoUTWFjaGluZVNldHVwUmVzcG9uc2USGgoSQXBwbGlj", + "YXRpb25WZXJzaW9uGAEgASgJEh4KFkFwcGxpY2F0aW9uRnRwRmlsZVBhdGgY", + "AiABKAkSFwoPRW1iZWRkZWRWZXJzaW9uGAMgASgJEhsKE0VtYmVkZGVkRnRw", + "RmlsZVBhdGgYBCABKAkSEgoKRnRwQWRkcmVzcxgFIAEoCRIQCghVc2VyTmFt", + "ZRgGIAEoCRIQCghQYXNzd29yZBgHIAEoCRIRCglEYkFkZHJlc3MYCCABKAlC", + "JQojY29tLnR3aW5lLnRhbmdvLnBtci5zeW5jaHJvbml6YXRpb25iBnByb3Rv", + "Mw==")); + 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[]{ "ApplicationVersion", "ApplicationFtpFilePath", "EmbeddedVersion", "EmbeddedFtpFilePath", "FtpAddress", "UserName", "Password", "DbAddress" }, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class MachineSetupResponse : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MachineSetupResponse()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Tango.PMR.Synchronization.MachineSetupResponseReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MachineSetupResponse() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MachineSetupResponse(MachineSetupResponse other) : this() { + applicationVersion_ = other.applicationVersion_; + applicationFtpFilePath_ = other.applicationFtpFilePath_; + embeddedVersion_ = other.embeddedVersion_; + embeddedFtpFilePath_ = other.embeddedFtpFilePath_; + ftpAddress_ = other.ftpAddress_; + userName_ = other.userName_; + password_ = other.password_; + dbAddress_ = other.dbAddress_; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MachineSetupResponse Clone() { + return new MachineSetupResponse(this); + } + + /// Field number for the "ApplicationVersion" field. + public const int ApplicationVersionFieldNumber = 1; + private string applicationVersion_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ApplicationVersion { + get { return applicationVersion_; } + set { + applicationVersion_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "ApplicationFtpFilePath" field. + public const int ApplicationFtpFilePathFieldNumber = 2; + private string applicationFtpFilePath_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ApplicationFtpFilePath { + get { return applicationFtpFilePath_; } + set { + applicationFtpFilePath_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "EmbeddedVersion" field. + public const int EmbeddedVersionFieldNumber = 3; + private string embeddedVersion_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string EmbeddedVersion { + get { return embeddedVersion_; } + set { + embeddedVersion_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "EmbeddedFtpFilePath" field. + public const int EmbeddedFtpFilePathFieldNumber = 4; + private string embeddedFtpFilePath_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string EmbeddedFtpFilePath { + get { return embeddedFtpFilePath_; } + set { + embeddedFtpFilePath_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "FtpAddress" field. + public const int FtpAddressFieldNumber = 5; + private string ftpAddress_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string FtpAddress { + get { return ftpAddress_; } + set { + ftpAddress_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "UserName" field. + public const int UserNameFieldNumber = 6; + private string userName_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string UserName { + get { return userName_; } + set { + userName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "Password" field. + public const int PasswordFieldNumber = 7; + private string password_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Password { + get { return password_; } + set { + password_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "DbAddress" field. + public const int DbAddressFieldNumber = 8; + private string dbAddress_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string DbAddress { + get { return dbAddress_; } + set { + dbAddress_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as MachineSetupResponse); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(MachineSetupResponse other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (ApplicationVersion != other.ApplicationVersion) return false; + if (ApplicationFtpFilePath != other.ApplicationFtpFilePath) return false; + if (EmbeddedVersion != other.EmbeddedVersion) return false; + if (EmbeddedFtpFilePath != other.EmbeddedFtpFilePath) return false; + if (FtpAddress != other.FtpAddress) return false; + if (UserName != other.UserName) return false; + if (Password != other.Password) return false; + if (DbAddress != other.DbAddress) return false; + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (ApplicationVersion.Length != 0) hash ^= ApplicationVersion.GetHashCode(); + if (ApplicationFtpFilePath.Length != 0) hash ^= ApplicationFtpFilePath.GetHashCode(); + if (EmbeddedVersion.Length != 0) hash ^= EmbeddedVersion.GetHashCode(); + if (EmbeddedFtpFilePath.Length != 0) hash ^= EmbeddedFtpFilePath.GetHashCode(); + if (FtpAddress.Length != 0) hash ^= FtpAddress.GetHashCode(); + if (UserName.Length != 0) hash ^= UserName.GetHashCode(); + if (Password.Length != 0) hash ^= Password.GetHashCode(); + if (DbAddress.Length != 0) hash ^= DbAddress.GetHashCode(); + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (ApplicationVersion.Length != 0) { + output.WriteRawTag(10); + output.WriteString(ApplicationVersion); + } + if (ApplicationFtpFilePath.Length != 0) { + output.WriteRawTag(18); + output.WriteString(ApplicationFtpFilePath); + } + if (EmbeddedVersion.Length != 0) { + output.WriteRawTag(26); + output.WriteString(EmbeddedVersion); + } + if (EmbeddedFtpFilePath.Length != 0) { + output.WriteRawTag(34); + output.WriteString(EmbeddedFtpFilePath); + } + if (FtpAddress.Length != 0) { + output.WriteRawTag(42); + output.WriteString(FtpAddress); + } + if (UserName.Length != 0) { + output.WriteRawTag(50); + output.WriteString(UserName); + } + if (Password.Length != 0) { + output.WriteRawTag(58); + output.WriteString(Password); + } + if (DbAddress.Length != 0) { + output.WriteRawTag(66); + output.WriteString(DbAddress); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (ApplicationVersion.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ApplicationVersion); + } + if (ApplicationFtpFilePath.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ApplicationFtpFilePath); + } + if (EmbeddedVersion.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(EmbeddedVersion); + } + if (EmbeddedFtpFilePath.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(EmbeddedFtpFilePath); + } + if (FtpAddress.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(FtpAddress); + } + if (UserName.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(UserName); + } + if (Password.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Password); + } + if (DbAddress.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(DbAddress); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(MachineSetupResponse other) { + if (other == null) { + return; + } + if (other.ApplicationVersion.Length != 0) { + ApplicationVersion = other.ApplicationVersion; + } + if (other.ApplicationFtpFilePath.Length != 0) { + ApplicationFtpFilePath = other.ApplicationFtpFilePath; + } + if (other.EmbeddedVersion.Length != 0) { + EmbeddedVersion = other.EmbeddedVersion; + } + if (other.EmbeddedFtpFilePath.Length != 0) { + EmbeddedFtpFilePath = other.EmbeddedFtpFilePath; + } + if (other.FtpAddress.Length != 0) { + FtpAddress = other.FtpAddress; + } + if (other.UserName.Length != 0) { + UserName = other.UserName; + } + if (other.Password.Length != 0) { + Password = other.Password; + } + if (other.DbAddress.Length != 0) { + DbAddress = other.DbAddress; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 10: { + ApplicationVersion = input.ReadString(); + break; + } + case 18: { + ApplicationFtpFilePath = input.ReadString(); + break; + } + case 26: { + EmbeddedVersion = input.ReadString(); + break; + } + case 34: { + EmbeddedFtpFilePath = input.ReadString(); + break; + } + case 42: { + FtpAddress = input.ReadString(); + break; + } + case 50: { + UserName = input.ReadString(); + break; + } + case 58: { + Password = input.ReadString(); + break; + } + case 66: { + DbAddress = input.ReadString(); + break; + } + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj index ebd34b210..6456be076 100644 --- a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj +++ b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj @@ -101,6 +101,8 @@ + + @@ -127,7 +129,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Transport/Web/ITransportWebClient.cs b/Software/Visual_Studio/Tango.Transport/Web/ITransportWebClient.cs new file mode 100644 index 000000000..81d443671 --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Web/ITransportWebClient.cs @@ -0,0 +1,14 @@ +using Google.Protobuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Transport.Web +{ + public interface ITransportWebClient : IDisposable + { + Task Post(String url, Request request) where Request : class, IMessage where Response : class, IMessage; + } +} diff --git a/Software/Visual_Studio/Tango.Transport/Web/ProtoWebClient.cs b/Software/Visual_Studio/Tango.Transport/Web/ProtoWebClient.cs new file mode 100644 index 000000000..43ff482fd --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Web/ProtoWebClient.cs @@ -0,0 +1,42 @@ +using Google.Protobuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Transport.Web +{ + public class ProtoWebClient : ITransportWebClient + { + private HttpClient _httpClient; + + public ProtoWebClient() + { + _httpClient = new HttpClient(); + } + + public Task Post(String url, Request request) where Request : class, IMessage where Response : class, IMessage + { + return Task.Factory.StartNew(() => + { + + var req = new ByteArrayContent(request.ToByteArray()); + req.Headers.Add("Content-Type", "application/x-protobuf"); + + var response = _httpClient.PostAsync(url, req).Result; + var data = response.Content.ReadAsByteArrayAsync().Result; + + Response dummy = Activator.CreateInstance() as Response; + + return dummy.GetParser().ParseFrom(data) as Response; + }); + } + + public void Dispose() + { + _httpClient.Dispose(); + } + } +} diff --git a/Software/Visual_Studio/Tango.sln b/Software/Visual_Studio/Tango.sln index ee189e840..2ae4fecab 100644 --- a/Software/Visual_Studio/Tango.sln +++ b/Software/Visual_Studio/Tango.sln @@ -3799,12 +3799,12 @@ Global {91B70E9B-66A7-4873-AE10-400E71CF404F} = {0048447D-1D94-4E60-9DAD-7349C777CB4E} 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/App_Start/WebApiConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs index 15f0e7afc..28968684e 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs @@ -15,10 +15,9 @@ namespace Tango.MachineService config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( - name: "DefaultApi", - routeTemplate: "api/{controller}/{id}", - defaults: new { id = RouteParameter.Optional } - ); + name: "API Default", + routeTemplate: "api/{controller}/{action}/{id}", + defaults: new { id = RouteParameter.Optional }); config.Formatters.Insert(0, new ProtoBufFormatter()); } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs index 28d0cd3f1..aed78f1a6 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs @@ -1,6 +1,7 @@ using Google.Protobuf; using System; using System.Collections.Generic; +using System.Configuration; using System.IO; using System.Linq; using System.Net; @@ -8,6 +9,7 @@ using System.Net.Http; using System.Threading.Tasks; using System.Web.Hosting; using System.Web.Http; +using Tango.BL; using Tango.Core.Helpers; using Tango.Core.IO; using Tango.PMR.Stubs; @@ -64,5 +66,83 @@ namespace Tango.MachineService.Controllers tempFolder.Delete(); } } + + [HttpPost] + public MachineSetupResponse MachineSetup(MachineSetupRequest request) + { + MachineSetupResponse response = new MachineSetupResponse(); + + try + { + using (ObservablesContext db = ObservablesContext.CreateDefault(GetLocalServerAddress())) + { + db.Configuration.LazyLoadingEnabled = false; + String serial_number = request.SerialNumber; + + var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); + + if (machine == null) + { + OnError(HttpStatusCode.NotFound, "The specified serial number could not be found."); + } + + var configuration = db.Configurations.SingleOrDefault(x => x.Guid == machine.ConfigurationGuid); + + var appVersion = db.ApplicationVersions.SingleOrDefault(x => x.Guid == configuration.ApplicationVersionGuid); + var embeddedVersion = db.EmbeddedSoftwareVersions.SingleOrDefault(x => x.Guid == configuration.EmbeddedSoftwareVersionGuid); + + response.ApplicationVersion = appVersion.Version; + response.ApplicationFtpFilePath = appVersion.FtpFilePath; + + response.EmbeddedVersion = embeddedVersion.Version; + response.EmbeddedFtpFilePath = embeddedVersion.FtpFilePath; + + response.DbAddress = GetRemoteServerAddress(); + response.FtpAddress = GetFtpAddress(); + response.UserName = GetFtpUserName(); + response.Password = GetFtpPassword(); + } + } + catch (Exception ex) + { + OnError(HttpStatusCode.InternalServerError, ex.Message); + } + + return response; + } + + #region Helpers + + private void OnError(HttpStatusCode code, String message) + { + throw new HttpResponseException(Request.CreateErrorResponse(code, message)); + } + + private String GetLocalServerAddress() + { + return ConfigurationManager.AppSettings["LocalServerAddress"].ToString(); + } + + private String GetRemoteServerAddress() + { + return ConfigurationManager.AppSettings["RemoteServerAddress"].ToString(); + } + + private String GetFtpAddress() + { + return ConfigurationManager.AppSettings["FtpAddress"].ToString(); + } + + private String GetFtpUserName() + { + return ConfigurationManager.AppSettings["FtpUserName"].ToString(); + } + + private String GetFtpPassword() + { + return ConfigurationManager.AppSettings["FtpPassword"].ToString(); + } + + #endregion } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs b/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs index 8078f1d8f..529cbde54 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs @@ -98,19 +98,24 @@ namespace Tango.MachineService /// public override Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContent content, TransportContext transportContext) { - var tcs = new TaskCompletionSource(); - - try - { - (value as IMessage).WriteTo(stream); - tcs.SetResult(null); - } - catch (Exception ex) + if (value is IMessage) { - tcs.SetException(ex); + var tcs = new TaskCompletionSource(); + + try + { + (value as IMessage).WriteTo(stream); + tcs.SetResult(null); + } + catch (Exception ex) + { + tcs.SetException(ex); + } + + return tcs.Task; } - return tcs.Task; + return base.WriteToStreamAsync(type, value, stream, content, transportContext); } } } \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj index 20fa14d62..9beaf8923 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -26,6 +26,7 @@ + true @@ -201,6 +202,10 @@ + + {F441FEEE-322A-4943-B566-110E12FD3B72} + Tango.BL + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core @@ -246,7 +251,7 @@ False - + diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index 88fb2afc4..4185b4e7b 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -13,6 +13,12 @@ + + + + + +