From 0f5040d66983d5b0a32a834cfd4653d119d22f5e Mon Sep 17 00:00:00 2001 From: lukeIam Date: Sun, 18 Jan 2015 20:44:47 +0100 Subject: [PATCH] [App] - The app stores the Vocaluxe version it was created with [Server] -getServerVersion added [App] - Checks if the server has the right version, otherwise fallback to inApp WebVersion --- ServerLib/CServer.cs | 8 ++++-- ServerLib/CWebservice.cs | 5 ++++ ServerLib/DataStructs.cs | 2 ++ ServerLib/ICWebservice.cs | 5 ++++ Vocaluxe/Base/Server/CVocaluxeServer.cs | 13 +++++++++ Vocaluxe/Vocaluxe.csproj | 22 +++++++++++++-- Vocaluxe/Website/js/main.js | 37 +++++++++++++++++-------- 7 files changed, 75 insertions(+), 17 deletions(-) diff --git a/ServerLib/CServer.cs b/ServerLib/CServer.cs index f9bf489d..2971f7af 100644 --- a/ServerLib/CServer.cs +++ b/ServerLib/CServer.cs @@ -51,10 +51,12 @@ namespace ServerLib public static GetSiteFileDelegate GetSiteFile { internal get; set; } public static GetDelayedImageDelegate GetDelayedImage { internal get; set; } - #endregion - #region songs - public static GetSongDelegate GetSong { internal get; set; } + public static GetServerVersionDelegate GetServerVersion { internal get; set; } + #endregion + + #region songs + public static GetSongDelegate GetSong { internal get; set; } public static GetAllSongsDelegate GetAllSongs { internal get; set; } diff --git a/ServerLib/CWebservice.cs b/ServerLib/CWebservice.cs index 1b2762f5..785fdfb4 100644 --- a/ServerLib/CWebservice.cs +++ b/ServerLib/CWebservice.cs @@ -300,6 +300,11 @@ namespace ServerLib _GetSession(); return true; } + + public string GetServerVersion() + { + return CServer.GetServerVersion(); + } #endregion #region songs diff --git a/ServerLib/DataStructs.cs b/ServerLib/DataStructs.cs index 591b5f98..ebec95c9 100644 --- a/ServerLib/DataStructs.cs +++ b/ServerLib/DataStructs.cs @@ -64,6 +64,8 @@ namespace ServerLib public delegate byte[] GetSiteFileDelegate(string filename); public delegate CBase64Image GetDelayedImageDelegate(string hashedFilename); + + public delegate String GetServerVersionDelegate(); #endregion [DataContract] diff --git a/ServerLib/ICWebservice.cs b/ServerLib/ICWebservice.cs index 27d68081..ea0e8a6e 100644 --- a/ServerLib/ICWebservice.cs +++ b/ServerLib/ICWebservice.cs @@ -115,6 +115,11 @@ namespace ServerLib ResponseFormat = WebMessageFormat.Json, UriTemplate = "/isServerOnline")] bool IsServerOnline(); + + [OperationContract, WebInvoke(Method = "GET", + ResponseFormat = WebMessageFormat.Json, + UriTemplate = "/getServerVersion")] + String GetServerVersion(); #endregion #region songs diff --git a/Vocaluxe/Base/Server/CVocaluxeServer.cs b/Vocaluxe/Base/Server/CVocaluxeServer.cs index 252c0ef7..abc18556 100644 --- a/Vocaluxe/Base/Server/CVocaluxeServer.cs +++ b/Vocaluxe/Base/Server/CVocaluxeServer.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; +using System.Reflection; using System.Security.Cryptography; using System.Text; using System.Windows.Forms; @@ -70,6 +71,7 @@ namespace Vocaluxe.Base.Server CServer.GetProfileList = _GetProfileList; CServer.SendPhoto = _SendPhoto; CServer.GetSiteFile = _GetSiteFile; + CServer.GetServerVersion = _GetServerVersion; CServer.GetSong = _GetSong; CServer.GetAllSongs = _GetAllSongs; CServer.GetCurrentSongId = _GetCurrentSongId; @@ -93,6 +95,7 @@ namespace Vocaluxe.Base.Server //_Discover = new CDiscover(CConfig.ServerPort, CCommands.BroadcastKeyword); } + public static void Start() { @@ -435,6 +438,16 @@ namespace Vocaluxe.Base.Server return hashedFilename; } + private static string _GetServerVersion() + { + var informationalVersion = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).FirstOrDefault(); + if (informationalVersion != null) + { + informationalVersion = ""; + } + return Assembly.GetExecutingAssembly().GetName().Version.ToString() + " (" + informationalVersion + ")"; + } + private static CBase64Image _GetDelayedImage(string hashedFilename) { if (!_DelayedImagePath.ContainsKey(hashedFilename)) diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 0c0d6aac..5c1cea83 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -515,8 +515,12 @@ - xcopy /E /D /Y "$(ProjectDir)\Website" "$(SolutionDir)\PhoneGap" -powershell -command "(Get-Content -Encoding UTF8 '$(ProjectDir)Properties\AssemblyInfo.cs') | Foreach-Object {$_ -replace '(?<=AssemblyInformationalVersion\()(.*)(?=\))', '\"GITVERSION\"'} | Set-Content -Encoding UTF8 '$(ProjectDir)Properties\AssemblyInfo.cs'" + + xcopy /E /D /Y "$(ProjectDir)\Website" "$(SolutionDir)\PhoneGap" + + powershell -command "$version = git describe --long; (Get-Content -Encoding UTF8 '$(ProjectDir)..\Output\Website\js\main.js') | Foreach-Object {$_ -replace '(?<=var *matchingServerVersion * = *\\\")\w*(?=\\\" *;)', %24('@(VersionNumber)'+' ('+$version+')')} | Set-Content -Encoding UTF8 '$(ProjectDir)..\Output\Website\js\main.js'" + + powershell -command "(Get-Content -Encoding UTF8 '$(ProjectDir)Properties\AssemblyInfo.cs') | Foreach-Object {$_ -replace '(?<=AssemblyInformationalVersion\()(.*)(?=\))', '\"GITVERSION\"'} | Set-Content -Encoding UTF8 '$(ProjectDir)Properties\AssemblyInfo.cs'" powershell -command "$version = git describe --long; (Get-Content -Encoding UTF8 '$(ProjectDir)Properties\AssemblyInfo.cs') | Foreach-Object {$_ -replace 'GITVERSION', $version} | Set-Content -Encoding UTF8 '$(ProjectDir)Properties\AssemblyInfo.cs'" @@ -528,4 +532,18 @@ powershell -command "(Get-Content -Encoding UTF8 '$(ProjectDir)Properties\Assemb --> + + + + + + + + + + + $(PostBuildEventDependsOn); + PostBuildMacros; + + \ No newline at end of file diff --git a/Vocaluxe/Website/js/main.js b/Vocaluxe/Website/js/main.js index b51c9841..39b38b49 100644 --- a/Vocaluxe/Website/js/main.js +++ b/Vocaluxe/Website/js/main.js @@ -6,6 +6,7 @@ var translator; var pageHandler; var sessionHandler; + var matchingServerVersion = ""; var initMain = function () { if (document.location.protocol == "file:") { @@ -47,7 +48,7 @@ } if ((typeof data.type) == "undefined") { - data.type = "GET"; + data.type = "GET"; } if (message != "noOverlay") { @@ -377,13 +378,19 @@ } sessionHandler.serverBaseAddress = ""; request({ - url: address + "isServerOnline", + url: address + "getServerVersion", timeout: 10000 }, "Checking...") - .done(function () { - sessionHandler.serverBaseAddress = address; - window.localStorage.setItem("VocaluxeServerAddress", address); - $.mobile.changePage("#login", { transition: "slidefade" }); + .done(function (serverVersion) { + if(serverVersion === matchingServerVersion){ + sessionHandler.serverBaseAddress = address; + window.localStorage.setItem("VocaluxeServerAddress", address); + $.mobile.changePage("#login", { transition: "none" }); + } + else{ + window.location.href = address; + return; + } }) .fail(function () { $('#discoverServerAddress').prop("value", ""); @@ -429,12 +436,18 @@ if (address != null) { sessionHandler.serverBaseAddress = ""; var prom = request({ - url: address + "isServerOnline", + url: address + "getServerVersion", timeout: 10000 - }, "Checking...").done(function () { - sessionHandler.serverBaseAddress = address; - window.localStorage.setItem("VocaluxeServerAddress", address); - $.mobile.changePage("#login", { transition: "none" }); + }, "Checking...").done(function (serverVersion) { + if (serverVersion === matchingServerVersion) { + sessionHandler.serverBaseAddress = address; + window.localStorage.setItem("VocaluxeServerAddress", address); + $.mobile.changePage("#login", { transition: "none" }); + } + else { + window.location.href = address; + return; + } }).fail(function () { if (typeof window.BarcodeScanner != "undefined") { $('#discoverReadQr').show(); @@ -443,7 +456,7 @@ $(this).data('promise', prom); return; } - if (typeof window.BarcodeScanner != "undefined") { + else if (typeof window.BarcodeScanner != "undefined") { $('#discoverReadQr').show(); } }