Exemplo n.º 1
0
        public static InvolvementTableColumnSet GetColumnSet(string page)
        {
            string customTextName, defaultXml;

            switch (page)
            {
            default:
                customTextName = "InvolvementTableCurrent";
                defaultXml     = Resource1.InvolvementTableCurrent;
                break;

            case "Pending":
                customTextName = "InvolvementTablePending";
                defaultXml     = Resource1.InvolvementTablePending;
                break;

            case "Previous":
                customTextName = "InvolvementTablePrevious";
                defaultXml     = Resource1.InvolvementTablePrevious;
                break;
            }

            //var db = Db;

            var s = HttpRuntime.Cache[DbUtil.Db.Host + customTextName] as string;

            if (s == null)
            {
                s = DbUtil.Db.ContentText(customTextName, defaultXml);
                HttpRuntime.Cache.Insert(DbUtil.Db.Host + customTextName, s, null,
                                         DateTime.Now.AddMinutes(Util.IsDebug() ? 0 : 1), Cache.NoSlidingExpiration);
            }
            if (!s.HasValue())
            {
                return(null);
            }

            XDocument xdoc;

            try
            {
                xdoc = XDocument.Parse(s);
            }
            catch (Exception)
            {
                // If the above fails for any reason, fall back on the default
                xdoc = XDocument.Parse(defaultXml);
            }

            if (xdoc?.Root == null)
            {
                return(new InvolvementTableColumnSet());
            }

            var set = new InvolvementTableColumnSet();

            foreach (var d in xdoc.XPathSelectElements("/InvolvementTable").Elements())
            {
                if (d.Name.LocalName.ToLower() == "columns")
                {
                    var list = new List <InvolvementTableColumn>();

                    foreach (var e in d.DescendantsAndSelf())
                    {
                        if (e.Name.LocalName.ToLower() == "column")
                        {
                            var column = new InvolvementTableColumn();
                            column.Field = e.Attribute("field")?.Value;
                            column.Label = e.Attribute("label")?.Value ?? column.Field;
                            column.Page  = page;

                            bool sortable;
                            bool.TryParse(e.Attribute("sortable")?.Value ?? "false", out sortable);
                            column.Sortable = sortable;
                            column.Roles    = e.Attribute("role")?.Value.Split(',').ToList();

                            list.Add(column);
                        }
                    }

                    var orgtype = d.Attribute("orgtype")?.Value;
                    if (orgtype != null)
                    {
                        set.OrgTypeColumns.Add(orgtype, list);
                    }
                    else
                    {
                        set.DefaultColumns = list;
                    }
                }
            }
            return(set);
        }
Exemplo n.º 2
0
        public static InvolvementTableColumnSet GetColumnSet(string page)
        {
            string customTextName, defaultXml;
            switch (page)
            {
                default:
                    customTextName = "InvolvementTableCurrent";
                    defaultXml = Resource1.InvolvementTableCurrent;
                    break;
                case "Pending":
                    customTextName = "InvolvementTablePending";
                    defaultXml = Resource1.InvolvementTablePending;
                    break;
                case "Previous":
                    customTextName = "InvolvementTablePrevious";
                    defaultXml = Resource1.InvolvementTablePrevious;
                    break;
            }

            var db = DbUtil.Db;

            var s = HttpRuntime.Cache[DbUtil.Db.Host + customTextName] as string;
            if (s == null)
            {
                s = db.ContentText(customTextName, defaultXml);
                HttpRuntime.Cache.Insert(db.Host + customTextName, s, null,
                    DateTime.Now.AddMinutes(Util.IsDebug() ? 0 : 1), Cache.NoSlidingExpiration);
            }
            if (!s.HasValue())
                return null;

            XDocument xdoc;

            try
            {
                xdoc = XDocument.Parse(s);
            }
            catch (Exception)
            {
                // If the above fails for any reason, fall back on the default
                xdoc = XDocument.Parse(defaultXml);
            }

            if (xdoc?.Root == null)
                return new InvolvementTableColumnSet();

            var set = new InvolvementTableColumnSet();
            foreach (var d in xdoc.XPathSelectElements("/InvolvementTable").Elements())
            {
                if (d.Name.LocalName.ToLower() == "columns")
                {
                    var list = new List<InvolvementTableColumn>();

                    foreach (var e in d.DescendantsAndSelf())
                    {
                        if (e.Name.LocalName.ToLower() == "column")
                        {
                            var column = new InvolvementTableColumn();
                            column.Field = e.Attribute("field")?.Value;
                            column.Label = e.Attribute("label")?.Value ?? column.Field;
                            column.Page = page;

                            bool sortable;
                            bool.TryParse(e.Attribute("sortable")?.Value ?? "false", out sortable);
                            column.Sortable = sortable;

                            list.Add(column);
                        }
                    }

                    var orgtype = d.Attribute("orgtype")?.Value;
                    if (orgtype != null)
                        set.OrgTypeColumns.Add(orgtype, list);
                    else
                        set.DefaultColumns = list;
                }
            }
            return set;
        }