Composite C1 MvcPlayer render fails when containing a Url.Action with a 'Page' parameter - c1-cms

Updated
Please ignore this issue, I was completely misconceived, the issue had nothing to do with what I thought it was, but is rather due to the fact that Composite treats all it's html that it renders from functions as XML, therefore you have to escape certain characters (here is a handy reference: http://www.faqs.org/docs/htmltut/characterentities_famsupp_69.html). In my case I had to replace & with &.
Hope this info helps someone else.
Also, here is a great post on how to escape your strings: String escape into XML
My old misconceived issue:
I have a View which fails to render by the MvcPlayer function of Composite. Through a process of elimination I was able to track it down to the following line in the View:
Url.Action("Action", "Controller", new { Page = 123, PageSize = 180 });
I then went further and discovered that if I changed it to the following:
Url.Action("Action", "Controller", new { PageSize = 180 });
The page then renders with no issues.
I checked the Composite error log, which stated:
System.Xml.XmlException: '=' is an unexpected token. The expected token is ';'. Line 81, position 63.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
at System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(String expectedToken1, String expectedToken2)
at System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(Int32 pos, String expectedToken1, String expectedToken2)
at System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(Int32 pos, String expectedToken)
at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& charRefEndPos)
at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr)
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at System.Xml.Linq.XDocument.Parse(String text, LoadOptions options)
at System.Xml.Linq.XDocument.Parse(String text)
at Composite.AspNet.MvcPlayer.Functions.RenderInternal(String path) in c:\***************\MvcPlayer\Player.cs:line 125
I know in Composite you reference pages within the system like so:
Page
The output of my Url.Action is /Controller/Action?Page=123&Page=180
So I assume that composite is picking up on the "?Page=123" part of the URL result from the Action and then is trying to process it as a composite Page reference, which of course it isn't.
Does anyone know how I could get around this issue?

Related

SQL Server 2012 assembly execution failure - System.NullReferenceException: Object reference not set to an instance of an object

