private void btnConnection_Click(object sender, EventArgs e) { var form = new FormConnection(DTE); if (form.ShowDialog() == DialogResult.OK) { Cursor = Cursors.WaitCursor; xrmHelper = new XrmHelper(form.CrmService); if (FormType == FormType.PluginItem) { ddlMessage.DataSource = xrmHelper.GetSdkMessages(LogicalName); } else if (FormType == FormType.CustomActionItem) { ddlMessage.DisplayMember = "LogicalName"; ddlMessage.ValueMember = "Name"; ddlMessage.DataSource = xrmHelper.GetAllCustomActions(); } btnOk.Enabled = ddlMessage.Items.Count > 0; Cursor = Cursors.Default; } }
private void btnConnection_Click(object sender, EventArgs e) { var form = new FormConnection(Dte); if (form.ShowDialog() == DialogResult.OK) { progressBar.Visible = true; btnConnection.Enabled = false; btnCancel.Enabled = false; List <string> list = null; List <XrmEntity> list2 = null; _xrmHelper = new XrmHelper(form.CrmService); var failed = false; Task task = Task.Factory.StartNew(() => { if (FormType == FormType.PluginItem) { try { list = _xrmHelper.GetSdkMessages(LogicalName); } catch { failed = true; } } else if (FormType == FormType.CustomActionItem) { list2 = _xrmHelper.GetAllCustomActions(); } }); while (!task.IsCompleted) { Application.DoEvents(); } if (failed) { var form2 = new FormProject(FormType.SelectEntity, Dte); form2.LoadSelectEntity(_xrmHelper.GetAllEntities()); if (form2.ShowDialog() == DialogResult.OK) { list = _xrmHelper.GetSdkMessages(form2.SelectedEntity.ToLower()); EntityName = form2.SelectedEntity; LogicalName = form2.SelectedEntity.ToLower(); } } btnConnection.Enabled = true; progressBar.Visible = false; if (FormType == FormType.PluginItem) { ddlMessage.DataSource = list; } else if (FormType == FormType.CustomActionItem) { ddlMessage.DisplayMember = "LogicalName"; ddlMessage.ValueMember = "Name"; ddlMessage.DataSource = list2; } btnOk.Enabled = ddlMessage.Items.Count > 0; ddlMessage.Enabled = btnOk.Enabled; ddlStage.Enabled = btnOk.Enabled; ddlExecution.Enabled = btnOk.Enabled; btnCancel.Enabled = true; btnOk.Focus(); } }