diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-22 13:23:49 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-22 13:23:49 +0200 |
| commit | 042b4d3e7b0af729792ca20e086756c36d2f5768 (patch) | |
| tree | 90fe664895ae143c25f1afb15b8ccbbcad94837e /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/MachineStudioUpdateService.svc.cs | |
| parent | f991f37a95a854e9b2aada52982d83ddaa0ca1b0 (diff) | |
| download | Tango-042b4d3e7b0af729792ca20e086756c36d2f5768.tar.gz Tango-042b4d3e7b0af729792ca20e086756c36d2f5768.zip | |
Working on machine studio update center !
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/MachineStudioUpdateService.svc.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/MachineStudioUpdateService.svc.cs | 130 |
1 files changed, 128 insertions, 2 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/MachineStudioUpdateService.svc.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/MachineStudioUpdateService.svc.cs index 4cfea1b8a..e573a0d77 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/MachineStudioUpdateService.svc.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UpdateService/MachineStudioUpdateService.svc.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; using System.Configuration; +using System.IO; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; +using Tango.Core.Helpers; using Tango.Integration.Observables; using Tango.Logging; using Tango.MachineStudio.Common.Update; @@ -14,6 +16,26 @@ namespace Tango.MachineStudio.UpdateService { public class MachineStudioUpdateService : IMachineStudioUpdateService { + 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 FilePath { get; set; } + } + + private static List<PendingUpload> _pendingUploads; + + MachineStudioUpdateService() + { + _pendingUploads = new List<PendingUpload>(); + } + public CheckForUpdatesResponse CheckForUpdates(CheckForUpdatesRequest request) { LogManager.Log("Request received..."); @@ -31,9 +53,9 @@ namespace Tango.MachineStudio.UpdateService if (user != null) { var latestVersion = db.MachineStudioVersions.FirstOrDefault(); - Version currentVersionNumber = Version.Parse(request.Version); + Version currentVersion = Version.Parse(request.Version); - if (latestVersion != null && Version.Parse(latestVersion.Version) > currentVersionNumber) + if (latestVersion != null && Version.Parse(latestVersion.Version) > currentVersion) { response.IsUpdateAvailable = true; @@ -58,5 +80,109 @@ namespace Tango.MachineStudio.UpdateService throw new FaultException(ex.ToString()); } } + + public UploadVersionResponse UploadVersion(UploadVersionRequest request) + { + try + { + UploadVersionResponse response = new UploadVersionResponse(); + + using (ObservablesContext db = ObservablesContext.CreateDefaultForWeb()) + { + db.Configuration.LazyLoadingEnabled = false; + + var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password); + + if (user != null) + { + var latestVersion = db.MachineStudioVersions.FirstOrDefault(); + Version currentVersion = Version.Parse(request.Version); + + String newVersionFileName = Path.GetRandomFileName() + ".zip"; + + String newVersionFilePath = "/machine studio versions/" + newVersionFileName; + + if (currentVersion > Version.Parse(latestVersion.Version)) + { + response.FtpHost = ConfigurationManager.AppSettings["FtpHost"].ToString(); + response.UserName = ConfigurationManager.AppSettings["UserName"].ToString(); + response.Password = ConfigurationManager.AppSettings["Password"].ToString(); + response.FilePath = newVersionFilePath; + response.FileName = newVersionFileName; + response.Token = Guid.NewGuid().ToString(); + + _pendingUploads.Add(new PendingUpload() + { + UserGuid = user.Guid, + Comments = request.Comments, + Token = response.Token, + Version = request.Version, + FilePath = response.FilePath, + }); + } + else + { + throw new FaultException("New version must be greater than latest version."); + } + } + else + { + throw new FaultException("Invalid user credentials."); + } + } + + return response; + } + catch (Exception ex) + { + LogManager.Log(ex); + throw new FaultException(ex.ToString()); + } + } + + public void NotifyUploadCompleted(UploadCompletedRequest request) + { + try + { + PendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.Token); + + if (upload != null) + { + _pendingUploads.RemoveAll(x => x.Token == upload.Token); + + using (ObservablesContext db = ObservablesContext.CreateDefaultForWeb()) + { + db.Configuration.LazyLoadingEnabled = false; + + db.MachineStudioVersions.Add(new MachineStudioVersion() + { + Comments = upload.Comments, + FtpFilePath = upload.FilePath, + UserGuid = upload.UserGuid, + Version = upload.Version + }); + + db.SaveChanges(); + } + } + else + { + throw new FaultException("Invalid Token."); + } + } + catch (Exception ex) + { + LogManager.Log(ex); + throw new FaultException(ex.ToString()); + } + } + + public string GetLatestVersion() + { + using (ObservablesContext db = ObservablesContext.CreateDefaultForWeb()) + { + return db.MachineStudioVersions.FirstOrDefault().Version; + } + } } } |
