public static bool HasDependencies(
     IOrganizationService orgSvc,
     componenttype componentType,
     Guid objectId)
 {
     return(GetDependencies(orgSvc, componentType, objectId).Any());
 }
 public static int CountDependencies(
     IOrganizationService orgSvc,
     componenttype componentType,
     Guid objectId)
 {
     return(GetDependencies(orgSvc, componentType, objectId).Count());
 }
 private void AddComponentToSolution(Solution solution, Guid componentId, componenttype componentTypeCode)
 {
     if (solution.UniqueName != "Default")
     {
         orgService.Execute(new AddSolutionComponentRequest
         {
             SolutionUniqueName = solution.UniqueName,
             ComponentId        = componentId,
             ComponentType      = (int)componentTypeCode
         });
     }
 }
        public static IEnumerable <Dependency> GetDependencies(
            IOrganizationService orgSvc,
            componenttype componentType,
            Guid objectId)
        {
            var dependentComponentsRequest = new RetrieveDependentComponentsRequest
            {
                ComponentType = (int)componentType,
                ObjectId      = objectId
            };

            var dependentComponentsResponse = (RetrieveDependentComponentsResponse)orgSvc.Execute(dependentComponentsRequest);

            return(dependentComponentsResponse.EntityCollection.Entities.Select(e => e.ToEntity <Dependency>()));
        }
        public ComponentInfo GetComponentInfo(componenttype componentType, Guid componentId)
        {
            switch (componentType)
            {
            case componenttype.OptionSet: return(GetGlobalOptionSetName(componentId));

            case componenttype.Attribute: return(GetAttributeInformation(componentId));

            case componenttype.Entity: return(GetEntityName(componentId));

            case componenttype.Relationship: return(GetRelationshipName(componentId));

            case componenttype.EntityRelationship: return(GetRelationshipName(componentId));

            // These need to be implemented
            case componenttype.AttributePicklistValue:
            case componenttype.AttributeLookupValue:
            case componenttype.ViewAttribute:
            case componenttype.LocalizedLabel:
            case componenttype.RelationshipExtraCondition:
            case componenttype.EntityRelationshipRole:
            case componenttype.EntityRelationshipRelationships:
            case componenttype.ManagedProperty:
            case componenttype.EntityKey:
            case componenttype.Privilege:
            case componenttype.PrivilegeObjectTypeCode:
            case componenttype.Role:
            case componenttype.RolePrivilege:
            case componenttype.DisplayString:
            case componenttype.DisplayStringMap:
            case componenttype.Form:
            case componenttype.Organization:
            case componenttype.SavedQuery:
            case componenttype.Workflow:
            case componenttype.Report:
            case componenttype.ReportEntity:
            case componenttype.ReportCategory:
            case componenttype.ReportVisibility:
            case componenttype.Attachment:
            case componenttype.EmailTemplate:
            case componenttype.ContractTemplate:
            case componenttype.KBArticleTemplate:
            case componenttype.MailMergeTemplate:
            case componenttype.DuplicateRule:
            case componenttype.DuplicateRuleCondition:
            case componenttype.EntityMap:
            case componenttype.AttributeMap:
            case componenttype.RibbonCommand:
            case componenttype.RibbonContextGroup:
            case componenttype.RibbonCustomization:
            case componenttype.RibbonRule:
            case componenttype.RibbonTabToCommandMap:
            case componenttype.RibbonDiff:
            case componenttype.SavedQueryVisualization:
            case componenttype.SystemForm:
            case componenttype.WebResource:
            case componenttype.SiteMap:
            case componenttype.ConnectionRole:
            case componenttype.ComplexControl:
            case componenttype.FieldSecurityProfile:
            case componenttype.FieldPermission:
            case componenttype.PluginType:
            case componenttype.PluginAssembly:
            case componenttype.SDKMessageProcessingStep:
            case componenttype.SDKMessageProcessingStepImage:
            case componenttype.ServiceEndpoint:
            case componenttype.RoutingRule:
            case componenttype.RoutingRuleItem:
            case componenttype.SLA:
            case componenttype.SLAItem:
            case componenttype.ConvertRule:
            case componenttype.ConvertRuleItem:
            case componenttype.HierarchyRule:
            case componenttype.MobileOfflineProfile:
            case componenttype.MobileOfflineProfileItem:
            case componenttype.SimilarityRule:
            case componenttype.CustomControl:
            case componenttype.CustomControlDefaultConfig:
            case componenttype.DataSourceMapping:
            case componenttype.SDKMessage:
            case componenttype.SDKMessageFilter:
            case componenttype.SdkMessagePair:
            case componenttype.SdkMessageRequest:
            case componenttype.SdkMessageRequestField:
            case componenttype.SdkMessageResponse:
            case componenttype.SdkMessageResponseField:
            case componenttype.WebWizard:
            case componenttype.Index:
            case componenttype.ImportMap:
            case componenttype.CanvasApp:
            default: return(new ComponentInfo
                {
                    Name = "<N/A>"
                });
            }
        }