コード例 #1
0
        private void UpdateEntityOptionSet()
        {
            AttributeMetadata attribute = _repository.GetAttribute(Entity, Attribute);

            // Can be new or update
            OptionSetMetadataBase attributeOptionSet = null;

            if (attribute is BooleanAttributeMetadata booleanAttribute)
            {
                attributeOptionSet = booleanAttribute.OptionSet;
            }
            else if (attribute is PicklistAttributeMetadata picklistAttribute)
            {
                attributeOptionSet = picklistAttribute.OptionSet;
            }

            if (IsNewOptionSetValue(attributeOptionSet, Value))
            {
                _repository.AddOptionSetValue(Entity, Attribute, DisplayName, Value, Description);
            }
            else
            {
                _repository.UpdateOptionSetValue(Entity, Attribute, Value.Value, DisplayName, Description);
            }
        }
コード例 #2
0
        public IEnumerable <CompletionResult> CompleteArgument(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters)
        {
            if (fakeBoundParameters == null)
            {
                throw new ArgumentNullException("fakeBoundParameters");
            }

            List <CompletionResult> result = new List <CompletionResult>();

            foreach (string filterParameter in _filterParameters)
            {
                if (fakeBoundParameters.Contains(filterParameter))
                {
                    MetadataRepository repository = new MetadataRepository();
                    IEnumerable <AttributeMetadata> attributeMetadatas = null;
                    try
                    {
                        if (fakeBoundParameters[filterParameter] is string)
                        {
                            attributeMetadatas = repository.GetAttribute(fakeBoundParameters[filterParameter] as string, false, false, true);
                        }
                        else if (fakeBoundParameters[filterParameter] is Entity)
                        {
                            attributeMetadatas = repository.GetAttribute((fakeBoundParameters[filterParameter] as Entity).LogicalName, false, false, true);
                        }
                    }
                    catch { }

                    if (attributeMetadatas != null)
                    {
                        result.AddRange(from attributeMetadata in attributeMetadatas
                                        where attributeMetadata.LogicalName.StartsWith(wordToComplete.Trim('\'', '"'), StringComparison.InvariantCultureIgnoreCase)
                                        orderby attributeMetadata.LogicalName
                                        select new CompletionResult($"'{attributeMetadata.LogicalName}'", attributeMetadata.LogicalName, CompletionResultType.Text, attributeMetadata.LogicalName));
                    }
                }
            }

            if (result.Count == 0)
            {
                return(null);
            }
            else
            {
                return(result);
            }
        }
コード例 #3
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            switch (this.ParameterSetName)
            {
            case GetAttributeByIdParameterSet:
                WriteObject(_repository.GetAttribute(Id));
                break;

            case GetAttributesByFilterParameterSet:
                GetAttributeByFilter();
                break;

            default:
                break;
            }
        }
コード例 #4
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            _repository.UpdateAttribute(Entity, InputObject);
            if (PassThru)
            {
                WriteObject(_repository.GetAttribute(InputObject.MetadataId.Value));
            }
        }
コード例 #5
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            Guid id = _repository.AddAttribute(Entity, InputObject);

            if (PassThru)
            {
                WriteObject(_repository.GetAttribute(id));
            }
        }
コード例 #6
0
        public override PSAdaptedProperty GetProperty(object baseObject, string propertyName)
        {
            PSAdaptedProperty prop = base.GetProperty(baseObject, propertyName);

            if (prop == null && baseObject is Entity internalObject)
            {
                MetadataRepository repository        = new MetadataRepository();
                AttributeMetadata  attributeMetadata = null;
                try
                {
                    attributeMetadata = repository.GetAttribute(internalObject.LogicalName, propertyName);
                }
                catch { }

                if (attributeMetadata != null)
                {
                    return(new PSAdaptedProperty(attributeMetadata.LogicalName, new EntityAttributePropertyHandler(attributeMetadata.LogicalName)));
                }
            }
            return(prop);
        }
