Rule CA1709 and two letter-words - code-analysis

I have a library with a lot of functions that use two letter-non english-words like this:
FinDeDia
EsPrimo
EnPreparacion
...
Anyway, I activated code analysys for the project, and I'm getting the CA1709 warning:
CA1709 : Microsoft.Naming :
Corrija el uso de mayúsculas y minúsculas en 'De' en el nombre del miembro '...' cambiándolo a 'DE'.
I added a code analysis dictionary as stated here but it doesn't ignore the warnings. Here is the structure of the dictionary.
<?xml version="1.0" encoding="utf-8" ?>
<Dictionary>
<Words>
<Recognized>
<Word>de</Word>
<Word>el</Word>
<Word>en</Word>
<Word>es</Word>
<Word>si</Word>
...
</Recognized>
</Words>
</Dictionary>
What else should i do for handling this warning Without supressing the message?.
thanks in advance

You need to add them as CasingExceptions aswell:
<Acronyms>
<CasingExceptions>
<Acronym>De</Acronym>
<Acronym>El</Acronym>
<Acronym>En</Acronym>
<Acronym>Es</Acronym>
<Acronym>Si</Acronym>
</CasingExceptions>
</Acronyms>
</Dictionary>
EDIT:
Just be aware of the fact that this is somewhat a misuse, since none of those words are acronyms. Maybe you'd rather want to disable those specific rules. Afterall, many of code analysis' rules are based on the assumption that the API is written in English.

Related

How can I use pagemap with google custom search refinements?

I'm trying to add refinements to my google custom search.
I have meta tags on just about every page of the site, such as
<meta name="type-id" content="241" />
Where there are many different types, and I want to have one refinement for each type.
In the docs, it says
You can also use these more:pagemap: operators with refinement labels
But I have been unable to do that.
Note that I have had success using more:pagemap:metatags-type-id:241 in the search input, or as a webSearchQueryAddition - but despite googles docs, I haven't been able to get it to work with a refinement.
Here's a sample from my cse.xml (removing some attributes from the CustomSearchEngine tag):
<?xml version="1.0" encoding="UTF-8"?>
<CustomSearchEngine>
<Title>Test</Title>
<Context>
<Facet>
<FacetItem>
<Label name="videos" mode="FILTER">
<Rewrite>more:p:metatags-article-keyword:121</Rewrite>
</Label>
<Title>Videos</Title>
</FacetItem>
</Facet>
</Context>
</CustomSearchEngine>
Is this supposed to work? Am I using wrong syntax in the rewrite rule? Has anyone else done something like this?
Your label in the facet should be mode="BOOST" if you want to restrict to a structured data field within the scope of your engine.
<Facet>
<FacetItem>
<Label name="videos" mode="BOOST">
<Rewrite>more:p:metatags-article-keyword:121</Rewrite>
</Label>
<Title>Videos</Title>
</FacetItem>
</Facet>

Hey Cortana, how to handle multiple VCD languages in code?

