Пример #1
0
        private async void Fix_Click(object sender, RoutedEventArgs e)
        {
            // only one instance of the UserDataAccountManager pane can be launched at once per thread
            if (isLaunched == false)
            {
                isLaunched = true;
                rootPage.NotifyUser("", NotifyType.StatusMessage);

                var selectedAccount = (UserDataAccount)AccountsListComboBox.SelectedValue;
                if (selectedAccount != null)
                {
                    if (await IsFixNeededAsync(selectedAccount))
                    {
                        await UserDataAccountManager.ShowAccountErrorResolverAsync(selectedAccount.Id);
                    }
                    else
                    {
                        rootPage.NotifyUser("Account is not in an error state", NotifyType.ErrorMessage);
                    }

                    await rootPage.LoadDataAccountsAsync(AccountsListComboBox);
                }

                isLaunched = false;
            }
        }
Пример #2
0
        private async Task <UserDataAccount> GetUserDataAccountAsync()
        {
            try
            {
                var store = await UserDataAccountManager.RequestStoreAsync(UserDataAccountStoreAccessType.AppAccountsReadWrite);

                UserDataAccount userDataAccount = null;
                if (_cacheService.Options.TryGetValue("x_user_data_account", out string id))
                {
                    userDataAccount = await store.GetAccountAsync(id);
                }

                if (userDataAccount == null)
                {
                    userDataAccount = await store.CreateAccountAsync($"{_cacheService.Options.MyId}");

                    await _protoService.SendAsync(new Telegram.Td.Api.SetOption("x_user_data_account", new Telegram.Td.Api.OptionValueString(userDataAccount.Id)));
                }

                return(userDataAccount);
            }
            catch
            {
                return(null);
            }
        }
Пример #3
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            Debug.WriteLine("task running");

            BackgroundTaskDeferral _deferral = taskInstance.GetDeferral();

            // Not using this...
            var details = (EmailStoreNotificationTriggerDetails)(taskInstance.TriggerDetails);

            try
            {
                UserDataAccountStore store =
                    await UserDataAccountManager.RequestStoreAsync(UserDataAccountStoreAccessType.AllAccountsReadOnly);

                var accts = await store.FindAccountsAsync();

                foreach (var acct in accts)
                {
                    foreach (EmailMailbox mailbox in await acct.FindEmailMailboxesAsync())
                    {
                        if (mailbox.ChangeTracker.IsTracking == false)
                        {
                            mailbox.ChangeTracker.Enable();
                        }

                        var changeReader = mailbox.ChangeTracker.GetChangeReader();
                        var batch        = await changeReader.ReadBatchAsync();

                        Debug.WriteLine($"Num Changes in batch = {batch.Count}");
                        foreach (var change in batch)
                        {
                            Debug.WriteLine($"change type is {change.ChangeType.ToString()}");
                            foreach (var act in change.MailboxActions)
                            {
                                Debug.WriteLine($"kind = {act.Kind}");
                                Debug.WriteLine($"number = {act.ChangeNumber}");
                            }
                            if (change.Message != null)
                            {
                                Debug.WriteLine($"subject: {change.Message.Subject}");
                            }
                        }

                        changeReader.AcceptChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"exception - {ex.Message}");
            }

            Debug.WriteLine("task triggered");
            _deferral.Complete();
        }
Пример #4
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // 获取当前用户下的全部数据账号
            UserDataAccountStore store = await UserDataAccountManager.RequestStoreAsync(UserDataAccountStoreAccessType.AllAccountsReadOnly);

            IReadOnlyList <UserDataAccount> accounts = await store.FindAccountsAsync();

            lblMsg.Text += string.Join(",", accounts.Select(p => p.UserDisplayName));
            lblMsg.Text += Environment.NewLine;
        }
