コード例 #1
0
 private async void Delete_Click(object sender, EventArgs e)
 {
     if (contact != null)
     {
         await store.DeleteContactAsync(contact.Id);
     }
     NavigationService.GoBack();
 }
コード例 #2
0
ファイル: Contacts.cs プロジェクト: tecinfoj/contatos
        /// <summary>
        /// Delete Contact
        /// </summary>
        /// <param name="id"></param>
        async private void DeleteContact(string id)
        {
            store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);

            StoredContact contact = await store.FindContactByIdAsync(id);


            await store.DeleteContactAsync(id);
        }
コード例 #3
0
ファイル: Contacts.cs プロジェクト: tecinfoj/contatos
        /// <summary>
        /// Remove Contact
        /// </summary>
        /// <param name="parameters"></param>
        async public void removeContact(string parameters)
        {
            // WP8 does not allow the editing of the contact.  Just return NOT AVAILABLE IN WINDOES PHONE 8 message
            string js = "javascript: var e = document.createEvent('Events');" +
                        "e.initEvent('intel.xdk.contacts.remove',true,true);e.success=false;" +
                        "e.error='NOT AVAILABLE IN WINDOES PHONE 8';document.dispatchEvent(e);";

            //InjectJS("javascript:" + js);
            InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);
            return;


            string[] args = WPCordovaClassLib.Cordova.JSON.JsonHelper.Deserialize <string[]>(parameters);

            string contactId = HttpUtility.UrlDecode(args[0]);

            if (busy == true)
            {
                js = "javascript: var e = document.createEvent('Events');" +
                     "e.initEvent('intel.xdk.contacts.busy',true,true);e.success=false;" +
                     "e.message='busy';document.dispatchEvent(e);";
                //InjectJS(js);
                InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);
                return;
            }

            try{
                ContactStore store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);

                StoredContact contact = await store.FindContactByIdAsync(contactId);

                await store.DeleteContactAsync(contactId);

                getAllContacts();

                js = string.Format("var e = document.createEvent('Events');" +
                                   "e.initEvent('intel.xdk.contacts.remove',true,true);e.success=true;" +
                                   "e.contactid='{0}';document.dispatchEvent(e);", contactId);
                //InjectJS("javascript: "+js);
                InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);

                busy = false;
            }
            catch (Exception e)
            {
                js = string.Format("var e = document.createEvent('Events');" +
                                   "e.initEvent('intel.xdk.contacts.remove',true,true);e.success=false;" +
                                   "e.error='contact not found';e.contactid='{0}';document.dispatchEvent(e);", contactId);
                //InjectJS("javascript: "+errjs);
                InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);

                busy = false;
                return;
            }
        }
コード例 #4
0
ファイル: TelegramSession.cs プロジェクト: mtm9999/kilogram
        private static async void CleanContacts()
        {
            ContactStore store = await ContactStore.CreateOrOpenAsync();

            ContactQueryResult            result   = store.CreateContactQuery();
            IReadOnlyList <StoredContact> contacts = await result.GetContactsAsync();

            foreach (var contact in contacts)
            {
                await store.DeleteContactAsync(contact.Id);
            }
        }
コード例 #5
0
 /// <summary>
 /// 确认删除事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private async void btn_Confirm_Click(object sender, RoutedEventArgs e)
 {
     foreach (var id in selected_ID)
     {
         foreach (StoredContact strContact in conList)
         {
             if (id == strContact.Id)
             {
                 await conStore.DeleteContactAsync(id);
             }
         }
     }
     del_Message.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
     button.Visibility      = Windows.UI.Xaml.Visibility.Visible;
     (Window.Current.Content as Frame).Navigate(typeof(DelContact));
 }
