diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-11-25 10:44:37 +0200 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-11-25 10:44:37 +0200 |
| commit | beff6af103bb0ae9b9147a907c6567bdb33abd00 (patch) | |
| tree | 375eefd654c25f3b68c0cf5b3612df844a140d8e /Software/Visual_Studio/Web/Tango.MachineService | |
| parent | 57f20269fbb4c591aa73c9f5e50118310cc4892e (diff) | |
| parent | dff24e56a8906b8c9b355cf407f25f4b793beafe (diff) | |
| download | Tango-beff6af103bb0ae9b9147a907c6567bdb33abd00.tar.gz Tango-beff6af103bb0ae9b9147a907c6567bdb33abd00.zip | |
merge
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService')
15 files changed, 851 insertions, 254 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/App_Start/RouteConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/App_Start/RouteConfig.cs index 33fa703a8..60453c3a1 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/App_Start/RouteConfig.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/App_Start/RouteConfig.cs @@ -13,11 +13,11 @@ namespace Tango.MachineService { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); - routes.MapRoute( - name: "Default", - url: "{controller}/{action}/{id}", - defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } - ); + //routes.MapRoute( + // name: "Default", + // url: "{controller}/{action}/{id}", + // defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } + //); } } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Config.cs b/Software/Visual_Studio/Web/Tango.MachineService/Config.cs new file mode 100644 index 000000000..b1d2dafca --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Config.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Web; + +namespace Tango.MachineService +{ + public class Config + { + public static String DB_ADDRESS => ConfigurationManager.AppSettings["DbAddress"].ToString(); + public static String DB_USER_NAME => ConfigurationManager.AppSettings["DbUserName"].ToString(); + public static String DB_PASSWORD => ConfigurationManager.AppSettings["DbPassword"].ToString(); + public static String DB_CATALOG => ConfigurationManager.AppSettings["DbCatalog"].ToString(); + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs index 51cf6f96b..304ea34f2 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs @@ -1,4 +1,7 @@ using Google.Protobuf; +using Microsoft.Azure; +using Microsoft.Azure.Management.Sql; +using Microsoft.SqlServer.Management.Smo; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; @@ -7,6 +10,7 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; +using System.Security.Authentication; using System.Threading.Tasks; using System.Web.Hosting; using System.Web.Http; @@ -17,7 +21,9 @@ using Tango.Core.DB; using Tango.Core.Helpers; using Tango.Core.IO; using Tango.Logging; +using Tango.MachineService.Helpers; using Tango.MachineService.Models; +using Tango.MachineService.SMO; using Tango.PMR.Stubs; using Tango.PMR.Synchronization; using Tango.Synchronization.Local; @@ -25,112 +31,103 @@ using Tango.Synchronization.Remote; namespace Tango.MachineService.Controllers { - public class SynchronizationController : ApiController + public class SynchronizationController : ProtoController { - private LogManager logManager = LogManager.Default; + ///// <summary> + ///// Expects a DB synchronization request from a remote machine and returns the synchronized version of the machine database. + ///// </summary> + ///// <param name="request">The request.</param> + ///// <returns></returns> + //[HttpPost] + //public SynchronizeDBResponse Synchronize(SynchronizeDBRequest request) + //{ + // var tempFolder = TemporaryManager.Default.CreateFolder(); - /// <summary> - /// Expects a DB synchronization request from a remote machine and returns the synchronized version of the machine database. - /// </summary> - /// <param name="request">The request.</param> - /// <returns></returns> - [HttpPost] - public SynchronizeDBResponse Synchronize(SynchronizeDBRequest request) - { - var tempFolder = TemporaryManager.Default.CreateFolder(); + // try + // { + // //File path for the reflected remote data base SQLite. + // String masterSQLiteFile = Path.Combine(tempFolder, "Remote.db"); + // //File path for the received machine SQLite db. + // String slaveSQLiteFile = Path.Combine(tempFolder, "Local.db"); - try - { - //File path for the reflected remote data base SQLite. - String masterSQLiteFile = Path.Combine(tempFolder, "Remote.db"); - //File path for the received machine SQLite db. - String slaveSQLiteFile = Path.Combine(tempFolder, "Local.db"); + // //Save the machine db to file. + // File.WriteAllBytes(slaveSQLiteFile, request.LocalDB.ToByteArray()); - //Save the machine db to file. - File.WriteAllBytes(slaveSQLiteFile, request.LocalDB.ToByteArray()); + // //Copy an SQLite db template. + // File.Copy(HostingEnvironment.MapPath(@"~/App_Data/Tango.db"), masterSQLiteFile); - //Copy an SQLite db template. - File.Copy(HostingEnvironment.MapPath(@"~/App_Data/Tango.db"), masterSQLiteFile); + // //Synchronize the SQL Server db with the new SQLite template. (Overwrite basically) + // RemoteDBSynchronizer.Synchronize(masterSQLiteFile, request.SerialNumber, true); - //Synchronize the SQL Server db with the new SQLite template. (Overwrite basically) - RemoteDBSynchronizer.Synchronize(masterSQLiteFile, request.SerialNumber, true); + // //Synchronize the received machine db with the filled template. + // LocalDBSynchronizer.Synchronize(masterSQLiteFile, slaveSQLiteFile); - //Synchronize the received machine db with the filled template. - LocalDBSynchronizer.Synchronize(masterSQLiteFile, slaveSQLiteFile); + // //Send the synchronized machine db to the machine to the machine. + // SynchronizeDBResponse response = new SynchronizeDBResponse(); + // response.RemoteDB = ByteString.CopyFrom(File.ReadAllBytes(slaveSQLiteFile)); - //Send the synchronized machine db to the machine to the machine. - SynchronizeDBResponse response = new SynchronizeDBResponse(); - response.RemoteDB = ByteString.CopyFrom(File.ReadAllBytes(slaveSQLiteFile)); - - return response; - } - catch (Exception) - { - throw; - } - finally - { - //Remove all temporary files and folder. - tempFolder.Delete(); - } - } + // return response; + // } + // catch (Exception) + // { + // throw; + // } + // finally + // { + // //Remove all temporary files and folder. + // tempFolder.Delete(); + // } + //} [HttpPost] public MachineSetupResponse MachineSetup(MachineSetupRequest request) { MachineSetupResponse response = new MachineSetupResponse(); - logManager.Log("Setup request received: " + request.ToString()); + LogManager.Log("Setup request received: " + request.ToString()); - try + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - 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) { - db.Configuration.LazyLoadingEnabled = false; - String serial_number = request.SerialNumber; + throw new AuthenticationException("The specified serial number could not be found."); + } - var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); + var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); - if (machine == null) - { - ThrowError(HttpStatusCode.NotFound, "The specified serial number could not be found."); - } + var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); - var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); + response.Version = latest_machine_version.Version; - var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + var client = StorageHelper.GetStorageBlobClient(); + var container = StorageHelper.GetTangoVersionsContainer(client); + var blob = container.GetBlockBlobReference(latest_machine_version.BlobName); - response.Version = latest_machine_version.Version; + response.BlobAddress = StorageHelper.GenerateBlobReadSignature(blob, TimeSpan.FromMinutes(60)); - response.FtpAddress = GetFtpAddress(); - response.FtpFilePath = latest_machine_version.FtpFilePath; - response.FtpUserName = GetFtpUserName(); - response.FtpPassword = GetFtpPassword(); + DbCredentials credentials = new DbCredentials(); - DbCredentials credentials = new DbCredentials(); + using (SmoManager manager = new SmoManager()) + { + credentials = manager.CreateRandomLoginAndUser(); - using (DbManager manager = DbManager.FromAddressAndName(GetDbAddress(), "Tango")) + Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => { - credentials = manager.CreateRandomLoginAndUser("Tango"); - - Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => + using (SmoManager m = new SmoManager()) { - using (DbManager m = DbManager.FromAddressAndName(GetDbAddress(), "Tango")) - { - m.DeleteLoginAndUser(credentials.UserName, "Tango"); - } - }); - } - - response.DbAddress = GetDbAddress(); - response.DbUserName = credentials.UserName; - response.DbPassword = credentials.Password; + m.DeleteLoginAndUser(credentials.UserName); + } + }); } - } - catch (Exception ex) - { - logManager.Log(ex); - throw; + + response.DbAddress = Config.DB_ADDRESS; + response.DbUserName = credentials.UserName; + response.DbPassword = credentials.Password; } return response; @@ -141,54 +138,48 @@ namespace Tango.MachineService.Controllers { DownloadUpdateResponse response = new DownloadUpdateResponse(); - try + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - 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) { - db.Configuration.LazyLoadingEnabled = false; - String serial_number = request.SerialNumber; + throw new AuthenticationException("The specified serial number could not be found."); + } - var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); + var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); - if (machine == null) - { - OnError(HttpStatusCode.NotFound, "The specified serial number could not be found."); - } + var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); - var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); + response.Version = latest_machine_version.Version; - var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + var client = StorageHelper.GetStorageBlobClient(); + var container = StorageHelper.GetTangoVersionsContainer(client); + var blob = container.GetBlockBlobReference(latest_machine_version.BlobName); - response.Version = latest_machine_version.Version; + response.BlobAddress = StorageHelper.GenerateBlobReadSignature(blob, TimeSpan.FromMinutes(60)); - response.FtpAddress = GetFtpAddress(); - response.FtpFilePath = latest_machine_version.FtpFilePath; - response.FtpUserName = GetFtpUserName(); - response.FtpPassword = GetFtpPassword(); + DbCredentials credentials = new DbCredentials(); - DbCredentials credentials = new DbCredentials(); + using (SmoManager manager = new SmoManager()) + { + credentials = manager.CreateRandomLoginAndUser(); - using (DbManager manager = DbManager.FromAddressAndName(GetDbAddress(), "Tango")) + Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => { - credentials = manager.CreateRandomLoginAndUser("Tango"); - - Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => + using (SmoManager m = new SmoManager()) { - using (DbManager m = DbManager.FromAddressAndName(GetDbAddress(), "Tango")) - { - m.DeleteLoginAndUser(credentials.UserName, "Tango"); - } - }); - } - - response.DbAddress = GetDbAddress(); - response.DbUserName = credentials.UserName; - response.DbPassword = credentials.Password; + m.DeleteLoginAndUser(credentials.UserName); + } + }); } - } - catch (Exception ex) - { - OnError(HttpStatusCode.InternalServerError, ex.Message); + + response.DbAddress = Config.DB_ADDRESS; + response.DbUserName = credentials.UserName; + response.DbPassword = credentials.Password; } return response; @@ -199,34 +190,27 @@ namespace Tango.MachineService.Controllers { CheckForUpdateResponse response = new CheckForUpdateResponse(); - try + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - using (ObservablesContext db = ObservablesContext.CreateDefault(GetLocalServerAddress())) - { - db.Configuration.LazyLoadingEnabled = false; + db.Configuration.LazyLoadingEnabled = false; - var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == request.SerialNumber); - - if (machine == null) - { - OnError(HttpStatusCode.NotFound, "The specified serial number could not be found."); - } + var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == request.SerialNumber); - var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); + if (machine == null) + { + throw new AuthenticationException("The specified serial number could not be found."); + } - var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); - if (Version.Parse(latest_machine_version.Version) > Version.Parse(request.Version)) - { - response.IsUpdateAvailable = true; - } + 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; + if (Version.Parse(latest_machine_version.Version) > Version.Parse(request.Version)) + { + response.IsUpdateAvailable = true; } - } - catch (Exception ex) - { - OnError(HttpStatusCode.InternalServerError, ex.Message); + + response.Version = latest_machine_version.Version; } return response; @@ -237,43 +221,36 @@ namespace Tango.MachineService.Controllers { UpdateDBResponse response = new UpdateDBResponse(); - try + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - using (ObservablesContext db = ObservablesContext.CreateDefault(GetLocalServerAddress())) - { - db.Configuration.LazyLoadingEnabled = false; - String serial_number = request.SerialNumber; + db.Configuration.LazyLoadingEnabled = false; + String serial_number = request.SerialNumber; - var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); + var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); - if (machine == null) - { - OnError(HttpStatusCode.NotFound, "The specified serial number could not be found."); - } + if (machine == null) + { + throw new AuthenticationException("The specified serial number could not be found."); + } - DbCredentials credentials = new DbCredentials(); + DbCredentials credentials = new DbCredentials(); - using (DbManager manager = DbManager.FromAddressAndName(GetDbAddress(), "Tango")) - { - credentials = manager.CreateRandomLoginAndUser("Tango"); + using (SmoManager manager = new SmoManager()) + { + credentials = manager.CreateRandomLoginAndUser(); - Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => + Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => + { + using (SmoManager m = new SmoManager()) { - using (DbManager m = DbManager.FromAddressAndName(GetDbAddress(), "Tango")) - { - m.DeleteLoginAndUser(credentials.UserName, "Tango"); - } - }); - } - - response.DbAddress = GetDbAddress(); - response.DbUserName = credentials.UserName; - response.DbPassword = credentials.Password; + m.DeleteLoginAndUser(credentials.UserName); + } + }); } - } - catch (Exception ex) - { - OnError(HttpStatusCode.InternalServerError, ex.Message); + + response.DbAddress = Config.DB_ADDRESS; + response.DbUserName = credentials.UserName; + response.DbPassword = credentials.Password; } return response; @@ -282,7 +259,7 @@ namespace Tango.MachineService.Controllers [HttpPost] public Machine PersonTest(Person p) { - using (var db = ObservablesContext.CreateDefault(GetLocalServerAddress())) + using (var db = ObservablesContextHelper.CreateContext()) { var machine = new MachineBuilder(db) .Set(x => x.SerialNumber == "1111") @@ -292,44 +269,5 @@ namespace Tango.MachineService.Controllers return machine; } } - - #region Helpers - - private void ThrowError(HttpStatusCode code, String message) - { - throw new WebApiException(code, message); - } - - private void OnError(HttpStatusCode code, String message) - { - throw new HttpResponseException(Request.CreateErrorResponse(code, message)); - } - - private String GetLocalServerAddress() - { - return ConfigurationManager.AppSettings["LocalServerAddress"].ToString(); - } - - private String GetDbAddress() - { - return ConfigurationManager.AppSettings["DbAddress"].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/Controllers/VersionUpdateController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/VersionUpdateController.cs new file mode 100644 index 000000000..b68da06a7 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/VersionUpdateController.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Security.Authentication; +using System.Web.Http; +using Tango.BL; +using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.Logging; +using Tango.MachineService.Helpers; +using Tango.PPC.Common.Update; + +namespace Tango.MachineService.Controllers +{ + public class VersionUpdateController : JsonController + { + private class PendingUpload + { + public String Token { get; set; } + + public String Version { get; set; } + + public String UserGuid { get; set; } + + public String Comments { get; set; } + + public String MachineVersionGuid { get; set; } + + public String BlobName { get; set; } + } + + private static List<PendingUpload> _pendingUploads; + + static VersionUpdateController() + { + _pendingUploads = new List<PendingUpload>(); + } + + [HttpPost] + public LatestVersionResponse GetLatestVersion(LatestVersionRequest request) + { + LatestVersionResponse response = new LatestVersionResponse(); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + var versions = db.TangoVersions.Where(x => x.MachineVersionGuid == request.MachineVersionGuid).ToList(); + + if (versions.Count > 0) + { + response.Version = db.TangoVersions.Where(x => x.MachineVersionGuid == request.MachineVersionGuid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault().Version; + } + else + { + throw new ArgumentException("The specified machine version was not found!"); + } + } + + return response; + } + + [HttpPost] + public UploadVersionResponse UploadVersion(UploadVersionRequest request) + { + UploadVersionResponse response = new UploadVersionResponse(); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + //Load relations first... + db.Roles.ToList(); + db.Permissions.ToList(); + db.UsersRoles.ToList(); + db.RolesPermissions.ToList(); + + var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password); + + if (user != null && user.HasPermission(Permissions.PublishMachineStudioVersion)) + { + var versions = db.TangoVersions.ToList().Where(x => x.MachineVersionGuid == request.MachineVersionGuid).OrderByDescending(x => Version.Parse(x.Version)).ToList(); + + TangoVersion latestVersion = new TangoVersion(); + latestVersion.Version = "0.0.0.0"; + + if (versions.Count > 0) + { + latestVersion = versions.FirstOrDefault(); + } + + Version currentVersion = Version.Parse(request.Version); + + if (currentVersion > Version.Parse(latestVersion.Version)) + { + String newVersionFileName = "Tango Version" + " " + currentVersion.ToString() + ".zip"; + + var client = StorageHelper.GetStorageBlobClient(); + var container = StorageHelper.GetTangoVersionsContainer(client); + var blob = StorageHelper.CreateEmptyBlob(container, newVersionFileName); + + response.Token = Guid.NewGuid().ToString(); + response.BlobAddress = StorageHelper.GenerateBlobWriteSignature(blob, TimeSpan.FromMinutes(30)); + + _pendingUploads.Add(new PendingUpload() + { + UserGuid = user.Guid, + Comments = request.Comments, + Token = response.Token, + Version = request.Version, + BlobName = blob.Name, + MachineVersionGuid = request.MachineVersionGuid, + }); + } + else + { + throw new ArgumentException("New version must be greater than latest version."); + } + } + else + { + throw new AuthenticationException("Invalid user credentials."); + } + } + + return response; + } + + [HttpPost] + public UploadCompletedResponse NotifyUploadCompleted(UploadCompletedRequest request) + { + PendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.Token); + + if (upload != null) + { + _pendingUploads.RemoveAll(x => x.Token == upload.Token); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + db.TangoVersions.Add(new TangoVersion() + { + Comments = upload.Comments, + BlobName = upload.BlobName, + UserGuid = upload.UserGuid, + Version = upload.Version, + MachineVersionGuid = upload.MachineVersionGuid + }); + + db.SaveChanges(); + } + + return new UploadCompletedResponse(); + } + else + { + throw new AuthenticationException("Invalid upload token."); + } + } + } +} diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Global.asax.cs b/Software/Visual_Studio/Web/Tango.MachineService/Global.asax.cs index ffb8042e2..ef698bb25 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Global.asax.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Global.asax.cs @@ -29,7 +29,8 @@ namespace Tango.MachineService FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); - LogManager.Default.RegisterLogger(new FileLogger()); + //LogManager.Default.RegisterLogger(new FileLogger()); + LogManager.Default.RegisterLogger(new VSOutputLogger("MachineService")); //register your filter with Web API pipeline GlobalConfiguration.Configuration.Filters.Add(new LogExceptionFilterAttribute()); diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/ObservablesContextHelper.cs b/Software/Visual_Studio/Web/Tango.MachineService/Helpers/ObservablesContextHelper.cs new file mode 100644 index 000000000..fff0eebea --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Helpers/ObservablesContextHelper.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Web; +using Tango.BL; +using Tango.Core; + +namespace Tango.MachineService.Helpers +{ + public static class ObservablesContextHelper + { + public static ObservablesContext CreateContext() + { + return new ObservablesContext(new DataSource() + { + Address = Config.DB_ADDRESS, + Catalog = Config.DB_CATALOG, + IntegratedSecurity = false, + Type = DataSourceType.SQLServer, + UserName = Config.DB_USER_NAME, + Password = Config.DB_PASSWORD + }); + } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/StorageHelper.cs b/Software/Visual_Studio/Web/Tango.MachineService/Helpers/StorageHelper.cs new file mode 100644 index 000000000..04d5bbffe --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Helpers/StorageHelper.cs @@ -0,0 +1,62 @@ +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Blob; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.IO; +using System.Linq; +using System.Web; + +namespace Tango.MachineService.Helpers +{ + public static class StorageHelper + { + public static CloudBlobClient GetStorageBlobClient() + { + String storageAddress = ConfigurationManager.AppSettings["Storage"].ToString(); + CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageAddress); + return storageAccount.CreateCloudBlobClient(); + } + + public static CloudBlobContainer GetTangoVersionsContainer(CloudBlobClient client) + { + var container = client.GetContainerReference("tango-versions"); + return container; + } + + public static CloudBlockBlob CreateEmptyBlob(CloudBlobContainer container, String name) + { + CloudBlockBlob emptyBlob = container.GetBlockBlobReference(name); + using (MemoryStream ms = new MemoryStream()) + { + emptyBlob.UploadFromStream(ms);//Empty memory stream. Will create an empty blob. + } + + return emptyBlob; + } + + public static String GenerateBlobReadSignature(CloudBlockBlob blob, TimeSpan duration) + { + String signature = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy() + { + SharedAccessStartTime = DateTime.UtcNow, + SharedAccessExpiryTime = DateTime.UtcNow.Add(duration), + Permissions = SharedAccessBlobPermissions.Read + }); + + return new Uri(blob.Uri + signature).ToString(); + } + + public static String GenerateBlobWriteSignature(CloudBlockBlob blob, TimeSpan duration) + { + String signature = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy() + { + SharedAccessStartTime = DateTime.UtcNow, + SharedAccessExpiryTime = DateTime.UtcNow.Add(duration), + Permissions = SharedAccessBlobPermissions.Write + }); + + return new Uri(blob.Uri + signature).ToString(); + } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/JsonController.cs b/Software/Visual_Studio/Web/Tango.MachineService/JsonController.cs new file mode 100644 index 000000000..163a89589 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/JsonController.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Security.Authentication; +using System.Threading; +using System.Threading.Tasks; +using System.Web; +using System.Web.Http; +using System.Web.Http.Controllers; +using Tango.Logging; + +namespace Tango.MachineService +{ + public class JsonController : ApiController + { + protected LogManager LogManager { get; private set; } + + public JsonController() + { + LogManager = LogManager.Default; + } + + public override async Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext context, CancellationToken cancellationToken) + { + string controllerName = String.Empty; + string actionName = String.Empty; + + try + { + var routeData = HttpContext.Current.Request.RequestContext.RouteData; + actionName = routeData.Values["action"].ToString(); + controllerName = routeData.Values["controller"].ToString(); + } + catch { } + + try + { + String request = String.Empty; + + try + { + request = context.Request.Content.ReadAsStringAsync().Result; + } + catch {} + + LogManager.Log($"Request Received on {controllerName + "/" + actionName}: \n{request}"); + + var result = await base.ExecuteAsync(context, cancellationToken); + return result; + } + catch (Exception ex) + { + LogManager.Log(ex, $"An error occurred while processing the request message on {controllerName + "/" + actionName}."); + + HttpStatusCode code = HttpStatusCode.InternalServerError; + + if (ex is ArgumentException) + { + code = HttpStatusCode.BadRequest; + } + else if (ex is AuthenticationException) + { + code = HttpStatusCode.Unauthorized; + } + + throw new HttpResponseException(Request.CreateErrorResponse(code, ex.Message)); + } + } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/MachineService - Web Deploy.pubxml b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/MachineService - Web Deploy.pubxml new file mode 100644 index 000000000..277a89d38 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/MachineService - Web Deploy.pubxml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +This file is used by the publish/package process of your Web project. You can customize the behavior of this process +by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. +--> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <WebPublishMethod>MSDeploy</WebPublishMethod> + <ResourceId>/subscriptions/10c8aa60-3b15-4e0d-b412-6aeef90e5e91/resourceGroups/Tango/providers/Microsoft.Web/sites/MachineService</ResourceId> + <ResourceGroup>Tango</ResourceGroup> + <PublishProvider>AzureWebSite</PublishProvider> + <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration> + <LastUsedPlatform>Any CPU</LastUsedPlatform> + <SiteUrlToLaunchAfterPublish>http://machineservice.azurewebsites.net</SiteUrlToLaunchAfterPublish> + <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish> + <ExcludeApp_Data>False</ExcludeApp_Data> + <MSDeployServiceURL>machineservice.scm.azurewebsites.net:443</MSDeployServiceURL> + <DeployIisAppPath>MachineService</DeployIisAppPath> + <RemoteSitePhysicalPath /> + <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer> + <InstallAspNetCoreSiteExtension>False</InstallAspNetCoreSiteExtension> + <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod> + <EnableMSDeployBackup>True</EnableMSDeployBackup> + <UserName>$MachineService</UserName> + <_SavePWD>True</_SavePWD> + <_DestinationType>AzureWebSite</_DestinationType> + </PropertyGroup> +</Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs b/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs index ef233df7d..b82f1adef 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs @@ -123,7 +123,7 @@ namespace Tango.MachineService try { HttpProtoException msg = new HttpProtoException(); - msg.Message = httpError.ExceptionMessage; + msg.Message = httpError["Message"].ToString(); msg.StatusCode = (int)HttpStatusCode.InternalServerError; msg.WriteTo(stream); diff --git a/Software/Visual_Studio/Web/Tango.MachineService/ProtoController.cs b/Software/Visual_Studio/Web/Tango.MachineService/ProtoController.cs new file mode 100644 index 000000000..572604d3c --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/ProtoController.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Security.Authentication; +using System.Threading; +using System.Threading.Tasks; +using System.Web; +using System.Web.Http; +using System.Web.Http.Controllers; +using Tango.Logging; + +namespace Tango.MachineService +{ + public class ProtoController : ApiController + { + protected LogManager LogManager { get; private set; } + + public ProtoController() + { + LogManager = LogManager.Default; + } + + public override async Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext context, CancellationToken cancellationToken) + { + string controllerName = String.Empty; + string actionName = String.Empty; + + try + { + var routeData = HttpContext.Current.Request.RequestContext.RouteData; + actionName = routeData.Values["action"].ToString(); + controllerName = routeData.Values["controller"].ToString(); + } + catch { } + + try + { + LogManager.Log($"Request Received on {controllerName + "/" + actionName}."); + + var result = await base.ExecuteAsync(context, cancellationToken); + return result; + } + catch (Exception ex) + { + LogManager.Log(ex, $"An error occurred while processing the request message on {controllerName + "/" + actionName}."); + + HttpStatusCode code = HttpStatusCode.InternalServerError; + + if (ex is ArgumentException) + { + code = HttpStatusCode.BadRequest; + } + else if (ex is AuthenticationException) + { + code = HttpStatusCode.Unauthorized; + } + + throw new HttpResponseException(Request.CreateErrorResponse(code, ex.Message)); + } + } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/SMO/SmoManager.cs b/Software/Visual_Studio/Web/Tango.MachineService/SMO/SmoManager.cs new file mode 100644 index 000000000..d2ee0ed5f --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/SMO/SmoManager.cs @@ -0,0 +1,73 @@ +using Microsoft.SqlServer.Management.Common; +using Microsoft.SqlServer.Management.Smo; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using Tango.Core.DB; + +namespace Tango.MachineService.SMO +{ + public class SmoManager : IDisposable + { + private ServerConnection _connection; + private Server _server; + private static Random random = new Random(); + + public SmoManager() + { + _connection = new ServerConnection(Config.DB_ADDRESS, Config.DB_USER_NAME, Config.DB_PASSWORD); + _server = new Server(_connection); + } + + public DbCredentials CreateRandomLoginAndUser() + { + var database = _server.Databases.OfType<Database>().SingleOrDefault(x => x.Name == Config.DB_CATALOG); + + String userName = GetRandomString(36); + String password = System.Web.Security.Membership.GeneratePassword(16, 2); + + Login login = new Login(_server, userName); + login.LoginType = LoginType.SqlLogin; + login.DefaultDatabase = Config.DB_CATALOG; + login.PasswordPolicyEnforced = false; + login.Create(password); + + User user = new User(database, userName); + user.Login = userName; + user.Create(); + user.AddToRole("db_datareader"); + + return new DbCredentials() { UserName = userName, Password = password }; + } + + public void DeleteLoginAndUser(String userName) + { + var database = _server.Databases.OfType<Database>().SingleOrDefault(x => x.Name == Config.DB_CATALOG); + + var user = database.Users.OfType<User>().SingleOrDefault(x => x.Name == userName); + + if (user != null) + { + user.Drop(); + } + + Login login = _server.Logins.OfType<Login>().SingleOrDefault(x => x.Name == userName); + if (login != null) + { + login.Drop(); + } + } + + public string GetRandomString(int length) + { + const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + return "TEMP_" + new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()); + } + + public void Dispose() + { + _connection.Disconnect(); + } + } +}
\ 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 f3b4a228e..9f0b2cba2 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -56,10 +56,105 @@ <Reference Include="Google.Protobuf, Version=3.4.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL"> <HintPath>..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll</HintPath> </Reference> + <Reference Include="Microsoft.Azure.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> + <Reference Include="Microsoft.Azure.Common.NetFramework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> + <Reference Include="Microsoft.Azure.Management.Sql, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> + <Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> <Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <HintPath>..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath> </Reference> <Reference Include="Microsoft.CSharp" /> + <Reference Include="Microsoft.SqlServer.AzureStorageEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.AzureStorageEnum.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.BatchParserClient, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.BatchParserClient.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.ConnectionInfo, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.ConnectionInfo.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.ConnectionInfoExtended, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.ConnectionInfoExtended.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Diagnostics.Strace, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Diagnostics.Strace.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Dmf, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Dmf.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Dmf.Common, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Dmf.Common.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Management.Collector, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.Collector.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Management.CollectorEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.CollectorEnum.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Management.RegisteredServers, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.RegisteredServers.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Management.Sdk.Sfc, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.Sdk.Sfc.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Management.SqlParser, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.SqlParser.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Management.Utility, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.Utility.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Management.UtilityEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.UtilityEnum.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Management.XEvent, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.XEvent.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Management.XEventDbScoped, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.XEventDbScoped.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Management.XEventDbScopedEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.XEventDbScopedEnum.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Management.XEventEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Management.XEventEnum.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.PolicyEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.PolicyEnum.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.RegSvrEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.RegSvrEnum.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.ServiceBrokerEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.ServiceBrokerEnum.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Smo, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Smo.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.SmoExtended, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.SmoExtended.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.SqlClrProvider, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.SqlClrProvider.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.SqlEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.SqlEnum.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.SqlTDiagm, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.SqlTDiagm.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.SqlWmiManagement, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.SqlWmiManagement.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.SString, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.SString.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.Types.dll</HintPath> + </Reference> + <Reference Include="Microsoft.SqlServer.WmiEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.WmiEnum.dll</HintPath> + </Reference> + <Reference Include="Microsoft.WindowsAzure.Storage, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> <Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <HintPath>..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> </Reference> @@ -79,6 +174,7 @@ <Private>True</Private> </Reference> <Reference Include="System.Drawing" /> + <Reference Include="System.Security" /> <Reference Include="System.Web.DynamicData" /> <Reference Include="System.Web.Entity" /> <Reference Include="System.Web.ApplicationServices" /> @@ -173,6 +269,11 @@ </Compile> <Compile Include="App_Start\BundleConfig.cs" /> <Compile Include="App_Start\FilterConfig.cs" /> + <Compile Include="Config.cs" /> + <Compile Include="Controllers\VersionUpdateController.cs" /> + <Compile Include="Helpers\ObservablesContextHelper.cs" /> + <Compile Include="Helpers\StorageHelper.cs" /> + <Compile Include="JsonController.cs" /> <Compile Include="JsonNetFormatter.cs" /> <Compile Include="ProtoBufFormatter.cs" /> <Compile Include="App_Start\RouteConfig.cs" /> @@ -185,6 +286,8 @@ </Compile> <Compile Include="Models\Person.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="ProtoController.cs" /> + <Compile Include="SMO\SmoManager.cs" /> <Compile Include="WebApiException.cs" /> </ItemGroup> <ItemGroup> @@ -204,6 +307,10 @@ <Content Include="packages.config" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\..\PPC\Tango.PPC.Common\Tango.PPC.Common.csproj"> + <Project>{0be74eee-22cb-4dba-b896-793b9e1a3ac0}</Project> + <Name>Tango.PPC.Common</Name> + </ProjectReference> <ProjectReference Include="..\..\Tango.BL\Tango.BL.csproj"> <Project>{F441FEEE-322A-4943-B566-110E12FD3B72}</Project> <Name>Tango.BL</Name> @@ -229,6 +336,7 @@ <Folder Include="App_Data\" /> </ItemGroup> <ItemGroup> + <None Include="Properties\PublishProfiles\MachineService - Web Deploy.pubxml" /> <None Include="Properties\PublishProfiles\Publish Machine Service via FTP.pubxml" /> </ItemGroup> <PropertyGroup> @@ -267,11 +375,13 @@ <Error Condition="!Exists('..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" /> <Error Condition="!Exists('..\..\packages\Microsoft.Net.Compilers.2.4.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.2.4.0\build\Microsoft.Net.Compilers.props'))" /> <Error Condition="!Exists('..\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets'))" /> + <Error Condition="!Exists('..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\build\net40\Microsoft.SqlServer.SqlManagementObjects.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\build\net40\Microsoft.SqlServer.SqlManagementObjects.targets'))" /> </Target> <PropertyGroup> <PreBuildEvent>copy /Y "$(SolutionDir)..\DB\Tango.db" "$(ProjectDir)App_Data\Tango.db"</PreBuildEvent> </PropertyGroup> <Import Project="..\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" /> + <Import Project="..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\build\net40\Microsoft.SqlServer.SqlManagementObjects.targets" Condition="Exists('..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\build\net40\Microsoft.SqlServer.SqlManagementObjects.targets')" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index 281fdadeb..3590b89d8 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -1,4 +1,4 @@ -<?xml version="1.0"?> +<?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET application, please visit https://go.microsoft.com/fwlink/?LinkId=301879 @@ -6,18 +6,22 @@ <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/> + <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <appSettings> - <add key="webpages:Version" value="3.0.0.0"/> - <add key="webpages:Enabled" value="false"/> - <add key="ClientValidationEnabled" value="true"/> - <add key="UnobtrusiveJavaScriptEnabled" value="true"/> - <add key="LocalServerAddress" value="twine01\SQLTWINE_TEST"/> - <add key="FtpAddress" value="Twine01"/> - <add key="FtpUserName" value="Tango|FTPReader"/> - <add key="FtpPassword" value="Aa123456"/> - <add key="DbAddress" value="twine01\SQLTWINE_TEST"/> + <add key="webpages:Version" value="3.0.0.0" /> + <add key="webpages:Enabled" value="false" /> + <add key="ClientValidationEnabled" value="true" /> + <add key="UnobtrusiveJavaScriptEnabled" value="true" /> + <add key="LocalServerAddress" value="twine01\SQLTWINE_TEST" /> + <add key="FtpAddress" value="Twine01" /> + <add key="FtpUserName" value="Tango|FTPReader" /> + <add key="FtpPassword" value="Aa123456" /> + <add key="DbAddress" value="twine.database.windows.net" /> + <add key="DbUserName" value="Roy" /> + <add key="DbPassword" value="Aa123456" /> + <add key="DbCatalog" value="Tango" /> + <add key="Storage" value="DefaultEndpointsProtocol=https;AccountName=tangostorage;AccountKey=S4z/D+Yg6mwMis+bs/VpcDLA9yE1iZaYq23shQlRIi2KmM9E7JY8zdZjeAPOPdG3gONHoNDEpsgH6D4cqQ/bsA==;EndpointSuffix=core.windows.net" /> </appSettings> <!-- For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367. @@ -28,76 +32,120 @@ </system.Web> --> <system.web> - <compilation debug="true" targetFramework="4.7.2"/> - <httpRuntime targetFramework="4.5"/> + <compilation debug="true" targetFramework="4.7.2" /> + <httpRuntime targetFramework="4.5" /> <httpModules> - <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/> + <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /> </httpModules> </system.web> <system.webServer> <handlers> - <remove name="ExtensionlessUrlHandler-Integrated-4.0"/> - <remove name="OPTIONSVerbHandler"/> - <remove name="TRACEVerbHandler"/> - <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/> + <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> + <remove name="OPTIONSVerbHandler" /> + <remove name="TRACEVerbHandler" /> + <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> - <validation validateIntegratedModeConfiguration="false"/> + <validation validateIntegratedModeConfiguration="false" /> <modules> - <remove name="ApplicationInsightsWebTracking"/> - <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler"/> + <remove name="ApplicationInsightsWebTracking" /> + <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /> </modules> </system.webServer> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> - <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/> - <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/> + <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /> + <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" /> </dependentAssembly> <dependentAssembly> - <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/> - <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/> + <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> + <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> </dependentAssembly> <dependentAssembly> - <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/> - <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/> + <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> + <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> </dependentAssembly> <dependentAssembly> - <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/> - <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/> + <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> + <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> - <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/> - <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/> + <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> + <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> - <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/> - <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/> + <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> + <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> </dependentAssembly> <dependentAssembly> - <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral"/> - <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0"/> + <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Reactive.Core" publicKeyToken="94bc3704cddfc263" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-1.2.2.0" newVersion="1.2.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-1.4.2.0" newVersion="1.4.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Console" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> </dependentAssembly> </assemblyBinding> </runtime> <system.codedom> <compilers> - <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/> - <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/> + <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /> + <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" /> </compilers> </system.codedom> <entityFramework> - <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/> + <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> <providers> - <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/> - <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/> + <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> + <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /> </providers> </entityFramework> <system.data> <DbProviderFactories> - <remove invariant="System.Data.SQLite.EF6"/> - <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6"/> - <remove invariant="System.Data.SQLite"/> - <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/> + <remove invariant="System.Data.SQLite.EF6" /> + <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" /> + <remove invariant="System.Data.SQLite" /> + <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /> </DbProviderFactories> </system.data> </configuration>
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/packages.config b/Software/Visual_Studio/Web/Tango.MachineService/packages.config index a9c0d3f6c..ede4fa80d 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/packages.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/packages.config @@ -21,6 +21,7 @@ <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" /> <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.3" targetFramework="net45" /> <package id="Microsoft.Net.Compilers" version="2.4.0" targetFramework="net46" developmentDependency="true" /> + <package id="Microsoft.SqlServer.SqlManagementObjects" version="140.17283.0" targetFramework="net461" /> <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" /> <package id="Modernizr" version="2.6.2" targetFramework="net45" /> <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net46" /> |
