예제 #1
0
                /// <summary>
                /// Gets a managed operation result for a specific operation handle.
                /// </summary>
                /// <param name="handle">Handle to a specific operation.</param>
                /// <param name="result">Managed operation result.</param>
                /// <returns>
                /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if any of the parameters are invalid.
                /// MLResult.Result will be <c>MLResult.Code.Pending</c> if the request is still pending.
                /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if the operation failed with an unspecified error.
                /// MLResult.Result will be <c>MLResult.Code.ContactsCompleted</c> if the request is completed.
                /// MLResult.Result will be <c>MLResult.Code.ContactsHandleNotFound</c> if the request corresponding to the handle was not found.
                /// </returns>
                public static MLResult.Code GetManagedOperationResult(ulong handle, out MLContacts.OperationResult result)
                {
                    MLResult.Code resultCode = NativeBindings.MLContactsTryGetOperationResult(handle, out IntPtr operationResultPtr);
                    if (resultCode != MLResult.Code.Pending)
                    {
                        if (resultCode != MLResult.Code.ContactsCompleted)
                        {
                            MLPluginLog.ErrorFormat("NativeBindings.GetManagedOperationResult failed to get operation result. Reason: {0}", MLResult.CodeToString(resultCode));
                        }

                        NativeBindings.OperationResultNative internalResult  = (NativeBindings.OperationResultNative)Marshal.PtrToStructure(operationResultPtr, typeof(NativeBindings.OperationResultNative));
                        NativeBindings.ContactNative         internalContact = (NativeBindings.ContactNative)Marshal.PtrToStructure(internalResult.Contact, typeof(NativeBindings.ContactNative));

                        result = new MLContacts.OperationResult()
                        {
                            Status  = internalResult.Status,
                            Contact = internalContact.Data,
                        };
                    }
                    else
                    {
                        result = new MLContacts.OperationResult();
                    }

                    return(resultCode);
                }
예제 #2
0
        /// <summary>
        /// Handler when Contacts API fails any operation.
        /// </summary>
        /// <param name="operationResult">Result of the operation.</param>
        /// <param name="requestHandle">Handle of the request.</param>
        private void HandleOnOperationFailed(MLContacts.OperationResult operationResult, ulong requestHandle)
        {
            string reason = "Unspecified failure";

            switch (operationResult.Status)
            {
            case MLContacts.OperationStatus.Duplicate:
                reason = "A contact, with the same details, already exist.";
                break;

            case MLContacts.OperationStatus.Fail:
                reason = "An internal error has occurred.";
                break;

            case MLContacts.OperationStatus.NotFound:
                reason = "The contact does not exist.";
                break;

            case MLContacts.OperationStatus.Success:
                // this case should never be reached in this callback.
                break;
            }

            Debug.LogErrorFormat("Error: ContactsExample encountered an error from an operation. {0}", reason);
            Log(string.Format("Operation Failed. {0}", reason));
        }
예제 #3
0
 /// <summary>
 /// Handler when Contacts API successfully adds a new contact.
 /// This is called from the add/edit contact page.
 /// </summary>
 /// <param name="operationResult">Result of the operation.</param>
 /// <param name="requestHandle">Handle of the request.</param>
 private void HandleOnContactAdded(MLContacts.OperationResult operationResult, ulong requestHandle)
 {
     _contactPage.Populate(operationResult.Contact);
     _needToReloadContacts = true;
 }
예제 #4
0
 /// <summary>
 /// Handler when Contacts API successfully removes a contact.
 /// This is called from the list contacts page.
 /// </summary>
 /// <param name="operationResult">Result of the operation.</param>
 /// <param name="requestHandle">Handle of the request.</param>
 private void HandleOnContactDeleted(MLContacts.OperationResult operationResult, ulong requestHandle)
 {
     _contacts.LoadContactsFromAPI();
 }
예제 #5
0
 /// <summary>
 /// Handler when Contacts API successfully adds a new contact.
 /// This is called from the add/edit contact page.
 /// </summary>
 /// <param name="operationResult">Result of the operation.</param>
 /// <param name="requestHandle">Handle of the request.</param>
 private void HandleOnContactAdded(MLContacts.OperationResult operationResult, ulong requestHandle)
 {
     Log("Contact added");
 }