In my app, I want to give the user the opportunity to switch a light on and off with voice commands (via Cortana for example). I understand the VCD concept and really like but I don't know how to handle the different languages in my code.
Given I have two languages (English and German):
<CommandSet xml:lang="en" Name="LightSwitch_en">
<CommandPrefix>Switch the light</CommandPrefix>
<Example>Switch the light on.</Example>
<Command Name="switchLight">
<Example>on</Example>
<ListenFor>{status}</ListenFor>
<Feedback>Light will be switched {status}.</Feedback>
<Navigate />
</Command>
<PhraseList Label="status">
<Item>on</Item>
<Item>off</Item>
</PhraseList>
</CommandSet>
<CommandSet xml:lang="de" Name="LightSwitch_de">
<CommandPrefix>Schalte das licht</CommandPrefix>
<Example>Schalte das Licht ein.</Example>
<Command Name="switchLight">
<Example>ein</Example>
<ListenFor>{status}</ListenFor>
<Feedback>Licht wird {status}geschaltet.</Feedback>
<Navigate />
</Command>
<PhraseList Label="status">
<Item>ein</Item>
<Item>aus</Item>
</PhraseList>
</CommandSet>
When my app launches by a voice command, I can easily extract the spoken words and can access the status parameter. But because it's a string I will get a different result depending on which language the user has spoken.
So if the user speaks English, the string is "on", but if he speaks German, the string would be "ein". So how do I know, which string I need to listen for inside my app? I am targeting something like this:
if (arg.Equals("on"))
Light.On();
else if (arg.Equals("off"))
Light.Off();
But this only works in English of cause, not in German. I resent checking for all different strings in all languages, that can't be the right way. Unfortuantely it is also not possible to give the <Item> tags an additional attribute due to they are just strings.
I could do something like if (arg.Equals("on") || arg.Equals("ein")) Light.On(); but as you can see this is really ugly and I have to adjust it every time I change something and well, imagine I had about 15 languages to check...
Do you know a smarter solution?
As Cortana will use the same localization as the built in app localization method can you not put all your strings in resource files and then compare the returned string with the localized resource?
In case you just need to solve that particular case you can do the following, instead a list just define two commands per language:
<Command Name="oncommand" >
<Example>switch on</Example>
<ListenFor>switch on</ListenFor>
<Feedback>Light will be switched on.</Feedback>
<Navigate />
</Command>
<Command Name="offcommand">
<Example>switch off</Example>
<ListenFor>switch off</ListenFor>
<Feedback>Light will be switched off.</Feedback>
<Navigate />
</Command>
and then detect in code what command was called:
if (args.Kind == ActivationKind.VoiceCommand)
{
var commandArgs = args as VoiceCommandActivatedEventArgs;
var speechRecognitionResult = commandArgs.Result;
string voiceCommandName = speechRecognitionResult.RulePath.First();
string textSpoken = speechRecognitionResult.Text;
return voiceCommandName;
}
where voiceCommandName is 'oncommand' or 'offcommand'.

CA1703 CodeAnalysis Error and CasingExceptions

I have a text resource "{0} by Test GmbH" which is correctly spelled because GmbH is the official Abbreviation for "Gesellschaft mit beschränkter Haftung". I understand that Microsoft CodeAnalysing tries to tokenize it into "Gmb" and "H" however I think it should be possible to introduce this term as known with that specific spelling and casing with this CodeAnalysingDictionary:
<?xml version="1.0" encoding="utf-8" ?>
<Dictionary>
<Words>
<Unrecognized>
</Unrecognized>
<Recognized>
<Word>Gmbh</Word>
</Recognized>
<Deprecated>
</Deprecated>
<DiscreteExceptions>
<Term>GmbH</Term>
</DiscreteExceptions>
</Words>
<Acronyms>
<CasingExceptions>
<Acronym>GmbH</Acronym>
</CasingExceptions>
</Acronyms>
</Dictionary>
However it does not work out:
CA1703 Resource strings should be spelled correctly
In resource 'MyCode.Properties.Resources.resx',
referenced by name 'CopyrightWithCompanyName',
correct the spelling of 'Gmb' in string value '{0} by Test GmbH'.
How can I adjust the dictionary correctly?
Actually, provided that GmbH should be interpreted as a compound word that consists of the words Gmb and H, the casing of GmbH is correct.
So, in order for GmbH to be seen as valid by Code Analysis and thereby eliminate CA1703, simply add gmb as a recognized word to your custom dictionary file:
<Dictionary>
<Words>
<Recognized>
<Word>gmb</Word>
<!-- ... -->
</Recognized>
<!-- ... -->
</Words>
<!-- ... -->
</Dictionary>
I confirmed that this works in Visual Studio 2013.
According to http://msdn.microsoft.com/en-us/library/bb514188.aspx#bkmk_dictionaryacronymscasingexceptionsacronym
entries in the CasingExceptions are only applied to CA1709: Identifiers should be cased correctly, not to resources.
I have the exact same problem but no solution other then suppress the warning

