private string GetSolutionComponentRelativeUrl(ComponentType componentType, Guid objectId)
        {
            switch (componentType)
            {
            case ComponentType.SavedQueryVisualization:
            {
                var respositorySolution = new SolutionRepository(this._service);

                var chart = _service.RetrieveByQuery <SavedQueryVisualization>(SavedQueryVisualization.EntityLogicalName, objectId, new ColumnSet(SavedQueryVisualization.Schema.Attributes.primaryentitytypecode));

                if (chart != null && !string.IsNullOrEmpty(chart.PrimaryEntityTypeCode))
                {
                    if ((this._service.ConnectionData.EntitiesIntellisenseData?.Entities?.ContainsKey(chart.PrimaryEntityTypeCode)).GetValueOrDefault())
                    {
                        var linkedEntityObjectCode = this._service.ConnectionData.EntitiesIntellisenseData.Entities[chart.PrimaryEntityTypeCode].ObjectTypeCode;

                        if (linkedEntityObjectCode.HasValue)
                        {
                            return($"/main.aspx?appSolutionId=%7b{Solution.Schema.InstancesUniqueId.DefaultId}%7d&extraqs=etc%3d{linkedEntityObjectCode}%26id%3d%7b{objectId}%7d&pagetype=vizdesigner");
                        }
                    }
                }
            }
            break;

            case ComponentType.SystemForm:
            {
                var respositorySolution = new SolutionRepository(this._service);

                var systemform = _service.RetrieveByQuery <SystemForm>(SystemForm.EntityLogicalName, objectId, new ColumnSet(SystemForm.Schema.Attributes.type, SystemForm.Schema.Attributes.objecttypecode));

                if (systemform != null && systemform.Type != null)
                {
                    if (systemform.Type.Value == (int)SystemForm.Schema.OptionSets.type.Task_Flow_Form_9)
                    {
                        var workflowRepository = new WorkflowRepository(_service);

                        var linkedWorkflow = workflowRepository.FindLinkedWorkflow(systemform.Id, ColumnSetInstances.None);

                        if (linkedWorkflow != null)
                        {
                            return(this.GetSolutionComponentRelativeUrl(ComponentType.Workflow, linkedWorkflow.Id));
                        }
                    }
                    else
                    {
                        return(_service.ConnectionData.GetSystemFormRelativeUrl(systemform.ObjectTypeCode, systemform.Id, systemform.Type.Value));
                    }
                }
            }
            break;

            case ComponentType.SiteMap:
            {
                var respositorySolution = new SolutionRepository(this._service);

                //designer/sitemap/FD140AAF-4DF4-11DD-BD17-0019B9312238/39983702-960A-E711-80DD-00155D018C04#/SiteMapHome/39983702-960a-e711-80dd-00155d018c04

                return($"/designer/sitemap/{Solution.Schema.InstancesUniqueId.DefaultId}/{objectId}#/SiteMapHome/{objectId}");
            }

            case ComponentType.AttributeMap:
            {
                var attributeMap = _service.RetrieveByQuery <AttributeMap>(AttributeMap.EntityLogicalName, objectId, new ColumnSet(AttributeMap.Schema.Attributes.entitymapid));

                if (attributeMap != null && attributeMap.EntityMapId != null)
                {
                    return(this.GetSolutionComponentRelativeUrl(ComponentType.EntityMap, attributeMap.EntityMapId.Id));
                }
            }
            break;

            case ComponentType.DisplayStringMap:
            {
                var displayMap = _service.RetrieveByQuery <DisplayStringMap>(DisplayStringMap.EntityLogicalName, objectId, new ColumnSet(DisplayStringMap.Schema.Attributes.displaystringid));

                if (displayMap != null && displayMap.DisplayStringId.HasValue)
                {
                    return(this.GetSolutionComponentRelativeUrl(ComponentType.DisplayString, displayMap.DisplayStringId.Value));
                }
            }
            break;

            case ComponentType.RolePrivileges:
            {
                var entity = _service.RetrieveByQuery <RolePrivileges>(RolePrivileges.EntityLogicalName, objectId, new ColumnSet(RolePrivileges.Schema.Attributes.roleid));

                if (entity != null && entity.RoleId.HasValue)
                {
                    return(this.GetSolutionComponentRelativeUrl(ComponentType.Role, entity.RoleId.Value));
                }
            }
            break;

            case ComponentType.FieldPermission:
            {
                var entity = _service.RetrieveByQuery <FieldPermission>(FieldPermission.EntityLogicalName, objectId, new ColumnSet(FieldPermission.Schema.Attributes.fieldsecurityprofileid));

                if (entity != null && entity.FieldSecurityProfileId != null)
                {
                    return(this.GetSolutionComponentRelativeUrl(ComponentType.FieldSecurityProfile, entity.FieldSecurityProfileId.Id));
                }
            }
            break;

            case ComponentType.ReportEntity:
            {
                var entity = _service.RetrieveByQuery <ReportEntity>(ReportEntity.EntityLogicalName, objectId, new ColumnSet(ReportEntity.Schema.Attributes.reportid));

                if (entity != null && entity.ReportId != null)
                {
                    return(this.GetSolutionComponentRelativeUrl(ComponentType.Report, entity.ReportId.Id));
                }
            }
            break;

            case ComponentType.ReportCategory:
            {
                var entity = _service.RetrieveByQuery <ReportCategory>(ReportCategory.EntityLogicalName, objectId, new ColumnSet(ReportCategory.Schema.Attributes.reportid));

                if (entity != null && entity.ReportId != null)
                {
                    return(this.GetSolutionComponentRelativeUrl(ComponentType.Report, entity.ReportId.Id));
                }
            }
            break;

            case ComponentType.ReportVisibility:
            {
                var entity = _service.RetrieveByQuery <ReportVisibility>(ReportVisibility.EntityLogicalName, objectId, new ColumnSet(ReportVisibility.Schema.Attributes.reportid));

                if (entity != null && entity.ReportId != null)
                {
                    return(this.GetSolutionComponentRelativeUrl(ComponentType.Report, entity.ReportId.Id));
                }
            }
            break;

            case ComponentType.AppModule:
            {
                var respositorySolution = new SolutionRepository(this._service);

                // /designer/app/47FB3607-13DA-E811-8114-001DD8B71D68/7A536683-A60D-E811-8105-001DD8B71D68#/AppDesignerCanvas/7a536683-a60d-e811-8105-001dd8b71d68

                return($"/designer/app/{Solution.Schema.InstancesUniqueId.DefaultId}/{objectId}#/AppDesignerCanvas/{objectId}");
            }

            case ComponentType.AppModuleRoles:
            {
                var appModuleRoles = _service.RetrieveByQuery <AppModuleRoles>(AppModuleRoles.EntityLogicalName, objectId, new ColumnSet(AppModuleRoles.Schema.Attributes.appmoduleid));

                if (appModuleRoles != null && appModuleRoles.AppModuleId != null)
                {
                    return(this.GetSolutionComponentRelativeUrl(ComponentType.AppModule, appModuleRoles.AppModuleId.Id));
                }
            }
            break;

                //case ComponentType.RibbonCommand:
                //   return $"";
                //case ComponentType.RibbonContextGroup:
                //   return $"";
                //case ComponentType.RibbonCustomization:
                //   return $"";
                //case ComponentType.RibbonRule:
                //   return $"";
                //case ComponentType.RibbonTabToCommandMap:
                //   return $"";
                //case ComponentType.RibbonDiff:
                //   return $"";

                //case ComponentType.SLAItem:
                //   return $"";



                //case ComponentType.Relationship:
                //   return $"";
                //case ComponentType.AttributePicklistValue:
                //   return $"";
                //case ComponentType.AttributeLookupValue:
                //   return $"";
                //case ComponentType.ViewAttribute:
                //   return $"";
                //case ComponentType.LocalizedLabel:
                //   return $"";
                //case ComponentType.RelationshipExtraCondition:
                //   return $"";

                //case ComponentType.EntityRelationshipRole:
                //   return $"";
                //case ComponentType.EntityRelationshipRelationships:
                //   return $"";

                //case ComponentType.ManagedProperty:
                //   return $"";

                //case ComponentType.Form:
                //   return $"";
                //case ComponentType.Organization:
                //   return $"";

                //case ComponentType.Attachment:
                //   return $"";

                //case ComponentType.PluginType:
                //   return $"";
                //case ComponentType.PluginAssembly:
                //   return $"";

                //case ComponentType.SDKMessageProcessingStep:
                //   return $"";
                //case ComponentType.SDKMessageProcessingStepImage:
                //   return $"";

                //case ComponentType.ServiceEndpoint:
                //   return $"";
                //case ComponentType.RoutingRule:
                //   return $"";
                //case ComponentType.RoutingRuleItem:
                //   return $"";

                //case ComponentType.ConvertRule:
                //   return $"";
                //case ComponentType.ConvertRuleItem:
                //   return $"";
                //case ComponentType.HierarchyRule:
                //   return $"";
                //case ComponentType.MobileOfflineProfileItem:
                //   return $"";
                //case ComponentType.SimilarityRule:
                //   return $"";
            }

            return(this._service.ConnectionData.GetSolutionComponentRelativeUrl(componentType, objectId));
        }
        private void LoadEntityStepProperties()
        {
            if (Step.EventHandler != null)
            {
                var nameColumn = PluginType.Schema.Attributes.name;

                if (string.Equals(Step.EventHandler.LogicalName, PluginType.EntityLogicalName, StringComparison.InvariantCultureIgnoreCase))
                {
                    nameColumn = PluginType.Schema.Attributes.typename;
                }
                else if (string.Equals(Step.EventHandler.LogicalName, ServiceEndpoint.EntityLogicalName, StringComparison.InvariantCultureIgnoreCase))
                {
                    nameColumn = ServiceEndpoint.Schema.Attributes.name;
                }

                var eventHandlerEntity = _service.RetrieveByQuery <Entity>(Step.EventHandler.LogicalName, Step.EventHandler.Id, new ColumnSet(nameColumn));

                if (eventHandlerEntity.Attributes.ContainsKey(nameColumn) &&
                    eventHandlerEntity.Attributes[nameColumn] != null &&
                    eventHandlerEntity.Attributes[nameColumn] is string name &&
                    !string.IsNullOrEmpty(name)
                    )
                {
                    _eventHandlerName = name;
                }
            }

            txtBEventHandler.Text = _eventHandlerName;

            cmBMessageName.Text = Step.SdkMessageId?.Name;
            if (cmBMessageName.Items.Contains(cmBMessageName.Text))
            {
                cmBMessageName.SelectedItem = cmBMessageName.Text;
            }

            cmBPrimaryEntity.Text = Step.PrimaryObjectTypeCodeName;
            if (cmBPrimaryEntity.Items.Contains(cmBPrimaryEntity.Text))
            {
                cmBPrimaryEntity.SelectedItem = cmBPrimaryEntity.Text;
            }

            cmBSecondaryEntity.Text = Step.SecondaryObjectTypeCodeName;
            if (cmBSecondaryEntity.Items.Contains(cmBSecondaryEntity.Text))
            {
                cmBSecondaryEntity.SelectedItem = cmBSecondaryEntity.Text;
            }

            txtBName.Text = Step.Name;

            if (Step.Rank.HasValue)
            {
                txtBExecutionOrder.Text = Step.Rank.ToString();
            }
            else
            {
                txtBExecutionOrder.Text = "1";
            }

            txtBDescription.Text           = Step.Description;
            txtBUnSecureConfiguration.Text = Step.Configuration;

            txtBFilteringBAttributes.Text    = Step.FilteringAttributesStringsSorted;
            txtBFilteringBAttributes.ToolTip = string.Join(System.Environment.NewLine, Step.FilteringAttributesStrings);

            if (Step.Stage?.Value == (int)SdkMessageProcessingStep.Schema.OptionSets.stage.Post_operation_40)
            {
                rBPostOperation.IsChecked = true;
            }
            else if (Step.Stage?.Value == (int)SdkMessageProcessingStep.Schema.OptionSets.stage.Pre_operation_20)
            {
                rBPreOperation.IsChecked = true;
            }
            else if (Step.Stage?.Value == (int)SdkMessageProcessingStep.Schema.OptionSets.stage.Pre_validation_10)
            {
                rBPreValidation.IsChecked = true;
            }
            else
            {
                rBPostOperation.IsChecked = true;
            }

            if (Step.Mode?.Value == (int)SdkMessageProcessingStep.Schema.OptionSets.mode.Synchronous_0)
            {
                rBSync.IsChecked = true;
            }
            else if (Step.Mode?.Value == (int)SdkMessageProcessingStep.Schema.OptionSets.mode.Asynchronous_1)
            {
                rBAsync.IsChecked = true;
            }
            else
            {
                rBSync.IsChecked = true;
            }

            if (Step.SupportedDeployment?.Value == (int)SdkMessageProcessingStep.Schema.OptionSets.supporteddeployment.Server_Only_0)
            {
                rBServer.IsChecked = true;
            }
            else if (Step.SupportedDeployment?.Value == (int)SdkMessageProcessingStep.Schema.OptionSets.supporteddeployment.Microsoft_Dynamics_365_Client_for_Outlook_Only_1)
            {
                rBOffline.IsChecked = true;
            }
            else if (Step.SupportedDeployment?.Value == (int)SdkMessageProcessingStep.Schema.OptionSets.supporteddeployment.Both_2)
            {
                rBDeploymentBoth.IsChecked = true;
            }
            else
            {
                rBServer.IsChecked = true;
            }

#pragma warning disable CS0612 // Type or member is obsolete
            if (Step.InvocationSource?.Value == (int)SdkMessageProcessingStep.Schema.OptionSets.invocationsource.Parent_0)
#pragma warning restore CS0612 // Type or member is obsolete
            {
                rBParent.IsChecked = true;
            }
#pragma warning disable CS0612 // Type or member is obsolete
            else if (Step.InvocationSource?.Value == (int)SdkMessageProcessingStep.Schema.OptionSets.invocationsource.Child_1)
#pragma warning restore CS0612 // Type or member is obsolete
            {
                rBChild.IsChecked = true;
            }
            else
            {
                rBParent.IsChecked = true;
            }

            chBDeleteAsyncOperationIfSuccessful.IsChecked = Step.AsyncAutoDelete.GetValueOrDefault();

            if (Step.SdkMessageProcessingStepSecureConfigId != null)
            {
                var config = _service.RetrieveByQuery <SdkMessageProcessingStepSecureConfig>(Step.SdkMessageProcessingStepSecureConfigId.LogicalName, Step.SdkMessageProcessingStepSecureConfigId.Id, new ColumnSet(SdkMessageProcessingStepSecureConfig.Schema.Attributes.secureconfig));

                if (config != null)
                {
                    txtBSecureConfiguration.Text = config.SecureConfig;
                }
            }

            this._impersonatingUser = Step.ImpersonatingUserId;

            if (Step.ImpersonatingUserId != null)
            {
                if (!string.IsNullOrEmpty(Step.ImpersonatingUserId.Name))
                {
                    txtBRunInUserContext.Text = Step.ImpersonatingUserId.Name;
                }
                else
                {
                    txtBRunInUserContext.Text = Step.ImpersonatingUserId.Id.ToString();
                }
            }
            else
            {
                txtBRunInUserContext.Text = _impersonatingUserNone;
            }
        }