I am trying to execute a UDF which uses a CLR assembly. Each time I try to run it I get the below error:
Msg 6522, Level 16, State 1, Line 45
A .NET Framework error occurred during execution of user-defined routine or aggregate "Geocode":
System.NullReferenceException: Object reference not set to an instance of an object.
at ProSpatial.UserDefinedFunctions.GeocodeUDF(SqlString countryRegion, SqlString adminDistrict, SqlString locality, SqlString postalCode, SqlString addressLine)
It is a geocoding assembly, which is based on the below blog:
https://alastaira.wordpress.com/2012/05/04/geocoding-in-sql-server-with-the-bing-maps-locations-api/
Is there anything I can do to fix it? It was working fine, but just stopped working recently. I changed the Bing Maps key to a new one, but that hasn't resolved the issue. Anyone have any ideas?
Cheers
Edit: I entered a formatted URL into Chrome, to see if I can get the error. I entered the below URL format:
http://dev.virtualearth.net/REST/v1/Locations?countryRegion={0}&adminDistrict={1}&locality={2}&postalCode={3}&addressLine={4}&key={5}&output=xml
All I did was to replace items 0 to 5 with their respective entries. I left the curly brackets in there, and then also tried it without the curly brackets. Without the curly brackets, the URL returned a result with no issues.
In the browser, I am getting geocoded results, but not in SQL any more
Just worked it out. One of the address fields that was being geocoded was null in the database, and the API did not like that. So I removed that from the geocoding list
Looking at the code in that blog, if you are passing in a NULL, then it's not the API that's throwing the error. The error is happening because NULL values are not being handled when the method is first called. The code just casts the SqlString input parameters to string without first checking to see if there is a value in the SqlString variable. SqlString is very similar to a nullable string.
Fortunately, it is rather easy to adjust the code to properly handle NULL values in the input parameters. Starting with a redacted snippet of the original code below, I will show how to do this for one parameter and you can repeat that modification for the others (well, the ones that might actually be NULL in the DB; no need to do this for parameters that are guaranteed to be there due to being in a NOT NULL column).
public static SqlGeography GeocodeUDF(
SqlString countryRegion,
SqlString adminDistrict,
SqlString locality,
SqlString postalCode,
SqlString addressLine
)
{
...
string localAdminDistrict = string.Empty;
if (!adminDistrict.IsNull)
{
localAdminDistrict = adminDistrict.Value;
}
// Attempt to geocode the requested address
try
{
geocodeResponse = Geocode(
(string)countryRegion,
localAdminDistrict,
(string)locality,
(string)postalCode,
(string)addressLine
);
}
All I did was:
Added a local variable for localAdminDistrict, defaulted to an empty string.
Added an if block to set localAdminDistrict if adminDistrict is not null.
Updated the call to Geocode() to use localAdminDistrict instead of (string)adminDistrict.
This should work as long as the Bing Maps API is ok with an empty value for adminDistrict (i.e. ...&adminDistrict=&locality=... ), as opposed to adminDistrict not being present in the GET request (which is easy enough, it just requires an additional modification).
ALSO: As long as you are going to be in there updating the code, you really should move the calls to the Close() and Dispose() methods into a finally block for that try / catch.
For more info on working with SQLCLR in general, please visit: SQLCLR Info

Gatling .sign issue

I am trying to build a Get request as follows and I would like CaseReference value to be populated via feeder .feed(CaseProviderSeq) but for some reason it's not picking CaseReference value and printing following for my println statement in .sign statement bellow
PATH KJ: /caseworkers/554355/jurisdictions/EMPLOYMENT/case-types/Manchester_Multiples/cases/$%7BCaseReference%7D/event-triggers/updateBulkAction_v2/token
My feeder CSV got following rows currently
1574761472170530
1574622770056940
so I am expecting this amended URL would be like
/caseworkers/554355/jurisdictions/EMPLOYMENT/case-types/Manchester_Multiples/cases/1574761472170530/event-triggers/updateBulkAction_v2/token
any idea what wrong I am doing here ??
.get(session => SaveEventUrl.replace(":case_reference","${CaseReference}").replaceAll("events", "") + s"event-triggers/${EventId}/token")
.header("ServiceAuthorization", s2sToken)
.header("Authorization", userToken)
.header("Content-Type","application/json")
.sign(new SignatureCalculator {
override def sign(request: Request): Unit = {
val path = request.getUri.getPath
println("PATH KJ: " + path)
request.getHeaders.add("uri", path)
}
})
This is not related to .sign, but your session attribute CaseReference not being interpreted. If you look closely you can see the braces %-encoded in $%7BCaseReference%7D.
Interpretation of the Gatling Expression Language strings happens only when a String is present when an Expression[Something] is needed1.
This bug you wrote is shown exactly in the warning in the documentation above.
I believe you can simply remove session => in your .get, so you are passing in a String rather than a Session => String2. That string will be implicitly converted to Expression[String]. That way Gatling will put the session attribute into the URL.
This happens because of the Scala implicit conversion.
In fact it is Session => Validation[String], because, again, of implicit conversions.

Load Delimiter Separated Values in D3

I am trying to load a pipe separated value file in D3 using the generic d3.dsvFormat() function. While I do not get an error, nothing happens which I think is because the callback function is not executed.
I did check the documentation here but did not find it that helpful: https://github.com/d3/d3-dsv/blob/master/README.md#dsvFormat
Is there a problem with my syntax?
var psv = d3.dsvFormat("|");
psv.parse("my_file.txt", function(error, data) {
Do a bunch of stuff with the data....
console.log(data); //nothing happens here
});
psv.parse wants text, you are passing text - just that it doesn't have any pipe in it: "my_file.txt". As this is one line of text and the first line of text translates into column names, you won't get any data with this.
Your problem is that psv.parse won't fetch a file for you like d3.csv or d3.tsv (Rather psv.parse() acts like d3.csvParse() or d3.tsvParse()). Luckily this is not too difficult to fix.
If we look at the API documentation for d3.csv we can recreate the same functionality for any delimited file. With d3.csv,
If a callback is specified, a GET request is sent, making it
equivalent to:
d3.request(url)
.mimeType("text/csv")
.response(function(xhr) { return d3.csvParse(xhr.responseText, row); })
.get(callback);
(from API docs)
We just have to emulate this for a pipe separated file:
var psv = d3.dsvFormat("|");
d3.request("my_file.txt")
.mimeType("text/plain")
.response(function(data) { return psv.parse(data.response) })
.get(function(data) {
console.log(data);
});
It's a little bit more verbose than a plain old d3.csv() or d3.tsv(), but achieves the same result with the callback function located in the get method.
You could also use data.responseText in the response method, I'm not sure what the difference is though, both appear identical in my quick testing.
You may have also noted that I did not specify a row function in the response method, this is an optional function that allows "conversion of row objects to a more-specific representation", eg: returning numbers rather than strings. API documentation).
One last note:
In relation to your original code, psv.parse("text") returns the data, you don't use a callback function for this method. The following snippet demonstrates how you might parse straight pipe delimited text:
var psv = d3.dsvFormat("|");
var data = psv.parse("a|b\n1|2\n4|3")
console.log(data);
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.10.0/d3.min.js"></script>

