Spring.Net without App.config - spring.net

I want to configure the spring.net in some other setting files like xml not through app.config.
Is it possible to configure the spring.net in xml not in app.config file.if yes how can i do it.

Yes, you can place your configuration in normal xml files. In the Spring.NET documentation, the following example is given:
services.xml:
<objects xmlns="http://www.springframework.net">
<object id="PetStore" type="PetStore.Services.PetStoreService, PetStore">
<property name="AccountDao" ref="AccountDao"/>
<property name="ItemDao" ref="ItemDao"/>
<!-- additional collaborators and configuration for this object go here -->
</object>
<!-- more object definitions for services go here -->
</objects>
The file daos.xml has a similar structure and contains definitions for ItemDao and AccountDao.
In code, you can create an instance of your container using the files services.xml and daos.xml as follows:
IApplicationContext context = new XmlApplicationContext("services.xml", "daos.xml")

Related

Ant xmlproperty task fails due to validation error

I want to extract an application version from a DITA map file. The ditamap file is valid and looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map id="user-manual">
<title><ph keyref="product"/> User Manual</title>
<topicmeta>
<prodinfo>
<prodname><keyword keyref="product"/></prodname>
<vrmlist>
<vrm version="4" release="3" modification="0"/>
</vrmlist>
</prodinfo>
</topicmeta>
<!--
[...]
-->
</map>
The information I want to get is in the <vrm> element.
"Easy peasy," I think to myself. So I use Ant's <xmlproperty> task to just load this XML file.
<project default="test">
<!-- notice #validate -->
<xmlproperty file="path/to/user-manual.ditamap" validate="false"/>
<target name="test">
<echo>${map.topicmeta.prodinfo.vrmlist.vrm(version)}</echo>
</target>
</project>
I don't want it to validate because Ant isn't going to find map.dtd.
Loading the file returns an error:
java.io.FileNotFoundException: /home/user/user-manual/map.dtd (No such file or directory)
If I remove the <!DOCTYPE> declaration or add a nested <xmlcatalog> with the path to the DTD, the file loads and I can use the properties from it.
I tested this with Ant 1.7.1 and 1.9.4. Is this a bug with Ant, or am I misunderstanding how Ant loads XML properties and the purpose of the validate attribute?
How can I make Ant obey my will?
I recommend to not use the <xmlproperty> for this. Please have a look at the docs:
For example, with semantic attribute processing enabled, this XML
property file:
<root>
<properties>
<foo location="bar"/>
<quux>${root.properties.foo}</quux>
</properties>
</root>
is roughly equivalent to the following fragments in a build.xml file:
<property name="root.properties.foo" location="bar"/>
<property name="root.properties.quux" value="${root.properties.foo}"/>
So the name of the properties you set is generated using their paths to the root element, so they rely on the structure of your DITA Map. But many elements in DITA may be set at different positions on your DITA Map. That means, if you move your metadata to another parent element, the property name changes and your build fails. This is probably not, what you want.
I'd recommend to grab those values via XSLT and than set the properties. That way, you could, for example, say, "give me the first occurance of that element with a simple //foo[1] XPath selector. Further on, you have the power of XSLT and XPath to slice values, format dates and so on before setting a property.
Update
You can use the oops consultancy Ant xmltask for that. It is very easy to set a property using <copy>:
<copy path="//critdates/created/#date"
property="document.date"
append="false"/>

How use property expansion in a Launch4j config file

I use Launch4j and will use a property ${dist} in its configuration.
It works when the task and it argument directly are in the build.xml file:
<project ...>
<property name="dist" location="/temp/dist" />
<launch4j>
<config headerType="gui" outfile="${dist}/myprogram.exe"
dontWrapJar="false" jarPath="${dist}/myprogram.jar">
...
</config>
</launch4j>
</project>
Launch4j can however use its own xml-configuration file, with <launch4jConfig> as root element:
in ant.xml:
<launch4j configFile="my_launch4j_config.xml" />
in my_launch4j_config.xml:
<launch4jConfig>
<headerType>gui</headerType>
<outfile>${dist}/myprogram.exe</outfile>
<dontWrapJar>false</dontWrapJar>
<jar>${dist}/myprogram.jar</jar>
...
</launch4jConfig>
In this case, ${dist} is not expanded, nor %dist% or everything I tried... Does a solution exist to use properties in an launch4j config file?
The code of launch4j did not accept such replacements of parameters, but I could change this behaviour (modifications to net.sf.launch4j.config.ConfigPersister). I check it in the Sourceforge project when I have enough time for it.

Cannot Import from a UNC path in Spring.NET?

