예제 #1
0
        /// <summary>
        /// Initialize template and default data
        /// </summary>
        public virtual void Initialize(DbContext ezContext)
        {
            var context = ezContext as EzCMSEntities;

            if (context != null)
            {
                // If do not defined setup configuration or empty default template then do nothing
                if (GetSetup() == null || string.IsNullOrEmpty(GetSetup().DefaultTemplate))
                {
                    return;
                }

                var template = new WidgetTemplate
                {
                    Name              = GetSetup().DefaultTemplate,
                    DataType          = GetSetup().Type.AssemblyQualifiedName,
                    Widget            = GetSetup().Widget,
                    Widgets           = DataInitializeHelper.GetTemplateWidgets(GetSetup()),
                    Content           = DataInitializeHelper.GetTemplateContent(GetSetup()),
                    Script            = DataInitializeHelper.GetTemplateScript(GetSetup()),
                    Style             = DataInitializeHelper.GetTemplateStyle(GetSetup()),
                    FullContent       = DataInitializeHelper.GetTemplateFullContent(GetSetup()),
                    IsDefaultTemplate = true
                };
                context.WidgetTemplates.AddIfNotExist(i => i.Name, template);
            }
        }
예제 #2
0
        /// <summary>
        /// Get template manage model from name
        /// </summary>
        /// <param name="widget"></param>
        /// <param name="templateId"></param>
        /// <returns></returns>
        public WidgetTemplateManageModel GetTemplateManageModel(string widget, int?templateId)
        {
            var template = GetById(templateId);

            if (template != null)
            {
                return(new WidgetTemplateManageModel(template)
                {
                    Id = 0,
                    IsDefaultTemplate = false,
                    Name = string.Empty
                });
            }

            var setup =
                WorkContext.Widgets.FirstOrDefault(
                    c => c.Widget.Equals(widget, StringComparison.CurrentCultureIgnoreCase));

            if (setup != null)
            {
                var model = new WidgetTemplateManageModel
                {
                    DataType          = setup.Type.AssemblyQualifiedName,
                    Widget            = widget,
                    IsDefaultTemplate = false
                };

                try
                {
                    if (!string.IsNullOrEmpty(setup.DefaultTemplate))
                    {
                        model.Content   = DataInitializeHelper.GetTemplateContent(setup);
                        model.Script    = DataInitializeHelper.GetTemplateScript(setup);
                        model.Style     = DataInitializeHelper.GetTemplateStyle(setup);
                        model.Shortcuts =
                            SerializeUtilities.Deserialize <List <Shortcut> >(
                                DataInitializeHelper.GetTemplateWidgets(setup));
                        model.FullContent = DataInitializeHelper.GetTemplateFullContent(setup);
                    }
                }
                catch
                {
                    //The default template may not existed in current dll
                    // Or maybe it come from plugins
                    // So we will get the default template
                    var defaultTemplate = GetTemplate(setup.DefaultTemplate);
                    if (defaultTemplate != null)
                    {
                        model = new WidgetTemplateManageModel(defaultTemplate)
                        {
                            Id = 0,
                            IsDefaultTemplate = false,
                            Name = string.Empty
                        };
                    }
                }

                return(model);
            }

            return(null);
        }