public static void RequestVoucherPackages(this PublisherDatabase database, IPublisherAPI api, Action <RequestResponse <VoucherPackage[]> > onCompleted = null) { api.GetVoucherPackages(api.Session.publisher, (r, result) => { RequestResponse <VoucherPackage[]> requestResponse = new RequestResponse <VoucherPackage[]>() { context = database, ok = false, error = null, result = null }; if (DataStructureExtension.CheckRequest(r, result, requestResponse) == true) { VoucherPackagesContainer container = JsonUtility.FromJson <VoucherPackagesContainer>(result.Replace("],[", ",").Replace("[[", "[").Replace("]]", "]")); if (Conf.DebugMode == Conf.DebugState.Verbose) { InternalNGDebug.Snapshot(container); } VoucherPackage[] packages = new VoucherPackage[container.aaData.Length >> 1]; for (int i = 0, max = container.aaData.Length; i < max; i += 2) { packages[i >> 1] = new VoucherPackage() { packageId = int.Parse(container.aaData[i]), packageName = container.aaData[i + 1], }; } requestResponse.ok = true; requestResponse.result = packages; database.VoucherPackages = requestResponse.result; } if (onCompleted != null) { onCompleted(requestResponse); } }); }
public bool HasPackageVouchers(Package package) { if (this.voucherPackages == null) { return(false); } for (int i = 0, max = this.voucherPackages.Length; i < max; ++i) { VoucherPackage voucherPackage = this.voucherPackages[i]; if (voucherPackage.packageId == package.id) { return(true); } } return(false); }