Is it possible to assign default values to NAnt properties? - nant

I'd like to use the property value as a part of an argument passed to a certain EXE via <exec/> task. There's a condition which influences the property initialization, that is, if condition is true, it should contain value, otherwise be just empty (but still defined).
This is what I ended up so far:
<property name="prop1" value="" />
<property name="prop1" value="some-value-based-on-condition" if="condition-goes-here" />
And later on:
<exec program="my.exe">
<arg value="C:\Root\Folder\${prop1}" />
...
</exec>
If the property is not set, I'd like to pass just C:\Root\Folder\ as an argument value.
Initializing the property in this way seems too much for such a simple operation. Is there a way to do it simpler using what's in NAnt at the moment? I would imagine something like:
<property name="prop1" value="somevalue-based-on-condition" if="condition" default="" />

The example below should meet your needs. It will create a property named 'SolutionConfiguration' and assign it the value 'Release' if and only if the same parameter isn't already defined (ie. it was defined via the command line).
<property name="SolutionConfiguration" value="Release" unless="${property::exists('SolutionConfiguration')}" />
For your scenario, try
<property name="RootFolder" value="c:\Root\Folder" unless="${property::exists('RootFolder')}" />
<exec program="my.exe">
<arg value="${RootFolder}\${prop1}" />
...
</exec>

Use overwrite="False"
<property name="RootFolder" value="c:\Root\Folder" overwrite="false" />

Related

phing loadfile to property does not override previous value

<loadfile property="test-from-file" file="value.txt" />
<echo message="test-from-file = ${test-from-file}" />
<loadfile property="test-from-file" file="value2.txt" />
<echo message="test-from-file = ${test-from-file}" />
The second loadfile does not change the value of the test-from-file property.
Is there any way to get this working?
As stated in comments by Jawi, properties are not overridden by design. A property works as a constant in Phing. So if it is already defined, then it won't be changed by later property definitions.
I think that you should revert your <property> task call in order to define your preferred sources first.
Alternatively, you can also use <property override="true"> to alter default behavior and override existing values, changing properties from constant to variable.

Jasper Reports - Removing pageHeader/columnHeader from subreport

I have a master report with 2 subreports. I use the same report to generate PDF and xls. Pagination is enabled but for excel, i need to disable pagination, which i do by rendering all in one sheet. The page header/column header get repeat for each page. These page header/column header are from the sub reports. This is fine for PDF but in case of excel, i want to get rid of the repeating header.
I set these properties:
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.3" value="pageHeader" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.3" value="pageHeader" />
<property name="net.sf.jasperreports.export.pdf.exclude.origin.keep.first.band.1" value="pageHeader" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.1" value="columnHeader" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.1" value="columnHeader" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.2" value="pageFooter" />
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true" />
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true" />
But these arent reflected in the data rendered by the subreport. In xls, i still see the pageHeader/columnHeader gets repeated. Please let me know, how to fix this.
For XLS (and HTML) reports, you may want to set the parameter IS_IGNORE_PAGINATION to true. See http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JRParameter.html for documentation.
I know this is an old question, but I keep forgetting how to do this myself and each time I search I seem to find this question so thought I'd put something so I find it next time.
In the main report file you also need to add the sub report to the filter:
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.1" value="columnHeader" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.1" value="columnHeader" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.report.1" value="sub-report-name" />
<property name="net.sf.jasperreports.export.xls.exclude.origin.keep.first.report.1" value="sub-report-name" />

In Entity Framework, getting the value of an identity column after inserting

