Using TextStringArray as a mediaType parameter and razor interogation
having some issues with using TextstringArray as a parameter on a mediaType
basically I think it's down to the razor lookup using the examin internal searcher... and so all content gets passed through a HTMLStrip function. (much the same as rte content on a media item can't be accessed with razor)
As you've noticed there is a difference in how the raw data is stored in Umbraco's database, than the rendered/cached XML.
Going back to your original approach, "imageNode.chartValues" should contain the DynamicXml - I think the ".ToString()" might just get the inner-text values.
Error Loading Razor Script (file: Chart) Data at the root level is invalid. Line 1, position 1. at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at uComponents.DataTypes.TableArray.TableArrayModelBinder.Init(Int32 CurrentNodeId, String PropertyData, Object& instance) in C:\WebDevelopment\Umbraco\v4.11.1\ucomponents\uComponents.DataTypes\TableArray\TableArrayModelBinder.cs:line 35 at umbraco.MacroEngines.DynamicNode.TryCreateInstanceRazorDataTypeModel(Guid dataType, Type dataTypeType, String value, Object& result) at umbraco.MacroEngines.DynamicNode.TryGetMember(GetMemberBinder binder, Object& result) at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at ASP._Page_macroScripts_chart_cshtml.Execute() in e:\WebDevelopment\15006_jpt\v9\devv9.dev.fidus.co.uk\LiveSite\macroScripts\chart.cshtml:line 23 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage) at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
That;s I think because chartValues coming out of the examine index isn't the xml represenation... like I postulated think it's as we're using the internal indexer and that's a Lucene.Net.Analysis.WhitespaceAnalyzer so all html tags are stripped from properties..
Have the exact same issues to work around with RTE as a mediatype parameter.. as documented here [http://issues.umbraco.org/issue/U4-1078]
Got there in the end - a table with the column headers from the textsrtringarray on a mediatype... but not sure on the performance as this will be hitting up the database rather than the in-memory objects..
@*
TITLE
=================================
Overview : what this is for and how it accomplishes it
Macro Params
------------
@param : parameter descripition
*@
@using umbraco.MacroEngines
@using umbraco
@using umbraco.cms.businesslogic.datatype
@using uComponents.DataTypes.TextstringArray
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
// get the media item we are dealing with (have to use this as razor uses examine strippedhtml from the index
int mediaId = !String.IsNullOrWhiteSpace(@Parameter.MediaNodeId) ? int.Parse(@Parameter.MediaNodeId) : 0;
umbraco.cms.businesslogic.media.Media m = new umbraco.cms.businesslogic.media.Media(mediaId);
// load the values into a string array/list.
var deserializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var values = deserializer.Deserialize<List<string[]>>(m.getProperty("chartValues").Value.ToString());
if (values.Count > 0)
{
// now get the column headers from the prevalues
TableArrayOptions options = null;
var dataType = m.getProperty("chartValues").PropertyType.DataTypeDefinition.DataType;
var prevalues = PreValues.GetPreValues(dataType.DataTypeDefinitionId);
// based on the deserialize from the AbstractJsonPrevalueEditor
if (prevalues.Count > 0)
{
var prevalue = (PreValue)prevalues[0];
if (!string.IsNullOrEmpty(prevalue.Value))
{
try
{
// deserialize the options
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
// return the options
options = serializer.Deserialize<TextstringArrayOptions>(prevalue.Value);
}
catch (Exception ex)
{
umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Error, dataType.DataTypeDefinitionId, string.Concat("umbraco.editorControls: Execption thrown: ", ex));
}
}
}
<table>
@{//add tHead
if (options != null)
{
if (options.ShowColumnLabels)
{
var columns = options.ColumnLabels.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
<thead>
<tr>
@foreach (string header in columns)
{
if (!header.StartsWith("color"))
{
<th>@(header)</th>
}
}
</tr>
</thead>
}
}
<tbody>
@foreach (string[] row in values)
{
// loop through the list/array items add each row.
<tr>
@for (int i = 0; i < row.Length; i++)
{
if (!row[i].StartsWith("#"))
{
string xattr = "";
if (row[row.Length - 1].StartsWith("#"))
{
xattr = " style=\"color:" + row[row.Length - 1] + "\"";
}
<[email protected](xattr)>
@if (i == 0)
{
<strong>@row[i]</strong>
}
else
{
<span>@row[i]</span>
}
</td>
}
}
</tr>
}
</tbody>
}
</table>
}
}
Using TextStringArray as a mediaType parameter and razor interogation
having some issues with using TextstringArray as a parameter on a mediaType
basically I think it's down to the razor lookup using the examin internal searcher... and so all content gets passed through a HTMLStrip function. (much the same as rte content on a media item can't be accessed with razor)
If I used this on a document type I get
dynamic imageNode = Library.MediaById(Parameter.MediaNodeId); @Html.Raw(imageNode.chartValues.ToString());
results in
"helloworld" eg the above xml fragment stripped to plain text.
so I go the old school route..
umbraco.cms.businesslogic.media.Media d = new umbraco.cms.businesslogic.media.Media(Parameter.MediaNodeId);
@Html.Raw(d.getProperty("chartValues").Value.ToString())
so now I get...
[["2010","0-408","#fff"],["NAR","408-422","#fff"],["ITV1 Schedule Costs","422-451","#fff"],["Cost Savings","451-471","#fff"],["Investment","443-471","#fff"],["Other Non-NAR","443-462","#fff"],["2011","0-462","#fff"]]
but I'd much rather have the xml so I can stick it in a DynamicXml Obj and then carry on as normal...
Am I missing something simple?
Hi Mike,
As you've noticed there is a difference in how the raw data is stored in Umbraco's database, than the rendered/cached XML.
Going back to your original approach, "imageNode.chartValues" should contain the DynamicXml - I think the ".ToString()" might just get the inner-text values.
Cheers, Lee.
Error Loading Razor Script (file: Chart) Data at the root level is invalid. Line 1, position 1. at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.LoadXml(String xml)
at uComponents.DataTypes.TableArray.TableArrayModelBinder.Init(Int32 CurrentNodeId, String PropertyData, Object& instance) in C:\WebDevelopment\Umbraco\v4.11.1\ucomponents\uComponents.DataTypes\TableArray\TableArrayModelBinder.cs:line 35
at umbraco.MacroEngines.DynamicNode.TryCreateInstanceRazorDataTypeModel(Guid dataType, Type dataTypeType, String value, Object& result)
at umbraco.MacroEngines.DynamicNode.TryGetMember(GetMemberBinder binder, Object& result)
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at ASP._Page_macroScripts_chart_cshtml.Execute() in e:\WebDevelopment\15006_jpt\v9\devv9.dev.fidus.co.uk\LiveSite\macroScripts\chart.cshtml:line 23
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
That;s I think because chartValues coming out of the examine index isn't the xml represenation... like I postulated think it's as we're using the internal indexer and that's a Lucene.Net.Analysis.WhitespaceAnalyzer so all html tags are stripped from properties..
Have the exact same issues to work around with RTE as a mediatype parameter.. as documented here [http://issues.umbraco.org/issue/U4-1078]
Unfortunately if the Examine indexer is stripping the XML, there's not much we can do about.
At the moment I guess the only option is to take the raw data from the database (via the old school route) and deserialise it to a `List<string[]>`:
If you have any ideas/suggestions on how we can approach this going forwards, do let me know.
Cheers, Lee.
Not really related to this topic, but it might be good to mention that the xml might also be in the wrong format because of this issue: http://issues.umbraco.org/issue/U4-1636#comment=67-5259
Jeroen
Got there in the end - a table with the column headers from the textsrtringarray on a mediatype... but not sure on the performance as this will be hitting up the database rather than the in-memory objects..
is working on a reply...