コード例 #6
0
ファイル: MainPage.xaml.cs プロジェクト: jam3st/contacts
        /// <summary>
        /// Updates a contact specified the MyRemoteContact helper object from the contact store.
        /// </summary>
        /// <param name="remoteContact"></param>
        /// <returns></returns>
        public async Task DeleteContacts(ulong revision = 0)
        {
            Debug.WriteLine(String.Format("Getting changes since revision: {0}", revision));
            // Call GetChangesAsync to get all changes since the specified revision.
            var changeList = await contactStore.GetChangesAsync(revision);

            foreach (var change in changeList)
            {
                // Each change record returned contains the change type, remote and local ids, and revision number
                Debug.WriteLine(String.Format("Change Type: {0}\nLocal ID: {1}\nRemote ID: {2}\nRevision Number: {3}",
                                              change.ChangeType.ToString(),
                                              change.Id,
                                              await remoteIdHelper.GetUntaggedRemoteId(contactStore, change.RemoteId),
                                              change.RevisionNumber));
                await contactStore.DeleteContactAsync(change.Id);
            }
        }
コード例 #7
0
        public async Task SyncContactsAsync(List <User> friendsList)
        {
            if (this._synching || this._deleting)
            {
                return;
            }
            this._synching = true;
            friendsList    = friendsList.Take <User>(ContactsManager.MAX_FRIENDS_TO_SYNC).ToList <User>();
            long initiallyLoggedInUser = AppGlobalStateManager.Current.LoggedInUserId;

            try
            {
                SavedContacts savedContacts = await this.GetSavedList();

                List <User>         savedList = savedContacts.SavedUsers;
                Func <User, string> getKey    = (Func <User, string>)(u => u.uid.ToString());

                List <Tuple <User, User> > updatedUsersTuples;
                List <User> createdUsers;
                List <User> deletedUsers;

                ListUtils.GetListChanges <User>(savedList, friendsList, getKey, (Func <User, User, bool>)((u1, u2) =>
                {
                    if (ContactsManager.AreStringsEqualOrNullEmpty(u1.first_name, u2.first_name) && ContactsManager.AreStringsEqualOrNullEmpty(u1.last_name, u2.last_name) && (ContactsManager.AreStringsEqualOrNullEmpty(u1.mobile_phone, u2.mobile_phone) && ContactsManager.AreStringsEqualOrNullEmpty(u1.home_phone, u2.home_phone)) && (ContactsManager.AreStringsEqualOrNullEmpty(u1.site, u2.site) && ContactsManager.AreStringsEqualOrNullEmpty(u1.bdate, u2.bdate)))
                    {
                        return(ContactsManager.AreStringsEqualOrNullEmpty(u1.photo_max, u2.photo_max));
                    }
                    return(false);
                }), out updatedUsersTuples, out createdUsers, out deletedUsers);

                Logger.Instance.Info("ContactsManager got {0} updated users, {1} new users, {2} deleted users", updatedUsersTuples.Count, createdUsers.Count, deletedUsers.Count);
                int totalCountToSync = createdUsers.Count;
                int currentSyncing   = 0;
                if (initiallyLoggedInUser != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts)
                {
                    await this.DoDeleteAllContactsAsync();
                }
                else
                {
                    ContactStore contactStore = await ContactStore.CreateOrOpenAsync();

                    await this.EnsureProvisioned(contactStore);

                    StoredContact meContact = await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(AppGlobalStateManager.Current.GlobalState.LoggedInUser));

                    if (meContact != null)
                    {
                        await this.SetContactProperties(meContact, AppGlobalStateManager.Current.GlobalState.LoggedInUser, (User)null);

                        await meContact.SaveAsync();
                    }
                    contactStore.CreateContactQuery();
                    foreach (Tuple <User, User> tuple in updatedUsersTuples)
                    {
                        User updUser      = tuple.Item2;
                        User originalUser = tuple.Item1;
                        if (initiallyLoggedInUser != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts)
                        {
                            await this.DoDeleteAllContactsAsync();

                            return;
                        }
                        try
                        {
                            StoredContact contact = await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(updUser));

                            await this.SetContactProperties(contact, updUser, originalUser);

                            if (contact != null)
                            {
                                await contact.SaveAsync();
                            }
                            contact = null;
                        }
                        catch (Exception ex)
                        {
                            Logger.Instance.Error("Failed to update contact for user " + updUser.Name, ex);
                        }
                        updUser      = (User)null;
                        originalUser = (User)null;
                    }
                    //List<Tuple<User, User>>.Enumerator enumerator1 = new List<Tuple<User, User>>.Enumerator();
                    foreach (User user in createdUsers)
                    {
                        User newUser = user;
                        ++currentSyncing;
                        if (initiallyLoggedInUser != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts)
                        {
                            await this.DoDeleteAllContactsAsync();

                            return;
                        }
                        try
                        {
                            if (await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(newUser)) == null)
                            {
                                Stopwatch sw = Stopwatch.StartNew();
                                this.FireSyncStatusChanged(currentSyncing, totalCountToSync);
                                Logger.Instance.Info("ContactsManager begin creating user");
                                StoredContact contact = new StoredContact(contactStore);
                                await this.SetContactProperties(contact, newUser, null);

                                await contact.SaveAsync();

                                Logger.Instance.Info("ContactsManager end creating user");
                                sw.Stop();
                                long num = 500L - sw.ElapsedMilliseconds;
                                if (num > 0L)
                                {
                                    await Task.Delay((int)num);
                                }
                                sw      = null;
                                contact = null;
                            }
                            savedList.Add(newUser);
                        }
                        catch (Exception ex)
                        {
                            Logger.Instance.Error("Failed to create contact for user " + newUser.Name, ex);
                        }
                        newUser = null;
                    }
                    //List<User>.Enumerator enumerator2 = new List<User>.Enumerator();
                    foreach (User user in deletedUsers)
                    {
                        User deletedUser = user;
                        if (initiallyLoggedInUser != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts)
                        {
                            await this.DoDeleteAllContactsAsync();

                            return;
                        }
                        try
                        {
                            StoredContact contactByRemoteIdAsync = await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(deletedUser));

                            if (contactByRemoteIdAsync != null)
                            {
                                await contactStore.DeleteContactAsync(contactByRemoteIdAsync.Id);
                            }
                            savedList.Remove(deletedUser);
                        }
                        catch (Exception ex)
                        {
                            Logger.Instance.Error("Failed to delete contact for user " + deletedUser.Name, ex);
                        }
                        deletedUser = null;
                    }
                    //enumerator2 = new List<User>.Enumerator();
                    savedContacts.SyncedDate = DateTime.UtcNow;
                    await this.EnsurePersistSavedContactsAsync();

                    savedContacts      = null;
                    savedList          = null;
                    deletedUsers       = null;
                    createdUsers       = null;
                    updatedUsersTuples = null;
                    contactStore       = null;
                    meContact          = null;
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error("Failed to sync contacts. ", ex);
            }
            finally
            {
                this._synching = false;
                this.FireSyncStatusChanged(0, 0);
            }
        }
