Added first version for updater

This commit is contained in:
2018-08-15 20:58:47 +02:00
parent 285a4c2cce
commit 3f46d326cc
35 changed files with 24884 additions and 5 deletions

View File

@@ -25,8 +25,6 @@ namespace RothenburgAR.Exhibition
return false;
// Todo: More validations
// TODO: POIs sollen ein optionales Sprite erhalten - Angeben in der XML und laden von der Platte
return true;
}
@@ -47,8 +45,6 @@ namespace RothenburgAR.Exhibition
string exhibitionId = doc.DocumentElement.Attributes["id"].Value;
// Todo: Implement "Title"
PreloadedExhibition resultExhibition = new PreloadedExhibition
{
ContainedExhibits = new List<PreloadedExhibit>(),

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 04af75ade4f76434a8a2025477f03af9
folderAsset: yes
timeCreated: 1534257697
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,72 @@
using System.Collections.Generic;
using System;
namespace RothenburgAR.Updater
{
[Serializable]
public class ApiInfo
{
private static string baseUrl = "https://lambdalike.pa.kaim.network";
public static string VersionCheckEndpoint
{
get { return baseUrl + "/versioncheck"; }
}
public static string ExhibitionEndpoint
{
get { return baseUrl + "/meta/{id}/{lang}"; }
}
public static string FileEndpoint
{
get { return baseUrl + "/files/{id}"; }
}
public static string TrackerEndpoint
{
get { return baseUrl + "/tracker/{id}"; }
}
}
[Serializable]
public class VersioncheckAnswer
{
public List<string> languages { get; set; }
public List<Version> data { get; set; }
}
[Serializable]
public class Version
{
public string id { get; set; }
public VersionInfo meta;
//VersionInfo tracker;
}
[Serializable]
public class VersionInfo
{
public VersionStatus status;
public string updateUrl;
}
public enum VersionStatus
{
ok,
updated,
deleted
}
[Serializable]
public class ExhibitionData
{
public string title { get; set; }
public string description { get; set; }
public List<string> tags { get; set; }
public List<string> exhibitionIds { get; set; }
public string mediaId { get; set; }
public object createdTime { get; set; }
public object updatedTime { get; set; }
public string id { get; set; }
public List<string> pois { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: a76ff73dc064a3642a18497d15719d10
timeCreated: 1534357024
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine.Networking;
namespace RothenburgAR.Updater
{
public class HttpRequest
{
private string url;
private HttpVerb verb;
private string uploadData;
public HttpRequest(String url, HttpVerb verb, String uploadData = null)
{
this.url = url;
this.verb = verb;
this.uploadData = uploadData;
}
public HttpHandler send()
{
UploadHandlerRaw ul = new UploadHandlerRaw(Encoding.UTF8.GetBytes(uploadData.ToCharArray()));
DownloadHandler dl = new DownloadHandlerBuffer();
string verb = Enum.GetName(typeof(HttpVerb), this.verb);
UnityWebRequest wr = new UnityWebRequest(url, verb, dl, ul);
wr.SetRequestHeader("Content-Type", "application/json;charset=UTF-8"); //or sth like that
var operation = wr.SendWebRequest();
return new HttpHandler(ul, dl, wr, operation);
}
}
public enum HttpVerb
{
GET,
POST,
PUT,
DELETE
}
public class HttpHandler
{
public UploadHandler upload { get; set; }
public DownloadHandler download { get; set; }
public UnityWebRequest request { get; set; }
public UnityWebRequestAsyncOperation operation {get;set;}
public HttpHandler(UploadHandler upload, DownloadHandler download, UnityWebRequest request, UnityWebRequestAsyncOperation operation)
{
this.upload = upload;
this.download = download;
this.request = request;
this.operation = operation;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 2b86098bd8091364fa115b01f2e4cc3e
timeCreated: 1534260448
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,93 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Newtonsoft.Json;
namespace RothenburgAR.Updater
{
public class UpdaterBehaviour : MonoBehaviour
{
public VersioncheckAnswer VersionAnswer { get; set; }
void Start()
{
/*
zum app-start einmal prüfen, wenn neues da ist anzeigen und evtl. runterladen (wenn nicht getaktete verbindung)
neue startszene, die guckt und updatet und dann zur mainScene weiterleitet
auf getaktete verbindung prüfen (Application.internetReachability)
punkt zum eintragen der credentials? user will ja nur seine/nur bestimmte exhibitions haben schätz ich
oder beim update auswählen lassen, welche kommen sollen
*/
if (Application.internetReachability == NetworkReachability.NotReachable)
{
// just continue to app
LoadMainScene();
return;
}
CheckForUpdates();
}
private void CheckForUpdates()
{
// check for updates and ask for permission to download if there are any
//TODO generate versionmap (i guess by crawling all subdirs of /exhibitions)
string versionMap = "[]";
HttpHandler httpHandler = new HttpRequest(ApiInfo.VersionCheckEndpoint, HttpVerb.POST, versionMap).send();
// httpHandler.operation.progress needs to be polled
httpHandler.operation.completed += ar =>
{
//TODO check for network errors/timeouts (and find out if operation.completed() is the right place for that)
Debug.Log(httpHandler.download.text);
//versionAnswer = JsonConvert.DeserializeObject<VersioncheckAnswer>(httpHandler.download.text);
VersionAnswer = JsonConvert.DeserializeObject<VersioncheckAnswer>(@"{""data"":[{""id"":""a"",""meta"":{""status"":""ok"",""updateUrl"":""https://lambdalike.pa.kaim.network/meta/006e164c-5e31-4ddf-adf5-df7016c8b3a7/de""}},{""id"":""b"",""meta"":{""status"":""updated"",""updateUrl"":""https://lambdalike.pa.kaim.network/meta/006e164c-5e31-4ddf-adf5-df7016c8b3a7/de""}}]}");
if (VersionAnswer.data.TrueForAll(d => d.meta.status == VersionStatus.ok))
{
// no updates required, continue to app
LoadMainScene();
return;
}
if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
{
TriggerUpdate();
}
else
{
// TODO ask for user permission to perform update
}
};
}
private void TriggerUpdate()
{
// TODO instantiate component that performs the update?
/* trigger tiered updates in order
* languages //no http
* data //no http
* tracker //1 request
* meta //1 request
* poi //n requests
* media //n requests
*/
}
private static void LoadMainScene()
{
UnityEngine.SceneManagement.SceneManager.LoadScene("mainScene");
}
void Update()
{
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: f086f910087528a48b17fdfced69c0c9
timeCreated: 1534257778
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: