public LayoutEntity Create(LayoutEntity layout)
        {
            var result = _context.Add(layout);

            _context.SaveChanges();
            return(result.Entity);
        }
        public LayoutEntity Update(LayoutEntity layoutEntity)
        {
            var result = _context.Update(layoutEntity);

            _context.SaveChanges();
            return(result.Entity);
        }
Ejemplo n.º 3
0
 public static void TrySetLayout(this HttpContext httpContext, LayoutEntity layout)
 {
     if (!httpContext.Items.ContainsKey(StringKeys.LayoutItem))
     {
         httpContext.Items.Add(StringKeys.LayoutItem, layout);
     }
 }
 public static Layout ToContract(this LayoutEntity entity)
 {
     return(new Layout
     {
         Name = entity.Name,
         Rows = entity.Rows.ToContracts().ToList(),
     });
 }
Ejemplo n.º 5
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            Zones = new ZoneWidgetCollection();
            //Page
            var page = GetPage(filterContext);

            if (page != null)
            {
                var          cache         = new StaticCache();
                var          layoutService = ServiceLocator.Current.GetInstance <ILayoutService>();
                LayoutEntity layout        = layoutService.Get(page.LayoutId);
                layout.Page = page;
                Action <WidgetBase> processWidget = m =>
                {
                    IWidgetPartDriver partDriver = cache.Get("IWidgetPartDriver_" + m.AssemblyName + m.ServiceTypeName, source =>
                                                             Activator.CreateInstance(m.AssemblyName, m.ServiceTypeName).Unwrap() as IWidgetPartDriver
                                                             );
                    WidgetPart part = partDriver.Display(partDriver.GetWidget(m), filterContext.HttpContext);
                    lock (Zones)
                    {
                        if (Zones.ContainsKey(part.Widget.ZoneID))
                        {
                            Zones[part.Widget.ZoneID].Add(part);
                        }
                        else
                        {
                            var partCollection = new WidgetCollection {
                                part
                            };
                            Zones.Add(part.Widget.ZoneID, partCollection);
                        }
                    }
                };
                var widgetService = ServiceLocator.Current.GetInstance <IWidgetService>();
                IEnumerable <WidgetBase> widgets = widgetService.GetAllByPageId(page.ID);
                var parallel = from widget in widgets.AsParallel() select widget;
                parallel.ForAll(processWidget);

                layout.ZoneWidgets = Zones;
                var viewResult = (filterContext.Result as ViewResult);
                if (viewResult != null)
                {
                    string layoutView = GetLayout();
                    if (layoutView.IsNotNullAndWhiteSpace())
                    {
                        viewResult.MasterName = layoutView;
                    }
                    viewResult.ViewData[LayoutEntity.LayoutKey] = layout;
                }
            }
            else
            {
                filterContext.Result = new HttpStatusCodeResult(404);
            }
        }
Ejemplo n.º 6
0
        public int InsertLayoutDetails(LayoutEntity ObjLayoutEntity, char Operation)
        {
            Hashtable ht = new Hashtable();

            ht.Add("@LayoutID", ObjLayoutEntity.LayoutID);
            ht.Add("@LogoImage", ObjLayoutEntity.LogoImage);
            ht.Add("@PhoneNumber", ObjLayoutEntity.PhoneNumber);
            ht.Add("@EmailID", ObjLayoutEntity.EmailID);
            ht.Add("@Operation", Operation);
            return(objUtilities.ExecuteNonQuery("InsertLayoutDetails", ht));
        }
Ejemplo n.º 7
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //Page
            var page = GetPage(filterContext);

            if (page != null)
            {
                LayoutEntity layout = ServiceLocator.Current.GetInstance <ILayoutService>().Get(page.LayoutId);
                layout.Page  = page;
                page.Favicon = ServiceLocator.Current.GetInstance <IApplicationSettingService>().Get(SettingKeys.Favicon, "~/favicon.ico");
                if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated && page.IsPublishedPage)
                {
                    layout.PreViewPage = PageService.GetByPath(page.Url, true);
                }
                layout.CurrentTheme = ServiceLocator.Current.GetInstance <IThemeService>().GetCurrentTheme();
                layout.ZoneWidgets  = new ZoneWidgetCollection();
                filterContext.HttpContext.TrySetLayout(layout);
                var widgetService = ServiceLocator.Current.GetInstance <IWidgetService>();
                widgetService.GetAllByPage(page).Each(widget =>
                {
                    IWidgetPartDriver partDriver = widget.CreateServiceInstance();
                    WidgetPart part = partDriver.Display(widget, filterContext.HttpContext);
                    lock (layout.ZoneWidgets)
                    {
                        if (layout.ZoneWidgets.ContainsKey(part.Widget.ZoneID))
                        {
                            layout.ZoneWidgets[part.Widget.ZoneID].TryAdd(part);
                        }
                        else
                        {
                            layout.ZoneWidgets.Add(part.Widget.ZoneID, new WidgetCollection {
                                part
                            });
                        }
                    }
                });
                var viewResult = (filterContext.Result as ViewResult);
                if (viewResult != null)
                {
                    viewResult.MasterName = GetLayout();
                    filterContext.Controller.ViewData.Model = layout;
                }
                if (page.IsPublishedPage)
                {
                    ServiceLocator.Current.GetAllInstances <IOnPageExecuted>().Each(m => m.OnExecuted(page, HttpContext.Current));
                }
            }
            else
            {
                filterContext.Result = new RedirectResult("~/error/notfond");
            }
        }
