示例#1
0
        /// <summary>
        /// Asks this manager to select a Crm connection to use
        /// </summary>
        /// <param name="connectionDetail">The <see cref="ConnectionDetail"/> to use</param>
        /// <param name="connectionParameter">The connection parameter.</param>
        /// <param name="preConnectionRequestAction">The action to be performed before the async call to create the connection.  Useful to display a please wait message</param>
        /// <returns></returns>
        public bool AskForConnection(ConnectionDetail connectionDetail, object connectionParameter, Action preConnectionRequestAction)
        {
            if (!connectionDetail.UseConnectionString && connectionDetail.IsCustomAuth)
            {
                if (connectionDetail.PasswordIsEmpty)
                {
                    var pForm = new PasswordForm(connectionDetail)
                    {
                        UserDomain = connectionDetail.UserDomain,
                        UserLogin  = connectionDetail.UserName
                    };
                    if (pForm.ShowDialog(innerAppForm) == DialogResult.OK)
                    {
                        connectionDetail.SetPassword(pForm.UserPassword);
                        connectionDetail.SavePassword = pForm.SavePassword;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            preConnectionRequestAction?.Invoke();

            ConnectionManager.Instance.ConnectToServer(new List <ConnectionDetail> {
                connectionDetail
            }, connectionParameter);

            return(true);
        }
示例#2
0
        /// <summary>
        /// Asks this manager to select a Crm connection to use
        /// </summary>
        /// <param name="connectionDetail">The <see cref="ConnectionDetail"/> to use</param>
        /// <param name="connectionParameter">The connection parameter.</param>
        /// <param name="preConnectionRequestAction">The action to be performed before the async call to create the connection.  Useful to display a please wait message</param>
        /// <returns></returns>
        public bool AskForConnection(ConnectionDetail connectionDetail, object connectionParameter, Action preConnectionRequestAction)
        {
            if (!connectionDetail.UseConnectionString && connectionDetail.IsCustomAuth)
            {
                if (connectionDetail.PasswordIsEmpty && connectionDetail.Certificate == null)
                {
                    var pForm = new PasswordForm(connectionDetail)
                    {
                        UserDomain = connectionDetail.UserDomain,
                        UserLogin  = connectionDetail.UserName
                    };
                    if (pForm.ShowDialog(innerAppForm) == DialogResult.OK)
                    {
                        connectionDetail.SetPassword(pForm.UserPassword);
                        connectionDetail.SavePassword = pForm.SavePassword;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            preConnectionRequestAction?.Invoke();

            if (connectionDetail.IsFromSdkLoginCtrl)
            {
                //var cd = connectionDetail;

                //var ctrl = new CRMLoginForm1(cd.ConnectionId.Value);
                //if (cd.AzureAdAppId != Guid.Empty)
                //{
                //    ctrl.AppId = cd.AzureAdAppId.ToString();
                //    ctrl.RedirectUri = new Uri(cd.ReplyUrl);
                //}

                //ctrl.ShowDialog();

                //ConnectionManager.Instance.ConnectToServerWithSdkLoginCtrl(cd, ctrl.CrmConnectionMgr.CrmSvc,
                //    connectionParameter);
            }
            else
            {
                ConnectionManager.Instance.ConnectToServer(new List <ConnectionDetail> {
                    connectionDetail
                }, connectionParameter);
            }
            return(true);
        }
示例#3
0
        /// <summary>
        /// Asks this manager to select a Crm connection to use
        /// </summary>
        public bool AskForConnection(object connectionParameter)
        {
            var cs = new ConnectionSelector(_connectionManager.LoadConnectionsList(), _connectionManager)
            {
                StartPosition  = FormStartPosition.CenterParent,
                ConnectionList = _connectionManager.LoadConnectionsList()
            };

            if (cs.ShowDialog(_innerAppForm) == DialogResult.OK)
            {
                var connectionDetail = cs.SelectedConnections.First();
                if (connectionDetail.IsCustomAuth)
                {
                    if (string.IsNullOrEmpty(connectionDetail.UserPassword))
                    {
                        var pForm = new PasswordForm()
                        {
                            UserDomain = connectionDetail.UserDomain,
                            UserLogin  = connectionDetail.UserName
                        };
                        if (pForm.ShowDialog(_innerAppForm) == DialogResult.OK)
                        {
                            connectionDetail.UserPassword = pForm.UserPassword;
                            connectionDetail.SavePassword = pForm.SavePassword;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }

                _connectionManager.ConnectToServer(connectionDetail, connectionParameter);

                if (cs.HadCreatedNewConnection)
                {
                    if (!_connectionManager.ConnectionsList.Connections.Contains(connectionDetail))
                    {
                        _connectionManager.ConnectionsList.Connections.Add(connectionDetail);
                    }
                    _connectionManager.SaveConnectionsFile(_connectionManager.ConnectionsList);
                }

                return(true);
            }

            return(false);
        }
示例#4
0
        /// <summary>
        /// Asks this manager to select a Crm connection to use
        /// </summary>
        /// <param name="connectionParameter">The connection parameter.</param>
        /// <param name="preConnectionRequestAction">The action to be performed before the async call to create the connection.  Useful to display a please wait message</param>
        /// <returns></returns>
        public bool AskForConnection(object connectionParameter, Action preConnectionRequestAction)
        {
            var cs = new ConnectionSelector
            {
                StartPosition = FormStartPosition.CenterParent,
            };

            if (cs.ShowDialog(_innerAppForm) == DialogResult.OK)
            {
                var connectionDetail = cs.SelectedConnections.First();
                if (connectionDetail.IsCustomAuth)
                {
                    if (connectionDetail.PasswordIsEmpty)
                    {
                        var pForm = new PasswordForm()
                        {
                            UserDomain = connectionDetail.UserDomain,
                            UserLogin = connectionDetail.UserName
                        };
                        if (pForm.ShowDialog(_innerAppForm) == DialogResult.OK)
                        {
                            connectionDetail.SetPassword(pForm.UserPassword);
                            connectionDetail.SavePassword = pForm.SavePassword;
                        }
                        else
                        {
                            return false;
                        }
                    }
                }

                if (preConnectionRequestAction != null)
                {
                    preConnectionRequestAction();
                }

                ConnectionManager.Instance.ConnectToServer(connectionDetail, connectionParameter);

                return true;
            }

            return false;
        }
示例#5
0
        /// <summary>
        /// Asks this manager to select a Crm connection to use
        /// </summary>
        /// <param name="connectionParameter">The connection parameter.</param>
        /// <param name="preConnectionRequestAction">The action to be performed before the async call to create the connection.  Useful to display a please wait message</param>
        /// <returns></returns>
        public bool AskForConnection(object connectionParameter, Action preConnectionRequestAction)
        {
            var cs = new ConnectionSelector
            {
                StartPosition = FormStartPosition.CenterParent,
            };

            if (cs.ShowDialog(_innerAppForm) == DialogResult.OK)
            {
                var connectionDetail = cs.SelectedConnections.First();
                if (!connectionDetail.UseConnectionString && connectionDetail.IsCustomAuth)
                {
                    if (connectionDetail.PasswordIsEmpty)
                    {
                        var pForm = new PasswordForm()
                        {
                            UserDomain = connectionDetail.UserDomain,
                            UserLogin  = connectionDetail.UserName
                        };
                        if (pForm.ShowDialog(_innerAppForm) == DialogResult.OK)
                        {
                            connectionDetail.SetPassword(pForm.UserPassword);
                            connectionDetail.SavePassword = pForm.SavePassword;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }

                if (preConnectionRequestAction != null)
                {
                    preConnectionRequestAction();
                }

                ConnectionManager.Instance.ConnectToServer(connectionDetail, connectionParameter);

                return(true);
            }

            return(false);
        }
示例#6
0
        /// <summary>
        /// Checks the existence of a user password and returns it
        /// </summary>
        /// <param name="detail">Details of the Crm connection</param>
        /// <returns>True if password defined</returns>
        public bool RequestPassword(ConnectionDetail detail)
        {
            if (!string.IsNullOrEmpty(detail.ConnectionString))
            {
                return(true);
            }

            if (!detail.PasswordIsEmpty || detail.Certificate != null)
            {
                return(true);
            }

            bool returnValue = false;

            var pForm = new PasswordForm(detail)
            {
                UserLogin  = detail.UserName,
                UserDomain = detail.UserDomain,
            };

            MethodInvoker mi = delegate
            {
                if (pForm.ShowDialog(innerAppForm) == DialogResult.OK)
                {
                    detail.SetPassword(pForm.UserPassword);
                    detail.SavePassword = pForm.SavePassword;
                    returnValue         = true;
                }
            };

            if (innerAppForm.InvokeRequired)
            {
                innerAppForm.Invoke(mi);
            }
            else
            {
                mi();
            }

            return(returnValue);
        }
示例#7
0
        /// <summary>
        /// Checks the existence of a user password and returns it
        /// </summary>
        /// <param name="detail">Details of the Crm connection</param>
        /// <returns>True if password defined</returns>
        public bool RequestPassword(ConnectionDetail detail)
        {
            if (!string.IsNullOrEmpty(detail.UserPassword))
            {
                return(true);
            }

            bool returnValue = false;

            var pForm = new PasswordForm
            {
                UserLogin     = detail.UserName,
                UserDomain    = detail.UserDomain,
                StartPosition = FormStartPosition.CenterParent
            };

            MethodInvoker mi = delegate
            {
                if (pForm.ShowDialog(_innerAppForm) == DialogResult.OK)
                {
                    detail.UserPassword = pForm.UserPassword;
                    detail.SavePassword = pForm.SavePassword;
                    returnValue         = true;
                }
            };

            if (_innerAppForm.InvokeRequired)
            {
                _innerAppForm.Invoke(mi);
            }
            else
            {
                mi();
            }

            return(returnValue);
        }
示例#8
0
        /// <summary>
        /// Checks the existence of a user password and returns it
        /// </summary>
        /// <param name="detail">Details of the Crm connection</param>
        /// <returns>True if password defined</returns>
        public bool RequestPassword(ConnectionDetail detail)
        {
            if (!detail.PasswordIsEmpty)
            {
                return(true);
            }

            bool returnValue = false;

            var pForm = new PasswordForm
            {
                UserLogin  = detail.UserName,
                UserDomain = detail.UserDomain,
            };

            MethodInvoker mi = delegate
            {
                if (pForm.ShowDialog(_innerAppForm) == DialogResult.OK)
                {
                    detail.SetPassword(pForm.UserPassword);
                    detail.SavePassword = pForm.SavePassword;
                    returnValue         = true;
                }
            };

            if (_innerAppForm.InvokeRequired)
            {
                _innerAppForm.Invoke(mi);
            }
            else
            {
                mi();
            }

            return(returnValue);
        }
示例#9
0
        /// <summary>
        /// Checks the existence of a user password and returns it
        /// </summary>
        /// <param name="detail">Details of the Crm connection</param>
        /// <returns>True if password defined</returns>
        public bool RequestPassword(ConnectionDetail detail)
        {
            if (!detail.PasswordIsEmpty)
                return true;

            bool returnValue = false;

            var pForm = new PasswordForm
            {
                UserLogin = detail.UserName,
                UserDomain = detail.UserDomain,
                StartPosition = FormStartPosition.CenterParent
            };

            MethodInvoker mi = delegate
            {
                if (pForm.ShowDialog(_innerAppForm) == DialogResult.OK)
                {
                    detail.SetPassword(pForm.UserPassword);
                    detail.SavePassword = pForm.SavePassword;
                    returnValue = true;
                }
            };

            if (_innerAppForm.InvokeRequired)
            {
                _innerAppForm.Invoke(mi);
            }
            else
            {
                mi();
            }

            return returnValue;
        }
示例#10
0
        /// <summary>
        /// Asks this manager to select a Crm connection to use
        /// </summary>
        /// <param name="connectionParameter">The connection parameter.</param>
        /// <param name="preConnectionRequestAction">The action to be performed before the async call to create the connection.  Useful to display a please wait message</param>
        /// <returns></returns>
        public bool AskForConnection(object connectionParameter, Action <List <ConnectionDetail> > preConnectionRequestAction)
        {
            var cs = new ConnectionSelector
            {
                StartPosition = FormStartPosition.CenterParent,
            };

            if (cs.ShowDialog(innerAppForm) == DialogResult.OK)
            {
                if (cs.SelectedConnections.Any(c => c.IsFromSdkLoginCtrl) &&
                    cs.SelectedConnections.Count > 1)
                {
                    MessageBox.Show(innerAppForm, @"You cannot select multiple connections that used SDK Login control",
                                    @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                foreach (var connectionDetail in cs.SelectedConnections)
                {
                    if (!connectionDetail.UseConnectionString)
                    {
                        if (connectionDetail.NewAuthType == AuthenticationType.ClientSecret &&
                            connectionDetail.ClientSecretIsEmpty)
                        {
                            var pForm = new SecretForm(connectionDetail)
                            {
                                ClientId = connectionDetail.AzureAdAppId.ToString("B")
                            };
                            if (pForm.ShowDialog(innerAppForm) == DialogResult.OK)
                            {
                                connectionDetail.SetClientSecret(pForm.ClientSecret);
                                connectionDetail.SavePassword = pForm.SaveSecret;
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else if (connectionDetail.IsCustomAuth)
                        {
                            if (connectionDetail.PasswordIsEmpty && connectionDetail.Certificate == null)
                            {
                                var pForm = new PasswordForm(connectionDetail)
                                {
                                    UserDomain = connectionDetail.UserDomain,
                                    UserLogin  = connectionDetail.UserName
                                };
                                if (pForm.ShowDialog(innerAppForm) == DialogResult.OK)
                                {
                                    connectionDetail.SetPassword(pForm.UserPassword);
                                    connectionDetail.SavePassword = pForm.SavePassword;
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }

                preConnectionRequestAction?.Invoke(cs.SelectedConnections);

                if (cs.SelectedConnections.First().IsFromSdkLoginCtrl)
                {
                    //var cd = cs.SelectedConnections.First();

                    //var ctrl = new CRMLoginForm1(cd.ConnectionId.Value);
                    //if (cd.AzureAdAppId != Guid.Empty)
                    //{
                    //    ctrl.AppId = cd.AzureAdAppId.ToString();
                    //    ctrl.RedirectUri = new Uri(cd.ReplyUrl);
                    //}

                    //ctrl.ShowDialog();

                    //ConnectionManager.Instance.ConnectToServerWithSdkLoginCtrl(cd, ctrl.CrmConnectionMgr.CrmSvc,
                    //    connectionParameter);
                }
                else
                {
                    ConnectionManager.Instance.ConnectToServer(cs.SelectedConnections, connectionParameter);
                }

                return(true);
            }

            return(false);
        }