コード例 #1
0
        private void GetEntityKeyByFilter()
        {
            IEnumerable<EntityKeyMetadata> result = _repository.GetEntityKey(Entity, ExcludeManaged.ToBool());
            if (!string.IsNullOrWhiteSpace(Name))
            {
                WildcardPattern includePattern = new WildcardPattern(Name, WildcardOptions.IgnoreCase);
                result = result.Where(a => includePattern.IsMatch(a.LogicalName));
            }
            if (!string.IsNullOrWhiteSpace(Exclude))
            {
                WildcardPattern excludePattern = new WildcardPattern(Exclude, WildcardOptions.IgnoreCase);
                result = result.Where(a => !excludePattern.IsMatch(a.LogicalName));
            }

            if (Attributes != null && Attributes.Length != 0)
            {
                result = result.Where(
                    a => a.KeyAttributes.Intersect(Attributes, StringComparer.InvariantCultureIgnoreCase).Count() == Attributes.Length);
            }

            result = result.OrderBy(k => k.LogicalName);

            WriteObject(result, true);
        }
コード例 #2
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            switch (this.ParameterSetName)
            {
            case GetEntityByIdParameterSet:
                WriteObject(_repository.GetEntity(Id));
                break;

            case GetEntitiesByFilterParameterSet:
                IEnumerable <EntityMetadata> result = _repository.GetEntity(CustomOnly.ToBool(), ExcludeManaged.ToBool(), IncludeIntersects.ToBool());
                if (!string.IsNullOrWhiteSpace(Name))
                {
                    WildcardPattern includePattern = new WildcardPattern(Name, WildcardOptions.IgnoreCase);
                    result = result.Where(e => includePattern.IsMatch(e.LogicalName));
                }
                if (!string.IsNullOrWhiteSpace(Exclude))
                {
                    WildcardPattern excludePattern = new WildcardPattern(Exclude, WildcardOptions.IgnoreCase);
                    result = result.Where(e => !excludePattern.IsMatch(e.LogicalName));
                }

                result = result.OrderBy(e => e.LogicalName);

                WriteObject(result, true);

                break;

            default:
                break;
            }
        }
コード例 #3
0
        private void GetAttributeByFilter()
        {
            IEnumerable <AttributeMetadata> result = _repository.GetAttribute(Entity, CustomOnly.ToBool(), ExcludeManaged.ToBool(), IncludeLinked.ToBool());

            if (!string.IsNullOrWhiteSpace(Name))
            {
                WildcardPattern includePattern = new WildcardPattern(Name, WildcardOptions.IgnoreCase);
                result = result.Where(a => includePattern.IsMatch(a.LogicalName));
            }
            if (!string.IsNullOrWhiteSpace(Exclude))
            {
                WildcardPattern excludePattern = new WildcardPattern(Exclude, WildcardOptions.IgnoreCase);
                result = result.Where(a => !excludePattern.IsMatch(a.LogicalName));
            }

            if (!string.IsNullOrWhiteSpace(AttributeType))
            {
                if (CrmVersionManager.IsSupported(CrmVersion.CRM2013_RTM))
                {
                    string attributeTypeName = AttributeType;
                    if (!attributeTypeName.EndsWith("Type", StringComparison.InvariantCultureIgnoreCase))
                    {
                        attributeTypeName = string.Format("{0}Type", attributeTypeName);
                    }
                    result = result.Where(a => a.AttributeTypeName == attributeTypeName);
                }
                else
                {
                    AttributeTypeCode typeCode = AttributeTypeCode.String;
                    if (Enum.TryParse <AttributeTypeCode>(AttributeType, true, out typeCode))
                    {
                        result = result.Where(a => a.AttributeType == typeCode);
                    }
                }
            }

            result = result.OrderBy(a => a.LogicalName);

            WriteObject(result, true);
        }