Ejemplo n.º 8
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            ZoneWidgetCollection zones = new ZoneWidgetCollection();

            //Page
            string       pageId      = filterContext.RequestContext.HttpContext.Request.QueryString["ID"];
            PageService  pageService = new PageService();
            PageEntity   page        = pageService.Get(pageId);
            LayoutEntity layout      = null;

            if (page != null)
            {
                LayoutService layoutService = new LayoutService();
                layout      = layoutService.Get(page.LayoutId);
                layout.Page = page;
                WidgetService            widgetService = new WidgetService();
                IEnumerable <WidgetBase> widgets       = widgetService.Get(new DataFilter().Where <WidgetBase>(m => m.PageID, OperatorType.Equal, page.ID));
                Action <WidgetBase>      processWidget = m =>
                {
                    IWidgetPartDriver partDriver = Activator.CreateInstance(m.AssemblyName, m.ServiceTypeName).Unwrap() as IWidgetPartDriver;
                    WidgetPart        part       = partDriver.Display(partDriver.GetWidget(m), filterContext.HttpContext);
                    if (zones.ContainsKey(part.Widget.ZoneID))
                    {
                        zones[part.Widget.ZoneID].Add(part);
                    }
                    else
                    {
                        WidgetCollection partCollection = new WidgetCollection();
                        partCollection.Add(part);
                        zones.Add(part.Widget.ZoneID, partCollection);
                    }
                };
                widgets.Each(processWidget);

                IEnumerable <WidgetBase> Layoutwidgets = widgetService.Get(new Data.DataFilter().Where <WidgetBase>(m => m.LayoutID, OperatorType.Equal, page.LayoutId));

                Layoutwidgets.Each(processWidget);

                layout.ZoneWidgets = zones;
                ViewResult viewResult = (filterContext.Result as ViewResult);
                if (viewResult != null)
                {
                    viewResult.MasterName = "~/Modules/Common/Views/Shared/_DesignPageLayout.cshtml";
                }
                viewResult.ViewData[LayoutEntity.LayoutKey] = layout;
            }
            else
            {
                filterContext.Result = new HttpStatusCodeResult(404);
            }
        }
Ejemplo n.º 9
0
        private LayoutEntity CreateLayout(string themeName)
        {
            LayoutEntity layoutEntity = _layoutService.Get(m => m.Title == themeName).FirstOrDefault();

            if (layoutEntity == null)
            {
                layoutEntity = new LayoutEntity
                {
                    Title      = themeName,
                    LayoutName = themeName
                };
                layoutEntity.Zones = new ZoneCollection();
                layoutEntity.Html  = new LayoutHtmlCollection();
                string[] zoneNames = new string[] { "Header", "Content", "Footer" };
                for (int i = 0; i < zoneNames.Length; i++)
                {
                    ZoneEntity zone = new ZoneEntity
                    {
                        ZoneName    = zoneNames[i],
                        HeadingCode = $"ZONE-{i}"
                    };
                    layoutEntity.Zones.Add(zone);
                    layoutEntity.Html.Add(new LayoutHtml
                    {
                        Html = "<div class=\"main custom-style container-fluid\"><div class=\"additional row\"><div class=\"additional col-md-12\"><div class=\"colContent row\"><div class=\"additional zone\">"
                    });
                    layoutEntity.Html.Add(new LayoutHtml {
                        Html = ZoneEntity.ZoneTag
                    });
                    layoutEntity.Html.Add(new LayoutHtml {
                        Html = zone.HeadingCode
                    });
                    layoutEntity.Html.Add(new LayoutHtml {
                        Html = ZoneEntity.ZoneEndTag
                    });
                    layoutEntity.Html.Add(new LayoutHtml {
                        Html = "</div></div></div></div></div>"
                    });
                }
                _layoutService.Add(layoutEntity);
            }
            return(layoutEntity);
        }
