private async void UpdateSolutionForm_Load(object sender, EventArgs e)
        {
            try
            {
                var solutionDetails = new List <SolutionDetail>();
                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(connectionDetail, ctrl.CrmConnectionMgr.CrmSvc, null);
                }
                solutionDetails = await connectionDetail.GetSolutionsListAsync();

                if (solutionDetails.Count == 0)
                {
                    throw new Exception("Failed to load solutions");
                }
                var solutions = solutionDetails.Select(x => new Solution()
                {
                    SolutionDetail = x
                });
                comboBoxSolutions.Items.AddRange(solutions.ToArray());
                if (connectionDetail != null && connectionDetail.SelectedSolution != null)
                {
                    var selectedSolution = connectionDetail.Solutions.FirstOrDefault(x => x.SolutionId == connectionDetail.SelectedSolution.SolutionId);
                    if (selectedSolution != null)
                    {
                        var index = connectionDetail.Solutions.IndexOf(selectedSolution);
                        comboBoxSolutions.SelectedIndex = index;
                    }
                }

                lbProgressBar.Visible = false;
                progressBar1.Visible  = false;

                lbSolution.Visible        = true;
                comboBoxSolutions.Visible = true;
                btnOk.Visible             = true;

                comboBoxSolutions.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }
        }
Esempio n. 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);
        }
        private void tsbUpdateConnection_Click(object sender, EventArgs e)
        {
            if (lvConnections.SelectedItems.Count == 1)
            {
                ListViewItem item = lvConnections.SelectedItems[0];

                var cd = (ConnectionDetail)item.Tag;

                if (cd.IsFromSdkLoginCtrl)
                {
                    var ctrl = new CRMLoginForm1(cd.ConnectionId.Value, true);
                    ctrl.ShowDialog();

                    if (ctrl.CrmConnectionMgr.CrmSvc?.IsReady ?? false)
                    {
                        cd.Organization               = ctrl.CrmConnectionMgr.ConnectedOrgUniqueName;
                        cd.OrganizationFriendlyName   = ctrl.CrmConnectionMgr.ConnectedOrgFriendlyName;
                        cd.OrganizationDataServiceUrl =
                            ctrl.CrmConnectionMgr.ConnectedOrgPublishedEndpoints[EndpointType.OrganizationDataService];
                        cd.OrganizationServiceUrl =
                            ctrl.CrmConnectionMgr.ConnectedOrgPublishedEndpoints[EndpointType.OrganizationService];
                        cd.WebApplicationUrl =
                            ctrl.CrmConnectionMgr.ConnectedOrgPublishedEndpoints[EndpointType.WebApplication];
                        cd.ServerName          = new Uri(cd.WebApplicationUrl).Host;
                        cd.OrganizationVersion = ctrl.CrmConnectionMgr.CrmSvc.ConnectedOrgVersion.ToString();

                        item.Tag = cd;
                        lvConnections.Items.Remove(item);
                        lvConnections.Items.Add(item);
                        lvConnections.Refresh();//RedrawItems(0, lvConnections.Items.Count - 1, false);

                        var updatedConnectionDetail = ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(
                            c => c.ConnectionId == cd.ConnectionId);

                        ConnectionManager.Instance.ConnectionsList.Connections.Remove(updatedConnectionDetail);
                        ConnectionManager.Instance.ConnectionsList.Connections.Add(cd);

                        ConnectionManager.Instance.SaveConnectionsFile();
                    }

                    return;
                }

                var cForm = new ConnectionWizard2(cd)
                {
                    StartPosition = FormStartPosition.CenterParent
                };

                if (cForm.ShowDialog(this) == DialogResult.OK)
                {
                    item.Tag = cForm.CrmConnectionDetail;
                    item.SubItems[0].Text = cForm.CrmConnectionDetail.ConnectionName;
                    item.SubItems[1].Text = cForm.CrmConnectionDetail.ServerName;
                    item.SubItems[2].Text = cForm.CrmConnectionDetail.Organization;
                    if (item.SubItems.Count == 4)
                    {
                        item.SubItems[3].Text = cForm.CrmConnectionDetail.OrganizationVersion;
                    }
                    else
                    {
                        item.SubItems.Add(cForm.CrmConnectionDetail.OrganizationVersion);
                    }
                    item.Group = GetGroup(cForm.CrmConnectionDetail);

                    lvConnections.Refresh();

                    var updatedConnectionDetail = ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(
                        c => c.ConnectionId == cForm.CrmConnectionDetail.ConnectionId);

                    ConnectionManager.Instance.ConnectionsList.Connections.Remove(updatedConnectionDetail);
                    ConnectionManager.Instance.ConnectionsList.Connections.Add(cForm.CrmConnectionDetail);

                    ConnectionManager.Instance.SaveConnectionsFile();
                }
            }
        }
Esempio n. 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 <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 && 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);
        }
Esempio n. 5
0
        private void actionItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem     clickedItem       = (ToolStripMenuItem)sender;
            ToolStripDropDownItem parentItem        = (ToolStripDropDownItem)clickedItem.OwnerItem;
            ConnectionDetail      currentConnection = (ConnectionDetail)parentItem.Tag;
            ToolStripDropDownItem connexionManager  = (ToolStripDropDownItem)parentItem.OwnerItem;

            switch (clickedItem.Text)
            {
            case "Connect":

                if (currentConnection.IsCustomAuth)
                {
                    if (_formHelper.RequestPassword(currentConnection))
                    {
                        ConnectionManager.Instance.ConnectToServer(new List <ConnectionDetail> {
                            currentConnection
                        });
                    }
                }
                else
                {
                    if (currentConnection.IsFromSdkLoginCtrl)
                    {
                        var ctrl = new CRMLoginForm1(currentConnection.ConnectionId.Value);
                        if (currentConnection.AzureAdAppId != Guid.Empty)
                        {
                            ctrl.AppId       = currentConnection.AzureAdAppId.ToString();
                            ctrl.RedirectUri = new Uri(currentConnection.ReplyUrl);
                        }

                        ctrl.ShowDialog();

                        ConnectionManager.Instance.ConnectToServerWithSdkLoginCtrl(currentConnection, ctrl.CrmConnectionMgr.CrmSvc,
                                                                                   null);
                    }
                    else
                    {
                        ConnectionManager.Instance.ConnectToServer(new List <ConnectionDetail> {
                            currentConnection
                        });
                    }
                }
                break;

            case "Edit":
                currentConnection = _formHelper.EditConnection(false, currentConnection);

                if (currentConnection != null && parentItem.Text != currentConnection.ConnectionName)
                {
                    parentItem.Text = currentConnection.ConnectionName;
                    parentItem.Tag  = currentConnection;
                }

                break;

            case "Delete":
                if (MessageBox.Show(this, "Are you sure you want to delete selected connection(s)?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }

                connexionManager.DropDownItems.Remove(parentItem);

                if (connexionManager.DropDownItems.Count == 2)
                {
                    connexionManager.DropDownItems.RemoveAt(0);
                }

                _formHelper.DeleteConnection(currentConnection.ConnectionId);

                break;
            }
        }