I have a simple Spring.NET demo, and I'm trying to have a shared object file that would reside on a shared drive. This works if I pass in the UNC path as a resource file to the constructor, but if use an <import resource construct it interprets it as relative, which is not supported. Is there a way I can use the import statement with a UNC path?
Works:
<context>
<resource uri="config://spring/objects"/>
<resource uri="\\server\share\folder\SpringConfig.xml"/>
</context>
Doesn't work:
<import resource="\\server\share\folder\SpringConfig.xml"></import>
Error message:
System.Configuration.ConfigurationErrorsException: Error creating context 'spring.root': ConfigSectionResource does not support relative resources. Please use fully qualified resource name. ---> Spring.Objects.Factory.ObjectDefinitionStoreException: Error registering object defined in 'config [C:\Users\user\documents\visual studio 2010\Projects\SpringExample\SpringExample\bin\Debug\SpringExample.vshost.exe.Config#spring/objects] at line 1' : Failed parsing element
---> System.NotSupportedException: ConfigSectionResource does not support relative resources. Please use fully qualified resource name.
Use the fully qualified resource string and use forward slashes throughout:
<objects xmlns="http://www.springframework.net">
<import resource="file:////server/share/folder/SpringConfig.xml" />
</objects>
Note that file: protocol identifier is followed by four slashes, two belong to the protocol and two to the server location.
Worked on my machine :). This also works:
<objects xmlns="http://www.springframework.net">
<import resource="file://\\server\share\folder\SpringConfig.xml" />
</objects>
Hmmm..
This should work. What I don't understand is why ConfigSectionResource throw the exception.
FileSystemResource should be used by default in a non Web application.
What version of Spring.NET are you using ? Are you using CodeCondig extension ?
Anyway, this should work:
<resource uri="file://\\server\share\folder\SpringConfig.xml"/>
I'm honestly not certain whether UNC paths are supported or not, but if you want a fully-qualified file path, you need to use <resource uri="file://c:/folder1/folder2/MyConfig.xml" /> IIRC.

NLog internal log not working with ASP.Net MVC

I have a problem with NLog for logging its internal logs with this configuration
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="true"
internalLogFile="${basedir}/App_Data/NLog.log"
internalLogLevel="Trace">
<targets>
<target name="debug"
xsi:type="File"
fileName="${basedir}/App_Data/Site.log" />
</targets>
<rules>
<logger name="*"
writeTo="debug" />
</rules>
</nlog>
The target "debug" is working well, but the internalLogFile is only working if I set it for exemple to "D:/NLog.log".
Any idea why this happening?
You can't use layout renderers ${...} in the internalLogFile property. They are for a target's layout only:
<target layout="${...}" />
Try to use relative path like "..\App_Data\NLog.log"
Update NLog 4.6 enables some simple layouts.
The internalLogFile attribute needs to be set to an absolute path and the executing assembly needs to have permission to write to that absolute path.
The following worked for me.
Create a folder somewhere - e.g. the route of your c: drive, e.g. c:\logs
Edit the permissions of this folder and give full control to everyone
Set your nlog config: internalLogFile="C:\logs\nlog.txt"
Remember to clean up after yourself and not leave a directory with those sorts of permissions on
NLog ver. 4.6 add support for environment-variables like %appdata% or %HOME%, and using these basic layouts in internalLogFile=:
${currentdir}
${basedir}
${tempdir}
NLog ver. 4.7 also adds this:
${processdir}
See also: https://github.com/NLog/NLog/wiki/Internal-Logging
from this link I think the path is absolute

Set the Document Template of a Document Library programmatically

I am creating a Document Library from an event receiver. I would like to change the Document Library to a custom Word document. In the user interface, this is simply done by changing the Template URL value in the Document Template property under Document Library Advanced Settings. I'm not sure how to do this via code.
I would also be open to creating a list template with my document template already setup, but I'd prefer to go the other route so I retain the flexibility of setting up each document library with a different template.
Thanks.
Specify it within your content type definition in the elements.xml for the feature and add a module file reeference.
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentType ID="0x010100DC863B72929F8148A8A84BF932C5356701"
Name="Word 2007"
Group="CEO Content Types"
Sealed="FALSE"
FeatureId="332a1967-3ae1-498b-ba11-f03743cab20b">
<FieldRefs />
<DocumentTemplate TargetName="Untitled.docx"/>
</ContentType>
<Module Name="WordDefaultFile" Url="_cts/MyWord" RootWebOnly="TRUE">
<File Url="Untitled.docx" Name="Untitled.docx" Type="Ghostable"></File>
</Module>
</Elements>
Copy the template to your feature directory and add an ElementFile reference to it within the ElementsManifest section of your feature.xml.
<ElementManifests>
<ElementManifest Location="MyWord-CT.xml" />
<ElementFile Location="Untitled.docx"/>
</ElementManifests>
</Feature>

Resources