Exemple #1
0
        private void tsbCopyComponents_Click(object sender, EventArgs e)
        {
            var settings = new CopySettings
            {
                SourceSolutions = sourceSolutionPicker.SelectedSolutions,
                TargetSolutions = targetSolutionPicker.SelectedSolutions
            };

            var csForm = new ComponentTypeSelector();
            if (csForm.ShowDialog(ParentForm) == DialogResult.OK)
            {
                settings.ComponentsTypes = csForm.SelectedComponents;
            }
            else
            {
                return;
            }

            WorkAsync("Starting copy...",
                (bw, evt) => sManager.CopyComponents((CopySettings) evt.Argument, bw),
                evt =>
                {
                    if (evt.Error != null)
                    {
                        MessageBox.Show(ParentForm, "An error occured: " + evt.Error.Message, "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                },
                evt => SetWorkingMessage(evt.UserState.ToString()),
                settings);
        }
Exemple #2
0
        /// <summary>
        /// Method copies components
        /// </summary>
        /// <param name="solutionFileInfo">solution info file</param>
        public void CopyComponents(SolutionFileInfo solutionFileInfo)
        {
            solutionFileInfo.Solution[Constants.SourceControlQueueAttributeNameForStatus] = Constants.SourceControlQueuemMergingStatus;
            solutionFileInfo.Update();
            var          solutions    = this.RetrieveSolutions();
            CopySettings copySettings = this.GetCopySettings();

            foreach (var solution in solutions)
            {
                if (solution["uniquename"].ToString().ToLower().Equals(solutionFileInfo.SolutionUniqueName.ToString().ToLower()))
                {
                    copySettings.TargetSolutions.Add(solution);
                }
                else if (solutionFileInfo.SolutionsToBeMerged.Any(cc => cc.ToString().ToLower().Equals(solution["uniquename"].ToString().ToLower())))
                {
                    copySettings.SourceSolutions.Add(solution);
                }
            }

            Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<br><br><table cellpadding='5' cellspacing='0' style='border: 1px solid #ccc;font-size: 9pt;font-family:Arial'><tr><th style='background-color: #B8DBFD;border: 1px solid #ccc'>Copying components into Master Solution</th></tr>");

            var components = this.CopyComponents(copySettings);

            Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</table><br><br>");

            var componentsMaster    = this.RetrieveComponentsFromSolutions(copySettings.TargetSolutions.Select(T => T.Id).ToList(), copySettings.ComponentsTypes);
            var differentComponents = (from cm in componentsMaster where !components.Any(list => list.GetAttributeValue <Guid>("objectid") == cm.GetAttributeValue <Guid>("objectid")) select cm).ToList();

            Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<br><br><table cellpadding='5' cellspacing='0' style='border: 1px solid #ccc;font-size: 9pt;font-family:Arial'><tr><th style='background-color: #B8DBFD;border: 1px solid #ccc'>Displaying different(additional) components after merging</th></tr>");

            if (differentComponents != null)
            {
                foreach (var target in copySettings.TargetSolutions)
                {
                    foreach (var componentdetails in differentComponents)
                    {
                        Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<tr>");
                        Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<td style='width:100px;background-color:LightCyan;border: 1px solid #ccc'>");

                        this.GetComponentDetails(copySettings, target, componentdetails, componentdetails.GetAttributeValue <OptionSetValue>("componenttype").Value, componentdetails.GetAttributeValue <Guid>("objectid"), "componenttype", null);
                        Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</td>");
                        Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</tr>");
                    }
                }
            }
            else
            {
                Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<tr>");
                Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<td style='width:100px;background-color:LightCyan;border: 1px solid #ccc'>");
                Singleton.SolutionFileInfoInstance.WebJobsLog.AppendLine(" No different(additional components found after Merging)");
                Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</td>");
                Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</tr>");
            }

            Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</table><br><br>");
            solutionFileInfo.Solution[Constants.SourceControlQueueAttributeNameForStatus] = Constants.SourceControlQueuemMergingSuccessfulStatus;
            solutionFileInfo.Update();
        }
Exemple #3
0
        /// <summary>
        /// copy settings
        /// </summary>
        /// <returns>returns copy settings object</returns>
        private CopySettings GetCopySettings()
        {
            CopySettings copySettings = new CopySettings()
            {
                ComponentsTypes = new List <int>(), SourceSolutions = new List <Entity>(), TargetSolutions = new List <Entity>()
            };

            copySettings.ComponentsTypes.AddRange(Singleton.ConstantsInstance.ComponentTypes);
            return(copySettings);
        }
Exemple #4
0
        /// <summary>
        /// method copies components with the specified settings
        /// </summary>
        /// <param name="settings">copy settings</param>
        /// <returns>list of components</returns>
        private List <Entity> CopyComponents(CopySettings settings)
        {
            var components = this.RetrieveComponentsFromSolutions(settings.SourceSolutions.Select(s => s.Id).ToList(), settings.ComponentsTypes);

            if (settings.TargetSolutions.Count > 0)
            {
                foreach (var target in settings.TargetSolutions)
                {
                    foreach (var component in components)
                    {
                        var request = new AddSolutionComponentRequest
                        {
                            AddRequiredComponents = false,
                            ComponentId           = component.GetAttributeValue <Guid>("objectid"),
                            ComponentType         = component.GetAttributeValue <OptionSetValue>("componenttype").Value,
                            SolutionUniqueName    = target.GetAttributeValue <string>("uniquename"),
                        };
                        Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<tr>");
                        Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<td style='width:100px;background-color:powderblue;border: 1px solid #ccc'>");
                        this.GetComponentDetails(settings, target, component, component.GetAttributeValue <OptionSetValue>("componenttype").Value, component.GetAttributeValue <Guid>("objectid"), "componenttype", null);
                        Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</td>");
                        Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</tr>");
                        request.DoNotIncludeSubcomponents =
                            component.GetAttributeValue <OptionSetValue>("rootcomponentbehavior")?.Value == 1 ||
                            component.GetAttributeValue <OptionSetValue>("rootcomponentbehavior")?.Value == 2;

                        this.service.Execute(request);
                    }
                }
            }
            else
            {
                Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<tr>");
                Singleton.SolutionFileInfoInstance.WebJobsLog.Append("<td style='width:100px;background-color:powderblue;border: 1px solid #ccc'>");
                Singleton.SolutionFileInfoInstance.WebJobsLog.Append("No Components to Display");
                Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</td>");
                Singleton.SolutionFileInfoInstance.WebJobsLog.Append("</tr>");
            }

            return(components);
        }
        /// <summary>
        /// Method copies components
        /// </summary>
        /// <param name="solutionFileInfo">solution info file</param>
        public void CopyComponents(SolutionFileInfo solutionFileInfo)
        {
            solutionFileInfo.Solution[Constants.SourceControlQueueAttributeNameForStatus] = Constants.SourceControlQueuemMergingStatus;
            solutionFileInfo.Update();
            var          solutions    = this.RetrieveSolutions();
            CopySettings copySettings = this.GetCopySettings();

            foreach (var solution in solutions)
            {
                if (solution["uniquename"].ToString().ToLower().Equals(solutionFileInfo.SolutionUniqueName.ToString().ToLower()))
                {
                    copySettings.TargetSolutions.Add(solution);
                }
                else if (solutionFileInfo.SolutionsToBeMerged.Any(cc => cc.ToString().ToLower().Equals(solution["uniquename"].ToString().ToLower())))
                {
                    copySettings.SourceSolutions.Add(solution);
                }
            }

            this.CopyComponents(copySettings);
            solutionFileInfo.Solution[Constants.SourceControlQueueAttributeNameForStatus] = Constants.SourceControlQueuemMergingSuccessfulStatus;
            solutionFileInfo.Update();
        }
Exemple #6
0
        internal void CopyComponents(CopySettings settings, BackgroundWorker backgroundWorker)
        {
            backgroundWorker.ReportProgress(0, "Retrieving source solution(s) components...");

            var components = RetrieveComponentsFromSolutions(settings.SourceSolutions.Select(s => s.Id).ToList(), settings.ComponentsTypes);

            foreach (var target in settings.TargetSolutions)
            {
                backgroundWorker.ReportProgress(0, string.Format("Adding {0} components to solution '{1}'", components.Count, target.GetAttributeValue <string>("friendlyname")));

                foreach (var component in components)
                {
                    var request = new AddSolutionComponentRequest
                    {
                        AddRequiredComponents = false,
                        ComponentId           = component.GetAttributeValue <Guid>("objectid"),
                        ComponentType         = component.GetAttributeValue <OptionSetValue>("componenttype").Value,
                        SolutionUniqueName    = target.GetAttributeValue <string>("uniquename")
                    };

                    service.Execute(request);
                }
            }
        }
        internal void CopyComponents(CopySettings settings, BackgroundWorker backgroundWorker)
        {
            backgroundWorker.ReportProgress(0,"Retrieving source solution(s) components...");

            var components = RetrieveComponentsFromSolutions(settings.SourceSolutions.Select(s => s.Id).ToList(), settings.ComponentsTypes);

            foreach (var target in settings.TargetSolutions)
            {
                backgroundWorker.ReportProgress(0, string.Format("Adding {0} components to solution '{1}'", components.Count, target.GetAttributeValue<string>("friendlyname")));

                foreach (var component in components)
                {
                    var request = new AddSolutionComponentRequest
                    {
                        AddRequiredComponents = false,
                        ComponentId =component.GetAttributeValue<Guid>("objectid"),
                        ComponentType = component.GetAttributeValue<OptionSetValue>("componenttype").Value,
                        SolutionUniqueName = target.GetAttributeValue<string>("uniquename")
                    };

                    service.Execute(request);
                }
            }
        }
        /// <summary>
        /// method copies components with the specified settings
        /// </summary>
        /// <param name="settings">copy settings</param>
        private void CopyComponents(CopySettings settings)
        {
            var components = this.RetrieveComponentsFromSolutions(settings.SourceSolutions.Select(s => s.Id).ToList(), settings.ComponentsTypes);

            foreach (var target in settings.TargetSolutions)
            {
                foreach (var component in components)
                {
                    var request = new AddSolutionComponentRequest
                    {
                        AddRequiredComponents = false,
                        ComponentId           = component.GetAttributeValue <Guid>("objectid"),
                        ComponentType         = component.GetAttributeValue <OptionSetValue>("componenttype").Value,
                        SolutionUniqueName    = target.GetAttributeValue <string>("uniquename"),
                    };

                    request.DoNotIncludeSubcomponents =
                        component.GetAttributeValue <OptionSetValue>("rootcomponentbehavior")?.Value == 1 ||
                        component.GetAttributeValue <OptionSetValue>("rootcomponentbehavior")?.Value == 2;

                    this.service.Execute(request);
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// To Get list of components in Solutions
        /// </summary>
        /// <param name="settings">settings details</param>
        /// <param name="target">target details</param>
        /// <param name="component">component details</param>
        /// <param name="componentType">component Type</param>
        /// <param name="componentId">component Id</param>
        /// <param name="componentDetails">component Details</param>
        /// <param name="targetService">target service proxy</param>
        public void GetComponentDetails(CopySettings settings, Entity target, Entity component, int componentType, Guid componentId, string componentDetails, IOrganizationService targetService)
        {
            Entity sourceSolution = null;

            if (settings != null)
            {
                sourceSolution = settings.SourceSolutions.Find(item => item.Id == component.GetAttributeValue <EntityReference>("solutionid").Id);
            }

            switch (componentType)
            {
            case Constants.Entity:
                var entityReq = new RetrieveEntityRequest();
                entityReq.MetadataId = componentId;
                var retrievedEntity = (RetrieveEntityResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(entityReq);
                if (targetService == null)
                {
                    this.PrintLog(retrievedEntity.EntityMetadata.LogicalName, component.FormattedValues[componentDetails], component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    var targetEntityReq = new RetrieveEntityRequest();
                    targetEntityReq.LogicalName = retrievedEntity.EntityMetadata.LogicalName;
                    var targetRetrievedEntity = (RetrieveEntityResponse)targetService.Execute(targetEntityReq);
                }

                break;

            case Constants.WebResources:
                var webresource = new RetrieveRequest();
                webresource.Target    = new EntityReference("webresource", componentId);
                webresource.ColumnSet = new ColumnSet(true);
                var retrievedWebresource = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(webresource);
                if (targetService == null)
                {
                    this.PrintLog(retrievedWebresource.Entity.Contains("name") ? retrievedWebresource.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedWebresource, "webresource");
                }

                break;

            case Constants.Attribute:
                var attributeReq = new RetrieveAttributeRequest();
                attributeReq.MetadataId = componentId;
                var retrievedAttribute = (RetrieveAttributeResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(attributeReq);
                if (targetService == null)
                {
                    this.PrintLog(retrievedAttribute.AttributeMetadata.LogicalName, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    var targetAttributeReq = new RetrieveAttributeRequest();
                    targetAttributeReq.EntityLogicalName = retrievedAttribute.AttributeMetadata.EntityLogicalName;
                    targetAttributeReq.LogicalName       = retrievedAttribute.AttributeMetadata.LogicalName;
                    var targetRetrievedAttribute = (RetrieveAttributeResponse)targetService.Execute(targetAttributeReq);
                }

                break;

            case Constants.Relationship:
                var relationshipReq = new RetrieveRelationshipRequest();
                relationshipReq.MetadataId = componentId;
                var retrievedrelationshipReq = (RetrieveRelationshipResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(relationshipReq);
                if (targetService == null)
                {
                    this.PrintLog(retrievedrelationshipReq.RelationshipMetadata.SchemaName, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    var targetRelationshipReq = new RetrieveRelationshipRequest();
                    targetRelationshipReq.Name = retrievedrelationshipReq.RelationshipMetadata.SchemaName;
                    var targetRetrievedrelationshipReq = (RetrieveRelationshipResponse)targetService.Execute(targetRelationshipReq);
                }

                break;

            case Constants.DisplayString:
                var displayStringRequest = new RetrieveRequest();
                displayStringRequest.Target    = new EntityReference("displaystring", componentId);
                displayStringRequest.ColumnSet = new ColumnSet(true);
                var retrievedDisplayString = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(displayStringRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedDisplayString.Entity.Contains("name") ? retrievedDisplayString.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedDisplayString, "displaystring");
                }

                break;

            case Constants.SavedQuery:
                var savedQueryRequest = new RetrieveRequest();
                savedQueryRequest.Target    = new EntityReference("savedquery", componentId);
                savedQueryRequest.ColumnSet = new ColumnSet(true);
                var retrievedSavedQuery = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(savedQueryRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedSavedQuery.Entity.Contains("name") ? retrievedSavedQuery.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedSavedQuery, "savedquery");
                }

                break;

            case Constants.SavedQueryVisualization:
                var savedQueryVisualizationRequest = new RetrieveRequest();
                savedQueryVisualizationRequest.Target    = new EntityReference("savedqueryvisualization", componentId);
                savedQueryVisualizationRequest.ColumnSet = new ColumnSet(true);
                var retrievedSavedQueryVisualization = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(savedQueryVisualizationRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedSavedQueryVisualization.Entity.Contains("name") ? retrievedSavedQueryVisualization.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedSavedQueryVisualization, "savedqueryvisualization");
                }

                break;

            case Constants.SystemForm:
                var systemFormRequest = new RetrieveRequest();
                systemFormRequest.Target    = new EntityReference("systemform", componentId);
                systemFormRequest.ColumnSet = new ColumnSet(true);
                var retrievedSystemForm = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(systemFormRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedSystemForm.Entity.Contains("name") ? retrievedSystemForm.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedSystemForm, "systemform");
                }

                break;

            case Constants.HierarchyRule:
                var hierarchyRuleRequest = new RetrieveRequest();
                hierarchyRuleRequest.Target    = new EntityReference("hierarchyrule", componentId);
                hierarchyRuleRequest.ColumnSet = new ColumnSet(true);
                var retrievedHierarchyRule = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(hierarchyRuleRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedHierarchyRule.Entity.Contains("name") ? retrievedHierarchyRule.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedHierarchyRule, "hierarchyrule");
                }

                break;

            case Constants.SiteMap:
                var siteMapRequest = new RetrieveRequest();
                siteMapRequest.Target    = new EntityReference("sitemap", componentId);
                siteMapRequest.ColumnSet = new ColumnSet(true);
                var retrievedSiteMap = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(siteMapRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedSiteMap.Entity.Contains("name") ? retrievedSiteMap.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedSiteMap, "sitemap");
                }

                break;

            case Constants.PluginAssembly:
                var pluginAssemblyRequest = new RetrieveRequest();
                pluginAssemblyRequest.Target    = new EntityReference("pluginassembly", componentId);
                pluginAssemblyRequest.ColumnSet = new ColumnSet(true);
                var retrievedPluginAssembly = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(pluginAssemblyRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedPluginAssembly.Entity.Contains("name") ? retrievedPluginAssembly.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedPluginAssembly, "pluginassembly");
                }

                break;

            case Constants.PluginType:
                var pluginTypeRequest = new RetrieveRequest();
                pluginTypeRequest.Target    = new EntityReference("plugintype", componentId);
                pluginTypeRequest.ColumnSet = new ColumnSet(true);
                var retrievedPluginTypeRequest = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(pluginTypeRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedPluginTypeRequest.Entity.Contains("name") ? retrievedPluginTypeRequest.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedPluginTypeRequest, "plugintype");
                }

                break;

            case Constants.SDKMessageProcessingStep:
                var sdkMessageProcessingStepRequest = new RetrieveRequest();
                sdkMessageProcessingStepRequest.Target    = new EntityReference("sdkmessageprocessingstep", componentId);
                sdkMessageProcessingStepRequest.ColumnSet = new ColumnSet(true);
                var retrievedSDKMessageProcessingStep = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(sdkMessageProcessingStepRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedSDKMessageProcessingStep.Entity.Contains("name") ? retrievedSDKMessageProcessingStep.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedSDKMessageProcessingStep, "sdkmessageprocessingstep");
                }

                break;

            case Constants.ServiceEndpoint:
                var serviceEndpointRequest = new RetrieveRequest();
                serviceEndpointRequest.Target    = new EntityReference("serviceendpoint", componentId);
                serviceEndpointRequest.ColumnSet = new ColumnSet(true);
                var retrievedServiceEndpoint = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(serviceEndpointRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedServiceEndpoint.Entity.Contains("name") ? retrievedServiceEndpoint.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedServiceEndpoint, "serviceendpoint");
                }

                break;

            case Constants.Report:
                var reportRequest = new RetrieveRequest();
                reportRequest.Target    = new EntityReference("report", componentId);
                reportRequest.ColumnSet = new ColumnSet(true);
                var retrievedReport = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(reportRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedReport.Entity.Contains("name") ? retrievedReport.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedReport, "report");
                }

                break;

            case Constants.Role:
                var roleRequest = new RetrieveRequest();
                roleRequest.Target    = new EntityReference("role", componentId);
                roleRequest.ColumnSet = new ColumnSet(true);
                var retrievedRole = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(roleRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedRole.Entity.Contains("name") ? retrievedRole.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedRole, "role");
                }

                break;

            case Constants.FieldSecurityProfile:
                var fieldSecurityProfileRequest = new RetrieveRequest();
                fieldSecurityProfileRequest.Target    = new EntityReference("fieldsecurityprofile", componentId);
                fieldSecurityProfileRequest.ColumnSet = new ColumnSet(true);
                var retrievedFieldSecurityProfile = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(fieldSecurityProfileRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedFieldSecurityProfile.Entity.Contains("name") ? retrievedFieldSecurityProfile.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedFieldSecurityProfile, "fieldsecurityprofile");
                }

                break;

            case Constants.ConnectionRole:
                var connectionRoleRequest = new RetrieveRequest();
                connectionRoleRequest.Target    = new EntityReference("connectionrole", componentId);
                connectionRoleRequest.ColumnSet = new ColumnSet(true);
                var retrievedConnectionRole = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(connectionRoleRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedConnectionRole.Entity.Contains("name") ? retrievedConnectionRole.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedConnectionRole, "connectionrole");
                }

                break;

            case Constants.Workflow:
                var workflowRequest = new RetrieveRequest();
                workflowRequest.Target    = new EntityReference("workflow", componentId);
                workflowRequest.ColumnSet = new ColumnSet(true);
                var retrievedWorkflow = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(workflowRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedWorkflow.Entity.Contains("name") ? retrievedWorkflow.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedWorkflow, "workflow");
                }

                break;

            case Constants.KBArticleTemplate:
                var articleTemplateRequest = new RetrieveRequest();
                articleTemplateRequest.Target    = new EntityReference("kbarticletemplate", componentId);
                articleTemplateRequest.ColumnSet = new ColumnSet(true);
                var retrievedKBArticleTemplate = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(articleTemplateRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedKBArticleTemplate.Entity.Contains("name") ? retrievedKBArticleTemplate.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedKBArticleTemplate, "kbarticletemplate");
                }

                break;

            case Constants.MailMergeTemplate:
                var mailMergeTemplateRequest = new RetrieveRequest();
                mailMergeTemplateRequest.Target    = new EntityReference("mailmergetemplate", componentId);
                mailMergeTemplateRequest.ColumnSet = new ColumnSet(true);
                var retrievedMailMergeTemplate = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(mailMergeTemplateRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedMailMergeTemplate.Entity.Contains("name") ? retrievedMailMergeTemplate.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedMailMergeTemplate, "mailmergetemplate");
                }

                break;

            case Constants.ContractTemplate:
                var contractTemplateRequest = new RetrieveRequest();
                contractTemplateRequest.Target    = new EntityReference("contracttemplate", componentId);
                contractTemplateRequest.ColumnSet = new ColumnSet(true);
                var retrievedContractTemplate = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(contractTemplateRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedContractTemplate.Entity.Contains("name") ? retrievedContractTemplate.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedContractTemplate, "contracttemplate");
                }

                break;

            case Constants.EmailTemplate:
                var emailTemplateRequest = new RetrieveRequest();
                emailTemplateRequest.Target    = new EntityReference("template", componentId);
                emailTemplateRequest.ColumnSet = new ColumnSet(true);
                var retrievedEmailTemplate = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(emailTemplateRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedEmailTemplate.Entity.Contains("name") ? retrievedEmailTemplate.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedEmailTemplate, "template");
                }

                break;

            case Constants.SLA:
                var slaRequest = new RetrieveRequest();
                slaRequest.Target    = new EntityReference("sla", componentId);
                slaRequest.ColumnSet = new ColumnSet(true);
                var retrievedSLA = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(slaRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedSLA.Entity.Contains("name") ? retrievedSLA.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedSLA, "sla");
                }

                break;

            case Constants.ConvertRule:
                var convertRuleRequest = new RetrieveRequest();
                convertRuleRequest.Target    = new EntityReference("convertrule", componentId);
                convertRuleRequest.ColumnSet = new ColumnSet(true);
                var retrievedConvertRule = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(convertRuleRequest);
                if (targetService == null)
                {
                    this.PrintLog(retrievedConvertRule.Entity.Contains("name") ? retrievedConvertRule.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedConvertRule, "convertrule");
                }

                break;

            case Constants.SDKMessageProcessingStepImage:
                var sdkmessageprocessingstepimage = new RetrieveRequest();
                sdkmessageprocessingstepimage.Target    = new EntityReference("sdkmessageprocessingstepimage", componentId);
                sdkmessageprocessingstepimage.ColumnSet = new ColumnSet(true);
                var retrievedSdkmessageprocessingstepimage = (RetrieveResponse)Singleton.CrmConstantsInstance.ServiceProxy.Execute(sdkmessageprocessingstepimage);
                if (targetService == null)
                {
                    this.PrintLog(retrievedSdkmessageprocessingstepimage.Entity.Contains("name") ? retrievedSdkmessageprocessingstepimage.Entity.Attributes["name"].ToString() : string.Empty, component.FormattedValues[componentDetails].ToString(), component.Id, sourceSolution?.Attributes["friendlyname"].ToString() ?? string.Empty, target?.Attributes["friendlyname"].ToString());
                }
                else
                {
                    this.QueryTargetComponents(targetService, retrievedSdkmessageprocessingstepimage, "sdkmessageprocessingstepimage");
                }

                break;

            default:
                Singleton.SolutionFileInfoInstance.WebJobsLog.AppendLine("Unable to copy component type: " + component.FormattedValues[componentDetails] + " and objectID: " + componentId.ToString());
                break;
            }
        }
        internal void CopyComponents(CopySettings settings, OptionMetadataCollection omc, BackgroundWorker backgroundWorker)
        {
            backgroundWorker.ReportProgress(0, "Retrieving source solution(s) components...");

            var components = RetrieveComponentsFromSolutions(settings.SourceSolutions.Select(s => s.Id).ToList(), settings.ComponentsTypes);

            var entityComponents = components.Where(c =>
                                                    c.GetAttributeValue <OptionSetValue>("componenttype").Value == 1 &&
                                                    c.GetAttributeValue <OptionSetValue>("rootcomponentbehavior").Value == 0 &&
                                                    (bool)c.GetAttributeValue <AliasedValue>("solution.ismanaged").Value == false).ToList();

            if (entityComponents.Any() && settings.CheckBestPractice)
            {
                backgroundWorker.ReportProgress(0, "Analyzing entities components behavior...");
                var emds = GetManagedEntities(entityComponents.Select(ec => ec.GetAttributeValue <Guid>("objectid"))
                                              .ToArray());

                if (emds.Any())
                {
                    throw new Exception($@"Best practices are not respected!

Managed entities should not be added in unmanaged solutions with all their assets.

Remove best practice check if you really want to copy the following entities to the target solution(s):
{string.Join(Environment.NewLine, emds.OrderBy(e => e.DisplayName?.UserLocalizedLabel?.Label).Select(e => "- " + e.DisplayName?.UserLocalizedLabel?.Label))}");
                }
            }

            foreach (var target in settings.TargetSolutions)
            {
                backgroundWorker.ReportProgress(0,
                                                $"Adding {components.Count} components to solution '{target.GetAttributeValue<string>("friendlyname")}'");

                AddSolutionComponentRequest request = new AddSolutionComponentRequest();

                foreach (var component in components)
                {
                    try
                    {
                        request = new AddSolutionComponentRequest
                        {
                            AddRequiredComponents = false,
                            ComponentId           = component.GetAttributeValue <Guid>("objectid"),
                            ComponentType         = component.GetAttributeValue <OptionSetValue>("componenttype").Value,
                            SolutionUniqueName    = target.GetAttributeValue <string>("uniquename"),
                        };

                        // If CRM 2016 or above, handle subcomponents behavior
                        if (settings.ConnectionDetail.OrganizationMajorVersion >= 8)
                        {
                            request.DoNotIncludeSubcomponents =
                                component.GetAttributeValue <OptionSetValue>("rootcomponentbehavior")?.Value == 1 ||
                                component.GetAttributeValue <OptionSetValue>("rootcomponentbehavior")?.Value == 2;
                        }

                        service.Execute(request);
                        backgroundWorker.ReportProgress(1,
                                                        $"Component {request.ComponentId} of type {omc.First(o => o.Value == request.ComponentType).Label?.UserLocalizedLabel?.Label} successfully added to solution '{request.SolutionUniqueName}'");
                    }
                    catch (Exception error)
                    {
                        backgroundWorker.ReportProgress(-1,
                                                        $"Error when adding component {request.ComponentId} of type {omc.First(o => o.Value == request.ComponentType).Label?.UserLocalizedLabel?.Label} to solution '{request.SolutionUniqueName}' : {error.Message}");
                    }
                }
            }
        }