private async void Start() { Debug.Log("Database start"); DataService.databaseName = ApplicationManager.instance.appSettings.databaseServerURL; var resultInit = await DataService.LoadData <InitData>(); var resultTCT = await DataService.LoadData <TargetCountThresholdData>(); if (resultInit.successful && resultTCT.successful) { if (resultInit.dataList.Count > 0) { foreach (InitData init in resultInit.dataList) { if (init.Equals(ApplicationManager.instance.appSettings)) { var targetCountThresholds = resultTCT.dataList.Count > 0 ? resultTCT.dataList.Where(x => x.initId == init.id).ToList() : new List <TargetCountThresholdData>(); if (CheckTargetCountThresholds(targetCountThresholds, ApplicationManager.instance.gameSettings.targetCountThreshold)) { currentInit = init; break; } } } } if (currentInit == null) { var newInit = InitData.CreateFromApplicationSettings(ApplicationManager.instance.appSettings); currentInit = newInit; DataService.InsertData(currentInit, result => { if (result.successful) { for (int i = 0; i < ApplicationManager.instance.gameSettings.targetCountThreshold.Length; i++) { DataService.InsertData(new TargetCountThresholdData(i, currentInit, ApplicationManager.instance.gameSettings.targetCountThreshold[i]), x => { return; }); } } else { Debug.LogError("Error while inserting init file."); } }); } } else { Debug.LogError("Couldn't find init file."); } if (currentInit == null) { Invoke("Start", ApplicationManager.instance.appSettings.databaseInitRefreshTime); } }
private void InsertTest() { var applicationSettings = ApplicationSettings.Load(Path.Combine(Application.streamingAssetsPath, ApplicationManager.appSettingsPath)); DataService.InsertData(new CrashData(0, DateTime.Now, null), result => Debug.Log(result)); DataService.InsertData(new CrashData(0, DateTime.Now, UnityEngine.Random.Range(0, 100000)), result => Debug.Log(result)); DataService.InsertData(InitData.CreateFromApplicationSettings(applicationSettings), result => { Debug.Log(result); if (result.successful) { DataService.InsertData(new SessionData(0, result.data, DateTime.Now, "fr", UnityEngine.Random.Range(0, 100), UnityEngine.Random.Range(0, 1000), UnityEngine.Random.Range(0, 2000), UnityEngine.Random.Range(0, 2) == 1, UnityEngine.Random.Range(0, 2) == 1, (GameMode)UnityEngine.Random.Range(0, 2), UnityEngine.Random.Range(0, 2000), UnityEngine.Random.Range(result.data.minPrecisionRating, result.data.maxPrecisionRating), UnityEngine.Random.Range(result.data.minSpeedRating, result.data.maxSpeedRating), UnityEngine.Random.Range(result.data.comboMin, result.data.comboMax)), result2 => { Debug.Log(result2); if (result2.successful) { DataService.InsertData(new PlayerData(0, result2.data, UnityEngine.Random.Range(0, 2), UnityEngine.Random.insideUnitSphere * 10.0f), result3 => { Debug.Log(result3); if (result3.successful) { DataService.InsertData(new HitData(0, result3.data, DateTime.Now, UnityEngine.Random.insideUnitCircle * 10.0f, UnityEngine.Random.Range(0, 2) == 1, UnityEngine.Random.insideUnitSphere * 10.0f, UnityEngine.Random.insideUnitSphere * 10.0f), result4 => Debug.Log(result4)); DataService.InsertData(new SurveyData(result3.data, "Q1A3"), result4 => Debug.Log(result4)); } }); } }); for (int i = 0; i < applicationSettings.gameSettings.targetCountThreshold.Length; i++) { DataService.InsertData(new TargetCountThresholdData(i, result.data, applicationSettings.gameSettings.targetCountThreshold[i]), x => Debug.Log(x)); } } } ); }