コード例 #1
0
        public void GetFormConfigurationConnection()
        {
            var ctrl = new CRMLoginForm1();

            ctrl.ConnectionToCrmCompleted += ctrl_ConnectionToCrmCompleted;
            ctrl.ShowDialog();

            if (ctrl.CrmConnectionMgr != null && ctrl.CrmConnectionMgr.CrmSvc != null && ctrl.CrmConnectionMgr.CrmSvc.IsReady)
            {
                c1_rbsTools.Enabled   = true;
                c1_DockingTab.Visible = true;
                this.ServerConnection = ctrl.CrmConnectionMgr.CrmSvc;
            }
            else
            {
                MessageBox.Show("Cannot connect; try again!", "Connection Status");
            }
        }
コード例 #2
0
        private void btnOpenSdkLoginCtrl_Click(object sender, EventArgs e)
        {
            var ctrl = new CRMLoginForm1(connectionDetailId, !isNew);

            if (rdbUseCustom.Checked)
            {
                ctrl.AppId       = txtAzureAdAppId.Text;
                ctrl.RedirectUri = new Uri(txtReplyUrl.Text);
            }
            else
            {
                ctrl.AppId       = "2ad88395-b77d-4561-9441-d0e40824f9bc";
                ctrl.RedirectUri = new Uri("app://5d3e90d6-aa8e-48a8-8f2c-58b45cc67315");
            }
            ctrl.ConnectionToCrmCompleted += (loginCtrl, evt) =>
            {
                ConnectionManager = ((CRMLoginForm1)loginCtrl).CrmConnectionMgr;
                SetAuthType();
                ConnectionSucceeded?.Invoke(this, null);
            };
            ctrl.ShowDialog();
        }
コード例 #3
0
        private void btnOpenSdkLoginCtrl_Click(object sender, EventArgs e)
        {
            var ctrl = new CRMLoginForm1(connectionDetailId, !isNew);

            if (rdbUseCustom.Checked)
            {
                ctrl.AppId       = txtAzureAdAppId.Text;
                ctrl.RedirectUri = new Uri(txtReplyUrl.Text);
            }
            else
            {
                ctrl.AppId       = "51f81489-12ee-4a9e-aaae-a2591f45987d";
                ctrl.RedirectUri = new Uri("app://58145B91-0C36-4500-8554-080854F2AC97");
            }
            ctrl.ConnectionToCrmCompleted += (loginCtrl, evt) =>
            {
                ConnectionManager = ((CRMLoginForm1)loginCtrl).CrmConnectionMgr;
                SetAuthType();
                ConnectionSucceeded?.Invoke(this, null);
            };
            ctrl.ShowDialog();
        }
コード例 #4
0
        public async Task <ConnectionDetail> UseSdkLoginControlAsync(Guid connectionDetailId, bool isUpdate)
        {
            try
            {
                var signal           = new SemaphoreSlim(0, 1);
                var connectionDetail = new ConnectionDetail();
                var thread           = new Thread(() => {
                    bool rdbUseCustom = false; string appId = null; string redirectUri = null;
                    var ctrl          = new CRMLoginForm1(connectionDetailId, isUpdate);

                    if (rdbUseCustom)
                    {
                        ctrl.AppId       = appId;
                        ctrl.RedirectUri = new Uri(redirectUri);
                    }
                    else
                    {
                        ctrl.AppId       = "51f81489-12ee-4a9e-aaae-a2591f45987d";
                        ctrl.RedirectUri = new Uri("app://58145B91-0C36-4500-8554-080854F2AC97");
                    }
                    ctrl.ConnectionToCrmCompleted += (loginCtrl, evt) =>
                    {
                        try
                        {
                            var connectionManager = ((CRMLoginForm1)loginCtrl).CrmConnectionMgr;
                            var authType          = DataModels.AuthenticationProviderType.None;
                            switch (connectionManager.CrmSvc.ActiveAuthenticationType)
                            {
                            case Microsoft.Xrm.Tooling.Connector.AuthenticationType.AD:
                                authType = DataModels.AuthenticationProviderType.ActiveDirectory;
                                break;

                            case Microsoft.Xrm.Tooling.Connector.AuthenticationType.IFD:
                            case Microsoft.Xrm.Tooling.Connector.AuthenticationType.Claims:
                                authType = DataModels.AuthenticationProviderType.Federation;
                                break;

                            default:
                                authType = DataModels.AuthenticationProviderType.OnlineFederation;
                                break;
                            }

                            connectionDetail.IsFromSdkLoginCtrl         = true;
                            connectionDetail.AuthType                   = authType;
                            connectionDetail.UseIfd                     = authType == DataModels.AuthenticationProviderType.Federation;
                            connectionDetail.Organization               = connectionManager.ConnectedOrgUniqueName;
                            connectionDetail.OrganizationFriendlyName   = connectionManager.ConnectedOrgFriendlyName;
                            connectionDetail.OrganizationDataServiceUrl =
                                connectionManager.ConnectedOrgPublishedEndpoints[EndpointType.OrganizationDataService];
                            connectionDetail.OrganizationServiceUrl =
                                connectionManager.ConnectedOrgPublishedEndpoints[EndpointType.OrganizationService];
                            connectionDetail.WebApplicationUrl =
                                connectionManager.ConnectedOrgPublishedEndpoints[EndpointType.WebApplication];
                            connectionDetail.OriginalUrl         = connectionDetail.WebApplicationUrl;
                            connectionDetail.ServerName          = new Uri(connectionDetail.WebApplicationUrl).Host;
                            connectionDetail.OrganizationVersion = connectionManager.CrmSvc.ConnectedOrgVersion.ToString();
                            if (!string.IsNullOrEmpty(connectionManager.ClientId))
                            {
                                connectionDetail.AzureAdAppId = new Guid(connectionManager.ClientId);
                                connectionDetail.ReplyUrl     = connectionManager.RedirectUri.AbsoluteUri;
                            }
                            connectionDetail.UserName = connectionManager.CrmSvc.OAuthUserId;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                        finally
                        {
                            signal.Release();
                        }
                    };

                    ctrl.ShowDialog();
                });
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                thread.Join();


                await signal.WaitAsync();

                thread.Abort();
                return(connectionDetail);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(null);
            }
        }