private void OnWorkerCompletedRegisterDevice(RunWorkerCompletedEventArgs args)
        {
            var deviceCredentials = args.Result as ClientCredentials;

            if (args.Error != null)
            {
                var errorPage = new ErrorPage(_connectionData)
                {
                    CaptionText      = "Failed to register device credentials.",
                    DetailsText      = args.Error.Message,
                    DetailsIsVisible = true
                };

                errorPage.Return += connectionPage_Return;

                if (NavigationService != null)
                {
                    NavigationService.Navigate(errorPage);
                }
            }
            else if (!args.Cancelled & deviceCredentials != null)
            {
                UpdateDeviceCredentials(deviceCredentials);

                const string           messageBoxText   = "New Device ID and Device Password values have been generated and registered.\n\nSave device credentials for future use?";
                const string           caption          = "Device Credentials";
                const MessageBoxButton messageBoxButton = MessageBoxButton.YesNo;
                const MessageBoxImage  messageBoxImage  = MessageBoxImage.None;

                var result = MessageBox.Show(messageBoxText, caption, messageBoxButton, messageBoxImage);

                switch (result)
                {
                case MessageBoxResult.Yes:

                    WriteDevice(deviceCredentials);

                    break;

                case MessageBoxResult.No:

                    return;
                }
            }
        }
示例#2
0
        private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            _progress.Close();

            if (e.Error != null)
            {
                var errorPage = new ErrorPage(_connectionData)
                {
                    CaptionText      = "Failed to connect to your Microsoft Dynamics CRM organization.",
                    DetailsText      = e.Error.Message,
                    DetailsIsVisible = true
                };

                errorPage.Return += connectionPage_Return;

                if (NavigationService != null)
                {
                    NavigationService.Navigate(errorPage);
                }
            }
            else if (e.Cancelled)
            {
                var errorPage = new ErrorPage(_connectionData)
                {
                    CaptionText = "User cancelled the process connecting to Microsoft Dynamics CRM organization."
                };

                errorPage.Return += connectionPage_Return;

                if (NavigationService != null)
                {
                    NavigationService.Navigate(errorPage);
                }
            }
            else
            {
                // Finish the connection dialog and return bound data to calling page
                OnReturn(new ReturnEventArgs <ConnectionResult>(ConnectionResult.Connected));
            }
        }
        private RunWorkerCompletedEventHandler GetWorkerCompleted(ProgressDialog progress, string captionText)
        {
            return((sender, args) =>
            {
                progress.Close();

                if (args.Error != null)
                {
                    var errorPage = new ErrorPage(_connectionData)
                    {
                        CaptionText = captionText,
                        DetailsText = args.Error.Message,
                        DetailsIsVisible = true
                    };

                    errorPage.Return += connectionPage_Return;

                    if (NavigationService != null)
                    {
                        NavigationService.Navigate(errorPage);
                    }
                }
            });
        }
        private void OnWorkerCompleted(RunWorkerCompletedEventArgs args)
        {
            if (args.Error != null)
            {
                var errorPage = new ErrorPage(_connectionData)
                {
                    CaptionText      = "Failed to connect to your Microsoft Dynamics CRM server.",
                    DetailsText      = args.Error.Message,
                    DetailsIsVisible = true
                };

                errorPage.Return += connectionPage_Return;

                if (NavigationService != null)
                {
                    NavigationService.Navigate(errorPage);
                }
            }
            else if (args.Cancelled)
            {
                var errorPage = new ErrorPage(_connectionData)
                {
                    CaptionText = "User canceled the process connecting to Microsoft Dynamics CRM server."
                };

                errorPage.Return += connectionPage_Return;

                if (NavigationService != null)
                {
                    NavigationService.Navigate(errorPage);
                }
            }
            else
            {
                //process completed successfully

                if (_connectionData.Organizations == null)
                {
                    var errorPage = new ErrorPage(_connectionData)
                    {
                        CaptionText = "There were no organizations found on the server specified.",
                    };

                    errorPage.Return += connectionPage_Return;

                    if (NavigationService != null)
                    {
                        NavigationService.Navigate(errorPage);
                    }
                }
                else
                {
                    var organizationPage = new OrganizationPage(_connectionData);

                    organizationPage.Return += connectionPage_Return;

                    if (NavigationService != null)
                    {
                        NavigationService.Navigate(organizationPage);
                    }
                }
            }
        }