Can someone help me add a new column in Google cloud Search Index using Java

I tried adding a new column to an existing search index but it is throwing an error, the error as stated below:-
Field docname is present 0 times; expected 1
java.lang.IllegalArgumentException: Field docname is present 0 times; expected 1
I can see that the new column has been added to the search index but cannot retrieve the index.
By my observation i can see that the existing records in the index dont have the new column data and hence it is giving a this error, but the new records will be having this column values. Can anyone help me with this.
Upon having this problem myself today, I searched a bit in the documentation. It was a rather frustrating error as it didn't actually pin point where the problem was in my code.
It appears that when you use getOnlyField("something") on a Document (in this case on one of many returned from a search query), if that field does not actually exist yet in that specific document it throws the java.lang.IllegalArgumentException.
Because that can often be the case when you update an index with new columns, I'm using something like this to get around it:
public static Long getNumberField(ScoredDocument d, String name, Long defaultValue) {
try {
return d.getOnlyField(name).getNumber().longValue();
} catch (IllegalArgumentException e) {
return defaultValue;
}
}
Which is called in the search results code:
Long numberValue = SearchUtils.getNumberField(scoredDocument, "featuredOrder", -1L)
This allows me to catch that error and return a default value when it doesn't exist.
You can find the documentation here:
https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/search/Document.html#getOnlyField-java.lang.String-

MVC 4 return entries from database excluding specific items

I've been changing this call around for some time and can not quite get it to work. I am trying to return some records from a database and exclude items based on their ID numbers.
This is a database of quotes and when someone hides a quote it stores the quoteID in a cookie (required) and when returning to the site, The cookie.value is read.
I need to filter these IDs out of the return query and display the results in a view using WebGrid. I have the cookie part working. I retrieve the values (could be multiple) and split this into a list of strings. I then run a foreach loop ans parse the string to an integer and then try to remove quotes that I have retrieved from the database. Here is the code as I am using it...
// Filter on Cookie Value using tokenizer
string value = Request.Cookies.Get("hideCookie").Value;
List<string> values = value.Split(' ').ToList();
var quotes2 = db.Quotes.Include(q => q.QName);
foreach (var i in values)
{
int idv = int.Parse(i);
quotes2 = from q in quotes2 where q.QuoteID != idv select q;
}
return View(quotes2.ToList());
This throws an error "A specified Include path is not valid. The EntityType 'Exercise4.Models.Quote' does not declare a navigation property with the name 'QName'." (QName being an entry in the database record).
If I remove the ToList() in the return View(), quotes2 gets passed to the View but throws this error on the webGrid "A specified Include path is not valid. The EntityType 'Exercise4.Models.Quote' does not declare a navigation property with the name 'QName'."
I'm sure there is a much better way of doing this. Can you please point me in the correct direction so I can stop banging my head against my desk...

Resources