Ejemplo n.º 10
0
        public override void SetData(XtraReport report, string url)
        {
            // Stores the specified report to a Report Storage using the specified URL.
            // This method is called only after the IsValidUrl and CanSetData methods are called.
            var          Layout = new LayoutEntity();
            MemoryStream output = new MemoryStream();

            report.SaveLayoutToXml(output);
            Layout.ds_conteudo = ByteArrayParaString(output.ToArray());
            var layoutService = (ILayoutService)services[DictionaryServices.LAYOUT_SERVICE_KEY];
            int idConvertido;

            if (Int32.TryParse(url, out idConvertido))
            {
                Layout.cd_codigo = idConvertido;
                layoutService.Update(Layout);
            }
            else
            {
                Layout.ds_nome = url;
                layoutService.Insert(Layout);
            }
        }
Ejemplo n.º 11
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //Page
            var page = GetPage(filterContext);

            if (page != null)
            {
                var          requestServices           = filterContext.HttpContext.RequestServices;
                var          onPageExecuteds           = requestServices.GetServices <IOnPageExecuted>();
                var          layoutService             = requestServices.GetService <ILayoutService>();
                var          widgetService             = requestServices.GetService <IWidgetBasePartService>();
                var          applicationSettingService = requestServices.GetService <IApplicationSettingService>();
                var          themeService    = requestServices.GetService <IThemeService>();
                var          widgetActivator = requestServices.GetService <IWidgetActivator>();
                LayoutEntity layout          = layoutService.Get(page.LayoutId);
                layout.Page  = page;
                page.Favicon = applicationSettingService.Get(SettingKeys.Favicon, "~/favicon.ico");
                if (filterContext.HttpContext.User.Identity.IsAuthenticated && page.IsPublishedPage)
                {
                    layout.PreViewPage = requestServices.GetService <IPageService>().Get(page.ReferencePageID);
                }
                layout.CurrentTheme = themeService.GetCurrentTheme();
                layout.ZoneWidgets  = new ZoneWidgetCollection();
                filterContext.HttpContext.TrySetLayout(layout);
                widgetService.GetAllByPage(page, GetPageViewMode() == PageViewMode.Publish && !IsPreView(filterContext)).Each(widget =>
                {
                    if (widget != null)
                    {
                        IWidgetPartDriver partDriver = widgetActivator.Create(widget);
                        WidgetViewModelPart part     = partDriver.Display(widget, filterContext);
                        lock (layout.ZoneWidgets)
                        {
                            if (layout.ZoneWidgets.ContainsKey(part.Widget.ZoneID))
                            {
                                layout.ZoneWidgets[part.Widget.ZoneID].TryAdd(part);
                            }
                            else
                            {
                                layout.ZoneWidgets.Add(part.Widget.ZoneID, new WidgetCollection {
                                    part
                                });
                            }
                        }
                        partDriver.Dispose();
                    }
                });
                var viewResult = (filterContext.Result as ViewResult);
                if (viewResult != null)
                {
                    layout.Layout = GetLayout();
                    if (GetPageViewMode() == PageViewMode.Design)
                    {
                        layout.Templates = widgetService.Get(m => m.IsTemplate == true);
                    }
                    (filterContext.Controller as Controller).ViewData.Model = layout;
                }
                if (page.IsPublishedPage && onPageExecuteds != null)
                {
                    onPageExecuteds.Each(m => m.OnExecuted(page, filterContext.HttpContext));
                }

                layoutService.Dispose();
                applicationSettingService.Dispose();
                widgetService.Dispose();
                themeService.Dispose();
            }
            else
            {
                if (!(filterContext.Result is RedirectResult))
                {
                    filterContext.Result = new RedirectResult("~/error/notfond?f=" + filterContext.HttpContext.Request.Path);
                }
            }
        }
