private void btnConnection_Click(object sender, System.EventArgs e) { var form = new FormConnection(DTE); if (form.ShowDialog() == DialogResult.OK) { Cursor = Cursors.WaitCursor; CrmConnection = form.CrmConnection; CrmService = form.CrmService; var xrmHelper = new XrmHelper(CrmService); if (FormType == FormType.Plugin || FormType == FormType.LateBoundClass || FormType == FormType.JsWebApiItem || FormType == FormType.Workflow) { cboEntity.DataSource = xrmHelper.GetAllEntities(); btnOk.Enabled = cboEntity.Items.Count > 0; txtName_TextChanged(null, null); cboEntity_SelectedIndexChanged(null, null); } if (FormType == FormType.ProxyTypes || FormType == FormType.WebResource || FormType == FormType.Console || FormType == FormType.CustomAction) { btnOk.Enabled = true; } 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(); } }