async private void Login_Click(object sender, RoutedEventArgs e)
        {
            //// Do sign-in logic here and store your authentication token using the AppSettings class
            App.MyAppSettings.AuthTokenSetting = ServerApi.GetAuthTokenFromWebService();
            App.MyAppSettings.UserIdSetting    = ServerApi.GetUserIdFromWebService();

            // log existing bindings
            {
                ContactBindingManager manager = await ContactBindings.GetAppContactBindingManagerAsync();

                foreach (ContactBinding binding in await manager.GetContactBindingsAsync())
                {
                    Logger.Log("MainPage", "existing binding = " + binding.RemoteId);
                }
            }

            // Add contact bindings for every contact information that we get from the web service
            // This bindings will be automatically linked to existent phone contacts.
            // The auto-linking is based on name, email or phone numbers match.
            await CreateContactBindingsAsync();

            // log new bindings
            {
                ContactBindingManager manager = await ContactBindings.GetAppContactBindingManagerAsync();

                foreach (ContactBinding binding in await manager.GetContactBindingsAsync())
                {
                    Logger.Log("MainPage", "binding = " + binding.RemoteId);
                }
            }

            MessageBox.Show("Done!");
        }
        private async Task CreateContactBindingsAsync()
        {
            ContactBindingManager bindingManager = await ContactBindings.GetAppContactBindingManagerAsync();

            // Simulate call to web service
            List <ServerApi.ContactBinding> bindings = ServerApi.GetContactsFromWebServiceAsync();

            foreach (ServerApi.ContactBinding binding in bindings)
            {
                ContactBinding myBinding = bindingManager.CreateContactBinding(binding.RemoteId);

                // This information is not displayed on the Contact Page in the People Hub app, but
                // is used to automatically link the contact binding with existent phone contacts.
                // Add as much information as possible for the ContactBinding to increase the
                // chances to find a matching Contact on the phone.
                myBinding.FirstName     = binding.GivenName;
                myBinding.LastName      = binding.FamilyName;
                myBinding.EmailAddress1 = binding.Email;
                myBinding.Name          = binding.CodeName;

                // Don't crash if one binding fails, log the error and continue saving
                try
                {
                    await bindingManager.SaveContactBindingAsync(myBinding);
                }
                catch (Exception e)
                {
                    Logger.Log("MainPage", "Binding (" + binding.RemoteId + ") failed to save. " + e.Message);
                }
            }
        }
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        /// <param name="task">
        /// The invoked task
        /// </param>
        /// <remarks>
        /// This method is called when a periodic or resource intensive task is invoked
        /// </remarks>
        async protected override void OnInvoke(ScheduledTask task)
        {
            Logger.Log("Agent", "- - - - - - - - - - - - -");
            Logger.Log("Agent", "Agent invoked -> " + task.Name);

            this.contactBindingManager = await ContactBindings.GetAppContactBindingManagerAsync();

            // Use the name of the task to differentiate between the ExtensilityTaskAgent
            // and the ScheduledTaskAgent
            if (task.Name == "ExtensibilityTaskAgent")
            {
                List <Task> inprogressOperations = new List <Task>();

                OperationQueue operationQueue = await SocialManager.GetOperationQueueAsync();

                ISocialOperation socialOperation = await operationQueue.GetNextOperationAsync();

                while (null != socialOperation)
                {
                    Logger.Log("Agent", "Dequeued an operation of type " + socialOperation.Type.ToString());

                    try
                    {
                        switch (socialOperation.Type)
                        {
                        case SocialOperationType.DownloadRichConnectData:
                            await ProcessOperationAsync(socialOperation as DownloadRichConnectDataOperation);

                            break;

                        default:
                            // This should never happen
                            HandleUnknownOperation(socialOperation);
                            break;
                        }

                        // The agent can only use up to 20 MB
                        // Logging the memory usage information for debugging purposes
                        Logger.Log("Agent", string.Format("Completed operation {0}, memusage: {1}kb/{2}kb",
                                                          socialOperation.ToString(),
                                                          (int)((long)DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage")) / 1024,
                                                          (int)((long)DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage")) / 1024));


                        // This can block for up to 1 minute. Don't expect to run instantly every time.
                        socialOperation = await operationQueue.GetNextOperationAsync();
                    }
                    catch (Exception e)
                    {
                        Helpers.HandleException(e);
                    }
                }

                Logger.Log("Agent", "No more operations in the queue");
            }

            NotifyComplete();
        }
Beispiel #4
0
        public async static void ClearContactData()
        {
            ContactBindingManager bindingManager = await ContactBindings.GetAppContactBindingManagerAsync();

            ContactStore store = await ContactStore.CreateOrOpenAsync();

            await store.DeleteAsync();

            await bindingManager.DeleteAllContactBindingsAsync();
        }
        async private void Logout_Click(object sender, RoutedEventArgs e)
        {
            ContactBindingManager bindingManager = await ContactBindings.GetAppContactBindingManagerAsync();

            await bindingManager.DeleteAllContactBindingsAsync();

            // Do sign-out logic here and clear the authentication token using the AppSettings class
            App.MyAppSettings.AuthTokenSetting = "";
            App.MyAppSettings.UserIdSetting    = "";

            MessageBox.Show("Done!");
        }
Beispiel #6
0
        public async void CreateContactBindingsAsync()
        {
            ContactBindingManager bindingManager = await ContactBindings.GetAppContactBindingManagerAsync();

            // Simulate call to web service
            TraktProfile[] profiles = await userDao.getUserFriends();

            ContactStore store = await ContactStore.CreateOrOpenAsync();

            foreach (TraktProfile profile in profiles)
            {
                ContactBinding myBinding = bindingManager.CreateContactBinding(profile.Username);

                if (!String.IsNullOrEmpty(profile.Name))
                {
                    if (profile.Name.Contains(" "))
                    {
                        Regex    regex     = new Regex(@"\s");
                        String[] nameSplit = regex.Split(profile.Name);

                        myBinding.FirstName = nameSplit[0];
                        myBinding.LastName  = nameSplit[1];
                    }
                    else
                    {
                        myBinding.LastName = profile.Name;
                    }
                }

                try
                {
                    if (!String.IsNullOrEmpty(profile.Name) && profile.Name.Contains(" "))
                    {
                        Regex    regex     = new Regex(@"\s");
                        String[] nameSplit = regex.Split(profile.Name);

                        AddContact(profile.Username, nameSplit[0], nameSplit[1], profile.Username, profile.Avatar, profile.Url);
                    }
                    else
                    {
                        AddContact(profile.Username, "", "", profile.Username, profile.Avatar, profile.Url);
                    }
                    await bindingManager.SaveContactBindingAsync(myBinding);
                }
                catch (Exception e)
                {
                    Console.Write(e.InnerException);
                }
            }
        }
Beispiel #7
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string[] uri = e.Uri.ToString().Split('=');

            if (uri.Length > 1)
            {
                bindingId = Uri.UnescapeDataString(uri[2]);
            }

            contactBindingManager = await ContactBindings.GetAppContactBindingManagerAsync();

            EntityList.ItemsSource = await contactBindingManager.GetContactBindingsAsync();

            EntityList.SelectionChanged += EntityList_SelectionChanged;
        }
        private async Task <bool> ProcessConnectData(DownloadRichConnectDataOperation downloadRichConnectDataOperation)
        {
            ContactBindingManager store = await ContactBindings.GetAppContactBindingManagerAsync();

            ContactStore contactStore = await ContactStore.CreateOrOpenAsync();

            foreach (string id in (IEnumerable <string>)downloadRichConnectDataOperation.Ids)
            {
                string remoteId = id;
                try
                {
                    string         title          = (await contactStore.FindContactByRemoteIdAsync(remoteId)).DisplayName;
                    ContactBinding contactBinding = await store.GetContactBindingByRemoteIdAsync(remoteId);

                    ConnectTileData connectTileData = new ConnectTileData();
                    connectTileData.Title = title;
                    BackendResult <PhotosListWithCount, ResultCode> profilePhotos = await PhotosService.Current.GetProfilePhotos(RemoteIdHelper.GetItemIdByRemoteId(remoteId), 0, 3);

                    if (profilePhotos.ResultCode == ResultCode.Succeeded)
                    {
                        for (int index = 0; index < Math.Min(3, profilePhotos.ResultData.response.Count); ++index)
                        {
                            Photo            photo            = profilePhotos.ResultData.response[index];
                            ConnectTileImage connectTileImage = new ConnectTileImage();
                            connectTileImage.ImageUrl = photo.src_big;
                            ((ICollection <ConnectTileImage>)connectTileData.Images).Add(connectTileImage);
                        }
                    }
                    contactBinding.TileData = connectTileData;
                    await store.SaveContactBindingAsync(contactBinding);

                    title           = null;
                    contactBinding  = null;
                    connectTileData = null;
                }
                catch (Exception ex)
                {
                    Logger.Instance.Error("ProcessConnectData failed", ex);
                }
                remoteId = null;
            }
            return(true);
        }
Beispiel #9
0
        async protected override void OnInvoke(ScheduledTask task)
        {
            //TODO: Add code to perform your task in background
            if (task is PeriodicTask && !task.Name.Equals("ExtensibilityTaskAgent"))
            {
                CreateTile();
            }
            else
            {
                this.contactBindingManager = await ContactBindings.GetAppContactBindingManagerAsync();

                // Use the name of the task to differentiate between the ExtensilityTaskAgent
                // and the ScheduledTaskAgent
                if (task.Name == "ExtensibilityTaskAgent")
                {
                    List <Task> inprogressOperations = new List <Task>();

                    OperationQueue operationQueue = await SocialManager.GetOperationQueueAsync();

                    ISocialOperation socialOperation = await operationQueue.GetNextOperationAsync();

                    while (null != socialOperation)
                    {
                        try
                        {
                            switch (socialOperation.Type)
                            {
                            case SocialOperationType.DownloadRichConnectData:
                                await ProcessOperationAsync(socialOperation as DownloadRichConnectDataOperation);

                                break;
                            }

                            socialOperation = await operationQueue.GetNextOperationAsync();
                        }
                        catch (Exception e)
                        {
                        }
                    }
                }
            }
        }
Beispiel #10
0
        private async void Grid_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            ListItemViewModel model = (ListItemViewModel)((Grid)sender).DataContext;

            String id;

            NavigationContext.QueryString.TryGetValue("id", out id);

            if (!String.IsNullOrEmpty(id))
            {
                ContactBindingManager bindingManager = await ContactBindings.GetAppContactBindingManagerAsync();

                ContactBinding entity = await bindingManager.GetContactBindingByRemoteIdAsync(model.Name);;

                await bindingManager.CreateContactBindingTileAsync(id, entity);

                NavigationService.Navigate(new Uri("/Friend.xaml?friendid=" + model.Name + "&assigned=true" + "&isKnown=true", UriKind.Relative));
            }
            else
            {
                Animation.NavigateToFadeOut(this, LayoutRoot, new Uri("/Friend.xaml?friendid=" + model.Name + "&isKnown=true", UriKind.Relative));
            }
        }