Custom Formatting

OData entities can include an optional category element. According to the specification, the term value of this element indicates the entity type of the entry. For example, entries returned from the NuGet package feed include this category term:

	<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
	<feed xml:base="" xmlns:d="" xmlns:m="" xmlns="">
		<category term="NuGetGallery.V1FeedPackage" scheme="" />

When this category term is present, the OData PowerShell provider uses it as the typename of the objects returned from the feed. In the case above, the entry is returned to the pipe as a generic object with a typename of "NuGetGallery.V1FeedPackage":

> get-item nuget:/packages -filter "Id eq 'StudioShell'" | get-member

	   TypeName: NuGetGallery.V1FeedPackage

	Name                     MemberType   Definition
	----                     ----------   ----------
	Equals                   Method       bool Equals(System.Object value)
	GetHashCode              Method       int GetHashCode()
	GetType                  Method       type GetType()
	ToString                 Method       string ToString()
	Authors                  NoteProperty System.String ...
	Categories               NoteProperty System.String ...
	Copyright                NoteProperty System.String ...

This allows you to include custom formats for different OData feeds. For instance, you can create a custom format file for the NuGet OData entities:

<?xml version="1.0" encoding="utf-8" ?>
                  <Text>Container: </Text>


By importing this format file into your session along with the OData provider, you can customize the output of the NuGet feed:

> import-module OData
> new-psdrive -psp odata -name n -root '';

	Name           Used (GB)     Free (GB) Provider      ...
	----           ---------     --------- --------      ...
	n                                      OData         ...

> get-item n:\packages -filter "Id eq 'StudioShell'"
	PSPath                   : OData::http:\\\packages
	PSParentPath             : OData::http:\\
	PSChildName              : packages
	PSDrive                  : nf
	PSProvider               : OData
	PSIsContainer            : True
	Id                       : StudioShell
	Version                  : 1.2

> Update-FormatData .\NuGet.Formats.ps1xml
> get-item n:\packages -filter "Id eq 'StudioShell'"

		Container: OData::http:\\

	Name                     Version                      Downloads
	----                     -------                      ---------
	StudioShell              1.2                                 51

Last edited Jan 27, 2012 at 9:06 PM by beefarino, version 1


No comments yet.