public virtual void Load(XElement element, string locale = "") { this.EnableVersioning = element.BoolAttr(VERSIONING); this.AllowComments = element.BoolAttr(ALLOW_COMMENTS); this.AllowAttachments = element.BoolAttr(ALLOW_ATTACHS); this.AllowVotes = element.BoolAttr(ALLOW_VOTES); this.AllowResharing = element.BoolAttr(ALLOW_RESHARING); this.AllowCategoriesAndTags = element.BoolAttr(ALLOW_CATE_TAGS); this.IsHierarchy = element.BoolAttr(HIERARCHY); this.IsModerated = element.BoolAttr(MODERATED); this.IsSingle = element.BoolAttr(SINGLE); this.IsSystem = element.BoolAttr(SYS); this.ItemType = element.StrAttr("itemtype"); this.UID = element.StrAttr("id"); this.Version = element.StrAttr("version"); if (string.IsNullOrEmpty(Version)) { this.Version = "1.0.0"; } this.Master = element.StrAttr("master"); this.IsActivity = element.BoolAttr(ACTIVITY); var ns = element.GetDefaultNamespace(); var defaultLocale = element.StrAttr(DEFAULT_LOCALE); var targetLocale = locale.Equals(defaultLocale, StringComparison.OrdinalIgnoreCase) ? "" : locale; var title = element.ElementWithLocale(ns + TITLE, targetLocale); var desc = element.ElementWithLocale(ns + DESC, targetLocale); this.Locale = targetLocale; if (string.IsNullOrEmpty(targetLocale)) { if (string.IsNullOrEmpty(this.Locale)) { this.Locale = "en-US"; } string baseType = element.StrAttr(BASE); if (string.IsNullOrEmpty(baseType)) { this.BaseType = element.StrAttr(NAME); } else { this.Name = element.StrAttr(NAME); this.BaseType = element.StrAttr(BASE); } } if (title == null) { title = element.ElementWithLocale(ns + TITLE, ""); } if (desc == null) { desc = element.ElementWithLocale(ns + DESC, ""); } if (title != null) { this.Title = title.Value; } if (desc != null) { this.Description = desc.Value; } var factory = new DNA.Web.Contents.ContentFieldFactory(); var fields = element.Elements(ns + FIELDS) .Elements(ns + FIELD) .Select(f => { var field = factory.Create(f, targetLocale); field.Parent = this; return(field); }); var fieldElements = new XElement(FIELDS, new XAttribute("xmlns", DefaultNamespace), fields.Select(f => f.Element())); this.FieldsXml = fieldElements.OuterXml(); //this.FieldsXml = element.Element(ns + FIELDS).OuterXml(); //Views var viewElements = element.Descendants(ns + "view"); this.Views = new List <ContentView>(); foreach (var viewEle in viewElements) { var v = new ContentView() { Parent = this }; v.Load(viewEle, targetLocale); this.Views.Add(v); } //Forms this.Forms = new List <ContentForm>(); var formElements = element.Descendants(ns + "form"); this.Forms = new List <ContentForm>(); foreach (var formEle in formElements) { var f = new ContentForm() { Parent = this }; f.Load(formEle, targetLocale); this.Forms.Add(f); } //Items this.Items = new List <ContentDataItem>(); var itemEles = element.Descendants(ns + "row"); this.Items = new List <ContentDataItem>(); foreach (var row in itemEles) { var r = new ContentDataItem() { Parent = this, Locale = this.Locale }; r.Load(row); this.Items.Add(r); } }
public virtual void Load(XElement element, string locale = "") { this.EnableVersioning = element.BoolAttr(VERSIONING); this.AllowComments = element.BoolAttr(ALLOW_COMMENTS); this.AllowAttachments = element.BoolAttr(ALLOW_ATTACHS); this.AllowVotes = element.BoolAttr(ALLOW_VOTES); this.AllowResharing = element.BoolAttr(ALLOW_RESHARING); this.AllowCategoriesAndTags = element.BoolAttr(ALLOW_CATE_TAGS); this.IsHierarchy = element.BoolAttr(HIERARCHY); this.IsModerated = element.BoolAttr(MODERATED); this.IsSingle = element.BoolAttr(SINGLE); this.IsSystem = element.BoolAttr(SYS); this.ItemType = element.StrAttr("itemtype"); this.UID = element.StrAttr("id"); this.Version = element.StrAttr("version"); if (string.IsNullOrEmpty(Version)) this.Version = "1.0.0"; this.Master = element.StrAttr("master"); this.IsActivity = element.BoolAttr(ACTIVITY); var ns = element.GetDefaultNamespace(); var defaultLocale = element.StrAttr(DEFAULT_LOCALE); var targetLocale = locale.Equals(defaultLocale, StringComparison.OrdinalIgnoreCase) ? "" : locale; var title = element.ElementWithLocale(ns + TITLE, targetLocale); var desc = element.ElementWithLocale(ns + DESC, targetLocale); this.Locale = targetLocale; if (string.IsNullOrEmpty(targetLocale)) { if (string.IsNullOrEmpty(this.Locale)) this.Locale = "en-US"; string baseType = element.StrAttr(BASE); if (string.IsNullOrEmpty(baseType)) { this.BaseType = element.StrAttr(NAME); } else { this.Name = element.StrAttr(NAME); this.BaseType = element.StrAttr(BASE); } } if (title == null) title = element.ElementWithLocale(ns + TITLE, ""); if (desc == null) desc = element.ElementWithLocale(ns + DESC, ""); if (title != null) this.Title = title.Value; if (desc != null) this.Description = desc.Value; var factory = new DNA.Web.Contents.ContentFieldFactory(); var fields = element.Elements(ns + FIELDS) .Elements(ns + FIELD) .Select(f => { var field = factory.Create(f, targetLocale); field.Parent = this; return field; }); var fieldElements = new XElement(FIELDS, new XAttribute("xmlns", DefaultNamespace), fields.Select(f => f.Element())); this.FieldsXml = fieldElements.OuterXml(); //this.FieldsXml = element.Element(ns + FIELDS).OuterXml(); //Views var viewElements = element.Descendants(ns + "view"); this.Views = new List<ContentView>(); foreach (var viewEle in viewElements) { var v = new ContentView() { Parent = this }; v.Load(viewEle, targetLocale); this.Views.Add(v); } //Forms this.Forms = new List<ContentForm>(); var formElements = element.Descendants(ns + "form"); this.Forms = new List<ContentForm>(); foreach (var formEle in formElements) { var f = new ContentForm() { Parent = this }; f.Load(formEle, targetLocale); this.Forms.Add(f); } //Items this.Items = new List<ContentDataItem>(); var itemEles = element.Descendants(ns + "row"); this.Items = new List<ContentDataItem>(); foreach (var row in itemEles) { var r = new ContentDataItem() { Parent = this, Locale = this.Locale }; r.Load(row); this.Items.Add(r); } }