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; } }
private void GetRelationshipByFilter() { IEnumerable <RelationshipMetadataBase> result = _repository.GetRelationship(Entity, RelatedEntity, Type, CustomOnly.ToBool(), ExcludeManaged.ToBool()); if (string.IsNullOrWhiteSpace(RelatedEntity)) { if (!string.IsNullOrWhiteSpace(Include)) { WildcardPattern includePattern = new WildcardPattern(Include, WildcardOptions.IgnoreCase); result = result.Where(r => (r.RelationshipType == RelationshipType.OneToManyRelationship && ( includePattern.IsMatch(((OneToManyRelationshipMetadata)r).ReferencingEntity) || includePattern.IsMatch(((OneToManyRelationshipMetadata)r).ReferencedEntity))) || (r.RelationshipType == RelationshipType.ManyToManyRelationship && ( includePattern.IsMatch(((ManyToManyRelationshipMetadata)r).Entity1LogicalName) || includePattern.IsMatch(((ManyToManyRelationshipMetadata)r).Entity2LogicalName)))); } if (!string.IsNullOrWhiteSpace(Exclude)) { WildcardPattern excludePattern = new WildcardPattern(Exclude, WildcardOptions.IgnoreCase); result = result.Where(r => (r.RelationshipType == RelationshipType.OneToManyRelationship && ( (!excludePattern.IsMatch(((OneToManyRelationshipMetadata)r).ReferencingEntity) && ((OneToManyRelationshipMetadata)r).ReferencedEntity.Equals(Entity, StringComparison.InvariantCultureIgnoreCase)) || (!excludePattern.IsMatch(((OneToManyRelationshipMetadata)r).ReferencedEntity) && ((OneToManyRelationshipMetadata)r).ReferencingEntity.Equals(Entity, StringComparison.InvariantCultureIgnoreCase)))) || (r.RelationshipType == RelationshipType.ManyToManyRelationship && ( (!excludePattern.IsMatch(((ManyToManyRelationshipMetadata)r).Entity1LogicalName) && ((ManyToManyRelationshipMetadata)r).Entity2LogicalName.Equals(Entity, StringComparison.InvariantCultureIgnoreCase)) || (!excludePattern.IsMatch(((ManyToManyRelationshipMetadata)r).Entity2LogicalName) && ((ManyToManyRelationshipMetadata)r).Entity1LogicalName.Equals(Entity, StringComparison.InvariantCultureIgnoreCase))))); } } result = result.OrderBy(r => r.SchemaName); WriteObject(result, true); }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); switch (this.ParameterSetName) { case GetOptionSetByIdParameterSet: foreach (Guid id in Id) { WriteObject(_repository.GetOptionSet(id)); } break; case GetOptionSetByFilterParameterSet: IEnumerable <OptionSetMetadataBase> result = _repository.GetOptionSet(CustomOnly.ToBool(), ExcludeManaged.ToBool()); if (!string.IsNullOrWhiteSpace(Name)) { WildcardPattern includePattern = new WildcardPattern(Name, WildcardOptions.IgnoreCase); result = result.Where(o => includePattern.IsMatch(o.Name)); } if (!string.IsNullOrWhiteSpace(Exclude)) { WildcardPattern excludePattern = new WildcardPattern(Exclude, WildcardOptions.IgnoreCase); result = result.Where(o => !excludePattern.IsMatch(o.Name)); } result = result.OrderBy(o => o.Name); WriteObject(result, true); break; default: break; } }
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); }