/// <summary> /// Gets an update for the request. /// </summary> protected void Update() { if (this.Status == PageStatus.Pending) { MLResult.Code resultCode = MLContacts.GetListResult(this.RequestHandle, out this.listResult); switch (resultCode) { case MLResult.Code.ContactsHandleNotFound: case MLResult.Code.InvalidParam: { this.PageFailed(resultCode); } break; case MLResult.Code.ContactsCompleted: { this.PageReady(); } break; case MLResult.Code.Pending: default: break; } } }
/// <summary> /// Handles a page request failure. /// </summary> /// <param name="resultCode">The result of the request.</param> private void PageFailed(MLResult.Code resultCode) { this.Status = PageStatus.Failed; MLContacts.ReleaseRequest(this.RequestHandle); this.RequestHandle = MagicLeapNativeBindings.InvalidHandle; this.PageFailedAction?.Invoke(this, MLResult.Create(resultCode)); this.UnregisterUpdate = false; MLDevice.Unregister(this.Update); }
/// <summary> /// Request a new page /// </summary> /// <param name="pageLength">The length of the page</param> /// <param name="offset">Offset into the page</param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successfully submitted /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if either of the parameters are invalid. /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if necessary privilege is missing. /// </returns> protected virtual MLResult InternalNewPage(uint pageLength, string offset) { MLResult.Code resultCode = MLContacts.GetList(pageLength, offset, out ulong handle); this.RequestHandle = handle; if (resultCode != MLResult.Code.Ok) { this.Status = PageStatus.Failed; return(MLResult.Create(resultCode)); } this.Status = PageStatus.Pending; MLDevice.Register(this.Update); this.UnregisterUpdate = true; return(MLResult.Create(MLResult.Code.Ok)); }
/// <summary> /// Handles a page being ready. /// </summary> private void PageReady() { this.Status = PageStatus.Ready; if (this.listResult.Offset == null) { this.nextPageOffset = string.Empty; this.Status = PageStatus.LastPage; } else { this.nextPageOffset = string.Copy(this.listResult.Offset); } MLContacts.ReleaseRequest(this.RequestHandle); this.RequestHandle = MagicLeapNativeBindings.InvalidHandle; this.PageReadyAction?.Invoke(this); this.TotalHits = this.listResult.TotalHits; this.UnregisterUpdate = false; MLDevice.Unregister(this.Update); }
/// <summary> /// Provides the string value for any MLResult.Code. /// </summary> /// <param name="resultCode">The code to convert into a string value.</param> /// <returns>The string value of the given MLResult.Code.</returns> public static string CodeToString(MLResult.Code resultCode) { string codeString = string.Empty; switch ((CodePrefix)((int)resultCode >> 16)) { case CodePrefix.MLResultGlobal: case CodePrefix.MLSnapshotResult: codeString = Marshal.PtrToStringAnsi(MagicLeapNativeBindings.MLSnapshotGetResultString(resultCode)); break; case CodePrefix.MLAudioResult: codeString = Marshal.PtrToStringAnsi(MLAudio.GetResultString(resultCode)); break; case CodePrefix.MLMediaDRMResult: case CodePrefix.MLMediaGenericResult: case CodePrefix.MLMediaPlayerResult: case CodePrefix.MLMediaResult: codeString = Marshal.PtrToStringAnsi(MLMediaPlayer.GetResultString(resultCode)); break; case CodePrefix.MLDispatchResult: codeString = Marshal.PtrToStringAnsi(MLDispatch.GetResultString(resultCode)); break; case CodePrefix.MLIdentityResult: codeString = Marshal.PtrToStringAnsi(MLIdentity.GetResultString(resultCode)); break; case CodePrefix.MLPassableWorldResult: codeString = Marshal.PtrToStringAnsi(MLPersistentCoordinateFrames.GetResultString(resultCode)); break; case CodePrefix.MLTokenAgentResult: codeString = Marshal.PtrToStringAnsi(MLTokenAgent.GetResultString(resultCode)); break; case CodePrefix.MLPrivilegesResult: codeString = Marshal.PtrToStringAnsi(MLPrivileges.GetResultString(resultCode)); break; case CodePrefix.MLContactsResult: codeString = Marshal.PtrToStringAnsi(MLContacts.GetResultString(resultCode)); break; case CodePrefix.MLLocationResult: codeString = Marshal.PtrToStringAnsi(MLLocation.GetResultString(resultCode)); break; case CodePrefix.MLNetworkingResult: codeString = Marshal.PtrToStringAnsi(MLNetworkingNativeBindings.MLNetworkingGetResultString(resultCode)); break; case CodePrefix.MLMovementResult: codeString = Marshal.PtrToStringAnsi(MLMovement.GetResultString(resultCode)); break; case CodePrefix.MLConnectionsResult: codeString = Marshal.PtrToStringAnsi(MLConnections.GetResultString(resultCode)); break; case CodePrefix.MLSecureStorageResult: codeString = Marshal.PtrToStringAnsi(MLSecureStorageNativeBindings.MLSecureStorageGetResultString(resultCode)); break; case CodePrefix.MLAppConnect: codeString = Marshal.PtrToStringAnsi(MLAppConnectNativeBindings.MLAppConnectGetResultString(resultCode)); break; case CodePrefix.MLWebRTC: codeString = Marshal.PtrToStringAnsi(MLWebRTC.NativeBindings.MLWebRTCGetResultString(resultCode)); break; case CodePrefix.MLBluetoothGattResult: codeString = Marshal.PtrToStringAnsi(MLBluetoothLE.NativeBindings.MLBluetoothGattGetResultString(resultCode)); break; default: // This will catch any unknown/invalid return values. codeString = MagicLeapNativeBindings.MLGetResultString(resultCode); break; } return(codeString); }