From 4954a924b8a5b8fd7a213a444027e74b936359be Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 16 Oct 2019 17:31:51 +0300 Subject: Added support for token authentication from MS to DB. --- Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs') diff --git a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs index 0e6d18ddf..e8165a4a6 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs @@ -15,5 +15,6 @@ namespace Tango.MachineService public static String JWT_TOKEN_SECRET => ConfigurationManager.AppSettings[nameof(JWT_TOKEN_SECRET)].ToString(); public static String REFRESH_TOKENS_TABLE_NAME => ConfigurationManager.AppSettings[nameof(REFRESH_TOKENS_TABLE_NAME)].ToString(); public static String REFRESH_TOKENS_TABLE_PARTITION => ConfigurationManager.AppSettings[nameof(REFRESH_TOKENS_TABLE_PARTITION)].ToString(); + public static bool USE_DB_ACCESS_TOKENS => bool.Parse(ConfigurationManager.AppSettings[nameof(USE_DB_ACCESS_TOKENS)].ToString()); } } \ No newline at end of file -- cgit v1.3.1 From 9259bc36791a7084ae33bcf0a698101ddb24d28f Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 5 Dec 2019 18:06:21 +0200 Subject: Integrated CDN downloads to PPC and MS. --- .../Web/CheckForUpdatesResponse.cs | 2 + .../Web/DownloadLatestVersionResponse.cs | 2 + .../ViewModels/UpdateViewVM.cs | 3 +- .../MachineSetup/MachineSetupManager.cs | 38 ++++--- .../MachineUpdate/MachineUpdateManager.cs | 32 ++++-- .../Tango.PPC.Common/Web/DownloadUpdateResponse.cs | 2 + .../Tango.PPC.Common/Web/MachineSetupResponse.cs | 2 + .../Tango.Transport/Tango.Transport.csproj | 7 +- .../Tango.Transport/Web/AutoFileDownloader.cs | 123 +++++++++++++++++++++ .../Tango.Transport/Web/IWebFileDownloader.cs | 15 +++ .../Tango.Transport/Web/StandardFileDownloader.cs | 77 +++++++++++++ .../Tango.Transport/Web/StorageBlobDownloader.cs | 23 +++- .../Web/StorageBlobProgressEventArgs.cs | 14 --- .../Tango.Transport/Web/StorageBlobUploader.cs | 4 +- .../Web/WebFileDownloaderProgressEventArgs.cs | 14 +++ .../Controllers/MachineStudioController.cs | 10 ++ .../Controllers/PPCController.cs | 12 +- .../Tango.MachineService/MachineServiceConfig.cs | 1 + .../Web/Tango.MachineService/Web.config | 1 + 19 files changed, 327 insertions(+), 55 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Transport/Web/AutoFileDownloader.cs create mode 100644 Software/Visual_Studio/Tango.Transport/Web/IWebFileDownloader.cs create mode 100644 Software/Visual_Studio/Tango.Transport/Web/StandardFileDownloader.cs delete mode 100644 Software/Visual_Studio/Tango.Transport/Web/StorageBlobProgressEventArgs.cs create mode 100644 Software/Visual_Studio/Tango.Transport/Web/WebFileDownloaderProgressEventArgs.cs (limited to 'Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesResponse.cs index 51608e6c4..b78047c85 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesResponse.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesResponse.cs @@ -17,5 +17,7 @@ namespace Tango.MachineStudio.Common.Web public String Comments { get; set; } public String BlobAddress { get; set; } + + public String CdnAddress { get; set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionResponse.cs index 3209b9a2f..60251d455 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionResponse.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionResponse.cs @@ -12,5 +12,7 @@ namespace Tango.MachineStudio.Common.Web public String Version { get; set; } public String BlobAddress { get; set; } + + public String CdnAddress { get; set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs index 2ee8574b1..160041b5f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -179,6 +179,7 @@ namespace Tango.MachineStudio.UI.ViewModels _updateInfo = new CheckForUpdatesResponse(); _updateInfo.BlobAddress = response.BlobAddress; _updateInfo.Version = response.Version; + _updateInfo.CdnAddress = response.CdnAddress; LatestVersion = _updateInfo.Version; StartUpdate(); @@ -270,7 +271,7 @@ namespace Tango.MachineStudio.UI.ViewModels { logManager.Log("Creating temporary file " + tempFile); - using (StorageBlobDownloader downloader = new StorageBlobDownloader(_updateInfo.BlobAddress, tempFile.Path)) + using (AutoFileDownloader downloader = new AutoFileDownloader(_updateInfo.BlobAddress, _updateInfo.CdnAddress, tempFile.Path)) { downloader.Progress += (x, e) => { 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 537e652e6..cce6c32ab 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -249,27 +249,29 @@ namespace Tango.PPC.Common.MachineSetup LogManager.Log("Downloading software package..."); - long fileSize = 0; - UpdateProgress("Downloading software package", "Downloading...", false); + AutoFileDownloader downloader = new AutoFileDownloader(setup_response.BlobAddress, setup_response.CdnAddress, tempFile); + await downloader.ResolveMode(); - await Task.Factory.StartNew(() => + if (downloader.Mode == AutoFileDownloader.DownloadMode.Standard) { - using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) => - { - UpdateProgress("Downloading software package", "Downloading...", false, current, fileSize); - })) - { + LogManager.Log($"Connecting to storage CDN with address {downloader.Address}"); + } + else + { + LogManager.Log($"Connecting to storage blob with address {downloader.Address}"); + } - LogManager.Log($"Connecting to storage blob with address {setup_response.BlobAddress}"); - CloudBlockBlob blob = new CloudBlockBlob(new Uri(setup_response.BlobAddress)); - LogManager.Log("Fetching blob attributes..."); - blob.FetchAttributes(); - fileSize = blob.Properties.Length; - LogManager.Log("Download size: " + fileSize + " bytes."); - LogManager.Log("Starting blob download..."); - blob.DownloadToStream(fs); - } - }); + downloader.Progress += (x, e) => + { + UpdateProgress("Downloading software package", "Downloading...", false, e.Current, e.Total); + }; + + var size = await downloader.GetFileSize(); + LogManager.Log("Download size: " + size + " bytes."); + LogManager.Log("Starting file download..."); + await downloader.Download(); + + downloader.Dispose(); UpdateProgress("Downloading software package", "Extracting package..."); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs index 8642c089f..333fb261d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -329,24 +329,32 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log("Downloading software package..."); - long fileSize = 0; UpdateProgress("Downloading software package", "Downloading...", false); - using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) => + AutoFileDownloader downloader = new AutoFileDownloader(update_response.BlobAddress, update_response.CdnAddress, tempFile); + await downloader.ResolveMode(); + + if (downloader.Mode == AutoFileDownloader.DownloadMode.Standard) { - UpdateProgress("Downloading software package", "Downloading...", false, current, fileSize); - })) + LogManager.Log($"Connecting to storage CDN with address {downloader.Address}"); + } + else { - LogManager.Log($"Connecting to storage blob with address {update_response.BlobAddress}"); - CloudBlockBlob blob = new CloudBlockBlob(new Uri(update_response.BlobAddress)); - LogManager.Log("Fetching blob attributes..."); - blob.FetchAttributes(); - fileSize = blob.Properties.Length; - LogManager.Log("Download size: " + fileSize + " bytes."); - LogManager.Log("Starting blob download..."); - blob.DownloadToStream(fs); + LogManager.Log($"Connecting to storage blob with address {downloader.Address}"); } + downloader.Progress += (x, e) => + { + UpdateProgress("Downloading software package", "Downloading...", false, e.Current, e.Total); + }; + + var size = await downloader.GetFileSize(); + LogManager.Log("Download size: " + size + " bytes."); + LogManager.Log("Starting file download..."); + await downloader.Download(); + + downloader.Dispose(); + UpdateProgress("Downloading software package", "Extracting package..."); LogManager.Log("Extracting downloaded zip file..."); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/DownloadUpdateResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/DownloadUpdateResponse.cs index 4396ce67a..b092aedbe 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/DownloadUpdateResponse.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/DownloadUpdateResponse.cs @@ -16,6 +16,8 @@ namespace Tango.PPC.Common.Web public String BlobAddress { get; set; } + public String CdnAddress { get; set; } + public DataSource DataSource { get; set; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/MachineSetupResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/MachineSetupResponse.cs index 73cdc8609..714a413ab 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/MachineSetupResponse.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/MachineSetupResponse.cs @@ -16,6 +16,8 @@ namespace Tango.PPC.Common.Web public String BlobAddress { get; set; } + public String CdnAddress { get; set; } + public DataSource DataSource { get; set; } public String OSKey { get; set; } diff --git a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj index 87af709e0..542a0a92d 100644 --- a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj +++ b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj @@ -109,14 +109,17 @@ + + + - + @@ -148,7 +151,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Transport/Web/AutoFileDownloader.cs b/Software/Visual_Studio/Tango.Transport/Web/AutoFileDownloader.cs new file mode 100644 index 000000000..1f45f10dc --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Web/AutoFileDownloader.cs @@ -0,0 +1,123 @@ +using Microsoft.WindowsAzure.Storage.Blob; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.IO; + +namespace Tango.Transport.Web +{ + public class AutoFileDownloader : IWebFileDownloader + { + public enum DownloadMode + { + Standard, + Blob + } + + private bool _disposed; + private StorageBlobDownloader _blobDownloader; + private StandardFileDownloader _standardDownloader; + private bool _isCdnOK = false; + private long _fileSize = -1; + + public event EventHandler Progress; + + public String Address { get; private set; } + + public String FileName { get; private set; } + + public DownloadMode Mode { get; private set; } + + public AutoFileDownloader(String blobAddress, String cdnAddress, String fileName) + { + FileName = fileName; + + _blobDownloader = new StorageBlobDownloader(blobAddress, fileName); + _standardDownloader = new StandardFileDownloader(cdnAddress, fileName); + + _blobDownloader.Progress += OnProgress; + _standardDownloader.Progress += OnProgress; + } + + private void OnProgress(object sender, WebFileDownloaderProgressEventArgs e) + { + Progress?.Invoke(this, e); + } + + public async Task Download() + { + if (_disposed) + { + throw new ObjectDisposedException("The file downloader can only be used once."); + } + + if (_fileSize == -1) + { + await GetFileSize(); + } + + if (_isCdnOK) + { + await _standardDownloader.Download(); + } + else + { + await _blobDownloader.Download(); + } + } + + public async Task ResolveMode() + { + await GetFileSize(); + } + + public Task GetFileSize() + { + if (_fileSize == -1) + { + return Task.Factory.StartNew(() => + { + try + { + _fileSize = _standardDownloader.GetFileSize().Result; + _isCdnOK = true; + Mode = DownloadMode.Standard; + Address = _standardDownloader.Address; + return _fileSize; + } + catch + { + try + { + _fileSize = _blobDownloader.GetFileSize().Result; + Mode = DownloadMode.Blob; + Address = _blobDownloader.Blob.Uri.ToString(); + return _fileSize; + } + catch + { + throw new Exception("Invalid address for standard download or blob."); + } + } + }); + } + else + { + return Task.FromResult(_fileSize); + } + } + + public void Dispose() + { + if (!_disposed) + { + _disposed = true; + _blobDownloader.Dispose(); + _standardDownloader.Dispose(); + } + } + } +} diff --git a/Software/Visual_Studio/Tango.Transport/Web/IWebFileDownloader.cs b/Software/Visual_Studio/Tango.Transport/Web/IWebFileDownloader.cs new file mode 100644 index 000000000..2f65553d5 --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Web/IWebFileDownloader.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Transport.Web +{ + public interface IWebFileDownloader : IDisposable + { + event EventHandler Progress; + Task Download(); + Task GetFileSize(); + } +} diff --git a/Software/Visual_Studio/Tango.Transport/Web/StandardFileDownloader.cs b/Software/Visual_Studio/Tango.Transport/Web/StandardFileDownloader.cs new file mode 100644 index 000000000..d254abd96 --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Web/StandardFileDownloader.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Transport.Web +{ + public class StandardFileDownloader : IWebFileDownloader + { + private WebClient _client; + private TaskCompletionSource _completionSource; + + public String Address { get; private set; } + + public String FileName { get; private set; } + + public event EventHandler Progress; + + public StandardFileDownloader(String address, String fileName) + { + Address = address; + FileName = fileName; + _client = new WebClient(); + _client.DownloadProgressChanged += _client_DownloadProgressChanged; + _client.DownloadFileCompleted += _client_DownloadFileCompleted; + + _completionSource = new TaskCompletionSource(); + } + + private void _client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) + { + if (e.Error != null) + { + _completionSource.SetException(e.Error); + } + else + { + _completionSource.SetResult(true); + } + } + + public Task Download() + { + _client.DownloadFileAsync(new Uri(Address), FileName); + return _completionSource.Task; + } + + private void _client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) + { + Progress?.Invoke(this, new WebFileDownloaderProgressEventArgs() + { + Current = e.BytesReceived, + Total = e.TotalBytesToReceive, + }); + } + + public Task GetFileSize() + { + return Task.Factory.StartNew(() => + { + using (var client = new WebClient()) + { + client.OpenRead(Address); + Int64 bytes_total = Convert.ToInt64(client.ResponseHeaders["Content-Length"]); + return bytes_total; + } + }); + } + + public void Dispose() + { + _client.Dispose(); + } + } +} diff --git a/Software/Visual_Studio/Tango.Transport/Web/StorageBlobDownloader.cs b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobDownloader.cs index 603463823..8977c5530 100644 --- a/Software/Visual_Studio/Tango.Transport/Web/StorageBlobDownloader.cs +++ b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobDownloader.cs @@ -9,20 +9,21 @@ using Tango.Core.IO; namespace Tango.Transport.Web { - public class StorageBlobDownloader : IDisposable + public class StorageBlobDownloader : IWebFileDownloader { private bool _disposed; private FileStreamWrapper _stream; private long _fileSize; + private String _fileName; public CloudBlockBlob Blob { get; private set; } - public event EventHandler Progress; + public event EventHandler Progress; public StorageBlobDownloader(CloudBlockBlob blob, String fileName) { Blob = blob; - _stream = new FileStreamWrapper(fileName, FileMode.Create, OnProgress); + _fileName = fileName; } public StorageBlobDownloader(String blobAddress, String fileName) : this(new CloudBlockBlob(new Uri(blobAddress)), fileName) @@ -32,7 +33,7 @@ namespace Tango.Transport.Web private void OnProgress(long current) { - Progress?.Invoke(this, new StorageBlobProgressEventArgs() + Progress?.Invoke(this, new WebFileDownloaderProgressEventArgs() { Current = current, Total = _fileSize, @@ -49,6 +50,8 @@ namespace Tango.Transport.Web await Blob.FetchAttributesAsync(); _fileSize = Blob.Properties.Length; + _stream = new FileStreamWrapper(_fileName, FileMode.Create, OnProgress); + await Blob.DownloadToStreamAsync(_stream); Dispose(); } @@ -58,8 +61,18 @@ namespace Tango.Transport.Web if (!_disposed) { _disposed = true; - _stream.Dispose(); + + if (_stream != null) + { + _stream.Dispose(); + } } } + + public async Task GetFileSize() + { + await Blob.FetchAttributesAsync(); + return Blob.Properties.Length; + } } } diff --git a/Software/Visual_Studio/Tango.Transport/Web/StorageBlobProgressEventArgs.cs b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobProgressEventArgs.cs deleted file mode 100644 index ae48e34cf..000000000 --- a/Software/Visual_Studio/Tango.Transport/Web/StorageBlobProgressEventArgs.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Transport.Web -{ - public class StorageBlobProgressEventArgs : EventArgs - { - public long Total { get; set; } - public long Current { get; set; } - } -} diff --git a/Software/Visual_Studio/Tango.Transport/Web/StorageBlobUploader.cs b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobUploader.cs index 8d645f33f..00600c679 100644 --- a/Software/Visual_Studio/Tango.Transport/Web/StorageBlobUploader.cs +++ b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobUploader.cs @@ -16,7 +16,7 @@ namespace Tango.Transport.Web public CloudBlockBlob Blob { get; private set; } - public event EventHandler Progress; + public event EventHandler Progress; public StorageBlobUploader(CloudBlockBlob blob, String fileName) { @@ -31,7 +31,7 @@ namespace Tango.Transport.Web private void OnProgress(long current) { - Progress?.Invoke(this, new StorageBlobProgressEventArgs() + Progress?.Invoke(this, new WebFileDownloaderProgressEventArgs() { Current = current, Total = _stream.Length, diff --git a/Software/Visual_Studio/Tango.Transport/Web/WebFileDownloaderProgressEventArgs.cs b/Software/Visual_Studio/Tango.Transport/Web/WebFileDownloaderProgressEventArgs.cs new file mode 100644 index 000000000..570c4058a --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Web/WebFileDownloaderProgressEventArgs.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Transport.Web +{ + public class WebFileDownloaderProgressEventArgs : EventArgs + { + public long Total { get; set; } + public long Current { get; set; } + } +} diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index dd8401570..2eeaa6e0e 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -99,6 +99,11 @@ namespace Tango.MachineService.Controllers response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); + if (!String.IsNullOrWhiteSpace(MachineServiceConfig.CDN_ENDPOINT)) + { + response.CdnAddress = MachineServiceConfig.CDN_ENDPOINT + blob.Uri.AbsolutePath; + } + response.IsUpdateAvailable = true; response.Version = latestVersion.Version; response.Comments = latestVersion.Comments; @@ -133,6 +138,11 @@ namespace Tango.MachineService.Controllers var container = manager.GetContainer(MachineServiceConfig.MACHINE_STUDIO_VERSIONS_CONTAINER); var blob = container.GetBlockBlobReference(latestVersion.BlobName); + if (!String.IsNullOrWhiteSpace(MachineServiceConfig.CDN_ENDPOINT)) + { + response.CdnAddress = MachineServiceConfig.CDN_ENDPOINT + blob.Uri.AbsolutePath; + } + response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); response.Version = latestVersion.Version; } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index 4c39aad80..f0239978f 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -32,7 +32,7 @@ namespace Tango.MachineService.Controllers private static List _pendingUploads; private static List _pendingUpdates; private ActiveDirectoryManager _ad_manager; - private const int SQL_TEMP_CREDENTIALS_EXP_MINUTS = 20; + private const int SQL_TEMP_CREDENTIALS_EXP_MINUTS = 20; public class TokenObject { @@ -114,6 +114,11 @@ namespace Tango.MachineService.Controllers response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); + if (!String.IsNullOrWhiteSpace(MachineServiceConfig.CDN_ENDPOINT)) + { + response.CdnAddress = MachineServiceConfig.CDN_ENDPOINT + blob.Uri.AbsolutePath; + } + DbCredentials credentials = new DbCredentials(); using (SmoManager smo = new SmoManager()) @@ -197,6 +202,11 @@ namespace Tango.MachineService.Controllers response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); + if (!String.IsNullOrWhiteSpace(MachineServiceConfig.CDN_ENDPOINT)) + { + response.CdnAddress = MachineServiceConfig.CDN_ENDPOINT + blob.Uri.AbsolutePath; + } + DbCredentials credentials = new DbCredentials(); using (SmoManager smo = new SmoManager()) diff --git a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs index e8165a4a6..014ef68ba 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs @@ -16,5 +16,6 @@ namespace Tango.MachineService public static String REFRESH_TOKENS_TABLE_NAME => ConfigurationManager.AppSettings[nameof(REFRESH_TOKENS_TABLE_NAME)].ToString(); public static String REFRESH_TOKENS_TABLE_PARTITION => ConfigurationManager.AppSettings[nameof(REFRESH_TOKENS_TABLE_PARTITION)].ToString(); public static bool USE_DB_ACCESS_TOKENS => bool.Parse(ConfigurationManager.AppSettings[nameof(USE_DB_ACCESS_TOKENS)].ToString()); + public static String CDN_ENDPOINT => ConfigurationManager.AppSettings[nameof(CDN_ENDPOINT)].ToString(); } } \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index dce9e1fb9..97a0d511f 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -30,6 +30,7 @@ +