예제 #1
0
        ///// <summary>
        ///// Gets/Sets the activity disply template
        ///// </summary>
        //public virtual string ActivityDispTemplate { get; set; }

        /// <summary>
        /// Read the fields from configXml
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerable <ContentField> ReadFields()
        {
            if (string.IsNullOrEmpty(FieldsXml))
            {
                throw new NullReferenceException("ConfigXml");
            }

            var element   = XElement.Parse(FieldsXml);
            var ns        = element.GetDefaultNamespace();
            var fieldEles = element.Elements(ns + FIELD).ToList();

            //if (fieldEles == null || fieldEles.Count() == 0)
            //    throw new Exception("The content list at less has one field defined");

            var factory = new DNA.Web.Contents.ContentFieldFactory();

            return(fieldEles.Select(f => { var field = factory.Create(f); field.Parent = this; return field; }));
        }
예제 #2
0
        public override ContentList Locale(string lang)
        {
            var contentElement = XElement.Parse(ConfigXml);
            var list           = new ContentList();

            list.Load(contentElement, lang);

            if (HasResouces)
            {
                //Use resource file localization
                var ns = contentElement.GetDefaultNamespace();

                //title
                var locTitle = GetString(ns + "title", contentElement, lang);
                if (!string.IsNullOrEmpty(locTitle))
                {
                    list.Title = locTitle;
                }

                //desc
                var locDesc = GetString(ns + "description", contentElement, lang);
                if (!string.IsNullOrEmpty(locDesc))
                {
                    list.Description = locDesc;
                }

                #region fields localization
                var FIELDS  = "fields";
                var factory = new DNA.Web.Contents.ContentFieldFactory();
                var fields  = contentElement.Element(ns + "fields")
                              .Elements()
                              .Select(f =>
                {
                    var field    = factory.Create(f, lang);
                    field.Parent = list;

                    //title
                    var _title = GetString(ns + "title", f, lang);
                    if (!string.IsNullOrEmpty(_title))
                    {
                        field.Title = _title;
                    }

                    //desc
                    var _desc = GetString(ns + "description", f, lang);
                    if (!string.IsNullOrEmpty(_desc))
                    {
                        field.Description = _desc;
                    }

                    //placeholder
                    var _placeholder = GetString(ns + "placeHolder", f, lang);
                    if (!string.IsNullOrEmpty(_placeholder))
                    {
                        field.Placeholder = _placeholder;
                    }

                    return(field);
                });

                var fieldElements = new XElement(FIELDS, new XAttribute("xmlns", DefaultNamespace),
                                                 fields.Select(f => f.Element()));

                list.FieldsXml = fieldElements.OuterXml();

                #endregion

                #region views localization
                var viewElements = contentElement.Descendants(ns + "view");
                foreach (var viewEle in viewElements)
                {
                    var viewName = viewEle.StrAttr("name");
                    var view     = list.Views.FirstOrDefault(v => v.Name.Equals(viewName));
                    if (view != null)
                    {
                        //title
                        var vTitle = GetString(ns + "title", viewEle, lang);
                        if (!string.IsNullOrEmpty(vTitle))
                        {
                            view.Title = vTitle;
                        }

                        //desc
                        var vDesc = GetString(ns + "description", viewEle, lang);
                        if (!string.IsNullOrEmpty(vDesc))
                        {
                            view.Description = vDesc;
                        }
                    }
                }
                #endregion

                #region forms localization
                var formElements = contentElement.Descendants(ns + "form");
                foreach (var formEle in formElements)
                {
                    var formType = (int)((ContentFormTypes)Enum.Parse(typeof(ContentFormTypes), formEle.StrAttr("type")));
                    var form     = list.Forms.FirstOrDefault(f => f.FormType.Equals(formType));
                    if (form != null)
                    {
                        //title
                        var fTitle = GetString(ns + "title", formEle, lang);
                        if (!string.IsNullOrEmpty(fTitle))
                        {
                            form.Title = fTitle;
                        }

                        //desc
                        var fDesc = GetString(ns + "description", formEle, lang);
                        if (!string.IsNullOrEmpty(fDesc))
                        {
                            form.Description = fDesc;
                        }
                    }
                }
                #endregion
            }

            return(list);
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        ///// <summary>
        ///// Gets/Sets the activity disply template
        ///// </summary>
        //public virtual string ActivityDispTemplate { get; set; }
        /// <summary>
        /// Read the fields from configXml
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerable<ContentField> ReadFields()
        {
            if (string.IsNullOrEmpty(FieldsXml))
                throw new NullReferenceException("ConfigXml");

            var element = XElement.Parse(FieldsXml);
            var ns = element.GetDefaultNamespace();
            var fieldEles = element.Elements(ns + FIELD).ToList();

            //if (fieldEles == null || fieldEles.Count() == 0)
            //    throw new Exception("The content list at less has one field defined");

            var factory = new DNA.Web.Contents.ContentFieldFactory();
            return fieldEles.Select(f => { var field = factory.Create(f); field.Parent = this; return field; });
        }
예제 #5
0
        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);
            }
        }