What does this web.xml error mean?

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
Referenced file contains errors (http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd). For more information, right click on the message in the Problems View and select "Show Details..."
The errors below were detected when validating the file "web-app_2_5.xsd" via the file "web.xml". In most cases these errors can be detected by validating "web-app_2_5.xsd" directly. However it is possible that errors will only occur when web-app_2_5.xsd is validated in the context of web.xml.
In details, I see a bunch of these:
s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than xs:appinfo and xs:documentation. Saw 'var _U="undefined";'
If you replace j2ee by javaee, it will work fine.
EDIT :
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
Edit:
To know anything further related to this error. Please follow the Link. Here you will find schemas for Java EE deployment descriptors (web.xml).
replace
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
with
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee;http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
The solution is that you have to put semicolon between URLs
I am sure you will not get the error again :)
I suggest you add ; between 2 passages:
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee and http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
Like this:
:xsi:schemaLocation="http://java.sun.com/xml/ns/javaee;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
Add semicolon between xsi:schemaLocation just as shown below
"http://java.sun.com/xml/ns/javaee;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
This resolved my this error in <servlet-name> tag line as well.
"cvc-id.3: A field of identity constraint 'web-common-servlet-name-uniqueness' matched element 'web-app', but this element does not have a simple type."
In my case, I had replaced
xsi:schemaLocation="http://java.sun.com/../.."
with
xsi:schemaLocation="http://xmlns.jcp.org/../.."
Cheers!
On the surface it appears that the schemaLocation is wrong. Resolving it appears to redirect to a HTML page rather than a XSD schema.
I would suggest simply removing this line unless you really want to do XSD validation at runtime. Bear in mind the relevant parts will be validated by your servlet container.
Replacing the schemaLocation as below has resovled the error for me:
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/j2ee; http://xmlns.jcp.org/xml/ns/j2ee/web-app_2_4.xsd"

What is the best way to prevent to see "options are not unique" error?

When I want to update a specific product how can I determine non unique options and prevent to see 'options are not unique' error?
This is xml of create product:
my $xml = qq~<?xml version="1.0" encoding="UTF-8"?>
<product>
<title>$title</title>
<body-html>$description</body-html>
<vendor>$vendor</vendor>
<product-type>$product_type</product-type>
<published type="boolean">$publish_status</published>~;
$xml.=qq{<variants type="array">
<variant>
<title>$title</title>
<option1>$title</option1>
<option2 nil="true"></option2>
<option3 nil="true"></option3>};
$xml.=qq{<price>$price</price>
<sku>$sku</sku>
<position type="integer">1</position>
</variant>
</variants>};
$xml.='</product>';
This is the xml of modify product:
my $xml = qq~<?xml version="1.0" encoding="UTF-8"?>
<product>~;
$xml.=qq~<title>$title</title>~;
$xml.=qq~<id type="integer">$id_product</id>~;
$xml.=qq~<body-html>$description</body-html>
<vendor>$vendor</vendor>
<product-type>$product_type</product-type>
<published type="boolean">$publish_status</published>
<variants type="array">
<variant>~;
$xml.= qq~<title>$title</title>~;
$xml.= qq~<option1>$title</option1>~;
$xml.= qq~<option2 nil="true"/>~;
$xml.= qq~<option3 nil="true"/>~;
$xml.=qq~<price>$price</price>
<sku>$sku</sku>
<position type="integer">1</position>
</variant>
</variants>~;
$xml.='</product>';
I am getting "options are not unique" error when I try to modify specific product. option1 tag content is same as previous option1 tag content. Is it a bug? or option1 value is must be different previous one? What I have to do not see "options are not unique" error?
Thanks in Advance
Yes, there is a bug in the API when updating products and you are passing in an option that already exists. The error message is actually quite misleading and is being worked on at the moment.