/// <summary>
 /// Selected entity changed, so update the Attributes list
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void EntityDropDown_SelectedItemChanged(object sender, EntitiesDropdownControl.SelectedItemChangedEventArgs e)
 {
     if (e.Entity != null)
     {
         RetrieveEntityAttributes(e.Entity.LogicalName);
     }
 }
Ejemplo n.º 2
0
        private void DoStuffWhenSelectingEntity(object sender, EntitiesDropdownControl.SelectedItemChangedEventArgs e)
        {
            var selected = entityDropdown.SelectedEntity;

            if (selected == null)
            {
                listbox.Enabled = false;
                return;
            }
            LookupHelper.Cache.Dispose();

            if (selected.LogicalName == _selectedEntity)
            {
                return;
            }
            _selectedEntity = selected.LogicalName;

            _attributes.Clear();
            _selectedAttributes.Clear();
            listbox.Items.Clear();

            for (var i = panel2.Controls.Count - 1; i >= 0; i--)
            {
                if (panel2.Controls[i].Name != lblDataType.Name)
                {
                    panel2.Controls.RemoveAt(i);
                }
            }

            panel3.Visible  = false;
            listbox.Enabled = true;

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Retrieving metadata",
                Work    = (worker, args) =>
                {
                    var metadataRequest = new RetrieveEntityRequest {
                        EntityFilters = EntityFilters.Attributes, LogicalName = selected.LogicalName
                    };
                    args.Result = (RetrieveEntityResponse)Service.Execute(metadataRequest);
                },
                PostWorkCallBack = (args) =>
                {
                    if (args.Error != null)
                    {
                        MessageBox.Show($"Failed to execute RetrieveEntityRequest. Error message:\n{args.Error}", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    var result = (RetrieveEntityResponse)args.Result;
                    AddAttributesToListBox(result);
                }
            });
        }