Ejemplo n.º 12
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var zones = new ZoneWidgetCollection();
            var cache = new StaticCache();
            //Page
            string path = filterContext.RequestContext.HttpContext.Request.Path;

            if (path.EndsWith("/") && path.Length > 1)
            {
                path = path.Substring(0, path.Length - 1);
                //filterContext.HttpContext.Response.Redirect(path);
                filterContext.Result = new RedirectResult(path);
                return;
            }
            bool publish = !ReView.Review.Equals(filterContext.RequestContext.HttpContext.Request.QueryString[ReView.QueryKey], StringComparison.CurrentCultureIgnoreCase);
            var  page    = new PageService().GetByPath(path, publish);

            if (page != null)
            {
                var          layoutService = new LayoutService();
                LayoutEntity layout        = layoutService.Get(page.LayoutId);
                layout.Page = page;

                Action <WidgetBase> processWidget = m =>
                {
                    IWidgetPartDriver partDriver = cache.Get("IWidgetPartDriver_" + m.AssemblyName + m.ServiceTypeName, source =>
                                                             Activator.CreateInstance(m.AssemblyName, m.ServiceTypeName).Unwrap() as IWidgetPartDriver
                                                             );
                    WidgetPart part = partDriver.Display(partDriver.GetWidget(m), filterContext.HttpContext);
                    lock (zones)
                    {
                        if (zones.ContainsKey(part.Widget.ZoneID))
                        {
                            zones[part.Widget.ZoneID].Add(part);
                        }
                        else
                        {
                            var partCollection = new WidgetCollection {
                                part
                            };
                            zones.Add(part.Widget.ZoneID, partCollection);
                        }
                    }
                };
                var layoutWidgetsTask = Task.Factory.StartNew(layoutId =>
                {
                    var widgetServiceIn = new WidgetService();
                    IEnumerable <WidgetBase> layoutwidgets = widgetServiceIn.Get(new DataFilter().Where("LayoutID", OperatorType.Equal, layoutId));
                    layoutwidgets.Each(processWidget);
                }, page.LayoutId);


                var widgetService = new WidgetService();
                IEnumerable <WidgetBase> widgets = widgetService.Get(new DataFilter().Where("PageID", OperatorType.Equal, page.ID));
                int middle          = widgets.Count() / 2;
                var pageWidgetsTask = Task.Factory.StartNew(() => widgets.Skip(middle).Each(processWidget));
                widgets.Take(middle).Each(processWidget);
                Task.WaitAll(new[] { pageWidgetsTask, layoutWidgetsTask });

                layout.ZoneWidgets = zones;
                var viewResult = (filterContext.Result as ViewResult);
                if (viewResult != null)
                {
                    //viewResult.MasterName = "~/Modules/Easy.Web.CMS.Page/Views/Shared/_Layout.cshtml";
                    viewResult.ViewData[LayoutEntity.LayoutKey] = layout;
                }
            }
            else
            {
                filterContext.Result = new HttpStatusCodeResult(404);
            }
        }
        private void ProcessLayoutElements(LayoutEntity current)
        {
            do
            {
                LayoutEntity child = current.AddChildEntity(mEnumerator);

                if (mEnumerator.MoveFirstChild())
                {
                    current = child;

                    ProcessLayoutElements(current);
                    mEnumerator.MoveParent();

                    current = current.Parent;
                }
            } while (mEnumerator.MoveNext());
        }
Ejemplo n.º 14
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //Page
            var page = GetPage(filterContext);

            if (page != null)
            {
                var requestServices           = filterContext.HttpContext.RequestServices;
                var onPageExecuteds           = requestServices.GetServices <IOnPageExecuted>();
                var layoutService             = requestServices.GetService <ILayoutService>();
                var widgetService             = requestServices.GetService <IWidgetBasePartService>();
                var applicationSettingService = requestServices.GetService <IApplicationSettingService>();
                var themeService    = requestServices.GetService <IThemeService>();
                var widgetActivator = requestServices.GetService <IWidgetActivator>();
                var ruleService     = requestServices.GetService <IRuleService>();

                LayoutEntity layout = layoutService.GetByPage(page);
                layout.Page  = page;
                page.Favicon = applicationSettingService.Get(SettingKeys.Favicon, "~/favicon.ico");
                if (filterContext.HttpContext.User.Identity.IsAuthenticated && page.IsPublishedPage)
                {
                    layout.PreViewPage = requestServices.GetService <IPageService>().Get(page.ReferencePageID);
                }
                layout.CurrentTheme = themeService.GetCurrentTheme();
                layout.ZoneWidgets  = new ZoneWidgetCollection();
                filterContext.HttpContext.TrySetLayout(layout);
                widgetService.GetAllByPage(page).Each(widget =>
                {
                    if (widget != null)
                    {
                        IWidgetPartDriver partDriver = widgetActivator.Create(widget);
                        WidgetViewModelPart part     = partDriver.Display(widget, filterContext);
                        if (part != null)
                        {
                            if (layout.ZoneWidgets.ContainsKey(part.Widget.ZoneID ?? UnknownZone))
                            {
                                layout.ZoneWidgets[part.Widget.ZoneID ?? UnknownZone].TryAdd(part);
                            }
                            else
                            {
                                layout.ZoneWidgets.Add(part.Widget.ZoneID ?? UnknownZone, new WidgetCollection {
                                    part
                                });
                            }
                        }
                        partDriver.Dispose();
                    }
                });
                var ruleWorkContext = new RuleWorkContext
                {
                    Url         = filterContext.HttpContext.Request.Path.Value,
                    QueryString = filterContext.HttpContext.Request.QueryString.ToString(),
                    UserAgent   = filterContext.HttpContext.Request.Headers["User-Agent"]
                };
                var rules   = ruleService.GetMatchRule(ruleWorkContext);
                var rulesID = rules.Select(m => m.RuleID).ToArray();
                if (rules.Any())
                {
                    widgetService.GetAllByRule(rulesID, !IsPreView(filterContext)).Each(widget =>
                    {
                        if (widget != null)
                        {
                            IWidgetPartDriver partDriver = widgetActivator.Create(widget);
                            WidgetViewModelPart part     = partDriver.Display(widget, filterContext);
                            var zone = layout.Zones.FirstOrDefault(z => z.ZoneName == rules.First(m => m.RuleID == widget.RuleID).ZoneName);
                            if (part != null && zone != null)
                            {
                                part.Widget.ZoneID = zone.HeadingCode;
                                if (layout.ZoneWidgets.ContainsKey(part.Widget.ZoneID ?? UnknownZone))
                                {
                                    layout.ZoneWidgets[part.Widget.ZoneID ?? UnknownZone].TryAdd(part);
                                }
                                else
                                {
                                    layout.ZoneWidgets.Add(part.Widget.ZoneID ?? UnknownZone, new WidgetCollection {
                                        part
                                    });
                                }
                            }
                            partDriver.Dispose();
                        }
                    });
                }
                var viewResult = (filterContext.Result as ViewResult);
                if (viewResult != null)
                {
                    layout.Layout = GetLayout();
                    if (GetPageViewMode() == PageViewMode.Design)
                    {
                        layout.Templates = widgetService.Get(m => m.IsTemplate == true);
                    }
                    (filterContext.Controller as Controller).ViewData.Model = layout;
                }
                if (page.IsPublishedPage && onPageExecuteds != null)
                {
                    onPageExecuteds.Each(m => m.OnExecuted(page, filterContext.HttpContext));
                }

                layoutService.Dispose();
                applicationSettingService.Dispose();
                widgetService.Dispose();
                themeService.Dispose();
            }
            else
            {
                if (!(filterContext.Result is RedirectResult))
                {
                    var viewResult = filterContext.Result as ViewResult;
                    if (viewResult != null)
                    {
                        viewResult.StatusCode = 404;
                        viewResult.ViewName   = "NotFound";
                    }
                    else
                    {
                        filterContext.Result = new RedirectResult("~/error/notfond?f=" + filterContext.HttpContext.Request.Path);
                    }
                }
            }
        }
