WPF Validation Message in Xml - wpf

I have a WPF application which is displaying field validation messages by implementing the IDataErrorInfo interface. This is all working well.
What I want to do now is to break out the validation messages into an separate xml file so that validation message key value pairs can be stored outside of the code and can be easily maintained possibly by an end (super)user.
I was thinking of having a method something like:
private void ValidateRequiredField<T>(ref T field, string fieldName)
{
string error = null;
if (Equals(field, null)
|| (field is string
&& (string.IsNullOrEmpty(field.ToString())
|| field.ToString().Replace(" ", string.Empty).Length == 0)
)
|| (field is int
&& int.Parse(field.ToString()) == 0)
)
{
error = GetValueFromConfig(fieldName);
}
SetFieldDataError(fieldName, error);
}
Is the best way to store these key value pairs in an xml file? I seem to remember that there used to be a Microsoft Configuration Application Block but I can't see an equivalent in Enterprise Library 5.0. Is there a better way?

For anyone who may be pondering the same question...after much deliberating, I opted to use the Microsoft Enterprise Library 5.0

Related

How to filter multiple line of text field using Sharepoint Rest API?

Hi I'm having trouble in filtering SharePoint documents through the use of Rest API since I'm using multiple lines of texts(Plain text) column to filter them out. It only returns null result after trying it out.
Single line of text column seems to work well but I need Multiple lines of text because the metadata exceeds the 255 char limit.
I'm new to SharePoint, please help. Thank you
I am using the API to pull from a multiple line column, Product.
The first part is just to keep looking if empty and I keep js old school for IE 11 users. Product is defined earlier in the js as a variable based on the page, I am using this in many ways. Basically the answer to your question is check for null and instruct to continue, then else if and use indexOf().
for (i = 0; i < data.d.results.length; i++) {
if (data.d.results[i].Product == null) {
continue;
} else if (data.d.results[i].Product.indexOf(product) !== -1) {
var xid = data.d.results[i];
insertText(xid);
}
}
The success function for the GET carries over the xid, insertText(xid). Hopefully this makes sense.
go to site settings > site permissions > anonymous access... you gotta disable the check against Client Object Model permission Requirement

To remove special characters from data while moving data from mssql to mysql using pentaho data integration

In a Table data, I have to remove these [*,=,#,&,^,%] from table data. I should not remove these
special characters [(,),/,.,#,',",:-,_,,\] while moving data from mssql to mysql using pentaho data
integration
example:-
Gujarat is the country’s largest castor oil seed producing state. The m*ajor
month’s
Why not use regular expressions in the query you are using to retrieve the data? It will simplify your transformation!
You can use either Regex Evaluation step or String operations step in Spoon
Try them and if you still have problems comment below.
You can use a "User Defined Java Class" in Pentaho and write a regex expression with the replace function.
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException{
Object[] r = getRow();
if (r == null) {
setOutputDone();
return false;
}
if (first)
{
first = false;
}
r = createOutputRow(r, 1);
if(get(Fields.In, "data").getString(r) != null)
{
String output= get(Fields.In, "data").getString(r);
output= output.replaceAll("[^a-zA-Z0-9\\s()/\\.#-_]+","");
get(Fields.Out, "output").setValue(r, output);
}else {
get(Fields.Out, "output").setValue(r, "");
}
putRow(data.outputRowMeta, r);
return true;
}
data is the input stream data and the cleaned output would be in "output" column. I have shared a sample code here.
Hope this will solve your issue. :)
Modifying my earlier answer to include the full code. Having said this, i have also created a plugin recently to handle special characters. You can have a look at my blog site :
Blog link: https://anotherreeshu.wordpress.com/2015/01/07/special-character-remover-clean-your-data-of-special-characters-pentaho-kettle-step-plugin/
Even though its only version 1.0.0, but you can have a try. It might also help ypu :)

solr : how to add extra fields values not in the document

I know lucene, just started to learn how to use solr. In the simple example, the way to add document is to used the example ../update -jar post.jar to add document, the question is without writing my own add document in java, using the same way (... post.jar), is there a way to add additional fields not in the document? For example, say my schema include name, age, id fields, but the document has no 'id' field but I want the id and its value to be included, of course I know what id and value I want but how do I include it?
Thanks in advanced!
I don't believe you can mix the two. You can use post.jar to add documents using arguments passed in on the commandline, a file, stdin or a simple crawl from a web page but there is no way to combine them. In the source code for post.jar you can see it's a series else if statements so they are mutually exclusive.
-Ddata args, stdin, files, web
Use args to pass arguments along the command line (such as a command
to delete a document). Use files to pass a filename or regex pattern
indicating paths and filenames. Use stdin to use standard input. Use
web for a very simple web crawler (arguments for this would be the URL
to crawl).
https://cwiki.apache.org/confluence/display/solr/Simple+Post+Tool
/**
* After initialization, call execute to start the post job.
* This method delegates to the correct mode method.
*/
public void execute() {
final long startTime = System.currentTimeMillis();
if (DATA_MODE_FILES.equals(mode) && args.length > 0) {
doFilesMode();
} else if(DATA_MODE_ARGS.equals(mode) && args.length > 0) {
doArgsMode();
} else if(DATA_MODE_WEB.equals(mode) && args.length > 0) {
doWebMode();
} else if(DATA_MODE_STDIN.equals(mode)) {
doStdinMode();
} else {
usageShort();
return;
}
if (commit) commit();
if (optimize) optimize();
final long endTime = System.currentTimeMillis();
displayTiming(endTime - startTime);
}
http://svn.apache.org/repos/asf/lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/SimplePostTool.java
You could try to modify the code but I think a better bet would be to either pre-process your xml files to include the missing fields, or learn to use the API (either via Java or hitting it with Curl) to do this on your own.

