private string RenderScoreToJson(DefinitionObject score, int idLanguage) { StringBuilder result = new StringBuilder(); if (score.IsScoreGroup()) { object _enabled = score.GetValue("Enabled"); result.Append("{"); result.Append(string.Format( " \"Type\": \"ScoreGroup\", \"Id\": \"{0}\", \"Name\": \"{1}\", \"Order\": \"{2}\", \"Path\": \"{3}\", \"Source\": \"{4}\", \"Value\": \"{5}\", \"Enabled\": {6}, \"Color\":\"{7}\", \"Scores\": [", score.GetValue("Id"), HttpUtility.HtmlEncode(score.GetLabel(idLanguage)), score.GetValue("Order"), score.Path.Replace("\"", "\\\""), score.Source, score.GetValue("Value"), _enabled != null ? _enabled.ToString().ToLower() : true.ToString().ToLower(), score.GetValue("Color") )); /*foreach (XmlNode xmlNodeScore in xmlNode.ChildNodes) * { * result.Append(RenderScoreToJson(xmlNodeScore, idLanguage)); * result.Append(","); * }*/ DefinitionObject[] childScores = score.GetChilds(); foreach (DefinitionObject childScore in childScores) { result.Append(RenderScoreToJson(childScore, idLanguage)); result.Append(","); } if (childScores.Length > 0) { result = result.Remove(result.Length - 1, 1); } result.Append("] }"); } else { object _enabled = score.GetValue("Enabled"); result.Append("{"); result.Append(string.Format( " \"Type\": \"{0}\", \"Id\": \"{1}\", \"Label\": \"{2}\", \"Order\": \"{3}\", \"Path\": \"{4}\", \"Enabled\": {5}, \"Source\": \"{6}\", \"Name\": \"{7}\", \"Value\": \"{8}\" ", score.TypeName, score.GetValue("Id"), HttpUtility.HtmlEncode(score.GetLabel(idLanguage)), score.GetValue("Order"), score.Path.Replace("\"", "\\\""), _enabled != null ? _enabled.ToString().ToLower() : true.ToString().ToLower(), score.Source, HttpUtility.HtmlEncode(score.GetValue("Name")), score.GetValue("Value") )); result.Append("}"); } return(result.ToString()); }
private void GetScores(HttpContext context) { string xPath = context.Request.Params["XPath"]; // Get the source string from the http request's parameters. string source = context.Request.Params["Source"]; DefinitionObject variable = new DefinitionObject( Global.Core, source, xPath ); StringBuilder result = new StringBuilder(); result.Append("{ \"Scores\" : ["); // Set the default for the language to english GB. int idLanguage = 2057; // Check if a specific language is defined. if (context.Request.Params["IdLanguage"] != null) { idLanguage = int.Parse(context.Request.Params["IdLanguage"]); } DefinitionObject[] scores = variable.GetChilds(); HierarchyFilter hierarchyFilter; if (context.Request.UrlReferrer.ToString().EndsWith("LinkBi.aspx")) { hierarchyFilter = Global.HierarchyFilters[(string)HttpContext.Current.Session["LinkBiDefinition"]]; } else if (HttpContext.Current.Session["ReportDefinition"] != null) { hierarchyFilter = Global.HierarchyFilters[(string)HttpContext.Current.Session["ReportDefinition"]]; } else { string fileName = System.IO.Path.Combine( HttpContext.Current.Request.PhysicalApplicationPath, "Fileadmin", "ExportDefinitions", Global.User.Id + ".xml" ); hierarchyFilter = Global.HierarchyFilters[fileName]; } if (!hierarchyFilter.IsLoaded) { hierarchyFilter.Load(); } bool isTaxonomy = false; if (context.Request.UrlReferrer.ToString().EndsWith("Exports.aspx") || context.Request.UrlReferrer.ToString().EndsWith("TaxonomyManager.aspx")) { if (variable.GetValue("Id").ToString() != "") { isTaxonomy = true; } } else { isTaxonomy = bool.Parse((string)variable.GetValue("IsTaxonomy")); } foreach (DefinitionObject score in scores) { object persistant = score.GetValue("Persistent", false, false); if (isTaxonomy && persistant != null) { if (!hierarchyFilter.TaxonomyCategories.ContainsKey(Guid.Parse(score.GetValue("Id").ToString()))) { continue; } } result.Append(RenderScoreToJson(score, idLanguage)); result.Append(","); } if (scores.Length > 0) { result = result.Remove(result.Length - 1, 1); } result.Append("]}"); context.Response.Write(result.ToString()); }