implemented exhibition metadata storage
This commit is contained in:
@@ -31,22 +31,22 @@ namespace RothenburgAR.Updater
|
|||||||
public class VersioncheckAnswer
|
public class VersioncheckAnswer
|
||||||
{
|
{
|
||||||
public List<string> languages { get; set; }
|
public List<string> languages { get; set; }
|
||||||
public List<Version> data { get; set; }
|
public List<ExhibitionVersion> data { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class Version
|
public class ExhibitionVersion
|
||||||
{
|
{
|
||||||
public string id { get; set; }
|
public string id { get; set; }
|
||||||
public VersionInfo meta;
|
public VersionInfo meta { get; set; }
|
||||||
//VersionInfo tracker;
|
public VersionInfo tracker { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class VersionInfo
|
public class VersionInfo
|
||||||
{
|
{
|
||||||
public VersionStatus status;
|
public VersionStatus status { get; set; }
|
||||||
public string updateUrl;
|
public string updateUrl { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum VersionStatus
|
public enum VersionStatus
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using RothenburgAR.Common;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace RothenburgAR.Updater
|
namespace RothenburgAR.Updater
|
||||||
{
|
{
|
||||||
@@ -12,11 +15,7 @@ namespace RothenburgAR.Updater
|
|||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
/*
|
/* TODO: allg. fragen
|
||||||
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
|
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
|
oder beim update auswählen lassen, welche kommen sollen
|
||||||
*/
|
*/
|
||||||
@@ -46,9 +45,9 @@ namespace RothenburgAR.Updater
|
|||||||
Debug.Log(httpHandler.download.text);
|
Debug.Log(httpHandler.download.text);
|
||||||
|
|
||||||
//versionAnswer = JsonConvert.DeserializeObject<VersioncheckAnswer>(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""}}]}");
|
VersionAnswer = JsonConvert.DeserializeObject<VersioncheckAnswer>(@"{""data"":[{""id"":""a"",""meta"":{""status"":""ok"",""updateUrl"":""https://lambdalike.pa.kaim.network/meta/006e164c-5e31-4ddf-adf5-df7016c8b3a7/de""},""tracker"":""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""},""tracker"":""meta"":{""status"":""ok"",""updateUrl"":""https://lambdalike.pa.kaim.network/meta/006e164c-5e31-4ddf-adf5-df7016c8b3a7/de""}}]}");
|
||||||
|
|
||||||
if (VersionAnswer.data.TrueForAll(d => d.meta.status == VersionStatus.ok))
|
if (VersionAnswer.data.TrueForAll(d => d.meta.status == VersionStatus.ok && d.tracker.status == VersionStatus.ok))
|
||||||
{
|
{
|
||||||
// no updates required, continue to app
|
// no updates required, continue to app
|
||||||
LoadMainScene();
|
LoadMainScene();
|
||||||
@@ -68,15 +67,74 @@ namespace RothenburgAR.Updater
|
|||||||
|
|
||||||
private void TriggerUpdate()
|
private void TriggerUpdate()
|
||||||
{
|
{
|
||||||
// TODO instantiate component that performs the update?
|
// TODO create centralized network error feedback hub thing
|
||||||
/* trigger tiered updates in order
|
/*
|
||||||
* languages //no http
|
* dir structure:
|
||||||
* data //no http
|
* data
|
||||||
* tracker //1 request
|
* exhibitions
|
||||||
* meta //1 request
|
* id
|
||||||
* poi //n requests
|
* tracker.dat
|
||||||
* media //n requests
|
* tracker.xml
|
||||||
|
* de
|
||||||
|
* meta.json
|
||||||
|
* en
|
||||||
|
* meta.json
|
||||||
|
* id
|
||||||
|
* ...
|
||||||
|
* poi
|
||||||
|
* ...
|
||||||
|
* media
|
||||||
|
* ...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//TODO write languages to file the app can read
|
||||||
|
|
||||||
|
var updatedMeta = VersionAnswer.data.Where(d => d.meta.status == VersionStatus.updated).ToList();
|
||||||
|
var updatedTracker = VersionAnswer.data.Where(d => d.tracker.status == VersionStatus.updated).ToList();
|
||||||
|
updatedMeta.Union(updatedTracker).ToList().ForEach(updatedExhibition =>
|
||||||
|
{
|
||||||
|
// create exhibition directories
|
||||||
|
var path = Path.Combine(PathHelper.ExhibitionPath, updatedExhibition.id);
|
||||||
|
if (!Directory.Exists(path))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
updatedMeta.ForEach(d => UpdateMeta(d));
|
||||||
|
updatedTracker.ForEach(d => UpdateTracker(d));
|
||||||
|
|
||||||
|
var deletedMeta = VersionAnswer.data.Where(d => d.meta.status == VersionStatus.deleted).ToList();
|
||||||
|
var deletedTracker = VersionAnswer.data.Where(d => d.tracker.status == VersionStatus.deleted).ToList();
|
||||||
|
//TODO figure out if you can delete a tracker but not the meta (or vice versa)
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateMeta(ExhibitionVersion exhibition)
|
||||||
|
{
|
||||||
|
foreach (var lang in VersionAnswer.languages)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(PathHelper.ExhibitionPath, lang);
|
||||||
|
var url = ApiInfo.ExhibitionEndpoint.Replace("{lang}", lang).Replace("{id}", exhibition.id);
|
||||||
|
var http = new HttpRequest(url, HttpVerb.GET).send();
|
||||||
|
http.operation.completed += ar =>
|
||||||
|
{
|
||||||
|
//TODO check for network errors/timeouts (and find out if operation.completed() is the right place for that)
|
||||||
|
if (!Directory.Exists(path))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllText(Path.Combine(path, "meta.json"), http.download.text, System.Text.Encoding.UTF8);
|
||||||
|
|
||||||
|
//TODO parse json into object and download poi data
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateTracker(ExhibitionVersion exhibition)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LoadMainScene()
|
private static void LoadMainScene()
|
||||||
|
|||||||
Reference in New Issue
Block a user