Ejemplo n.º 15
0
 public async Task <LayoutEntity> Post(LayoutEntity layout)
 {
     return(await _repository.InsertAsync(layout));
 }
Ejemplo n.º 16
0
        public ThemeEntity Import(string zipFile)
        {
            string themeName = null;
            List <PositionEntry> cssFiles  = new List <PositionEntry>();
            List <HtmlDocument>  documents = new List <HtmlDocument>();

            #region Decompression
            using (ZipArchive archive = ZipFile.OpenRead(zipFile))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.FullName.StartsWith("__MACOSX/"))
                    {
                        continue;
                    }
                    if (themeName.IsNotNullAndWhiteSpace() && !entry.FullName.StartsWith(themeName))
                    {
                        new DirectoryInfo(Path.Combine(ThemeBasePath, themeName)).Delete(true);
                        throw new Exception("The package is not correct!");
                    }

                    if (entry.Length == 0 && entry.Name == string.Empty && entry.FullName.EndsWith('/'))
                    {
                        if (themeName == null)
                        {
                            themeName = entry.FullName.TrimEnd('/');
                        }

                        DirectoryInfo dir = new DirectoryInfo(Path.Combine(ThemeBasePath, entry.FullName));
                        if (dir.Exists)
                        {
                            dir.Delete(true);
                        }
                        dir.Create();
                        continue;
                    }
                    if (themeName == null)
                    {
                        return(null);
                    }

                    string extractFilePath = Path.Combine(ThemeBasePath, entry.FullName);

                    if (entry.FullName.EndsWith(".html"))
                    {
                        if (entry.FullName.IndexOf('/') != entry.FullName.LastIndexOf('/'))
                        {
                            continue;
                        }
                        HtmlDocument doc = new HtmlDocument();
                        doc.PageName = Path.GetFileName(entry.FullName).Replace(".html", string.Empty);
                        doc.Load(entry.Open());
                        documents.Add(doc);
                    }
                    else
                    {
                        entry.ExtractToFile(extractFilePath, true);
                    }
                }
            }
            #endregion

            LayoutEntity layout = CreateLayout(themeName);

            #region Create Page
            int index = 1;
            foreach (var document in documents)
            {
                var page = _pageService.GetByPath($"/{document.PageName}", true);
                if (page != null)
                {
                    _pageService.Remove(page);
                }
                string title     = document.PageName;
                var    titleNode = document.DocumentNode.SelectSingleNode("/html/head/title");
                if (titleNode != null && titleNode.InnerText.IsNotNullAndWhiteSpace())
                {
                    title = titleNode.InnerText.Trim();
                }
                page = new PageEntity
                {
                    Title    = title,
                    PageName = title,
                    ParentId = "#",
                    LayoutId = layout.ID,
                    Url      = $"~/{document.PageName}".ToLower(),
                    Status   = (int)Easy.Constant.RecordStatus.Active
                };
                if (document.PageName.Equals("index", StringComparison.OrdinalIgnoreCase))
                {
                    page.DisplayOrder = 1;
                }
                else
                {
                    page.DisplayOrder = ++index;
                }
                var addPageResult = _pageService.Add(page);
                if (addPageResult.HasViolation)
                {
                    throw new Exception(addPageResult.ErrorMessage);
                }
                #region Collect css
                var cssLinks = document.DocumentNode.SelectNodes("//link[@rel='stylesheet']");
                if (cssLinks != null)
                {
                    for (int i = 0; i < cssLinks.Count; i++)
                    {
                        string href = cssLinks[i].GetAttributeValue("href", string.Empty);

                        if (href == string.Empty)
                        {
                            continue;
                        }
                        if (!isOutSidePath(href))
                        {
                            href = ConvertToThemePath(themeName, href);
                        }
                        if (!cssFiles.Any(m => m.Entry == href))
                        {
                            foreach (var item in cssFiles)
                            {
                                if (item.Position >= i)
                                {
                                    item.Position++;
                                }
                            }
                            cssFiles.Add(new PositionEntry
                            {
                                Entry    = href,
                                Position = i
                            });
                        }
                    }
                }

                #endregion

                #region Collect Scripts
                StringBuilder pageScripts = new StringBuilder();
                var           scripts     = document.DocumentNode.SelectNodes("//script");
                if (scripts != null)
                {
                    foreach (var item in scripts)
                    {
                        string path = item.GetAttributeValue("src", string.Empty);
                        if (path.IsNotNullAndWhiteSpace() && !isOutSidePath(path))
                        {
                            item.SetAttributeValue("src", ConvertToThemePath(themeName, path));
                        }
                        string fileName = Path.GetFileName(path);
                        if (!jQueryFilter.IsMatch(fileName) && !BootstrapFilter.IsMatch(fileName))
                        {
                            pageScripts.AppendLine(item.OuterHtml.Trim());
                        }
                        item.Remove();
                    }
                }
                #endregion

                #region Collect Style
                StringBuilder pageStyle   = new StringBuilder();
                var           innerStyles = document.DocumentNode.SelectNodes("//style");
                if (innerStyles != null)
                {
                    foreach (var item in innerStyles)
                    {
                        pageStyle.AppendLine(item.InnerText);
                    }
                }
                #endregion

                #region Url fix
                var links = document.DocumentNode.SelectNodes("//a");
                if (links != null)
                {
                    foreach (var item in links)
                    {
                        string href = item.GetAttributeValue("href", string.Empty);
                        if (href.IsNotNullAndWhiteSpace() && !isOutSidePath(href) && !href.StartsWith('/'))
                        {
                            if (Easy.Image.ImageHelper.IsImage(Path.GetExtension(href)))
                            {
                                item.SetAttributeValue("href", ConvertToThemePath(themeName, href));
                            }
                            else
                            {
                                item.SetAttributeValue("href", $"/{href}");
                            }
                        }
                    }
                }
                var images = document.DocumentNode.SelectNodes("//img");
                if (images != null)
                {
                    foreach (var item in images)
                    {
                        string src = item.GetAttributeValue("src", string.Empty);
                        if (src.IsNotNullAndWhiteSpace() && !isOutSidePath(src))
                        {
                            item.SetAttributeValue("src", ConvertToThemePath(themeName, src));
                        }
                    }
                }
                #endregion

                if (pageStyle.Length > 0)
                {
                    string section = $"<style>{pageStyle.ToString().Trim()}</style>";
                    section = StyleUrl.Replace(section, evaluator =>
                    {
                        return($"url({ConvertToThemePath(themeName, evaluator.Groups[1].Value)})");
                    });
                    var styleWidget = _widgetCreatorManager.Create(section, themeName);
                    styleWidget.PageID     = page.ID;
                    styleWidget.WidgetName = "Style";
                    styleWidget.Position   = 0;
                    styleWidget.ZoneID     = "ZONE-0";
                    styleWidget.StyleClass = "full";
                    _widgetActivator.Create(styleWidget).AddWidget(styleWidget);
                }
                var sections = document.DocumentNode.SelectSingleNode("/html/body").ChildNodes;
                for (int i = 0; i < sections.Count; i++)
                {
                    var node = sections[i];
                    if (node.NodeType == HtmlAgilityPack.HtmlNodeType.Element)
                    {
                        var    tNode       = node.SelectSingleNode(".//h1|.//h2|.//h3|.//h4|.//h5|.//h6");
                        string widgetTitle = tNode?.InnerText;

                        string section = StyleUrl.Replace(node.OuterHtml, evaluator =>
                        {
                            return($"url({ConvertToThemePath(themeName, evaluator.Groups[1].Value)})");
                        });
                        var widget = _widgetCreatorManager.Create(section, themeName);
                        widget.PageID     = page.ID;
                        widget.WidgetName = (widgetTitle ?? "Html Widget").Trim();
                        widget.Position   = i;
                        widget.ZoneID     = "ZONE-1";
                        widget.StyleClass = "full";
                        _widgetActivator.Create(widget).AddWidget(widget);
                    }
                }
                if (pageScripts.Length > 0)
                {
                    var scriptWidget = _widgetCreatorManager.Create(pageScripts.ToString().Trim(), themeName);
                    scriptWidget.PageID     = page.ID;
                    scriptWidget.WidgetName = "JavaScript";
                    scriptWidget.Position   = document.DocumentNode.ChildNodes.Count;
                    scriptWidget.ZoneID     = "ZONE-2";
                    scriptWidget.StyleClass = "full";
                    _widgetActivator.Create(scriptWidget).AddWidget(scriptWidget);
                }
            }
            #endregion
            return(CreateTheme(themeName, cssFiles));
        }
