Cmdlets Use Verb-Noun Names to Reduce Command Memorization in Windows PowerShell
Windows PowerShell uses a "verb-noun" naming system, where each cmdlet name consists of a standard verb hyphenated with a specific noun. Windows PowerShell verbs are not always English verbs, but they express specific actions in Windows PowerShell. Nouns are very much like nouns in any language, they describe specific types of objects that are important in system administration. It is easy to demonstrate how these two-part names reduce learning effort by looking at a few examples of verbs and nouns.
Nouns are less restricted, but they should always describe what a command acts upon. Windows PowerShell has commands such as Get-Process, Stop-Process, Get-Service, and Stop-Service.
In the case of two nouns and two verbs, consistency does not simplify learning that much. However, if you look at a standard set of 10 verbs and 10 nouns, you then have only 20 words to understand, but those words can be used to form 100 distinct command names.
Frequently, you can recognize what a command does by reading its name, and it is usually apparent what name should be used for a new command. For example, a computer shutdown command might be Stop-Computer. A command that lists all computers on a network might be Get-Computer. The command that gets the system date is Get-Date.
You can list all commands that include a particular verb with the -Verb parameter for Get-Command (We will discuss Get-Command in detail in the next section). For example, to see all cmdlets that use the verb Get, type:
| PS> Get-Command -Verb Get CommandType Name Definition ----------- ---- ---------- Cmdlet Get-Acl Get-Acl [[-Path] <String[]>]... Cmdlet Get-Alias Get-Alias [[-Name] <String[]... Cmdlet Get-AuthenticodeSignature Get-AuthenticodeSignature [-... Cmdlet Get-ChildItem Get-ChildItem [[-Path] <Stri... ... |
The -Noun parameter is even more useful because it allows you to see a family of commands that affect the same type of object. For example, if you want to see which commands are available for managing services, type following command:
| PS> Get-Command -Noun Service CommandType Name Definition ----------- ---- ---------- Cmdlet Get-Service Get-Service [[-Name] <String... Cmdlet New-Service New-Service [-Name] <String>... Cmdlet Restart-Service Restart-Service [-Name] <Str... Cmdlet Resume-Service Resume-Service [-Name] <Stri... Cmdlet Set-Service Set-Service [-Name] <String>... Cmdlet Start-Service Start-Service [-Name] <Strin... Cmdlet Stop-Service Stop-Service [-Name] <String... Cmdlet Suspend-Service Suspend-Service [-Name] <Str... ... |
A command is not necessarily a cmdlet, just because it has a verb-noun naming scheme. One example of a native Windows PowerShell command that is not a cmdlet but has a verb-noun name, is the command for clearing a console window, Clear-Host. The Clear-Host command is actually an internal function, as you can see if you run Get-Command against it:
| PS> Get-Command -Name Clear-Host CommandType Name Definition ----------- ---- ---------- Function Clear-Host $spaceType = [System.Managem... |
How to: Add a Cache Notification Callback (Velocity)
Adding a cache notification callback requires two steps. First, create a method that should be invoked when a cache notification is triggered by one or more cache operations. The method you invoke with the cache notifications must accept the same parameters as the DataCacheNotificationCallback delegate. Second, add a callback using one of the three available methods from the DataCache object: AddCacheLevelCallback, AddRegionLevelCallback, or AddItemLevelCallback. Use the filter parameter to define the types of cache operations you want to trigger cache notifications. Use the name of the method you created in the first step for the clientDelegate parameter.
Note
In order for your application to use notifications, you need to enable them on a named cache. Use the notificationsEnabled parameter with the New-Cache or Set-CacheConfig commands. For more information, see Cache Administration with PowerShell (Velocity).
How to add a callback for one or more cache operations
Create the method you want to be triggered by the cache notification. Make sure the method accepts the same parameters as the DataCacheNotificationCallback delegate.
Add a callback. Use one of the three available methods from the DataCache object to define the notification scope: AddCacheLevelCallback, AddRegionLevelCallback, or AddItemLevelCallback.
Use the DataCacheOperation enumeration in the filter parameter to specify what type of cache operations you want to trigger notifications. Select more than one enumeration by separating the enumerations with the binary OR operator to perform a bitwise OR. To do this, use the | character in C#, and the Or operator in Visual Basic.
Use the name of the method you want to invoke when these notifications occur in the clientDelegate parameter.
Set the add callback method equal to a DataCacheNotificationDescriptor object that you can use elsewhere in your program to remove the cache notification callback.
Posted in: .Net Programming| Tags: .net 4.0 parameter CTP CTP 3 Microsoft Velocity cache use delegate datacachenotificationcallback notification datacache method callbackHow to: Enable Local Cache (Code) (Velocity)
To programmatically enable local cache when creating your cache client, you must make sure the localCache parameter in the DataCacheFactory class constructor is equal to true. For more information about the application configuration settings, see Application Configuration Settings (Velocity).
Note
These procedures assume that you have already prepared your development environment and set references to the "Velocity" assemblies, and so on. For more information, see How to: Prepare the Development Environment (Velocity)
To create a cache client that has local cache enabled
Create an array of DataCacheServerEndPoint objects to specify the cache hosts for the client.
Configure your cache hosts by assigning the cache host array from the previous step to the servers parameter of the DataCacheFactory constructor. Note: For performance reasons, we recommend that you minimize the number of DataCacheFactory objects created in a cache-enabled application. Store the DataCacheFactory object in a variable available to all parts of the application that use cache clients.
Configure your cache client type by assigning a true or false value to the routingClient parameter of the DataCacheFactory constructor. Use the true value for a routing client, or a false value for a simple client.
Enable local cache by assigning a true value to the localCache parameter of the DataCacheFactory constructor.
(optional) Configure your cache client for cache notifications by using the DataCacheFactory constructor with the following additional parameters.
syncPolicy: Use the DataCacheLocalCacheSyncPolicy enumeration to choose how locally cached objects are invalidated. Use TimeoutBased to indicate that a time-out value should be used or NotificationBased to indicate that cache notifications will be used. For more information, see Cache Clients and Local Cache (Velocity).
localCacheTimeout: Use this parameter to specify the number of seconds that an object will remain in local cache before it is invalidated. This parameter is ignored if syncPolicy is set to NotificationBased.
pollInterval: Use this parameter to specify the interval of frequency, in seconds, that the cache client will check with the cache cluster for cache notifications. The default value is 300 seconds. Note: Local cache is not required for cache notifications. For more information, see Cache Notifications (Velocity).
Use the GetCache method to obtain an instance of the routing client.
Posted in: .Net Programming| Tags: .net 4.0 parameter Application Configuration CTP CTP 3 Microsoft Velocity cache code enable client local localcache