//发送购买配饰数据 private void SendPetAccessoryOrder() { if (this.actionDatas.Count > 0) { ActionData actionData = this.actionDatas[0]; Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>Header: {0}, Body: {1}, SendTimes: {2}", actionData.Header, actionData.Body, actionData.SendTimes); Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>Url: {0}", this.UrlProvider.BuyPetAccessories(this.LocalChildInfoAgent.getChildSN(), CupBuild.getCupSn())); this.NativeOkHttpMethodWrapper.post(this.UrlProvider.BuyPetAccessories(this.LocalChildInfoAgent.getChildSN(), CupBuild.getCupSn()), actionData.Header, actionData.Body, (result) => { Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>GotResponse: {0}", result); OrderReceipt orderReceipt = this.JsonUtils.String2Json <OrderReceipt>(result); this.OrderReceiptSignal.Dispatch(orderReceipt); if (actionData.OnSuccess != null) { Loom.QueueOnMainThread(() => actionData.OnSuccess(Result.Success(result))); } Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>Success:\n{0}", result); //检查数据 if (this.actionDatas.Count > 0) { this.lastActionData = null; this.actionDatas.RemoveAt(0); //移除已经执行成功的数据 if (this.actionDatas.Count > 0) //执行下一条数据 { this.SendPetAccessoryOrder(); } } }, (errorResult) => { Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>Error: {0}", errorResult.ErrorInfo); if (actionData.OnFailed != null) { Loom.QueueOnMainThread(() => actionData.OnFailed(Result.Error(errorResult.ErrorInfo))); } //检查数据 if (this.actionDatas.Count > 0) { this.lastActionData = null; if (this.actionDatas[0].SendTimes > 0) {//重复上传(最多3次) this.actionDatas[0].SendTimes -= 1; Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>Repeat, SendTimes: {0}, Body: {1}", actionData.SendTimes, actionData.Body); this.SendPetAccessoryOrder(); } else {//3次重传失败放弃 this.actionDatas.RemoveAt(0); Debug.LogFormat("<><PetAccessoryUtils.SendPetAccessoryOrder>Abandon, SendTimes: {0}, Body: {1}", actionData.SendTimes, actionData.Body); } } }); } }
//数据同步 private void SyncUnlockedPets() { if (this.actionDatas.Count > 0) { ActionData actionData = this.actionDatas[0]; Debug.LogFormat("--------UnlockedPetsUtils.SyncUnlockedPets--------Header: {0}, Body: {1}, SendTimes: {2}", actionData.Header, actionData.Body, actionData.SendTimes); mNativeOkHttpMethodWrapper.post(this.UrlProvider.GetUnlockedPets(this.LocalChildInfoAgent.getChildSN(), CupBuild.getCupSn()), actionData.Header, actionData.Body, (result) => { Debug.LogFormat("--------UnlockedPetsUtils.SyncUnlockedPets.GotResponse--------{0}", result); RemotePetsInfo remotePetsInfo = this.JsonUtils.String2Json <RemotePetsInfo>(result); this.LocalUnlockedPetsAgent.SaveUnlockedPets(remotePetsInfo.pets); if (actionData.OnSuccess != null) { Loom.QueueOnMainThread(() => actionData.OnSuccess(Result.Success(result))); } Debug.LogFormat("--------UnlockedPetsUtils.SyncUnlockedPets.Success--------\n{0}", result); //检查数据 if (this.actionDatas.Count > 0) { this.actionDatas.RemoveAt(0); //移除已经执行成功的数据 if (this.actionDatas.Count > 0) //执行下一条数据 { this.SyncUnlockedPets(); } } }, (errorResult) => { Debug.LogFormat("--------UnlockedPetsUtils.SyncUnlockedPets.Error--------{0}", Result.Error(errorResult.ErrorInfo)); if (actionData.OnFailed != null) { Loom.QueueOnMainThread(() => actionData.OnFailed(Result.Error(errorResult.ErrorInfo))); } //检查数据 if (this.actionDatas.Count > 0) { if (this.actionDatas[0].SendTimes > 0) {//重复上传(最多3次) this.actionDatas[0].SendTimes -= 1; Debug.LogFormat("--------UnlockedPetsUtils.SyncUnlockedPets.Repeat--------SendTimes: {0}, Body: {1}", actionData.SendTimes, actionData.Body); this.SyncUnlockedPets(); } else {//3次重传失败放弃 this.actionDatas.RemoveAt(0); Debug.LogFormat("--------UnlockedPetsUtils.SyncUnlockedPets.Abandon--------SendTimes: {0}, Body: {1}", actionData.SendTimes, actionData.Body); } } }); } }