Ejemplo n.º 17
0
 public async Task <LayoutEntity> Put(LayoutEntity layout)
 {
     return(await _repository.UpdateAsync(layout));
 }
Ejemplo n.º 18
0
 public void Update(LayoutEntity layout)
 {
     _repository.Update(layout);
 }
        public void TestToContract()
        {
            var entity = new LayoutEntity {
                Name = "TV1",
                Rows = new List <LayoutRowEntity>
                {
                    new LayoutRowEntity
                    {
                        Ordinal = 1,
                        Cells   = new List <LayoutCellEntity>
                        {
                            new LayoutCellEntity
                            {
                                Ordinal   = 2,
                                CellType  = "Class",
                                ClassName = "D10",
                            },
                            new LayoutCellEntity
                            {
                                Ordinal  = 1,
                                CellType = "Finish",
                            },
                        },
                    },
                    new LayoutRowEntity
                    {
                        Ordinal = 2,
                        Cells   = new List <LayoutCellEntity>
                        {
                            new LayoutCellEntity
                            {
                                Ordinal   = 1,
                                CellType  = "Class",
                                ClassName = "D10",
                            },
                            new LayoutCellEntity
                            {
                                Ordinal   = 2,
                                CellType  = "Class",
                                ClassName = "D12",
                            },
                        },
                    },
                },
            };

            var actual = entity.ToContract();

            Assert.Equal("TV1", actual.Name);
            Assert.Equal(2, actual.Rows.Count);
            Assert.Equal(2, actual.Rows[0].Cells.Count);

            Assert.Equal("Finish", actual.Rows[0].Cells[0].CellType);
            Assert.Null(actual.Rows[0].Cells[0].ClassName);

            Assert.Equal("Class", actual.Rows[0].Cells[1].CellType);
            Assert.Equal("D10", actual.Rows[0].Cells[1].ClassName);

            Assert.Equal(2, actual.Rows[1].Cells.Count);

            Assert.Equal("Class", actual.Rows[1].Cells[0].CellType);
            Assert.Equal("D10", actual.Rows[1].Cells[0].ClassName);

            Assert.Equal("Class", actual.Rows[1].Cells[1].CellType);
            Assert.Equal("D12", actual.Rows[1].Cells[1].ClassName);
        }
