I use C# and Spring Net 1.3.2 in console app.
I got :
an app.cfg
a spring-context.xml
a environnement.xml file wich contains specific variables values according to the where the app is running : a folder for production, one for qa, and one for test.
What I want to achieve :
in my shell (windows), before launching the app with foo.bat, I do :
set environment="qa"
When Spring loads the context, it picks the value contained in the environment var (say qa), and loads the correct file : thus replacing : configuration/{environment}/vars.xml
by configuration/qa/vars.xml.
In my my spring-context.xml file, I got objects like this : value = ${connectionString.DB1}" where the value is defined inside each vars.xml file (remember, one for prod, one for qa...).
For now, I am not able to replace the ${environment} variable. So I did it programmatically by getting the value of ${environment} with System.Environment.GetEnvironmentVariable("environnement"); and using Path.Combine, load the two contexts myself :
reader.LoadObjectDefinitions(envPath);
reader.LoadObjectDefinitions("configuration/common/springContext.xml");
BUT :
I would like to make it by configuration.
I've been playing with (with no luck) :
<object type="Spring.Objects.Factory.Config.VariablePlaceholderConfigurer, Spring.Core">
<property name="VariableSources">
<list>
<object type="Spring.Objects.Factory.Config.EnvironmentVariableSource, Spring.Core"/>
</list>
</property>
</object>
<object name="appConfigPropertyHolder"
type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
<property name="EnvironmentVariableMode" value="Override"/>
</object>
Any ideas ?
Ok, after much research, it works!
<object type="Spring.Objects.Factory.Config.VariablePlaceholderConfigurer, Spring.Core">
<property name="VariableSources">
<list>
<object type="Spring.Objects.Factory.Config.EnvironmentVariableSource, Spring.Core"/>
<object type="Spring.Objects.Factory.Config.PropertyFileVariableSource, Spring.Core">
<property name="Location" value="${root.config}/envars.properties" />
<property name="IgnoreMissingResources" value="false"/>
</object>
</list>
</property>
</object>
path to property file depends upon the environment variable.
Variables are replaced by the values obtained from the properties file.
I deploy one package + folder with 4 environment properties files
And I set my env var accordingly.
No need to mess with app.config or multiple Spring configuration files.
Related
I am trying to insert data to persistent data region with thin .NET client and after I call PutAllAsync method ignite process is terminated with the following error:
[15:45:09,616][SEVERE][exchange-worker-#66][] JVM will be halted immediately due to the failure: [failureCtx=FailureContext [type=SYSTEM_WORKER_TERMINATION, err=class o.a.i.IgniteCheckedException: Affinity for topology version is not initialized [locNode=8fda194c-c82f-4d52-80b0-24ac1d7c8be7, grp=ignite-sys-cache, topVer=AffinityTopologyVersion [topVer=1, minorTopVer=2], head=AffinityTopologyVersion [topVer=1, minorTopVer=1], history=[AffinityTopologyVersion [topVer=1, minorTopVer=1]]]]]
Here is default-config.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--
Alter configuration below as needed.
-->
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<property name="dataRegionConfigurations">
<list>
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<property name="name" value="data_persistent_region"/>
<property name="persistenceEnabled" value="true"/>
</bean>
</list>
</property>
</bean>
</property>
</bean>
</beans>
And here is an example of data insertion:
var cacheConfiguration = new CacheClientConfiguration(key, cacheEntity);
cacheConfiguration.CacheMode = CacheMode.Replicated;
cacheConfiguration.DataRegionName = "data_persistent_region";
_igniteClient.GetOrCreateCache<int, T>(cacheConfiguration)
.PutAll(data.Select((x, i) => new KeyValuePair<int, T>(i, x)));
Tried to use "-Djava.net.preferIPv4Stack=true" and "-DIGNITE_QUIET=false" options but it did not help.
PS. I am using Apache Ignite 2.10.0. If I disable region persistance everything works ok.
Seems I figured out what was the problem: cache key contains not supported symbol ":" to create file with the same name.
I am working in a .net web application than need to be able to create documents in Alfresco and then associate a particular aspect and his prperties to those documents.
I created my aspect (nameModel.xml, name-model-context.xml all this files in the extension folder, name.properties in messages folder and custom-slingshot-application-context.xml share-config-custom.xml in the web-extension folder) in /opt/bitnami/apache-tomcat/shared/classes/alfresco/ path.
In my C# code, i have two methods:
public void PutFile(CMISDocument document)
{
IObjectId cmisObjectFolder = (IObjectId)session.GetObject(document.FolderId);
IDictionary<string, object> properties = new Dictionary<string, object>();
properties[PropertyIds.Name] = document.ContentStreamFileName;
properties[PropertyIds.ObjectTypeId] = "cmis:document";
properties[PropertyIds.CreationDate] = DateTime.Now;
ContentStream contentStream = new ContentStream();
contentStream.FileName = document.ContentStreamFileName;
contentStream.MimeType = document.ContentStreamMimeType;
contentStream.Length = document.Stream.Length;
contentStream.Stream = document.Stream;
IObjectId objectId = session.CreateDocument(properties, cmisObjectFolder, contentStream, DotCMIS.Enums.VersioningState.None);
PutFileDetail(objectId,document.Owner);
}
internal void PutFileDetail(IObjectId objectId,string actorIdCard)
{
ICmisObject cmisObject = session.GetObject(objectId);
IDictionary<string, object> properties = new Dictionary<string, object>();
properties[PropertyIds.ObjectTypeId] = "adm:aridoctypBase";
properties["adm:actidcard"] = actorIdCard;
IObjectId newId = cmisObject.UpdateProperties(properties);
if (newId.Id == cmisObject.Id)
{
// the repository updated this object - refresh the object
cmisObject.Refresh();
}
else
{
// the repository created a new version - fetch the new version
cmisObject = session.GetObject(newId);
}
}
With this code i have as result a error:
The first one is for create the document and the second one is for add the aspect and his properties.
I was looking for a answer, and i finded this: http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Fconcepts%2Fopencmis-ext-intro.html
But a really do not know how install Alfresco OpenCMIS Extension; they say that i need put the jar file in my class path. But i do not know what is my class path in bitnami virtual machine.
Other thing is if i forgot something in the creation of my aspect.
pd: It is important but nor urgent for me, that the way to do it could be work if one day a need change Alfresco to Sharepoint or another else enterprise content management
I will apreciate any help.
Thanks! Do you know where can i see a good example? I think that the first point: i need change my model. In this moment i have the properties inside of aspect tags. I will need create the types and the properties ... can you tell me if i am going in good way...?
This is my model xml file (aridocsModel.xml) resume:
<?xml version="1.0" encoding="UTF-8"?>
<model name="adm:aridocsModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
...
<aspects>
<aspect name="adm:aridocsBase">
<title>AriDocs Base</title>
<properties>
<property name="adm:createdate">
<type>d:date</type>
</property>
<property name="adm:disabledate">
<type>d:date</type>
</property>
<property name="adm:artiddoc">
<type>d:text</type>
</property>
<property name="adm:accnumber">
<type>d:text</type>
</property>
<property name="adm:actidcard">
<type>d:text</type>
</property>
</properties>
</aspect>
</aspects>
</model>
Now, how i can not work with aspects; and i need types ...
<?xml version="1.0" encoding="UTF-8"?>
<model name="adm:aridocsModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
...
<types>
<type name="adm:aridoctypBase">
<title>Ari Docs Type Base</title>
<parent>cm:content</parent>
<properties>
<property name="adm:createdate">
<type>d:date</type>
</property>
<property name="adm:disabledate">
<type>d:date</type>
</property>
<property name="adm:artiddoc">
<type>d:text</type>
</property>
<property name="adm:accnumber">
<type>d:text</type>
</property>
<property name="adm:actidcard">
<type>d:text</type>
</property>
</properties>
</type>
</types>
...
<!-- i need put the aspect here... Even if i will work with types... -->
...
</model>
I will appreciate any advice.
You don't need the extensions on creating a document. The extension is only for managing aspects.
And from what I've heard the extension isn't available in all the languages, so I'm not sure if there is a .dll for you to include in your project.
Did you read these topics: integrate a .net application with alfresco using cmis
And: .net wcf and create document
I'm creating my first application using NHibernate. Unfortunately, I encountered a problem I cannot solve:
I'm accessing the database from "DAL" project that contains CRUD methods and NHibernateHelper class.
I wrote a test project and I tried to add an object to DB - it works perfectly. But when I try to call the same method from my application's ViewModel (it's in the other project as well) it throws an error at configuration.BuildSessionFactory() in the code below:
private static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{
var configuration = new Configuration();
configuration.Configure();
configuration.AddAssembly(typeof(Address).Assembly);
_sessionFactory = configuration.BuildSessionFactory();
}
return _sessionFactory;
}
}
The exception:
NHibernate.HibernateException: Could not create the driver from NHibernate.Driver.OracleDataClientDriver.
System.Reflection.TargetInvocationException: {"Exception has been thrown by the target of an invocation."}
System.NullReferenceException: {"Object reference not set to an instance of an object."}
In my test project I added reference to Oracle.DataAccess.dll and created App.config as it throws the same error without it:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Oracle.DataAccess"
fullName="Oracle.DataAccess,
Version=4.112.2.0,
Culture=neutral,
PublicKeyToken=89b483f429c47342" />
</assemblyBinding>
</runtime>
</configuration>
I made the same thing in my project containing ViewModel in which I need to get data from DB, but it didn't help. I also set Copy Local to True for that reference, but to no avail.
It's my App.config:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="dialect">
NHibernate.Dialect.Oracle10gDialect
</property>
<property name="connection.driver_class">
NHibernate.Driver.OracleDataClientDriver
</property>
<property name="connection.connection_string">
User Id=****;
Password=****;
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=
(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
(CONNECT_DATA=(SERVICE_NAME=xe)));
Pooling=true;
Enlist=false;
Statement Cache Size=50;
Min Pool Size=10;
Incr Pool Size=5;
Decr Pool Size=2;
</property>
<property name="show_sql">
true
</property>
</session-factory>
</hibernate-configuration>
I'm using NHibernate v 3.3.1.4000, Oracle 11g xe and 64-bit Windows 7 (I cannot choose to debug on 32 or 64-bit, there is only one possibility to select: "Active (Any CPU)" )
What can be the reason that I can use it from test project, but I cannot do it from the other?
Thank you in advance
Do you have a reference to driver's dll in your web project or in your DAL? it should be on your web project with Copy Local set to true, see this similar question
The problem is solved. I had to put app.config in main project, not in dll library from which I use the database. I didn't know that app.config placed in class library will be ignored.
It throws an exception that is something like this:
Initialization method MyAssemblyA.Initialize threw exception.
Spring.Objects.Factory.ObjectCreationException: Spring.Objects.Factory.ObjectCreationException:
Error thrown by a dependency of object 'messageSource' defined in 'assembly
[MyOtherAssembly.Test, Version=1.1.1016.1, Culture=neutral, PublicKeyToken=null],
resource [MyOtherAssembly.context.xml]
line 256' : Initialization of object failed : Could not load file or assembly 'MyAssemblyB'
or one of its dependencies. The system cannot find the file specified.
I don't know exactly why, but a lot of the unit tests are failing only on the build server and the exception that is thrown is something similar to what I wrote above.
In my context.xml I have something like this:
<object name="messageSource" type="Spring.Context.Support.ResourceSetMessageSource, Spring.Core">
<property name="resourceManagers">
<list>
<ref object="resMgrCoreServiceErrors"/>
<ref object="resMgrPersonnelErrors"/>
</list>
</property>
</object>
<object name="resMgrCoreServiceErrors"
type="Spring.Objects.Factory.Config.ResourceManagerFactoryObject, Spring.Core">
<property name="baseName" value="MyOtherAssembly.Resources.ErrorRes"/>
<property name="assemblyName" value="MyOtherAssembly"/>
</object>
<object name="resMgrPersonnelErrors"
type="Spring.Objects.Factory.Config.ResourceManagerFactoryObject, Spring.Core">
<property name="baseName" value="MyOtherAssemblyB.Resources.ErrorRes"/>
<property name="assemblyName" value="MyOtherAssemblyB"/>
</object>
where ErrorRes is a resource file (.resx).
Please help, any suggestions are welcomed !
are all of the dependencies of MyAssemblyB either installed in the gac or in the bin? has to be something in that vein.
I am trying to create an object in Spring where one of its propertys is of type object. Now if I do the following:
<object id="MyObject" type="...." singleton=false>
<property name="my_property" value="4">
</object>
Then the property my_property will be a string object. Is there a way do something like:
<object id="MyObject" type="...." singleton=false>
<property name="my_property" value="4" type="System.Double, System">
</object>
I know this should probably be done by generics but we can't really add this in now as the person who wrote it didn't think of this at the time.
You should be able to do this using the 'expression' tag. e.g.
<property name="my_property" expression="double.Parse('4')" />
See the Spring.NET documentation here