Ejemplo n.º 1
0
 public void AddDownload(DownloadContent download)
 {
     if (download != null && !string.IsNullOrEmpty(download.GetString()))
     {
         Script script = new Script();
         script.Body = download.GetString();
         script.Name = UrlHelper.FileName(this.DownloadTask.RelativeUrl);
         this.Manager.SiteDb.Routes.AddOrUpdate(this.DownloadTask.RelativeUrl, script, this.Manager.UserId);
         this.Manager.SiteDb.Scripts.AddOrUpdate(script, this.Manager.UserId);
     }
 }
Ejemplo n.º 2
0
        public void AddDownload(DownloadContent down)
        {
            var sitedb = this.Manager.SiteDb;

            string csstext = down.GetString();

            if (!String.IsNullOrEmpty(csstext))
            {
                Style style = new Style();
                style.Name = UrlHelper.FileName(this.DownloadTask.RelativeUrl);
                CssManager.ProcessResource(ref csstext, this.DownloadTask.AbsoluteUrl, this.Manager, this.DownloadTask.OwnerObjectId);
                style.Body = csstext;
                sitedb.Routes.AddOrUpdate(this.DownloadTask.RelativeUrl, style, this.Manager.UserId);
                sitedb.Styles.AddOrUpdate(style, this.Manager.UserId);
            }
        }
Ejemplo n.º 3
0
        public static SiteObject AddDownload(DownloadManager manager, DownloadContent download, string absoluteUrl, bool DefaultStartPage, bool AnalyzePage, string originalimporturl = "")
        {
            var sitedb = manager.SiteDb;

            bool issamehost = UrlHelper.isSameHost(originalimporturl, absoluteUrl);

            string relativeurl = UrlHelper.RelativePath(absoluteUrl, issamehost);

            byte consttype = 0;

            var FileType = Kooboo.Lib.Helper.UrlHelper.GetFileType(relativeurl, download.ContentType);

            switch (FileType)
            {
            case UrlHelper.UrlFileType.Image:
            {
                consttype = ConstObjectType.Image;
            }
            break;

            case UrlHelper.UrlFileType.JavaScript:
            {
                consttype = ConstObjectType.Script;
            }
            break;

            case UrlHelper.UrlFileType.Style:
            {
                consttype = ConstObjectType.Style;
            }
            break;

            case UrlHelper.UrlFileType.File:
            {
                consttype = ConstObjectType.File;
            }
            break;

            default:
            {
                string htmlsource = download.GetString();

                if (string.IsNullOrEmpty(htmlsource) || Kooboo.HtmlUtility.HasHtmlOrBodyTag(htmlsource))
                {
                    consttype = ConstObjectType.Page;
                }
                else
                {
                    consttype = ConstObjectType.View;
                }
            }
            break;
            }

            switch (consttype)
            {
            case ConstObjectType.Page:
            {
                Page page = new Page();
                page.IsStatic     = true;
                page.DefaultStart = DefaultStartPage;

                page.Name = Service.PageService.GetPageNameFromUrl(relativeurl);

                string htmlsource = UrlHelper.ReplaceMetaCharSet(download.GetString());

                if (AnalyzePage)
                {
                    var context = AnalyzerManager.Execute(htmlsource, absoluteUrl, page.Id, page.ConstType, manager, originalimporturl);
                    htmlsource = context.HtmlSource;
                }
                page.Body = htmlsource;

                if (page.Name == "untitled")
                {
                    var titleel = Service.DomService.GetTitleElement(page.Dom);
                    if (titleel != null)
                    {
                        string title = titleel.InnerHtml;
                        if (!string.IsNullOrEmpty(title))
                        {
                            title     = Lib.Helper.StringHelper.SementicSubString(title, 0, 30);
                            page.Name = title.Trim();
                        }
                    }
                }

                sitedb.Routes.AddOrUpdate(relativeurl, page, manager.UserId);
                sitedb.Pages.AddOrUpdate(page, manager.UserId);

                return(page);
            }

            case ConstObjectType.Style:
            {
                string csstext = download.GetString();
                if (AnalyzePage)
                {
                    CssManager.ProcessResource(ref csstext, absoluteUrl, manager, default(Guid));
                }
                var style = new Style();
                style.Body = csstext;
                sitedb.Routes.AddOrUpdate(relativeurl, style, manager.UserId);
                sitedb.Styles.AddOrUpdate(style, manager.UserId);
                return(style);
            }

            case ConstObjectType.Script:
            {
                Script script = new Script {
                    ConstType = ConstObjectType.Script, Body = download.GetString()
                };

                sitedb.Routes.AddOrUpdate(relativeurl, script, manager.UserId);
                sitedb.Scripts.AddOrUpdate(script, manager.UserId);
                return(script);
            }

            case ConstObjectType.Image:
            {
                Image koobooimage = new Image
                {
                    ContentBytes = download.DataBytes,
                    Extension    = UrlHelper.FileExtension(relativeurl),
                    Name         = UrlHelper.FileName(relativeurl),
                };


                sitedb.Routes.AddOrUpdate(relativeurl, koobooimage, manager.UserId);
                sitedb.Images.AddOrUpdate(koobooimage, manager.UserId);
                return(koobooimage);
            }

            case ConstObjectType.View:
            {
                var view = new View();

                string name = System.IO.Path.GetFileNameWithoutExtension(absoluteUrl);
                if (string.IsNullOrEmpty(name))
                {
                    name = "untitlted";
                }
                view.Name = name;

                string htmlsource = UrlHelper.ReplaceMetaCharSet(download.GetString());
                if (AnalyzePage)
                {
                    var context = AnalyzerManager.Execute(htmlsource, absoluteUrl, view.Id, view.ConstType, manager, originalimporturl);
                    htmlsource = context.HtmlSource;
                }

                view.Body = htmlsource;

                sitedb.Routes.AddOrUpdate(relativeurl, view, manager.UserId);
                sitedb.Views.AddOrUpdate(view, manager.UserId);
                return(view);
            }

            default:
            {
                /// default treat it as file.
                var kooboofile = new CmsFile
                {
                    ContentType   = download.ContentType,
                    ContentBytes  = download.DataBytes,
                    ContentString = download.ContentString,
                    Extension     = UrlHelper.FileExtension(relativeurl),
                    Name          = UrlHelper.FileName(relativeurl)
                };
                sitedb.Routes.AddOrUpdate(relativeurl, kooboofile, manager.UserId);
                sitedb.Files.AddOrUpdate(kooboofile, manager.UserId);
                return(kooboofile);
            }
            }
        }