private static void SaveInCloudLC(ModelData data, Action successAction, Action <string> failedAction) { AVObject avData = new AVObject("ServerData"); bool isNewModel = true; if (data.objectId != null && !data.objectId.Equals("")) { avData.ObjectId = data.objectId; isNewModel = false; } avData["name"] = data.name; avData["is_private"] = data.isPrivate; avData["unit_size"] = data.unitSize; avData["cpu_count"] = data.cpuCoresCount; avData["cpu_hz"] = data.cpuHz; avData["hdd_count"] = data.hddBaysCount; avData["memory_speed"] = data.memorySpeed; avData["memory_capacity"] = PairData.ToArrayOfInts(data.memoryCapacity); avData["raid"] = data.raid; avData["hdd"] = PairData.ToArrayOfInts(data.hdd); avData["network"] = PairData.ToArrayOfInts(data.network); avData["gpu"] = data.gpu; avData.SaveAsync().ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) { if (failedAction != null) { var dataString = ""; foreach (var key in t.Exception.Data.Keys) { dataString += t.Exception.Data[key] + "\n"; } failedAction(t.Exception.Message + "\n" + dataString); } } else { if (isNewModel) { var userToServers = new AVObject("UserServers"); userToServers["user"] = AVUser.CurrentUser; userToServers["model"] = avData; userToServers.SaveAsync().ContinueWith(t2 => { if (t2.IsFaulted || t2.IsCanceled) { Debug.Log("User To Servers Failed"); if (failedAction != null) { failedAction(t.Exception.Message); } } else { if (successAction != null) { successAction(); } } }); } else { if (successAction != null) { successAction(); } } } }); }
private static void SaveInCloudP(ModelData data, Action successAction, Action <string> failedAction) { ParseObject parseData = new ParseObject("ServerData"); bool isNewModel = true; if (data.objectId != null && !data.objectId.Equals("")) { parseData.ObjectId = data.objectId; isNewModel = false; } parseData["name"] = data.name; parseData["is_private"] = data.isPrivate; parseData["unit_size"] = data.unitSize; parseData["cpu_count"] = data.cpuCoresCount; parseData["cpu_hz"] = data.cpuHz; parseData["hdd_count"] = data.hddBaysCount; parseData["memory_speed"] = data.memorySpeed; parseData["memory_capacity"] = PairData.ToArrayOfInts(data.memoryCapacity); parseData["raid"] = data.raid; parseData["hdd"] = PairData.ToArrayOfInts(data.hdd); parseData["network"] = PairData.ToArrayOfInts(data.network); parseData["gpu"] = data.gpu; parseData.SaveAsync().ContinueWith(t => { // 1. Save basic data if (t.IsFaulted || t.IsCanceled) { if (failedAction != null) { var dataString = ""; foreach (var key in t.Exception.Data.Keys) { dataString += t.Exception.Data[key] + "\n"; } failedAction(t.Exception.Message + "\n" + dataString); } } else { if (isNewModel) { var userToServers = new ParseObject("UserServers"); userToServers["user"] = ParseUser.CurrentUser; userToServers["model"] = parseData; userToServers.SaveAsync().ContinueWith(t2 => { // 2. Save user information if (t2.IsFaulted || t2.IsCanceled) { Debug.Log("User To Servers Failed"); if (failedAction != null) { failedAction(t2.Exception.Message); } } else { var parts = data.modelPath.Split('.'); var file = new ParseFile("model." + parts[parts.Length - 1], File.ReadAllBytes(data.modelPath)); parseData["model_file"] = file; parseData.SaveAsync().ContinueWith(t3 => { // 3. save model file if (t3.IsFaulted || t3.IsCanceled) { Debug.Log("User To Servers Failed"); if (failedAction != null) { failedAction(t3.Exception.Message); } } else { if (successAction != null) { successAction(); } } }); } }); } else { if (successAction != null) { successAction(); } } } }); }