private void LoadComponentItems(IEnumerable <string> ids, XrmRecordService xrmRecordService)
            {
                if (ComponentTypeKey == OptionSets.SolutionComponent.ObjectTypeCode.Entity)
                {
                    AllItems = xrmRecordService
                               .GetAllRecordTypes()
                               .Select(r => xrmRecordService.GetRecordTypeMetadata(r))
                               .Where(m => ids.Contains(m.MetadataId))
                               .Select(m => new AddToSolutionComponentItem(m.MetadataId, m.DisplayName))
                               .ToArray();
                }
                else if (ComponentTypeKey == OptionSets.SolutionComponent.ObjectTypeCode.OptionSet)
                {
                    AllItems = xrmRecordService
                               .GetSharedPicklists()
                               .Where(m => ids.Contains(m.MetadataId))
                               .Select(m => new AddToSolutionComponentItem(m.MetadataId, m.DisplayName))
                               .ToArray();
                }
                else
                {
                    var propTypeMaps = new Dictionary <int, string>();
                    propTypeMaps.Add(OptionSets.SolutionComponent.ObjectTypeCode.SystemForm, Entities.systemform);
                    propTypeMaps.Add(OptionSets.SolutionComponent.ObjectTypeCode.EmailTemplate, Entities.template);
                    propTypeMaps.Add(OptionSets.SolutionComponent.ObjectTypeCode.PluginAssembly, Entities.pluginassembly);
                    propTypeMaps.Add(OptionSets.SolutionComponent.ObjectTypeCode.SDKMessageProcessingStep, Entities.sdkmessageprocessingstep);
                    propTypeMaps.Add(OptionSets.SolutionComponent.ObjectTypeCode.Report, Entities.report);
                    propTypeMaps.Add(OptionSets.SolutionComponent.ObjectTypeCode.Role, Entities.role);
                    propTypeMaps.Add(OptionSets.SolutionComponent.ObjectTypeCode.WebResource, Entities.webresource);
                    propTypeMaps.Add(OptionSets.SolutionComponent.ObjectTypeCode.Workflow, Entities.workflow);
                    if (!propTypeMaps.ContainsKey(ComponentTypeKey))
                    {
                        throw new NotImplementedException($"Component Type {ComponentTypeKey} Is Not Implemented");
                    }

                    var recordType      = propTypeMaps[ComponentTypeKey];
                    var primaryKeyField = xrmRecordService.GetPrimaryKey(recordType);
                    var nameField       = xrmRecordService.GetPrimaryField(recordType);

                    AllItems = xrmRecordService
                               .RetrieveAllOrClauses(recordType, ids.Select(i => new Condition(primaryKeyField, ConditionType.Equal, i)))
                               .Select(e => new AddToSolutionComponentItem(e.Id, e.GetStringField(nameField)))
                               .OrderBy(c => c.Name)
                               .ToArray();
                }

                ItemsSelection = AllItems
                                 .Select(i => new SelectableAddToSolutionComponentItem(i.Id, i.Name))
                                 .ToArray();
            }
        private void DeleteOptionSets(IEnumerable <CustomisationImportRequest> requests)
        {
            var response = new CustomisationImportResponse();

            foreach (var request in requests)
            {
                var optionMetadata =
                    CustomisationImportService.ExtractOptionSetsFromExcel(request.ExcelFile.FileName,
                                                                          Controller, response);
                foreach (var metadata in optionMetadata)
                {
                    if (metadata.IsSharedOptionSet &&
                        XrmRecordService.GetSharedPicklists().Any(p => p.SchemaName == metadata.SchemaName))
                    {
                        XrmRecordService.DeleteSharedOptionSet(metadata.SchemaName);
                    }
                    Assert.IsFalse(XrmRecordService.GetSharedPicklists().Any(p => p.SchemaName == metadata.SchemaName));
                }
            }
        }