Esempio n. 1
0
        /// <summary>
        /// Gets the Json deserialized body for the region.
        /// </summary>
        /// <returns>The body</returns>
        private IExtension GetBody()
        {
            if (RegionTemplate == null)
            {
                using (var db = new DataContext()) {
                    RegionTemplate = db.RegionTemplates.Where(t => t.Id == RegionTemplateId).Single();
                }
            }

            if (!String.IsNullOrEmpty(RegionTemplate.Type))
            {
                var js = new JavaScriptSerializer();

                if (!String.IsNullOrEmpty(InternalBody))
                {
                    if (typeof(HtmlString).IsAssignableFrom(ExtensionManager.Current.GetType(RegionTemplate.Type)))
                    {
                        return(ExtensionManager.Current.CreateInstance(RegionTemplate.Type, InternalBody));
                    }
                    return((IExtension)js.Deserialize(InternalBody, ExtensionManager.Current.GetType(RegionTemplate.Type)));
                }
                return(ExtensionManager.Current.CreateInstance(RegionTemplate.Type));
            }
            return(null);
        }
Esempio n. 2
0
        public override void OnSave(DataContext db, EntityState state)
        {
            if (RegionTemplate == null)
            {
                RegionTemplate = db.RegionTemplates.Where(t => t.Id == RegionTemplateId).Single();
            }

            if (!String.IsNullOrEmpty(RegionTemplate.Type))
            {
                var js = new JavaScriptSerializer();

                if (typeof(HtmlString).IsAssignableFrom(ExtensionManager.Current.GetType(RegionTemplate.Type)))
                {
                    InternalBody = ((HtmlString)Body).ToString();
                }
                else
                {
                    InternalBody = js.Serialize(Body);
                }
            }
            base.OnSave(db, state);
        }
Esempio n. 3
0
        /// <summary>
        /// Updates the internal & external body data.
        /// </summary>
        private void SetBody(IExtension data)
        {
            if (RegionTemplate == null)
            {
                using (var db = new DataContext()) {
                    RegionTemplate = db.RegionTemplates.Where(t => t.Id == RegionTemplateId).Single();
                }
            }

            if (!String.IsNullOrEmpty(RegionTemplate.Type))
            {
                var js = new JavaScriptSerializer();
                body = data;

                if (typeof(HtmlString).IsAssignableFrom(ExtensionManager.Current.GetType(RegionTemplate.Type)))
                {
                    InternalBody = ((HtmlString)data).ToString();
                }
                else
                {
                    InternalBody = js.Serialize(data);
                }
            }
        }