diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2019-01-02 08:47:29 +0200 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2019-01-02 08:47:29 +0200 |
| commit | 520e878bf98efcec9c75abcfe483175ff72620a2 (patch) | |
| tree | 62a7221e3c22187821f6a5e399eca0f7bd31168a /Software/Visual_Studio/Web/Tango.MachineService | |
| parent | 30574fe4a6e1bb4f60a43e9000acaf919811689a (diff) | |
| parent | 25f5e6ddef7ef2fa0a747305847eeb4ceee5a2c9 (diff) | |
| download | Tango-520e878bf98efcec9c75abcfe483175ff72620a2.tar.gz Tango-520e878bf98efcec9c75abcfe483175ff72620a2.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService')
26 files changed, 873 insertions, 1116 deletions
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 3129482cb..0a63e9acb 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Web.Http; +using Tango.Web.Formatters; namespace Tango.MachineService { diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Config.cs b/Software/Visual_Studio/Web/Tango.MachineService/Config.cs deleted file mode 100644 index b1d2dafca..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Config.cs +++ /dev/null @@ -1,16 +0,0 @@ -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/HomeController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/HomeController.cs deleted file mode 100644 index a7c526f67..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/HomeController.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; - -namespace Tango.MachineService.Controllers -{ - public class HomeController : Controller - { - public String Index() - { - return "Machine Service Started!"; - } - } -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs new file mode 100644 index 000000000..c9d7ea8b6 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -0,0 +1,274 @@ +using Microsoft.IdentityModel.Clients.ActiveDirectory; +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.Builders; +using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.Core.Cryptography; +using Tango.MachineService.Models; +using Tango.MachineStudio.Common.Authentication; +using System.Data.Entity; +using Tango.MachineStudio.Common.Update; +using Tango.Web.Controllers; +using Tango.Web.Helpers; +using Tango.Web.Storage; +using Tango.Web.Authentication; +using Tango.Web.ActiveDirectory; + +namespace Tango.MachineService.Controllers +{ + public class MachineStudioController : JsonController + { + private static TokensManager _tokens_manager; + private static List<MachineStudioPendingUpload> _pendingUploads; + private ActiveDirectoryManager _ad_manager; + + static MachineStudioController() + { + _tokens_manager = new TokensManager(); + _pendingUploads = new List<MachineStudioPendingUpload>(); + } + + public MachineStudioController() : base() + { + _ad_manager = new ActiveDirectoryManager(); + } + + #region Update + + [HttpPost] + public CheckForUpdatesResponse CheckForUpdates(CheckForUpdatesRequest request) + { + LogManager.Log("Request received..."); + + CheckForUpdatesResponse response = new CheckForUpdatesResponse(); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + if (_tokens_manager.Exists(request.AccessToken)) + { + var versions = db.MachineStudioVersions.ToList(); + + MachineStudioVersion latestVersion = null; + + if (request.AcceptBetaRelease) + { + latestVersion = versions.OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + } + else + { + latestVersion = versions.Where(x => x.Stable).OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + } + + Version currentVersion = Version.Parse(request.Version); + + String comments = String.Join(Environment.NewLine, versions.OrderBy(x => Version.Parse(x.Version)).Where(x => Version.Parse(x.Version) > currentVersion).Select(x => x.Comments)); + + if (latestVersion != null && Version.Parse(latestVersion.Version) > currentVersion) + { + var manager = new StorageManager(); + var container = manager.GetContainer(MachineServiceConfig.MACHINE_STUDIO_VERSIONS_CONTAINER); + var blob = container.GetBlockBlobReference(latestVersion.BlobName); + + response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); + + response.IsUpdateAvailable = true; + response.Version = latestVersion.Version; + response.Comments = latestVersion.Comments; + response.IsStable = latestVersion.Stable; + } + } + else + { + throw new AuthenticationException("Invalid token."); + } + } + + return response; + } + + [HttpPost] + public UploadVersionResponse UploadVersion(UploadVersionRequest request) + { + UploadVersionResponse response = new UploadVersionResponse(); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + //Load relation 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.PublishMachineStudioVersions)) + { + var latestVersion = db.MachineStudioVersions.ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + Version currentVersion = Version.Parse(request.Version); + + if (latestVersion == null || currentVersion > Version.Parse(latestVersion.Version)) + { + String newVersionFileName = "Machine Studio Version" + " " + currentVersion.ToString() + ".zip"; + + var manager = new StorageManager(); + var container = manager.GetContainer(MachineServiceConfig.MACHINE_STUDIO_VERSIONS_CONTAINER); + var blob = container.CreateEmptyBlob(newVersionFileName); + + response.Token = Guid.NewGuid().ToString(); + response.BlobAddress = blob.GenerateWriteSignature(TimeSpan.FromMinutes(30)); + + _pendingUploads.Add(new MachineStudioPendingUpload() + { + UserGuid = user.Guid, + Comments = request.Comments, + ForcedUpdate = request.ForcedUpdate, + Token = response.Token, + Version = request.Version, + IsStable = request.IsStable, + BlobName = blob.Name, + }); + } + 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) + { + MachineStudioPendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.AccessToken); + + if (upload != null) + { + _pendingUploads.RemoveAll(x => x.Token == upload.Token); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + db.MachineStudioVersions.Add(new MachineStudioVersion() + { + Comments = upload.Comments, + BlobName = upload.BlobName, + UserGuid = upload.UserGuid, + Version = upload.Version, + ForceUpdate = upload.ForcedUpdate, + Stable = upload.IsStable, + }); + + db.SaveChanges(); + } + + return new UploadCompletedResponse(); + } + else + { + throw new ArgumentException("Invalid Token."); + } + } + + [HttpPost] + public LatestVersionResponse GetLatestVersion(LatestVersionRequest request) + { + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + var version = db.MachineStudioVersions.ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + return new LatestVersionResponse() { Version = version != null ? version.Version : "0.0.0.0" }; + } + } + + #endregion + + [HttpPost] + public LoginResponse Login(LoginRequest request) + { + var authResult =_ad_manager.ValidateUserCredentials(request.Email, request.Password); + + if (!_ad_manager.CanUserAccessCurrentEnvironment(request.Email)) + { + throw new AuthenticationException($"You do not have permissions to access the {MachineServiceConfig.DEPLOYMENT_SLOT.ToDescription()} environment."); + } + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + db.Roles.ToList(); + db.Permissions.ToList(); + db.UsersRoles.ToList(); + db.RolesPermissions.ToList(); + + var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower()); + + IHashGenerator g = new BasicHashGenerator(); + + if (user == null) + { + //Than add the user !! + User new_user = new User(); + new_user.Email = request.Email; + new_user.Password = g.Encrypt(request.Password); + new_user.Organization = db.Organizations.Include(x => x.Address).Single(x => x.Name == "Twine"); + new_user.Address = new_user.Organization.Address.Clone(); + new_user.Contact = new Contact() + { + FirstName = authResult.UserInfo.GivenName, + LastName = authResult.UserInfo.FamilyName, + FullName = authResult.UserInfo.GivenName + " " + authResult.UserInfo.FamilyName, + Email = request.Email, + }; + + db.UsersRoles.Add(new UsersRole() + { + User = new_user, + Role = db.Roles.Single(x => (Roles)x.Code == Roles.User), + }); + + db.UsersRoles.Add(new UsersRole() + { + User = new_user, + Role = db.Roles.Single(x => (Roles)x.Code == Roles.MachineStudioUser), + }); + + new_user.LastLogin = DateTime.UtcNow; + db.Users.Add(new_user); + } + else + { + user.LastLogin = DateTime.UtcNow; + user.Password = g.Encrypt(request.Password); + } + + db.SaveChanges(); + } + + return new LoginResponse() + { + DataSource = new Core.DataSource() + { + Address = MachineServiceConfig.DB_ADDRESS, + Catalog = MachineServiceConfig.DB_CATALOG, + Type = Core.DataSourceType.Azure, + IntegratedSecurity = false, + UserName = request.Email, + Password = request.Password, + }, + + Token = _tokens_manager.CreateNew() + }; + } + + } +} diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs new file mode 100644 index 000000000..6d591edd8 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -0,0 +1,414 @@ +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; +using System.Configuration; +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; +using Tango.BL; +using Tango.BL.Builders; +using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.Core; +using Tango.Core.DB; +using Tango.Core.Helpers; +using Tango.Core.IO; +using Tango.Logging; +using Tango.MachineService.Models; +using Tango.PMR.Stubs; +using Tango.PMR.Synchronization; +using Tango.PPC.Common.MachineSetup; +using Tango.PPC.Common.MachineUpdate; +using Tango.PPC.Common.Update; +using Tango.Synchronization.Local; +using Tango.Synchronization.Remote; +using Tango.Web.Controllers; +using Tango.Web.Helpers; +using Tango.Web.SMO; +using Tango.Web.Storage; + +namespace Tango.MachineService.Controllers +{ + public class PPCController : JsonController + { + private static List<PPCPendingUpload> _pendingUploads; + + #region Constructors + + static PPCController() + { + _pendingUploads = new List<PPCPendingUpload>(); + } + + #endregion + + #region Setup & Update + + [HttpPost] + public MachineSetupResponse MachineSetup(MachineSetupRequest request) + { + MachineSetupResponse response = new MachineSetupResponse(); + + LogManager.Log("Setup request received: " + request.ToString()); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + db.Configuration.LazyLoadingEnabled = false; + String serial_number = request.SerialNumber; + + var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); + + if (machine == null) + { + throw new AuthenticationException("The specified serial number could not be found."); + } + + if (machine.SetupActivation && machine.OsKey == null) + { + throw new InvalidDataException("The specified machine is configured to perform an OS activation but is not associated with an OS activation key."); + } + + var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); + + 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; + + var manager = new StorageManager(); + var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER); + var blob = container.GetBlockBlobReference(latest_machine_version.BlobName); + + response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); + + DbCredentials credentials = new DbCredentials(); + + using (SmoManager smo = new SmoManager()) + { + credentials = smo.CreateRandomLoginAndUser(); + + Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => + { + using (SmoManager m = new SmoManager()) + { + m.DeleteLoginAndUser(credentials.UserName); + } + }); + } + + response.DataSource = new DataSource() + { + Address = MachineServiceConfig.DB_ADDRESS, + Catalog = MachineServiceConfig.DB_CATALOG, + UserName = credentials.UserName, + Password = credentials.Password, + IntegratedSecurity = false, + Type = DataSourceType.SQLServer, + }; + + response.OSKey = machine.OsKey; + response.SetupActivation = machine.SetupActivation; + response.SetupRemoteAssistance = machine.SetupRemoteAssistance; + response.SetupUWF = machine.SetupUwf; + response.SetupFirmware = machine.SetupFirmware; + response.IsDemo = machine.IsDemo; + + } + + return response; + } + + [HttpPost] + public DownloadUpdateResponse MachineUpdate(DownloadUpdateRequest request) + { + DownloadUpdateResponse response = new DownloadUpdateResponse(); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + db.Configuration.LazyLoadingEnabled = false; + String serial_number = request.SerialNumber; + + var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); + + if (machine == null) + { + throw new AuthenticationException("The specified serial number could not be found."); + } + + var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); + + 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; + + var manager = new StorageManager(); + var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER); + var blob = container.GetBlockBlobReference(latest_machine_version.BlobName); + + response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); + + DbCredentials credentials = new DbCredentials(); + + using (SmoManager smo = new SmoManager()) + { + credentials = smo.CreateRandomLoginAndUser(); + + Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => + { + using (SmoManager m = new SmoManager()) + { + m.DeleteLoginAndUser(credentials.UserName); + } + }); + } + + response.DataSource = new DataSource() + { + Address = MachineServiceConfig.DB_ADDRESS, + Catalog = MachineServiceConfig.DB_CATALOG, + UserName = credentials.UserName, + Password = credentials.Password, + IntegratedSecurity = false, + Type = DataSourceType.SQLServer, + }; + } + + return response; + } + + [HttpPost] + public CheckForUpdateResponse CheckForUpdate(CheckForUpdateRequest request) + { + CheckForUpdateResponse response = new CheckForUpdateResponse(); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + db.Configuration.LazyLoadingEnabled = false; + + var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == request.SerialNumber); + + if (machine == null) + { + throw new AuthenticationException("The specified serial number could not be found."); + } + + var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); + + var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + + if (Version.Parse(latest_machine_version.Version) > Version.Parse(request.Version)) + { + response.IsUpdateAvailable = true; + } + + response.Version = latest_machine_version.Version; + } + + return response; + } + + [HttpPost] + public UpdateDBResponse UpdateDB(UpdateDBRequest request) + { + UpdateDBResponse response = new UpdateDBResponse(); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + db.Configuration.LazyLoadingEnabled = false; + String serial_number = request.SerialNumber; + + var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); + + if (machine == null) + { + throw new AuthenticationException("The specified serial number could not be found."); + } + + DbCredentials credentials = new DbCredentials(); + + using (SmoManager manager = new SmoManager()) + { + credentials = manager.CreateRandomLoginAndUser(); + + Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => + { + using (SmoManager m = new SmoManager()) + { + m.DeleteLoginAndUser(credentials.UserName); + } + }); + } + + response.DataSource = new DataSource() + { + Address = MachineServiceConfig.DB_ADDRESS, + Catalog = MachineServiceConfig.DB_CATALOG, + UserName = credentials.UserName, + Password = credentials.Password, + IntegratedSecurity = false, + Type = DataSourceType.SQLServer, + }; + } + + return response; + } + + #endregion + + #region Version Upload + + [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) + { + return new LatestVersionResponse() + { + Version = "0.0.0.0", + }; + } + + response.Version = versions.OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault().Version; + } + + 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.PublishPPCVersions)) + { + 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 manager = new StorageManager(); + var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER); + var blob = container.CreateEmptyBlob(newVersionFileName); + + response.Token = Guid.NewGuid().ToString(); + response.BlobAddress = blob.GenerateWriteSignature(TimeSpan.FromMinutes(30)); + + _pendingUploads.Add(new PPCPendingUpload() + { + 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) + { + PPCPendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.AccessToken); + + 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."); + } + } + + [HttpPost] + public MachineVersionsResponse GetMachineVersions(MachineVersionsRequest request) + { + using (var db = ObservablesContextHelper.CreateContext()) + { + return new MachineVersionsResponse() + { + MachineVersions = db.MachineVersions.ToList(), + }; + } + } + + #endregion + + [HttpPost] + public Machine PersonTest(Person p) + { + using (var db = ObservablesContextHelper.CreateContext()) + { + var machine = new MachineBuilder(db) + .Set(x => x.SerialNumber == "1111") + .WithOrganization() + .WithConfiguration().Build(); + + return machine; + } + } + } +} diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs deleted file mode 100644 index 304ea34f2..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/SynchronizationController.cs +++ /dev/null @@ -1,273 +0,0 @@ -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; -using System.Configuration; -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; -using Tango.BL; -using Tango.BL.Builders; -using Tango.BL.Entities; -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; -using Tango.Synchronization.Remote; - -namespace Tango.MachineService.Controllers -{ - public class SynchronizationController : ProtoController - { - ///// <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"); - - // //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); - - // //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); - - // //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(); - // } - //} - - [HttpPost] - public MachineSetupResponse MachineSetup(MachineSetupRequest request) - { - MachineSetupResponse response = new MachineSetupResponse(); - - LogManager.Log("Setup request received: " + request.ToString()); - - using (ObservablesContext db = ObservablesContextHelper.CreateContext()) - { - db.Configuration.LazyLoadingEnabled = false; - String serial_number = request.SerialNumber; - - var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); - - if (machine == null) - { - throw new AuthenticationException("The specified serial number could not be found."); - } - - var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); - - 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; - - var client = StorageHelper.GetStorageBlobClient(); - var container = StorageHelper.GetTangoVersionsContainer(client); - var blob = container.GetBlockBlobReference(latest_machine_version.BlobName); - - response.BlobAddress = StorageHelper.GenerateBlobReadSignature(blob, TimeSpan.FromMinutes(60)); - - DbCredentials credentials = new DbCredentials(); - - using (SmoManager manager = new SmoManager()) - { - credentials = manager.CreateRandomLoginAndUser(); - - Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => - { - using (SmoManager m = new SmoManager()) - { - m.DeleteLoginAndUser(credentials.UserName); - } - }); - } - - response.DbAddress = Config.DB_ADDRESS; - response.DbUserName = credentials.UserName; - response.DbPassword = credentials.Password; - } - - return response; - } - - [HttpPost] - public DownloadUpdateResponse MachineUpdate(DownloadUpdateRequest request) - { - DownloadUpdateResponse response = new DownloadUpdateResponse(); - - using (ObservablesContext db = ObservablesContextHelper.CreateContext()) - { - db.Configuration.LazyLoadingEnabled = false; - String serial_number = request.SerialNumber; - - var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); - - if (machine == null) - { - throw new AuthenticationException("The specified serial number could not be found."); - } - - var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); - - 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; - - var client = StorageHelper.GetStorageBlobClient(); - var container = StorageHelper.GetTangoVersionsContainer(client); - var blob = container.GetBlockBlobReference(latest_machine_version.BlobName); - - response.BlobAddress = StorageHelper.GenerateBlobReadSignature(blob, TimeSpan.FromMinutes(60)); - - DbCredentials credentials = new DbCredentials(); - - using (SmoManager manager = new SmoManager()) - { - credentials = manager.CreateRandomLoginAndUser(); - - Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => - { - using (SmoManager m = new SmoManager()) - { - m.DeleteLoginAndUser(credentials.UserName); - } - }); - } - - response.DbAddress = Config.DB_ADDRESS; - response.DbUserName = credentials.UserName; - response.DbPassword = credentials.Password; - } - - return response; - } - - [HttpPost] - public CheckForUpdateResponse CheckForUpdate(CheckForUpdateRequest request) - { - CheckForUpdateResponse response = new CheckForUpdateResponse(); - - using (ObservablesContext db = ObservablesContextHelper.CreateContext()) - { - db.Configuration.LazyLoadingEnabled = false; - - var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == request.SerialNumber); - - if (machine == null) - { - throw new AuthenticationException("The specified serial number could not be found."); - } - - var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid); - - var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); - - if (Version.Parse(latest_machine_version.Version) > Version.Parse(request.Version)) - { - response.IsUpdateAvailable = true; - } - - response.Version = latest_machine_version.Version; - } - - return response; - } - - [HttpPost] - public UpdateDBResponse UpdateDB(UpdateDBRequest request) - { - UpdateDBResponse response = new UpdateDBResponse(); - - using (ObservablesContext db = ObservablesContextHelper.CreateContext()) - { - db.Configuration.LazyLoadingEnabled = false; - String serial_number = request.SerialNumber; - - var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == serial_number); - - if (machine == null) - { - throw new AuthenticationException("The specified serial number could not be found."); - } - - DbCredentials credentials = new DbCredentials(); - - using (SmoManager manager = new SmoManager()) - { - credentials = manager.CreateRandomLoginAndUser(); - - Task.Delay(TimeSpan.FromMinutes(10)).ContinueWith((x) => - { - using (SmoManager m = new SmoManager()) - { - m.DeleteLoginAndUser(credentials.UserName); - } - }); - } - - response.DbAddress = Config.DB_ADDRESS; - response.DbUserName = credentials.UserName; - response.DbPassword = credentials.Password; - } - - return response; - } - - [HttpPost] - public Machine PersonTest(Person p) - { - using (var db = ObservablesContextHelper.CreateContext()) - { - var machine = new MachineBuilder(db) - .Set(x => x.SerialNumber == "1111") - .WithOrganization() - .WithConfiguration().Build(); - - return machine; - } - } - } -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/ValuesController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/ValuesController.cs deleted file mode 100644 index f76d66836..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/ValuesController.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Web.Http; -using Tango.MachineService.Models; - -namespace Tango.MachineService.Controllers -{ - public class ValuesController : ApiController - { - private static List<Person> persons = new List<Person>(); - - // GET api/values - public IEnumerable<Person> Get() - { - return persons; - } - - // GET api/values/5 - public Person Get(int id) - { - return persons[id]; - } - - // POST api/values - public Person Post([FromBody]Person person) - { - persons.Add(person); - return person; - } - - // PUT api/values/5 - public void Put(Person person) - { - - } - - // DELETE api/values/5 - public void Delete(int id) - { - } - } -} diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/VersionUpdateController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/VersionUpdateController.cs deleted file mode 100644 index 2ad8bd735..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/VersionUpdateController.cs +++ /dev/null @@ -1,168 +0,0 @@ -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.ToList(); - - if (versions.Count == 0) - { - return new LatestVersionResponse() - { - Version = "0.0.0.0", - }; - } - - var machine_versions = versions.Where(x => x.MachineVersionGuid == request.MachineVersionGuid).ToList(); - - if (machine_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 ef698bb25..ef41ef3e7 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Global.asax.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Global.asax.cs @@ -9,40 +9,17 @@ using System.Web.Mvc; using System.Web.Optimization; using System.Web.Routing; using Tango.Logging; +using Tango.Web; namespace Tango.MachineService { - public class WebApiApplication : System.Web.HttpApplication + public class WebApiApplication : TangoWebApplication { - //Create filter - public class LogExceptionFilterAttribute : ExceptionFilterAttribute - { - public override void OnException(HttpActionExecutedContext context) - { - ErrorLogService.LogError(context.Exception); - } - } - - protected void Application_Start() + protected override void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); - - //LogManager.Default.RegisterLogger(new FileLogger()); - LogManager.Default.RegisterLogger(new VSOutputLogger("MachineService")); - - //register your filter with Web API pipeline - GlobalConfiguration.Configuration.Filters.Add(new LogExceptionFilterAttribute()); - } - - //common service to be used for logging errors - public static class ErrorLogService - { - public static void LogError(Exception ex) - { - LogManager.Default.Log(ex, "Global Exception!"); - } } } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/ObservablesContextHelper.cs b/Software/Visual_Studio/Web/Tango.MachineService/Helpers/ObservablesContextHelper.cs deleted file mode 100644 index fff0eebea..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/ObservablesContextHelper.cs +++ /dev/null @@ -1,26 +0,0 @@ -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 deleted file mode 100644 index 04d5bbffe..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/StorageHelper.cs +++ /dev/null @@ -1,62 +0,0 @@ -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 deleted file mode 100644 index 163a89589..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/JsonController.cs +++ /dev/null @@ -1,72 +0,0 @@ -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/JsonNetFormatter.cs b/Software/Visual_Studio/Web/Tango.MachineService/JsonNetFormatter.cs deleted file mode 100644 index 7cadceb0b..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/JsonNetFormatter.cs +++ /dev/null @@ -1,89 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Net.Http.Formatting; -using System.Net.Http.Headers; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using System.Web; -using Tango.BL; - -namespace Tango.MachineService -{ - public class JsonNetFormatter : MediaTypeFormatter - { - private class JsonIgnoreAttributeIgnorerContractResolver : DefaultContractResolver - { - protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) - { - var property = base.CreateProperty(member, memberSerialization); - - if (typeof(IObservableEntity).IsAssignableFrom(property.PropertyType)) - { - property.Ignored = false; - } - return property; - } - } - - private JsonSerializerSettings _jsonSerializerSettings; - - public JsonNetFormatter(JsonSerializerSettings jsonSerializerSettings) - { - _jsonSerializerSettings = jsonSerializerSettings ?? new JsonSerializerSettings(); - _jsonSerializerSettings.ContractResolver = new JsonIgnoreAttributeIgnorerContractResolver(); - - SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json")); - } - - public override bool CanReadType(Type type) - { - return true; - } - - public override bool CanWriteType(Type type) - { - return true; - } - - public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) - { - // Create a serializer - JsonSerializer serializer = JsonSerializer.Create(_jsonSerializerSettings); - - // Create task reading the content - return Task.Factory.StartNew(() => - { - using (StreamReader streamReader = new StreamReader(readStream)) - { - using (JsonTextReader jsonTextReader = new JsonTextReader(streamReader)) - { - return serializer.Deserialize(jsonTextReader, type); - } - } - }); - } - - public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) - { - // Create a serializer - JsonSerializer serializer = JsonSerializer.Create(_jsonSerializerSettings); - - // Create task writing the serialized content - return Task.Factory.StartNew(() => - { - using (JsonTextWriter jsonTextWriter = new JsonTextWriter(new StreamWriter(writeStream)) { CloseOutput = false }) - { - serializer.Serialize(jsonTextWriter, value); - jsonTextWriter.Flush(); - } - }); - } - } -}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs new file mode 100644 index 000000000..6039f55ac --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Web; +using Tango.Web; + +namespace Tango.MachineService +{ + public class MachineServiceConfig : WebConfig + { + public static String TANGO_VERSIONS_CONTAINER => ConfigurationManager.AppSettings[nameof(TANGO_VERSIONS_CONTAINER)].ToString(); + public static String MACHINE_STUDIO_VERSIONS_CONTAINER => ConfigurationManager.AppSettings[nameof(MACHINE_STUDIO_VERSIONS_CONTAINER)].ToString(); + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Models/MachineStudioPendingUpload.cs b/Software/Visual_Studio/Web/Tango.MachineService/Models/MachineStudioPendingUpload.cs new file mode 100644 index 000000000..0347d35ea --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Models/MachineStudioPendingUpload.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Tango.MachineService.Models +{ + public class MachineStudioPendingUpload + { + public String Token { get; set; } + + public String Version { get; set; } + + public String UserGuid { get; set; } + + public String Comments { get; set; } + + public bool ForcedUpdate { get; set; } + + public String FilePath { get; set; } + + public bool IsStable { get; set; } + + public String BlobName { get; set; } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Models/PPCPendingUpload.cs b/Software/Visual_Studio/Web/Tango.MachineService/Models/PPCPendingUpload.cs new file mode 100644 index 000000000..10797e758 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Models/PPCPendingUpload.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Tango.MachineService.Models +{ + public class PPCPendingUpload + { + 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; } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Development.pubxml b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Development.pubxml new file mode 100644 index 000000000..e847adbd8 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Development.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/slots/MachineService-DEV</ResourceId> + <ResourceGroup>Tango</ResourceGroup> + <PublishProvider>AzureWebSite</PublishProvider> + <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration> + <LastUsedPlatform>Any CPU</LastUsedPlatform> + <SiteUrlToLaunchAfterPublish>http://machineservice-machineservice-dev.azurewebsites.net</SiteUrlToLaunchAfterPublish> + <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish> + <ExcludeApp_Data>False</ExcludeApp_Data> + <MSDeployServiceURL>machineservice-machineservice-dev.scm.azurewebsites.net:443</MSDeployServiceURL> + <DeployIisAppPath>machineservice__MachineService-DEV</DeployIisAppPath> + <RemoteSitePhysicalPath /> + <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer> + <InstallAspNetCoreSiteExtension>False</InstallAspNetCoreSiteExtension> + <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod> + <EnableMSDeployBackup>True</EnableMSDeployBackup> + <UserName>$machineservice__MachineService-DEV</UserName> + <_SavePWD>True</_SavePWD> + <_DestinationType>AzureWebSite</_DestinationType> + </PropertyGroup> +</Project>
\ 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/Production.pubxml index 277a89d38..a611d5ffd 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/MachineService - Web Deploy.pubxml +++ b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Production.pubxml @@ -11,7 +11,7 @@ by editing this MSBuild file. In order to learn more about this please visit htt <PublishProvider>AzureWebSite</PublishProvider> <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration> <LastUsedPlatform>Any CPU</LastUsedPlatform> - <SiteUrlToLaunchAfterPublish>http://machineservice.azurewebsites.net</SiteUrlToLaunchAfterPublish> + <SiteUrlToLaunchAfterPublish>https://machineservice.twine-srv.com</SiteUrlToLaunchAfterPublish> <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish> <ExcludeApp_Data>False</ExcludeApp_Data> <MSDeployServiceURL>machineservice.scm.azurewebsites.net:443</MSDeployServiceURL> diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Testing.pubxml b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Testing.pubxml new file mode 100644 index 000000000..12e2de377 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Properties/PublishProfiles/Testing.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/slots/MachineService-TEST</ResourceId> + <ResourceGroup>Tango</ResourceGroup> + <PublishProvider>AzureWebSite</PublishProvider> + <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration> + <LastUsedPlatform>Any CPU</LastUsedPlatform> + <SiteUrlToLaunchAfterPublish>http://machineservice-machineservice-test.azurewebsites.net</SiteUrlToLaunchAfterPublish> + <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish> + <ExcludeApp_Data>False</ExcludeApp_Data> + <MSDeployServiceURL>machineservice-machineservice-test.scm.azurewebsites.net:443</MSDeployServiceURL> + <DeployIisAppPath>machineservice__MachineService-TEST</DeployIisAppPath> + <RemoteSitePhysicalPath /> + <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer> + <InstallAspNetCoreSiteExtension>False</InstallAspNetCoreSiteExtension> + <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod> + <EnableMSDeployBackup>True</EnableMSDeployBackup> + <UserName>$machineservice__MachineService-TEST</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 deleted file mode 100644 index b82f1adef..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/ProtoBufFormatter.cs +++ /dev/null @@ -1,143 +0,0 @@ -using Google.Protobuf; -using System; -using System.IO; -using System.Net; -using System.Net.Http; -using System.Net.Http.Formatting; -using System.Net.Http.Headers; -using System.Threading.Tasks; -using System.Web.Http; -using Tango.PMR.Stubs; -using Tango.PMR.Synchronization; - -namespace Tango.MachineService -{ - /// <summary> - /// Represents a protobuf web request/response formatter capable of formatting messages using protobuf. - /// </summary> - /// <seealso cref="System.Net.Http.Formatting.MediaTypeFormatter" /> - public class ProtoBufFormatter : MediaTypeFormatter - { - private static readonly MediaTypeHeaderValue mediaType = new MediaTypeHeaderValue("application/x-protobuf"); - - /// <summary> - /// Initializes a new instance of the <see cref="ProtoBufFormatter"/> class. - /// </summary> - public ProtoBufFormatter() - { - SupportedMediaTypes.Add(mediaType); - } - - /// <summary> - /// Gets the default type of the media. - /// </summary> - /// <value> - /// The default type of the media. - /// </value> - public static MediaTypeHeaderValue DefaultMediaType - { - get { return mediaType; } - } - - /// <summary> - /// Queries whether this <see cref="T:System.Net.Http.Formatting.MediaTypeFormatter" /> can deserializean object of the specified type. - /// </summary> - /// <param name="type">The type to deserialize.</param> - /// <returns> - /// true if the <see cref="T:System.Net.Http.Formatting.MediaTypeFormatter" /> can deserialize the type; otherwise, false. - /// </returns> - public override bool CanReadType(Type type) - { - return true; - } - - /// <summary> - /// Queries whether this <see cref="T:System.Net.Http.Formatting.MediaTypeFormatter" /> can serializean object of the specified type. - /// </summary> - /// <param name="type">The type to serialize.</param> - /// <returns> - /// true if the <see cref="T:System.Net.Http.Formatting.MediaTypeFormatter" /> can serialize the type; otherwise, false. - /// </returns> - public override bool CanWriteType(Type type) - { - return true; - } - - /// <summary> - /// Reads from stream asynchronous. - /// </summary> - /// <param name="type">The type.</param> - /// <param name="stream">The stream.</param> - /// <param name="content">The content.</param> - /// <param name="formatterLogger">The formatter logger.</param> - /// <returns></returns> - public override Task<object> ReadFromStreamAsync(Type type, Stream stream, HttpContent content, IFormatterLogger formatterLogger) - { - var tcs = new TaskCompletionSource<object>(); - - try - { - MessageParser parser = type.GetProperty("Parser").GetValue(null, null) as MessageParser; - IMessage req = parser.ParseFrom(stream); - tcs.SetResult(req); - } - catch (Exception ex) - { - tcs.SetException(ex); - } - - return tcs.Task; - } - - /// <summary> - /// Writes to stream asynchronous. - /// </summary> - /// <param name="type">The type.</param> - /// <param name="value">The value.</param> - /// <param name="stream">The stream.</param> - /// <param name="content">The content.</param> - /// <param name="transportContext">The transport context.</param> - /// <returns></returns> - public override Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContent content, TransportContext transportContext) - { - var tcs = new TaskCompletionSource<object>(); - - if (value is IMessage) - { - try - { - (value as IMessage).WriteTo(stream); - tcs.SetResult(null); - } - catch (Exception ex) - { - tcs.SetException(ex); - } - - return tcs.Task; - } - else if (value is HttpError) - { - var httpError = value as HttpError; - - try - { - HttpProtoException msg = new HttpProtoException(); - msg.Message = httpError["Message"].ToString(); - msg.StatusCode = (int)HttpStatusCode.InternalServerError; - - msg.WriteTo(stream); - tcs.SetResult(null); - } - catch (Exception ex) - { - tcs.SetException(ex); - } - - 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/ProtoController.cs b/Software/Visual_Studio/Web/Tango.MachineService/ProtoController.cs deleted file mode 100644 index 572604d3c..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/ProtoController.cs +++ /dev/null @@ -1,64 +0,0 @@ -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 deleted file mode 100644 index d2ee0ed5f..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/SMO/SmoManager.cs +++ /dev/null @@ -1,73 +0,0 @@ -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 9f0b2cba2..63c8521da 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -64,6 +64,12 @@ <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.IdentityModel.Clients.ActiveDirectory, Version=2.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.7.10707.1513-rc\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath> + </Reference> + <Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms, Version=2.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.7.10707.1513-rc\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath> + </Reference> <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> @@ -269,26 +275,18 @@ </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="MachineServiceConfig.cs" /> + <Compile Include="Controllers\MachineStudioController.cs" /> + <Compile Include="Models\MachineStudioPendingUpload.cs" /> + <Compile Include="Models\PPCPendingUpload.cs" /> <Compile Include="App_Start\RouteConfig.cs" /> <Compile Include="App_Start\WebApiConfig.cs" /> - <Compile Include="Controllers\HomeController.cs" /> - <Compile Include="Controllers\SynchronizationController.cs" /> - <Compile Include="Controllers\ValuesController.cs" /> + <Compile Include="Controllers\PPCController.cs" /> <Compile Include="Global.asax.cs"> <DependentUpon>Global.asax</DependentUpon> </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> <Content Include="Global.asax" /> @@ -307,6 +305,10 @@ <Content Include="packages.config" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\..\MachineStudio\Tango.MachineStudio.Common\Tango.MachineStudio.Common.csproj"> + <Project>{CB0B0AA2-BB24-4BCA-A720-45E397684E12}</Project> + <Name>Tango.MachineStudio.Common</Name> + </ProjectReference> <ProjectReference Include="..\..\PPC\Tango.PPC.Common\Tango.PPC.Common.csproj"> <Project>{0be74eee-22cb-4dba-b896-793b9e1a3ac0}</Project> <Name>Tango.PPC.Common</Name> @@ -331,12 +333,22 @@ <Project>{7ada4e86-cad7-4968-a210-3a8a9e5153ab}</Project> <Name>Tango.Synchronization</Name> </ProjectReference> + <ProjectReference Include="..\..\Tango.Transport\Tango.Transport.csproj"> + <Project>{74e700b0-1156-4126-be40-ee450d3c3026}</Project> + <Name>Tango.Transport</Name> + </ProjectReference> + <ProjectReference Include="..\..\Tango.Web\Tango.Web.csproj"> + <Project>{5001990f-977b-48ff-b217-0236a5022ad8}</Project> + <Name>Tango.Web</Name> + </ProjectReference> </ItemGroup> <ItemGroup> <Folder Include="App_Data\" /> </ItemGroup> <ItemGroup> - <None Include="Properties\PublishProfiles\MachineService - Web Deploy.pubxml" /> + <None Include="Properties\PublishProfiles\Development.pubxml" /> + <None Include="Properties\PublishProfiles\Testing.pubxml" /> + <None Include="Properties\PublishProfiles\Production.pubxml" /> <None Include="Properties\PublishProfiles\Publish Machine Service via FTP.pubxml" /> </ItemGroup> <PropertyGroup> @@ -365,7 +377,7 @@ <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile> </WebProjectProperties> </FlavorProperties> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index 3590b89d8..2d700244b 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -13,15 +13,23 @@ <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" /> + + <add key="DB_ADDRESS" value="twine.database.windows.net" /> + <add key="DB_USER_NAME" value="Roy" /> + <add key="DB_PASSWORD" value="Aa123456" /> + <add key="DB_CATALOG" value="Tango" /> + + <add key="STORAGE_ACCOUNT" value="DefaultEndpointsProtocol=https;AccountName=tangostorage;AccountKey=S4z/D+Yg6mwMis+bs/VpcDLA9yE1iZaYq23shQlRIi2KmM9E7JY8zdZjeAPOPdG3gONHoNDEpsgH6D4cqQ/bsA==;EndpointSuffix=core.windows.net" /> + + <add key="TENANT_ID" value="2ebd63a5-bc2f-41dc-9066-4409ed5e5dd4" /> + <add key="CLIENT_ID" value="ec612854-7abc-457b-808a-5d0c5ba80c57" /> + <add key="APP_SECRET" value="54)019A7wv+#86l*PQcQWYKu%fd4Dv!@G=VhCiDI5rD+H4BTH" /> + + <add key="TANGO_VERSIONS_CONTAINER" value="tango-versions" /> + <add key="MACHINE_STUDIO_VERSIONS_CONTAINER" value="machine-studio-versions" /> + + <add key="DEPLOYMENT_SLOT" value="DEV" /> + <add key="ENVIRONMENT_GROUP" value="Tango DEV" /> </appSettings> <!-- For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367. @@ -125,6 +133,22 @@ <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> + <dependentAssembly> + <assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-2.7.0.0" newVersion="2.7.0.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" /> + </dependentAssembly> </assemblyBinding> </runtime> <system.codedom> diff --git a/Software/Visual_Studio/Web/Tango.MachineService/WebApiException.cs b/Software/Visual_Studio/Web/Tango.MachineService/WebApiException.cs deleted file mode 100644 index a52a0ce6f..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/WebApiException.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Web; - -namespace Tango.MachineService -{ - public class WebApiException : Exception - { - public HttpStatusCode StatusCode { get; set; } - - public WebApiException(HttpStatusCode statusCode, String message) : base(message) - { - StatusCode = statusCode; - } - } -}
\ 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 ede4fa80d..080382800 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/packages.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/packages.config @@ -20,6 +20,7 @@ <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" /> <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.IdentityModel.Clients.ActiveDirectory" version="2.7.10707.1513-rc" targetFramework="net461" /> <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" /> |
