Exemplo n.º 1
0
        private async Task ExecuteLogin(string connectionId, string accessToken)
        {
            try
            {
                await userSession.Login(connectionId, accessToken);
            }
            catch (Exception ex)
            {
                ShowBalloonError("Login attempt failed.");
                return;
            }

            MhwAccount account = userSession.LoggedInAccount;

            ShowBalloonInfo(string.Format("Logged in as {0}", account.Name));
            labelDisplayName.Text = account.Name;
            SetPictureBox(account.PictureFileId, pictureBoxUser);

            await RefreshOnBehalfOfAccounts();

            accountsComboBox.Enabled = true;

            controlPrintToDrive.Enabled  = true;
            controlFolderToDrive.Enabled = true;
            controlPrintToFax.Enabled    = true;

            UpdateLoginButtonText();
        }
Exemplo n.º 2
0
        public async Task <string> Upload(Stream stream, string name, string uploadFolderDriveItemId)
        {
            string fileType = Path.GetExtension(name);

            // Show user we're uploading.
            string uploadingMessage = string.Format("Uploading {0}...", name);

            ShowBalloonInfo(uploadingMessage);
            SetTrayIcon(Resources.Uploading, uploadingMessage);

            string fileId;

            // Call MHW API to upload file.
            try
            {
                MhwAccount selected  = GetSelectedAccount();
                ApiFile    driveItem =
                    await Task.Run(() => Sdk.Account.UploadFile(selected.AccountId, name, fileType, stream, uploadFolderDriveItemId));

                fileId = driveItem.FileId;
            }
            catch (Exception ex)
            {
                ShowBalloonError(ex.Message);
                NotifyIfNetworkUnavailable();
                return(null);
            }
            finally
            {
                // Change tray icon back to normal.
                SetTrayIcon();
            }

            return(fileId);
        }
Exemplo n.º 3
0
        private void InitBrowser()
        {
            if (Cef.IsInitialized == false)
            {
                Cef.Initialize(new CefSettings());
            }

            MhwAccount  account = userSession.ActingAsAccount;
            Credentials creds   = userSession.Credentials;

            string url =
                string.Format(
                    "{0}/UI/Drive/Select?accountId={1}&containersOnly=true&itemName={2}&connection_id={3}&access_token={4}&app_key={5}&app_secret={6}",
                    userSession.Settings.myHEALTHwareDomain,
                    account.AccountId,
                    filename,
                    creds.ConnectionId,
                    creds.AccessToken,
                    creds.AppId,
                    creds.AppSecret);

            // Initially hide the control until the response is complete
            chromiumBrowser = new ChromiumBrowserUserControl(url, ResponseHandler);
            chromiumBrowser.PostMessageListener += ResultMessageHandler;
            chromiumBrowser.BrowserVisible      += ChromiumBrowserVisible;

            Controls.Add(chromiumBrowser);
        }
Exemplo n.º 4
0
        public async Task Login(string connectionId, string accessToken)
        {
            if (connectionId == null)
            {
                throw new ArgumentNullException("connectionId", "Invalid login credential");
            }
            if (accessToken == null)
            {
                throw new ArgumentNullException("accessToken", "Invalid login credential");
            }
            Contract.EndContractBlock();

            Logout();

            Sdk = GetMhwSdk(connectionId, accessToken);

            LoggedInAccount = AuthenticateAccount();

            Credentials = new Credentials(connectionId, accessToken, Settings);
            Credentials.Save();

            await GetMhwAccountsAsync();

            MhwAccount actingAs = accounts.FirstOrDefault(p => p.AccountId == Settings.SelectedAccountId) ?? LoggedInAccount;

            SetActingAsAccount(actingAs);
        }
Exemplo n.º 5
0
        private void InitBrowser()
        {
            if (Cef.IsInitialized == false)
            {
                Cef.Initialize(new CefSettings());
            }

            MhwAccount  account = userSession.ActingAsAccount;
            Credentials creds   = userSession.Credentials;

            string url =
                string.Format(
                    "{0}/UI/Fax/Send?accountId={1}&fileId={2}&connection_id={3}&access_token={4}&app_key={5}&app_secret={6}&responsive={7}",
                    userSession.Settings.myHEALTHwareDomain,
                    account.AccountId,
                    fileId,
                    creds.ConnectionId,
                    creds.AccessToken,
                    creds.AppId,
                    creds.AppSecret,
                    true);

            chromiumBrowser = new ChromiumBrowserUserControl(url, ResponseHandler);
            chromiumBrowser.PostMessageListener += ResultMessageHandler;
            chromiumBrowser.BrowserVisible      += ChromiumBrowserVisible;

            Controls.Add(chromiumBrowser);
        }
Exemplo n.º 6
0
        private void ChangeActingAs()
        {
            MhwAccount selected = GetSelectedAccount();

            userSession.SetActingAsAccount(selected);

            RefreshTabControl();
        }
Exemplo n.º 7
0
        public void SetActingAsAccount(MhwAccount account)
        {
            if (ActingAsAccount == account)
            {
                return;
            }

            ActingAsAccount = account;

            Settings.SelectedAccountId = account != null ? account.AccountId : null;
            Settings.Save();

            OnActingAsChanged();
        }
Exemplo n.º 8
0
        private async Task <IEnumerable <MhwAccount> > RefreshOnBehalfOfAccounts()
        {
            // Load the list of accounts that this account manages files for.
            IEnumerable <MhwAccount> accounts = await userSession.GetMhwAccountsAsync();

            var bindingList = (BindingList <MhwAccount>)accountsBindingSource.DataSource;

            bindingList.Clear();

            foreach (MhwAccount item in accounts)
            {
                bindingList.Add(item);
            }

            MhwAccount account = accounts.FirstOrDefault(p => p.AccountId == userSession.Settings.SelectedAccountId) ??
                                 accounts.FirstOrDefault(p => p.AccountId == userSession.LoggedInAccount.AccountId);

            accountsComboBox.SelectedItem = account;

            return(accounts);
        }
Exemplo n.º 9
0
        private void RefreshTabControl()
        {
            MhwAccount selected = GetSelectedAccount();

            if (selected == null)
            {
                return;
            }

            tabs.SuspendLayout();

            if (selected.IsPersonalAccount && tabs.TabPages.Contains(tabPagePrintToFax))
            {
                tabs.TabPages.Remove(tabPagePrintToFax);
            }
            else if (!selected.IsPersonalAccount && !tabs.TabPages.Contains(tabPagePrintToFax))
            {
                tabs.TabPages.Insert(faxTabIndex, tabPagePrintToFax);
            }

            tabs.ResumeLayout();
        }