Ejemplo n.º 20
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //Page
            var page = GetPage(filterContext);

            if (page != null)
            {
                var requestServices           = filterContext.HttpContext.RequestServices;
                var eventManager              = requestServices.GetService <IEventManager>();
                var layoutService             = requestServices.GetService <ILayoutService>();
                var widgetService             = requestServices.GetService <IWidgetBasePartService>();
                var applicationSettingService = requestServices.GetService <IApplicationSettingService>();
                var themeService              = requestServices.GetService <IThemeService>();
                var widgetActivator           = requestServices.GetService <IWidgetActivator>();
                var ruleService = requestServices.GetService <IRuleService>();
                var logger      = requestServices.GetService <ILogger <WidgetAttribute> >();
                var viewResult  = (filterContext.Result as ViewResult);

                LayoutEntity layout = layoutService.GetByPage(page);
                layout.Page  = page;
                page.Favicon = applicationSettingService.Get(SettingKeys.Favicon, "~/favicon.ico");
                if (filterContext.HttpContext.User.Identity.IsAuthenticated && page.IsPublishedPage)
                {
                    layout.PreViewPage = requestServices.GetService <IPageService>().Get(page.ReferencePageID);
                }
                layout.CurrentTheme = themeService.GetCurrentTheme();
                layout.ZoneWidgets  = new ZoneWidgetCollection();
                widgetService.GetAllByPage(page).Each(widget =>
                {
                    if (widget != null)
                    {
                        DateTime startTime           = DateTime.Now;
                        IWidgetPartDriver partDriver = widgetActivator.Create(widget);
                        object viewModel             = partDriver.Display(new WidgetDisplayContext
                        {
                            PageLayout    = layout,
                            ActionContext = filterContext,
                            Widget        = widget,
                            FormModel     = viewResult?.Model
                        });
                        WidgetViewModelPart part = new WidgetViewModelPart(widget, viewModel);
                        logger.LogInformation("{0}.Display(): {1}ms", widget.ServiceTypeName, (DateTime.Now - startTime).TotalMilliseconds);
                        if (part != null)
                        {
                            if (layout.ZoneWidgets.ContainsKey(part.Widget.ZoneID ?? UnknownZone))
                            {
                                layout.ZoneWidgets[part.Widget.ZoneID ?? UnknownZone].TryAdd(part);
                            }
                            else
                            {
                                layout.ZoneWidgets.Add(part.Widget.ZoneID ?? UnknownZone, new WidgetCollection {
                                    part
                                });
                            }
                        }
                        partDriver.Dispose();
                    }
                });

                var ruleWorkContext = new RuleWorkContext
                {
                    Url         = (filterContext.Controller as Controller).Url.Content(page.Url),
                    QueryString = filterContext.HttpContext.Request.QueryString.ToString(),
                    UserAgent   = filterContext.HttpContext.Request.Headers["User-Agent"]
                };
                var rules   = ruleService.GetMatchRule(ruleWorkContext);
                var ruleDic = rules.ToDictionary(m => m.RuleID, m => m);
                var rulesID = rules.Select(m => m.RuleID).ToArray();
                if (rules.Any())
                {
                    widgetService.GetAllByRule(rulesID, !IsPreView(filterContext)).Each(widget =>
                    {
                        if (widget != null)
                        {
                            DateTime startTime           = DateTime.Now;
                            IWidgetPartDriver partDriver = widgetActivator.Create(widget);
                            object viewModel             = partDriver.Display(new WidgetDisplayContext
                            {
                                PageLayout    = layout,
                                ActionContext = filterContext,
                                Widget        = widget,
                                FormModel     = viewResult?.Model
                            });
                            WidgetViewModelPart part = new WidgetViewModelPart(widget, viewModel);
                            logger.LogInformation("{0}.Display(): {1}ms", widget.ServiceTypeName, (DateTime.Now - startTime).TotalMilliseconds);
                            if (part != null)
                            {
                                var availableZones = layout.Zones.Where(z => ruleDic[widget.RuleID.Value].ZoneNames.Contains(z.ZoneName));
                                foreach (var zone in availableZones)
                                {
                                    part.Widget.SetZone(zone.HeadingCode);
                                    if (layout.ZoneWidgets.ContainsKey(zone.HeadingCode ?? UnknownZone))
                                    {
                                        layout.ZoneWidgets[zone.HeadingCode ?? UnknownZone].TryAdd(part);
                                    }
                                    else
                                    {
                                        layout.ZoneWidgets.Add(zone.HeadingCode ?? UnknownZone, new WidgetCollection {
                                            part
                                        });
                                    }
                                }
                            }
                            partDriver.Dispose();
                        }
                    });
                }

                if (viewResult != null)
                {
                    layout.Layout = GetLayout(filterContext, layout.CurrentTheme);
                    if (GetPageViewMode() == PageViewMode.Design)
                    {
                        layout.Templates = widgetService.Get(m => m.IsTemplate == true);
                    }
                    (filterContext.Controller as Controller).ViewData.Model = layout;
                }
                eventManager.Trigger(Events.OnPageExecuted, layout);

                layoutService.Dispose();
                applicationSettingService.Dispose();
                widgetService.Dispose();
                themeService.Dispose();
            }
            else
            {
                if (!(filterContext.Result is RedirectResult))
                {
                    var viewResult = filterContext.Result as ViewResult;
                    if (viewResult != null)
                    {
                        viewResult.StatusCode = 404;
                        viewResult.ViewName   = "NotFound";
                    }
                    else
                    {
                        filterContext.Result = new RedirectResult("~/error/notfond?f=" + filterContext.HttpContext.Request.Path);
                    }
                }
            }
        }
Ejemplo n.º 21
0
 public void Insert(LayoutEntity layout)
 {
     _repository.Insert(layout);
 }