コード例 #7
0
        public static string GetComponentName(int componentType, Guid objectId)
        {
            MetadataRepository mdr = new MetadataRepository();

            string componentLogicalName = null;
            string primaryNameAttribute = null;

            switch (componentType)
            {
            case 1:      //Entity
                return(mdr.GetEntity(objectId).LogicalName);

            case 2:      //Attribute
                return(mdr.GetAttribute(objectId).LogicalName);

            case 3:      //Relationship
                return(mdr.GetRelationship(objectId).SchemaName);

            case 9:      //Option Set
                return(mdr.GetOptionSet(objectId).Name);

            case 10:     //Entity Relationship
                return(mdr.GetRelationship(objectId).SchemaName);

            case 13:     //Managed Property
                return(mdr.GetManagedProperty(objectId).LogicalName);

            case 11:     //Relationship Role
                componentLogicalName = "relationshiprole";
                primaryNameAttribute = "name";
                break;

            case 20:     //Security Role
                componentLogicalName = "role";
                primaryNameAttribute = "name";
                break;

            case 21:     //Privilege
                componentLogicalName = "privilege";
                primaryNameAttribute = "name";
                break;

            case 24:     //User Dashboard
                componentLogicalName = "userform";
                primaryNameAttribute = "name";
                break;

            case 25:     //Organization
                componentLogicalName = "organization";
                primaryNameAttribute = "name";
                break;

            case 26:     //View
                componentLogicalName = "savedquery";
                primaryNameAttribute = "name";
                break;

            case 29:     //Process
                componentLogicalName = "workflow";
                primaryNameAttribute = "name";
                break;

            case 31:     //Report
                componentLogicalName = "report";
                primaryNameAttribute = "name";
                break;

            case 36:     //Email Template
                componentLogicalName = "template";
                primaryNameAttribute = "title";
                break;

            case 37:     //Contract Template
                componentLogicalName = "contracttemplate";
                primaryNameAttribute = "name";
                break;

            case 38:     //Article Template
                componentLogicalName = "kbarticletemplate";
                primaryNameAttribute = "title";
                break;

            case 39:     //Mail Merge Template
                componentLogicalName = "mailmergetemplate";
                primaryNameAttribute = "name";
                break;

            case 44:     //Duplicate Detection Rule
                componentLogicalName = "duplicaterule";
                primaryNameAttribute = "name";
                break;

            case 59:     //System Chart
                componentLogicalName = "savedqueryvisualization";
                primaryNameAttribute = "name";
                break;

            case 60:     //System Form
                componentLogicalName = "systemform";
                primaryNameAttribute = "name";
                break;

            case 61:     //Web Resource
                componentLogicalName = "webresource";
                primaryNameAttribute = "name";
                break;

            case 63:     //Connection Role
                componentLogicalName = "connectionrole";
                primaryNameAttribute = "name";
                break;

            case 65:     //Hierarchy Rule
                componentLogicalName = "hierarchyrule";
                primaryNameAttribute = "name";
                break;

            case 70:     //Field Security Profile
                componentLogicalName = "fieldsecurityprofile";
                primaryNameAttribute = "name";
                break;

            case 90:     //Plug-in Type
                componentLogicalName = "plugintype";
                primaryNameAttribute = "name";
                break;

            case 91:     //Plug-in Assembly
                componentLogicalName = "pluginassembly";
                primaryNameAttribute = "name";
                break;

            case 92:     //Sdk Message Processing Step
                componentLogicalName = "sdkmessageprocessingstep";
                primaryNameAttribute = "name";
                break;

            case 93:     //Sdk Message Processing Step Image
                componentLogicalName = "sdkmessageprocessingstepimage";
                primaryNameAttribute = "name";
                break;

            case 95:     //Service Endpoint
                componentLogicalName = "serviceendpoint";
                primaryNameAttribute = "name";
                break;

            case 150:     //Routing Rule Set
                componentLogicalName = "routingrule";
                primaryNameAttribute = "name";
                break;

            case 151:     //Rule Item
                componentLogicalName = "routingruleitem";
                primaryNameAttribute = "name";
                break;

            case 152:     //SLA
                componentLogicalName = "sla";
                primaryNameAttribute = "name";
                break;

            case 154:     //Record Creation and Update Rule
                componentLogicalName = "convertrule";
                primaryNameAttribute = "name";
                break;

            case 155:     //Record Creation and Update Rule Item
                componentLogicalName = "convertruleitem";
                primaryNameAttribute = "name";
                break;

            default:
                componentLogicalName = null;
                primaryNameAttribute = null;
                break;
            }

            if (!string.IsNullOrWhiteSpace(componentLogicalName) && !string.IsNullOrWhiteSpace(primaryNameAttribute))
            {
                ContentRepository ctr             = new ContentRepository();
                Entity            componentEntity = ctr.Get(componentLogicalName, objectId);

                return(componentEntity.GetAttributeValue <string>(primaryNameAttribute));
            }

            return(null);
        }