I'm using EF4. I want to insert a new MyObject into the database. MyObject has two fields:
Id: int (Identity) and
Name: string
As I've seen in documentation Entity Framework is supposed to set MyObject.Id to the value generated by database after the call to SaveChanges() but in my case that doesn't happen.
using (var context = new MyEntities())
{
var myObject = MyObjects.CreateMyObject(0, "something"); // The first parameter is identity "Id"
context.MyObjects.AddObject(myObject);
context.SaveChanges();
return myObject.Id; // The returned value is 0
}
UPDATE:
This happens in one of my entities and others work fine. By the way, I checked and the DB column is identity and StoreGeneratedPattern is set to Identity.
Here is the SSDL. I don't see any difference. The first one isn't working right:
<EntityType Name="OrgUnit">
<Key>
<PropertyRef Name="Srl" />
</Key>
<Property Name="Srl" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="TypeId" Type="smallint" Nullable="false" />
<Property Name="Name" Type="varchar" Nullable="false" MaxLength="80" />
</EntityType>
<EntityType Name="OrgType">
<Key>
<PropertyRef Name="Srl" />
</Key>
<Property Name="Srl" Type="smallint" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="Title" Type="varchar" Nullable="false" MaxLength="120" />
<Property Name="Options" Type="int" Nullable="false" />
</EntityType>
The update is done successfully in the database and the identity is generated but the entity object is not updated with the new identity.
In that case, you EF model is probably not up to date - EF should automagically get your new ID from the database. Try refreshing your EF model.
Your identity column's properties should look like this in your EDMX model:
If you're using Oracle Entity Framework 4 Provider, like I do, from ODP.NET, there is a bug in Designer. Just selecting the Identity value in drop down box will not do. It will annotate the conceptual property in conceptual model with
annotation:StoreGeneratedPattern="Identity"
like in
<Property Type="Int32" Name="Id" Nullable="false" cg:SetterAccess="Private" annotation:StoreGeneratedPattern="Identity" />
But, it will fail to do the same for Storage Model, ie. you need to do it manually. Find the Property (in my case ID) in EntityType of interest and add StoreGeneratedPattern="Identity".
<EntityType Name="PROBLEMI">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="number" Nullable="false" Precision="10" StoreGeneratedPattern="Identity" />
I'm not aware of the same bug in SQL EF provider 'cos I didn't use it.
This should "just work." Make sure the DB column actually is IDENTITY, and that StoreGeneratedPattern is set to Identity in EDMX.
wow! that was a nightmare but at last I solved it, although I didn't understand what the problem was. Maybe this helps someone with the same problem.
Generate the script for creating the table and its data.
Drop the table.
Run the script.
If you are using Linq To Entities, and get this error even if you followed the advices of marc_s (that are really good), you should look at your entites directly in the edmx (xml view) and check if they have the following attribute :
<EntityType Name="MyEntity">
<Key>
<PropertyRef Name="pk" />
</Key>
<Property Name="pk" Type="bigint" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="value" Type="float" Nullable="false" />
</EntityType>
The StoreGeneratedPattern="Identity" is also required.
Try using refresh method after Save Changes, it has been documented in MSDN
"To ensure that objects on the client have been updated by data source-side logic, you can call the Refresh method with the StoreWins value after you call SaveChanges."
http://msdn.microsoft.com/en-us/library/bb336792.aspx
Though i feel what #Craig has suggested might also work.
I ran into this today. The difference though was I was using an insert function, where the above person doesn't specify that. What I had to do was make my insert function stored procedure return SCOPE_IDENTITY() and use a result binding for the id returned.
Fixed my issue.

function import in entity framework error

hi i have an error in the entity framework. i imported the sp get() into EF and return results as complex datatype 'GetResult'.In the edmx xml i have set the 'Amount' type to decimal.
<ComplexType Name="Get_Result">
<Property Type="String" Name="Description" Nullable="true" MaxLength="255" />
<Property Type="Decimal" Name="Amount" Nullable="false" />
<Property Type="Decimal" Name="Gst" Nullable="false" Precision="19" />
<Property Type="Decimal" Name="Total" Nullable="true" Precision="19" />
</ComplexType>
I try to bind the result with datagridview
gridview.DataSource = db.Get().ToList();
it kept giving me error message like this. and i couldn't find int32 anywhere in EF and have updated & built the EF multiple times.
The 'Amount' property on 'Get_Result' could not be set to a 'Int32' value. You must set this property to a non-null value of type 'Decimal'.
any help appreciated...
solved the issue by handling null exception

Property Inject an Array with Spring.Net

I've been using the Spring.Net IoC container and can use it to inject properties that are of type IList and even IList<T> but I'm a bit stumped as to how to inject a property thats of type string[].
There doesn't seem to be an <array> element defined in the XSD's and using <list> <value> </list> doesn't work either.
If anyone could post the xml I need to inject using an array for a property it'd be much appreciated
As mentioned here in the documentation you can inject a string array as a comma delimited string (not sure what the syntax is for escaping actual commas in strings if necessary). In other words your config would look something like this:
<object id="MyObject" type="Blah.SomeClass, Blah" >
<property name="StringArrayProperty" value="abc,def,ghi" />
</object>
Manually constructing a string[] with the following syntax also works, if you need something more complex (for example if you're looking the individual values up from some other reference rather than hard coding them):
<object id="TestStrArr" type="string[]" >
<constructor-arg value="3" />
<property name="[0]" value="qwe" />
<property name="[1]" value="asd" />
<property name="[2]" value="zxc" />
</object>
<object id="MyObject" type="Blah.SomeClass, Blah" >
<property name="StringArrayProperty" ref="TestStrArr" />
</object>