Пример #5
0
        /// <summary>
        /// 获取用户数据账户信息
        /// 要使用 UserDataAccounts 相关 API,要求应用在清单文件中声明联系人(contacts)、预约(appointments)、邮件(email)等功能中的一个或多个。
        /// </summary>
        /// <param name="userDataAccountStoreAccessType">用于指定要求的用户数据账户存储区的访问类型</param>
        /// <returns>用户数据账户的储存区</returns>
        public static async Task <IReadOnlyList <UserDataAccount> > FindAllAccountsAsync(UserDataAccountStoreAccessType userDataAccountStoreAccessType)
        {
            try
            {
                var userDataAccountStore = await UserDataAccountManager.RequestStoreAsync(userDataAccountStoreAccessType);

                var userDataAccounts = await userDataAccountStore.FindAccountsAsync();

                return(userDataAccounts.Any() ? userDataAccounts : null);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Пример #6
0
        private async Task DisplayUserInformationAsync(String id)
        {
            // Requires the email, contacts, or appointments in the app's manifest
            UserDataAccountStore store = await UserDataAccountManager.RequestStoreAsync(UserDataAccountStoreAccessType.AllAccountsReadOnly);

            // If the store is null, that means all access to Contacts, Calendar and Email data
            // has been revoked.
            if (store == null)
            {
                rootPage.NotifyUser("Access to Contacts, Calendar and Email has been revoked", NotifyType.ErrorMessage);
                return;
            }

            UserDataAccount account = await store.GetAccountAsync(id);

            rootPage.NotifyUser("Added account: " + account.UserDisplayName, NotifyType.StatusMessage);
        }
Пример #7
0
        private async void Manage_Click(object sender, RoutedEventArgs e)
        {
            // only one instance of the UserDataAccountManager pane can be launched at once per thread
            if (isLaunched == false)
            {
                isLaunched = true;

                var selectedAccount = (UserDataAccount)AccountsListComboBox.SelectedValue;
                if (selectedAccount != null)
                {
                    await UserDataAccountManager.ShowAccountSettingsAsync(selectedAccount.Id);

                    // User may have deleted the account
                    await rootPage.LoadDataAccountsAsync(AccountsListComboBox);
                }

                isLaunched = false;
            }
        }
Пример #8
0
        private async void OnLoad(object sender, RoutedEventArgs e)
        {
            var status = await BackgroundExecutionManager.RequestAccessAsync();

            Debug.WriteLine($"background execution status = {status}");

            // Register background task...
            var taskRegistered  = false;
            var exampleTaskName = "MyEmailBackgroundTask";

            foreach (var task in BackgroundTaskRegistration.AllTasks)
            {
                if (task.Value.Name == exampleTaskName)
                {
                    taskRegistered = true;
                    break;
                }
            }

            if (taskRegistered == false)
            {
                var builder = new BackgroundTaskBuilder();

                builder.Name           = nameof(EmailBackgroundTask);
                builder.TaskEntryPoint = typeof(EmailBackgroundTask).ToString();
                builder.SetTrigger(new EmailStoreNotificationTrigger());
                builder.Register().Completed += EmailTriggered;
            }

            UserDataAccountStore store =
                await UserDataAccountManager.RequestStoreAsync(UserDataAccountStoreAccessType.AllAccountsReadOnly);

            var accts = await store.FindAccountsAsync();

            foreach (var acct in accts)
            {
                foreach (EmailMailbox mailbox in await acct.FindEmailMailboxesAsync())
                {
                    //mailbox.MailboxChanged += Mailbox_MailboxChanged;
                    Debug.WriteLine($"mailbox id {mailbox.DisplayName}");
                }
            }
        }
Пример #9
0
        private async Task <UserDataAccount> GetUserDataAccountAsync()
        {
            var store = await UserDataAccountManager.RequestStoreAsync(UserDataAccountStoreAccessType.AppAccountsReadWrite);

            UserDataAccount userDataAccount = null;
            var             id = _cacheService.GetOption <Telegram.Td.Api.OptionValueString>("x_user_data_account");

            if (id != null)
            {
                userDataAccount = await store.GetAccountAsync(id.Value);
            }

            if (userDataAccount == null)
            {
                userDataAccount = await store.CreateAccountAsync($"{_cacheService.GetMyId()}");

                await _protoService.SendAsync(new Telegram.Td.Api.SetOption("x_user_data_account", new Telegram.Td.Api.OptionValueString(userDataAccount.Id)));
            }

            return(userDataAccount);
        }
Пример #10
0
        private async void AddAccount_Click(object sender, RoutedEventArgs e)
        {
            // only one instance of the UserDataAccountManager pane can be launched at once per thread
            if (isLaunched == false)
            {
                isLaunched = true;

                // Allow user to add email, contacts and appointment providing accounts.
                String userDataAccountId = await UserDataAccountManager.ShowAddAccountAsync(UserDataAccountContentKinds.Email | UserDataAccountContentKinds.Appointment | UserDataAccountContentKinds.Contact);

                if (String.IsNullOrEmpty(userDataAccountId))
                {
                    rootPage.NotifyUser("User cancelled or add account failed", NotifyType.StatusMessage);
                }
                else
                {
                    await DisplayUserInformationAsync(userDataAccountId);
                }

                isLaunched = false;
            }
        }
Пример #11
0
        private async void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            // 弹出账号添加界面,如果添加成功会返回新建的数据账号的在本地设备上的唯一标识
            string userDataAccountId = await UserDataAccountManager.ShowAddAccountAsync(UserDataAccountContentKinds.Email | UserDataAccountContentKinds.Appointment | UserDataAccountContentKinds.Contact);

            if (string.IsNullOrEmpty(userDataAccountId))
            {
                lblMsg.Text += "用户取消了或添加账号失败";
                lblMsg.Text += Environment.NewLine;
            }
            else
            {
                UserDataAccountStore store = await UserDataAccountManager.RequestStoreAsync(UserDataAccountStoreAccessType.AllAccountsReadOnly);

                if (store != null)
                {
                    // 通过数据账号在本地设备上的唯一标识来获取 UserDataAccount 对象
                    UserDataAccount account = await store.GetAccountAsync(userDataAccountId);

                    lblMsg.Text += "新增的数据账号:" + account.UserDisplayName;
                }
            }
        }
Пример #12
0
        // Fill the specified ComboBox with user data accounts.
        public async Task LoadDataAccountsAsync(ComboBox comboBox)
        {
            // Requires the email, contacts, or appointments capability in the app's manifest.
            UserDataAccountStore store = await UserDataAccountManager.RequestStoreAsync(UserDataAccountStoreAccessType.AllAccountsReadOnly);

            if (store != null)
            {
                IReadOnlyList <UserDataAccount> userDataAccounts = await store.FindAccountsAsync();

                comboBox.DataContext = new ObservableCollection <UserDataAccount>(userDataAccounts);

                if (userDataAccounts.Count > 0)
                {
                    comboBox.SelectedIndex = 0;
                }
            }
            else
            {
                // If the store is null, that means all access to Contacts, Calendar and Email data
                // has been revoked.
                NotifyUser("Access to Contacts, Calendar and Email has been revoked", NotifyType.ErrorMessage);
            }
        }