コード例 #8
0
        protected void WriteAttribute(AttributeMetadata attribute)
        {
            attribute.LogicalName = Name;
            attribute.DisplayName = new Label(DisplayName, CrmContext.Language);
            attribute.Description = new Label(Description ?? string.Empty, CrmContext.Language);

            AttributeRequiredLevel requiredLevel = AttributeRequiredLevel.ApplicationRequired;

            if (Required == CrmRequiredLevel.Required)
            {
                requiredLevel = AttributeRequiredLevel.ApplicationRequired;
            }
            if (Required == CrmRequiredLevel.Recommended)
            {
                requiredLevel = AttributeRequiredLevel.Recommended;
            }
            if (Required == CrmRequiredLevel.Optional)
            {
                requiredLevel = AttributeRequiredLevel.None;
            }
            attribute.RequiredLevel = new AttributeRequiredLevelManagedProperty(requiredLevel);

            if (CanModifyAdditionalSettings.HasValue)
            {
                attribute.CanModifyAdditionalSettings = new BooleanManagedProperty(CanModifyAdditionalSettings.Value);
            }
            if (IsAuditEnabled.HasValue)
            {
                attribute.IsAuditEnabled = new BooleanManagedProperty(IsAuditEnabled.Value);
            }
            if (IsCustomizable.HasValue)
            {
                attribute.IsCustomizable = new BooleanManagedProperty(IsCustomizable.Value);
            }
            if (IsRenameable.HasValue)
            {
                attribute.IsRenameable = new BooleanManagedProperty(IsRenameable.Value);
            }
            if (IsSecured.HasValue)
            {
                attribute.IsSecured = IsSecured.Value;
            }
            if (IsValidForAdvancedFind.HasValue)
            {
                attribute.IsValidForAdvancedFind = new BooleanManagedProperty(IsValidForAdvancedFind.Value);
            }
            if (!string.IsNullOrWhiteSpace(SchemaName))
            {
                attribute.SchemaName = SchemaName;
            }
            else
            {
                attribute.SchemaName = Name;
            }

            if (_context != null)
            {
                _context.SetParametersOnAttribute(attribute);
            }

            Guid id = _repository.AddAttribute(Entity, attribute);

            if (PassThru)
            {
                WriteObject(_repository.GetAttribute(id));
            }
        }
コード例 #9
0
        private void UpdateEntityOptionSet()
        {
            int?newValue = Value;

            if (!Value.HasValue)
            {
                // Must be new
                newValue = _repository.AddOptionSetValue(Entity, Attribute, DisplayName, Value, Description);
            }
            else
            {
                // Can be new or update
                PicklistAttributeMetadata optionSetAttribute = (PicklistAttributeMetadata)_repository.GetAttribute(Entity, Attribute);

                if (optionSetAttribute.OptionSet.Options.Any(o => o.Value.Value.Equals(Value.Value)))
                {
                    // Existing; Do update
                    _repository.UpdateOptionSetValue(Entity, Attribute, Value.Value, DisplayName, Description);
                }
                else
                {
                    // Not existing; Do new
                    newValue = _repository.AddOptionSetValue(Entity, Attribute, DisplayName, Value, Description);
                }
            }
        }
コード例 #10
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            _attribute = _repository.GetAttribute(Entity, Name);
        }