On Google App Engine (GAE), how do I search on the Key/ID field?

I've got this code (Java, GAE):
// Much earlier:
playerKey = KeyFactory.keyToString(somePlayer.key);
// Then, later...
PersistenceManager pm = assassin.PMF.get().getPersistenceManager();
Key targetKey = KeyFactory.stringToKey(playerKey);
Query query = pm.newQuery(Player.class);
query.setFilter("__key__ == keyParam");
query.declareParameters("com.google.appengine.api.datastore.Key keyParam");
List<Player> players = (List<Player>) query.execute(targetKey); // <-- line 200
which generates this error:
javax.jdo.JDOFatalUserException: Unexpected expression type while parsing query. Are you certain that a field named __key__ exists on your object?
at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:354)
at org.datanucleus.jdo.JDOQuery.execute(JDOQuery.java:252)
at myapp.Player.validPlayerWithKey(Player.java:200)
// [etc., snip]
But I'm not sure what it wants. I'm trying to search on the JDO id field, which I I thought I read had the special name __key__, in the documentation.
I've tried it with both
query.setFilter("__key__ == keyParam");
and
query.setFilter("ID == keyParam");
with the same results. So, what am I doing wrong? Or, more importantly, how do I do it correctly?
Thanks!
Edit: For completeness's sake, here is the final, working code (based on Gordon's answer, which I have accepted as correct):
Player result = null;
if (playerKey == null)
{
log.log(Level.WARNING, "Tried to find player with null key.");
}
else
{
PersistenceManager pm = assassin.PMF.get().getPersistenceManager();
try {
result = (Player) pm.getObjectById(Player.class, playerKey);
} catch (javax.jdo.JDOObjectNotFoundException notFound) {
// Player not found; we will return null.
result = null;
}
pm.close();
}
return result;
If your objective is to get an object by key, then you should use the PersistenceManager's getObjectByID() method. More details here.
As an aside, trying to construct a query to get something by it's key is something you shouldn't need to do. Although this is how you would work with an SQL database, the Google Data Store does things differently, and this is one of those cases where rather than go through the trouble of constructing a query, Google App Engine lets you get what you want directly. After all, you should only have one entity in the database with a particular key, so there's nothing in the rest of the machinery of a GQL query that you need in this case, hence it can all be skipped for efficiency.
I would recommend you to use the JPA ( http://code.google.com/appengine/docs/java/datastore/usingjpa.html ) to access your data in GAE, it has the very important advantage that you can use the widely known and documented JPA standard (and its JPAQL querying language) to do this kind of things, in portable way (if you stick to the JPA standard, your code will work for GAE, for Hibernate or with EclipseLink without modification)

The application sorts strings differently than the database

I am trying to sort a list of products by their name in a .Net application written in C#, to obtain the same list that I would get from an SQL Server database through an order by:
select * from Products order by ProductName
Unfortunately, the application sorting behaves differently than the database sorting. It is probably related to the collation: the database has an SQL_Latin1_General_CP1_CI_AS collation.
How can I make the application sort these strings exactly like the database does?
Thanks.
UPDATE: I finally obtained a good result by using the code from the comments below, and changing the compare options to Ordinal:
private CompareOptions myOptions = CompareOptions.Ordinal ;
Also, this link contains some very useful information related to SQL collations: http://www.siao2.com/2005/11/08/490305.aspx
Thanks. It does not work yet, but this is probably the right direction.
Here is the code I am trying now:
((List)orderDetails).Sort(new OrderDetailComparer());
where OrderDetailComparer is:
public class OrderDetailComparer : IComparer<OrderDetail>
{
private CompareInfo myComp = CompareInfo.GetCompareInfo("en-US");
private CompareOptions myOptions = CompareOptions.StringSort;
public int Compare(OrderDetail a, OrderDetail b)
{
if (a == b) return 0;
if (a == null) return -1;
if (b == null) return 1;
return myComp.Compare ( a.Product.ProductNameForSorting, b.Product.ProductNameForSorting, myOptions );
}
}
Still no result.
What do you think? How do I get the information from the database, to know what culture I should use?
Thanks.
you'll probably need to use the culture you wish to sort in. Look at the example of the StringComparer:
http://msdn.microsoft.com/en-us/library/system.stringcomparer.currentculture.aspx

Resources