Пример #1
0
        public static string ToJson(XPathNavigator navigator, string root, bool metadata, params System.String[] arrays)
        {
            XmlConverter xmlc = new XmlConverter(navigator, root, metadata, arrays);

            return(xmlc.ToJson());
        }
Пример #2
0
        public string ToJson()
        {
            ControllerConfiguration config = this.Virtualize(this.ControllerName);

            Complete();
            XPathNodeIterator ruleIterator = config.Select("/c:dataController/c:businessRules/c:rule");
            bool newOnServer       = false;
            bool calculateOnServer = false;

            while (ruleIterator.MoveNext())
            {
                string type        = ruleIterator.Current.GetAttribute("type", String.Empty);
                string commandName = ruleIterator.Current.GetAttribute("commandName", String.Empty);
                if (type != "JavaScript")
                {
                    if ((commandName == "New") && !(newOnServer))
                    {
                        newOnServer = true;
                        config.SelectSingleNode("/c:dataController").CreateAttribute(String.Empty, "newOnServer", null, "true");
                    }
                    else
                    if ((commandName == "Calculate") && !(calculateOnServer))
                    {
                        calculateOnServer = true;
                        config.SelectSingleNode("/c:dataController").CreateAttribute(String.Empty, "calculateOnServer", null, "true");
                    }
                }
            }
            string expressions = JArray.FromObject(this.Expressions).ToString();

            string[] exceptions = new string[] {
                "//comment()",
                "c:dataController/c:commands",
                "c:dataController/@handler",
                "//c:field/c:formula",
                "//c:businessRules/c:rule[@type=\"Code\" or @type=\"Sql\" or @type=\"Email\"]",
                "//c:businessRules/c:rule/text()",
                "//c:validate",
                "//c:styles",
                "//c:visibility",
                "//c:readOnly",
                "//c:expression"
            };
            foreach (string ex in exceptions)
            {
                List <XPathNavigator> toDelete = new List <XPathNavigator>();
                XPathNodeIterator     iterator = config.Select(ex);
                while (iterator.MoveNext())
                {
                    toDelete.Add(iterator.Current.Clone());
                }
                foreach (XPathNavigator node in toDelete)
                {
                    node.DeleteSelf();
                }
            }
            // special case of items/item serialization
            XPathNodeIterator itemsIterator = config.Select("//c:items[c:item]");

            while (itemsIterator.MoveNext())
            {
                StringBuilder     lovBuilder   = new StringBuilder("<list>");
                XPathNodeIterator itemIterator = itemsIterator.Current.SelectChildren(XPathNodeType.Element);
                while (itemIterator.MoveNext())
                {
                    lovBuilder.Append(itemIterator.Current.OuterXml);
                }
                lovBuilder.Append("</list>");
                itemsIterator.Current.InnerXml = lovBuilder.ToString();
            }
            // load custom view layouts
            XPathNodeIterator viewIterator = config.Select("//c:views/c:view");

            while (viewIterator.MoveNext())
            {
                string layout = LoadLayout(viewIterator.Current.GetAttribute("id", String.Empty));
                if (!(String.IsNullOrEmpty(layout)))
                {
                    viewIterator.Current.AppendChild(String.Format("<layout><![CDATA[{0}]]></layout>", layout));
                }
            }
            // extend JSON with "expressions"
            string json = XmlConverter.ToJson(config.Navigator, "dataController", true, "commands", "output", "fields", "views", "categories", "dataFields", "actions", "actionGroup", "businessRules", "list");
            Match  eof  = Regex.Match(json, "\\}\\s*\\}\\s*$");

            json = (json.Substring(0, eof.Index)
                    + (",\"expressions\":"
                       + (expressions + eof.Value)));
            return(json);
        }