コード例 #8
0
        public async Task SyncContactsAsync(List <User> friendsList)
        {
            if (!this._synching && !this._deleting)
            {
                this._synching = true;
                friendsList    = Enumerable.ToList <User>(Enumerable.Take <User>(friendsList, ContactsManager.MAX_FRIENDS_TO_SYNC));
                long loggedInUserId = AppGlobalStateManager.Current.LoggedInUserId;
                try
                {
                    SavedContacts savedContacts = await this.GetSavedList();

                    SavedContacts       savedContacts2 = savedContacts;
                    List <User>         list           = savedContacts2.SavedUsers;
                    List <User>         arg_1E7_0      = list;
                    List <User>         arg_1E7_1      = friendsList;
                    Func <User, string> arg_1E7_2      = new Func <User, string>((u) => { return(u.uid.ToString()); });

                    Func <User, User, bool> arg_1E7_3 = new Func <User, User, bool>((u1, u2) =>
                    {
                        return(ContactsManager.AreStringsEqualOrNullEmpty(u1.first_name, u2.first_name) && ContactsManager.AreStringsEqualOrNullEmpty(u1.last_name, u2.last_name) && ContactsManager.AreStringsEqualOrNullEmpty(u1.mobile_phone, u2.mobile_phone) && ContactsManager.AreStringsEqualOrNullEmpty(u1.home_phone, u2.home_phone) && ContactsManager.AreStringsEqualOrNullEmpty(u1.site, u2.site) && ContactsManager.AreStringsEqualOrNullEmpty(u1.bdate, u2.bdate) && ContactsManager.AreStringsEqualOrNullEmpty(u1.photo_max, u2.photo_max));
                    });

                    List <Tuple <User, User> > list2;
                    List <User> list3;
                    List <User> list4;
                    ListUtils.GetListChanges <User>(arg_1E7_0, arg_1E7_1, arg_1E7_2, arg_1E7_3, out list2, out list3, out list4);
                    Logger.Instance.Info("ContactsManager got {0} updated users, {1} new users, {2} deleted users", new object[]
                    {
                        list2.Count,
                        list3.Count,
                        list4.Count
                    });
                    int count = list3.Count;
                    int num   = 0;
                    if (loggedInUserId != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts)
                    {
                        await this.DoDeleteAllContactsAsync();
                    }
                    else
                    {
                        ContactStore contactStore = await ContactStore.CreateOrOpenAsync();

                        await this.EnsureProvisioned(contactStore);

                        StoredContact storedContact = await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(AppGlobalStateManager.Current.GlobalState.LoggedInUser));

                        if (storedContact != null)
                        {
                            await this.SetContactProperties(storedContact, AppGlobalStateManager.Current.GlobalState.LoggedInUser, null);

                            await storedContact.SaveAsync();
                        }
                        contactStore.CreateContactQuery();
                        List <Tuple <User, User> > .Enumerator enumerator = list2.GetEnumerator();
                        //int num2;
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                Tuple <User, User> var_8_57F = enumerator.Current;
                                User user         = var_8_57F.Item2;
                                User originalUser = var_8_57F.Item1;
                                if (loggedInUserId != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts)
                                {
                                    await this.DoDeleteAllContactsAsync();

                                    return;
                                }
                                try
                                {
                                    StoredContact storedContact2 = await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(user));

                                    await this.SetContactProperties(storedContact2, user, originalUser);

                                    if (storedContact2 != null)
                                    {
                                        await storedContact2.SaveAsync();
                                    }
                                    storedContact2 = null;
                                }
                                catch (Exception var_9_7B5)
                                {
                                    Logger.Instance.Error("Failed to update contact for user " + user.Name, var_9_7B5);
                                }
                                user         = null;
                                originalUser = null;
                            }
                        }
                        finally
                        {
                            //if (num2 < 0)
                            //{
                            enumerator.Dispose();
                            //}
                        }
                        enumerator = default(List <Tuple <User, User> > .Enumerator);
                        List <User> .Enumerator enumerator2 = list3.GetEnumerator();
                        try
                        {
                            while (enumerator2.MoveNext())
                            {
                                User user2 = enumerator2.Current;
                                num++;
                                if (loggedInUserId != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts)
                                {
                                    await this.DoDeleteAllContactsAsync();

                                    return;
                                }
                                try
                                {
                                    if (await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(user2)) == null)//todo:bug?
                                    {
                                        Stopwatch stopwatch = Stopwatch.StartNew();
                                        this.FireSyncStatusChanged(num, count);
                                        Logger.Instance.Info("ContactsManager begin creating user", new object[0]);
                                        StoredContact storedContact3 = new StoredContact(contactStore);
                                        await this.SetContactProperties(storedContact3, user2, null);

                                        await storedContact3.SaveAsync();

                                        Logger.Instance.Info("ContactsManager end creating user", new object[0]);
                                        stopwatch.Stop();
                                        long var_11_AF3 = 500L - stopwatch.ElapsedMilliseconds;
                                        if (var_11_AF3 > 0L)
                                        {
                                            await Task.Delay((int)var_11_AF3);
                                        }
                                        stopwatch      = null;
                                        storedContact3 = null;
                                    }
                                    list.Add(user2);
                                }
                                catch (Exception var_12_B82)
                                {
                                    Logger.Instance.Error("Failed to create contact for user " + user2.Name, var_12_B82);
                                }
                                user2 = null;
                            }
                        }
                        finally
                        {
                            //if (num2 < 0)
                            //{
                            enumerator2.Dispose();
                            //}
                        }
                        enumerator2 = default(List <User> .Enumerator);
                        enumerator2 = list4.GetEnumerator();
                        try
                        {
                            while (enumerator2.MoveNext())
                            {
                                User user3 = enumerator2.Current;
                                if (loggedInUserId != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts)
                                {
                                    await this.DoDeleteAllContactsAsync();

                                    return;
                                }
                                try
                                {
                                    StoredContact var_13_D35 = await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(user3));

                                    if (var_13_D35 != null)
                                    {
                                        await contactStore.DeleteContactAsync(var_13_D35.Id);
                                    }
                                    list.Remove(user3);
                                }
                                catch (Exception var_14_DBF)
                                {
                                    Logger.Instance.Error("Failed to delete contact for user " + user3.Name, var_14_DBF);
                                }
                                user3 = null;
                            }
                        }
                        finally
                        {
                            //if (num2 < 0)
                            //{
                            enumerator2.Dispose();
                            //}
                        }
                        enumerator2 = default(List <User> .Enumerator);
                        savedContacts2.SyncedDate = DateTime.UtcNow;
                        await this.EnsurePersistSavedContactsAsync();

                        savedContacts2 = null;
                        list           = null;
                        list4          = null;
                        list3          = null;
                        list2          = null;
                        contactStore   = null;
                        storedContact  = null;
                    }
                }
                catch (Exception var_15_ECB)
                {
                    Logger.Instance.Error("Failed to sync contacts. ", var_15_ECB);
                }
                finally
                {
                    //int num2;
                    //if (num2 < 0)
                    //{
                    this._synching = false;
                    this.FireSyncStatusChanged(0, 0);
                    //}
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Invoke the method specified by the
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </summary>
        /// <param name="message">
        /// <see cref="CloudPact.MowblyFramework.Core.Features.JSMessage">JSMessage</see> object
        /// </param>
        internal async override void InvokeAsync(JSMessage message)
        {
            string        callbackId = message.CallbackId;
            List <string> properties = null;

            try
            {
                switch (message.Method)
                {
                case "callContact":

                    Logger.Info("Calling contact...");

                    // Get the phone number
                    string phonenumber = message.Args[0] as string;

                    // Create and show the PhoneCall task
                    PhoneCallTask phoneCallTask = new PhoneCallTask();
                    phoneCallTask.PhoneNumber = phonenumber;
                    UiDispatcher.BeginInvoke(() =>
                    {
                        phoneCallTask.Show();
                    });

                    // Set app navigated to external page
                    Mowbly.AppNavigatedToExternalPage = true;
                    break;

                case "deleteContact":

                    Logger.Info("Deleting contact...");

                    string contactId = message.Args[0] as string;

                    try
                    {
                        ContactStore contactStore = await ContactStore.CreateOrOpenAsync(
                            ContactStoreSystemAccessMode.ReadWrite,
                            ContactStoreApplicationAccessMode.ReadOnly);

                        await contactStore.DeleteContactAsync(contactId);

                        InvokeCallbackJavascript(callbackId, new MethodResult {
                            Result = true
                        });
                    }
                    catch (Exception e)
                    {
                        string error = String.Concat(
                            Mowbly.GetString(Constants.STRING_CONTACT_DELETE_ERROR),
                            e.Message);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code  = MethodResult.FAILURE_CODE,
                            Error = new MethodError
                            {
                                Message = error
                            }
                        });
                    }
                    break;

                case "findContact":

                    // Read args
                    string filter  = message.Args[0] as string;
                    JToken options = message.Args[1] as JToken;
                    properties = options["properties"].ToObject <List <string> >();
                    double limit = (double)options["limit"];

                    Logger.Info("Searching contacts for " + filter);

                    // Contacts search results handler
                    EventHandler <MowblyContactsSearchEventArgs> OnContactsSearchCompleted = null;
                    OnContactsSearchCompleted = (sender, e) =>
                    {
                        if (e.Status)
                        {
                            // Notify result to JS
                            InvokeCallbackJavascript(message.CallbackId, new MethodResult {
                                Result = e.W3Contacts
                            });
                        }
                        else
                        {
                            InvokeCallbackJavascript(message.CallbackId, new MethodResult {
                                Result = null
                            });
                        }
                    };

                    if (Regex.IsMatch(filter, @"^[0-9()-]+$"))
                    {
                        // Only numbers, search by phone number
                        SearchContactInUserDataAsync(filter, OnContactsSearchCompleted, true, FilterKind.PhoneNumber, limit, properties);
                    }
                    else
                    {
                        // Search by display name
                        SearchContactInUserDataAsync(filter, OnContactsSearchCompleted, true, FilterKind.DisplayName, limit, properties);
                    }
                    break;

                case "pickContact":


                    properties = ((JToken)message.Args[0]).ToObject <List <string> >();
                    ContactChooserTask contactChooserTask = new ContactChooserTask(callbackId);
                    EventHandler <ContactChooserTaskEventArgs> OnContactChooserTaskCompleted = null;
                    OnContactChooserTaskCompleted = (sender, e) =>
                    {
                        // Unsubscribe
                        contactChooserTask.OnCompleted -= OnContactChooserTaskCompleted;

                        // Notify result to JS
                        if (e.Contact != null)
                        {
                            W3Contact contact = new W3Contact(e.Contact, properties);
                            InvokeCallbackJavascript(e.CallbackId, new MethodResult {
                                Result = contact
                            });
                        }
                        else
                        {
                            InvokeCallbackJavascript(e.CallbackId, new MethodResult
                            {
                                Code  = MethodResult.FAILURE_CODE,
                                Error = new MethodError
                                {
                                    Message = Mowbly.GetString(Constants.STRING_ACTIVITY_CANCELLED)
                                }
                            });
                        }
                    };

                    // Subscribe to OnCompleted event
                    contactChooserTask.OnCompleted += OnContactChooserTaskCompleted;

                    // Show contact chooser task
                    UiDispatcher.BeginInvoke(() =>
                    {
                        try
                        {
                            contactChooserTask.Show();
                        }
                        catch (Exception e)
                        {
                            // Might fail at times since navigation is not allowed when task is not in foreground
                            string error = String.Concat(Mowbly.GetString(Constants.STRING_CONTACT_CHOOSE_FAILED), e.Message);
                            Logger.Error(error);
                            InvokeCallbackJavascript(callbackId, new MethodResult
                            {
                                Code  = MethodResult.FAILURE_CODE,
                                Error = new MethodError
                                {
                                    Message = error
                                }
                            });
                        }
                    });
                    break;

                case "saveContact":

                    try
                    {
                        // Create W3Contact object from JS contact
                        W3Contact w3Contact       = JsonConvert.DeserializeObject <W3Contact>(message.Args[0].ToString());
                        string    storedContactId = await w3Contact.SaveToNativeContactStore();

                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Result = storedContactId
                        });
                    }
                    catch (Exception e)
                    {
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_CONTACT_SAVE_FAILED), e.Message);
                        Logger.Error(error);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code  = MethodResult.FAILURE_CODE,
                            Error = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                case "viewContact":

                    // Get the param and type
                    string id = message.Args[0] as string;
                    Tuple <string, string> paramAndType = await GetSearchParamAndType(id);

                    if (paramAndType != null)
                    {
                        string            param             = paramAndType.Item1;
                        string            type              = paramAndType.Item2;
                        ContactViewerTask contactViewerTask = new ContactViewerTask(param, type);

                        // Show contact viewer task
                        UiDispatcher.BeginInvoke(() =>
                        {
                            try
                            {
                                contactViewerTask.Show();
                            }
                            catch (Exception e)
                            {
                                // Might fail at times since navigation is not allowed when task is not in foreground
                                string error = String.Concat(Mowbly.GetString(Constants.STRING_CONTACT_VIEW_FAILED), e.Message);
                                Logger.Error(error);
                                InvokeCallbackJavascript(callbackId, new MethodResult
                                {
                                    Code  = MethodResult.FAILURE_CODE,
                                    Error = new MethodError
                                    {
                                        Message = error
                                    }
                                });
                            }
                        });
                    }
                    else
                    {
                        string error = String.Concat(Mowbly.GetString(Constants.STRING_CONTACT_VIEW_FAILED),
                                                     Mowbly.GetString(Constants.STRING_CONTACT_NOT_FOUND));
                        Logger.Error(error);
                        InvokeCallbackJavascript(callbackId, new MethodResult
                        {
                            Code  = MethodResult.FAILURE_CODE,
                            Error = new MethodError
                            {
                                Message = error
                            }
                        });
                    }

                    break;

                default:
                    Logger.Error("Feature " + Name + " does not support method " + message.Method);
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.Error("Exception occured. Reason - " + e.Message);
            }
        }