How to pass custom object as input parameter to custom PS cmdlets? - powershell-2.0

"New-CustomTemplate" my custom PS cmdlet which takes .txt filepath as one of its parameter. Text file in turn contains custom object definition in JSON format.
Is there any way to pass custom object as one of the parameter to my PS cmdlet (New-CustomTemplate) rather than creating object structure inside local file and providing its 'filepath' as cmdlet's parameter? please suggest.
Actual custom PS cmdlet:
New-CustomTemplate -TemplateName May1219 -FilePath "F:\test\customkvp.txt" -Owner John
Expected:
New-CustomTemplate -TemplateName May1219 -KVP customKVPobject -Owner John

Related

Can we Read Config file(managed files .properties file) in jenkins active choice parameters?

I want to Read My properties File in active choice parameters grovy script , my properties file is stored in manged files .
Properties file look like these
[1]: https://i.stack.imgur.com/flvP5.png
I want to call these properties file in Active Choice Reference Parameter Groovy script and retrive
all the values as per my previous selection.I had been using differnt not able to retrive values is their any way that we could retrive values?
The properties file would like this 'cat /var/jenkins_home/workspace/ss.properties'
100.1.1.1=outside_in,wireless_in
200.x.x.x=mgmt_in,inside_in
Create a Parameter called "Active Choices Parameter", call it "hostnames" and write the following groovy script there. In the following groovy script, we are simply reading the keys from the property file, converting it into a list and populating the same in a choice parameter. The choice type for this in my case is single select or you can set it according to your needs.
Properties properties = new Properties()
File propertiesFile = new File('/var/jenkins_home/workspace/ss.properties')
def stream = propertiesFile.newDataInputStream()
properties.load(stream)
Enumeration e = properties.propertyNames();
List<String> list = Collections.list(e);
return list
Create another Parameter called "Active Choices Reactive Parameter" and call it "config_list" and paste the following groovy script there
Properties properties = new Properties()
File propertiesFile = new File('/var/jenkins_home/workspace/ss.properties')
def stream = propertiesFile.newDataInputStream()
properties.load(stream)
Enumeration e = properties.propertyNames();
def var = Arrays.asList(properties.getProperty(hostnames).split(','))
return var
The Referenced Parameter for the above would be "hostnames". That would mean, based on the selection of hostnames choice parameter, the data will be populated in this parameter. The choice type for this in my case is single select or you can set it according to your needs.
Save the configuration and click on build with parameters in your Jenkins Job, it should look like the following

XSLT 2 : How to pass an input stream as a parameter to XSL sheet

I am using Saxon HE 10
(using Xslt30Transformer)
How to pass input stream as a parameter to XSL?
I see there is a setStylesheetParameters . How to send input stream , as this expects object of type XdmValue?
I used to set the file name parameter , trying to pass the stream instead
<xsl:param name="test" select="'test.xml'"/>
You can pass any Java object (including a Stream) by wrapping it in an XdmExternalObject (which is a subclass of XdmValue). But is it a good idea? What are you actually trying to achieve? A Stream is a mutable object (reading from the stream changes its state) and mutable objects and XSLT don't really play very well together. If we knew what you wanted to achieve we might be able to suggest a better design.

How to return a string value from a Delphi application as output parameter

I have a small Delphi 2009-application that serves as a way to call some SQL procedures and do some background work.
It can be called with a path to a text file containing a SQL statement as input parameter and executes it.
Now I want the Delphi-application to return an output value, a string.
I found how to deal with output values when calling applications from a batch file (How do I get the result of a command in a variable in windows?), but I don't know how to fill this value from within Delphi. Where in Delphi do I assign my string value to some kind of output parameter, so the calling batch file can use the value?
Thanks
Write it to the standard output:
Writeln(MyOutputText);

MKNetworkKit - Host Name and apiPath parameters

I was thinking of using MKNetworkKit as base for Network operations for an iOS App. I'm a bit confused about using the initWithHostName:customerHeaders: and initWithHostName: apiPath:customerHeaders: methods.
In the App, I need to communicate to a number of hosts and they have different ways of specifying the Host Name and URL. For example:
HostNameX.com - The Domain Name for HostX,
The first host has the service prepended to the Hostname as so:
serviceA.HostNameX.com?someparam=value The Path for ServiceA (returns info)
serviceB.HostNameX.com?someparam=value The Path for ServiceB (returns info)
HostNameY.com - The Domain Name for HostY
The second host has the service or command appended to the Hostname as so:
HostNameY.com/serviceA?someparam =value The Path for ServiceA (returns info)
HostNameY.com/serviceB?someparam =value The Path for ServiceB (returns info)
For the HostNameY.com case, I was thinking of creating one MKEngine Instance and then passing in the "serviceA?someparam=value" or "serviceB?someparam=value" string as the Path parameter to the operationWithPath:params:httpMethod:ssl: method.
This would work well for what I want to do, however for HostNameX.com I'm not sure how to prepend "serviceA." or "serviceB." to the host name? The only way I can see of doing it is to create two separate MKEngine Instances one for "serviceA" and one for "serviceB". Is this the case?
Am I missing something or is there a way to be able to prepend the service to the domain name after calling initWithHostName:apiPath:customerHeaders: ?
Thanks in advance for any suggestions.
All the Best
Dave
For HostNameY.com, you are right. The service name can be part of the path.
And as you mentioned, you should use multiple instances of MKEngine to manage HostNameX.com.
Why you should use multiple instances :
Hostname is a private property of MKNetworkEngine and the only way to change the hostname is to create a new instance of MKNetworkEngine (without modifying MKNetworkEngine). Hostname property is used by MKNetworkEngine to observe Reachability changes and freeze/restore operations. If you change the hostname at runtime for a single instance of MKNetworkEngine (by making hostname property public for example), this feature won't work well on all situations. Just take a look at freezeOperations (called when you loose network) method in MKNetworkEngine.m. It checks if and operation url contains the current hostname. If you have changed the hostname and the operation was created for another host, the operation will not be archived to restore it later when the network is back.
I solved this problem by using the operationWithURLString and building my own URL String. To me anyway, this seems a much better solution than allocating a number of MKEngine Instances just to handle something that can be passed as a parameter. This way I can also append path components as well as parameters to the URL String, for example:
http://serviceA.hostname.com/fred/simmons?isvip=true&hasBooked=false
Interestingly, the parameter dictionary that is passed to operationWithURLString:params:httpMethod: works in two ways:
if the httpMethod is GET, then the dictionary is used to pass parameters in the URL, if the httpMethod is POST or PUT (or DELETE?) then the Dictionary is formatted and sent as the Request Body.
Question - is it valid to have a POST Command with parameters?
For example:
http://bookingservice.hostname.com/bookings?isvip=true&lastname=simmons
Is this a valid URL as a POST not a GET?

Grails - Bind parameter to command object field of a different name

If I have a command object SomeClassCommand with a String field someField but want to bind data from a parameter params.otherField, how do I go about doing that? Is there an annotation I can put in the command object?
Actually there is a horrendous work around which defies the purpose of auto binding in your case.
def map = [:]
map.someField = params.otherField
//plus set all the other params to map
map << params
def commandObj = new SomeCommandObj()
//Explicitly bind map to command object
bindData(commandObj, map)
It really is horrendous, because you are doing extra work only to bind data. You could have directly set values to Command Object.
I would suggest either to change the command object field name or the parameter field name, which ever is controllable. AFAIK there is no annotation available unless you have your own utility to do such.

Resources