Esempio n. 1
0
 public void Remove(ScriptFile item)
 {
     if (item.Exists())
     {
         item.Delete();
     }
 }
        /// <summary>
        /// The script file url o fsite
        /// </summary>
        /// <param name="frontUrlHelper">The front url helper</param>
        /// <param name="site">The site</param>
        /// <param name="baseUri">Base uri</param>
        /// <param name="relativeScriptFilePath">The relative script file path of site</param>
        /// <returns></returns>
        public static IHtmlString ScriptFileUrl(this FrontUrlHelper frontUrlHelper, Site site, string baseUri, string relativeScriptFilePath, bool forceSSL = false)
        {
            string resourceDomain = site.ResourceDomain.FormatUrlWithProtocol(forceSSL);

            bool scriptFileExists = false;
            string scriptFileUrl = String.Empty;
            string scriptFilePhysicalPath = String.Empty;

            do
            {
                site = site.AsActual();

                ScriptFile scriptFile = new ScriptFile(site, String.Empty);
                if (scriptFile != null)
                {
                    scriptFileUrl = UrlUtility.Combine(scriptFile.VirtualPath, relativeScriptFilePath);

                    scriptFilePhysicalPath = HttpContext.Current.Server.MapPath(scriptFileUrl);
                    scriptFileExists = File.Exists(scriptFilePhysicalPath);
                }

                site = site.Parent;
            } while (site != null && !scriptFileExists);

            if (!String.IsNullOrEmpty(resourceDomain))
            {
                baseUri = resourceDomain; // CDN have high priority
            }
            return new HtmlString(UrlUtility.ToHttpAbsolute(baseUri, scriptFileUrl));
        }
Esempio n. 3
0
        public void TestVirtualPath()
        {
            var site = new Site("Site1");
            var scriptFile = new ScriptFile(site, "script1.js");

            string expected1 = Kooboo.Web.Url.UrlUtility.Combine(site.VirtualPath, "scripts", "script1.js");

            Assert.AreEqual(expected1, scriptFile.VirtualPath, true);
        }
Esempio n. 4
0
        public void TestPhysicalPath()
        {
            var site = new Site("Site1");
            var scriptFile = new ScriptFile(site, "script1.js");

            string expected1 = Path.Combine(site.PhysicalPath, "scripts", "script1.js");

            Assert.AreEqual(expected1, scriptFile.PhysicalPath, true);
        }
Esempio n. 5
0
        public void TestParseFromPhysicalPath()
        {
            string siteName = "site1";
            string fileName = "script1";
            string extension = ".js";
            string physicalPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sites", siteName, "scripts", fileName + extension);

            var scriptFile = new ScriptFile(physicalPath);

            Assert.AreEqual(fileName, scriptFile.Name);
            Assert.AreEqual(extension, scriptFile.FileExtension);

            Assert.IsTrue(scriptFile.Site.IsDummy);
            Assert.AreEqual(siteName, scriptFile.Site.Name);
        }
Esempio n. 6
0
        /// <summary>
        /// Get the file url under "Scripts" folder.
        /// </summary>
        /// <param name="relativeScriptFilePath">The relative file path.</param>
        /// <param name="withCDNResolving">if set to <c>true</c> [with CDN resolving].</param>
        /// <returns></returns>
        public virtual IHtmlString ScriptFileUrl(string relativeScriptFilePath, bool withCDNResolving)
        {
            Site site = this.Site;
            var dir = Path.GetDirectoryName(relativeScriptFilePath);
            var fileVirtualPath = "";

            if (string.IsNullOrEmpty(dir))
            {
                fileVirtualPath = new ScriptFile(site, relativeScriptFilePath).VirtualPath;
            }
            else
            {
                do
                {
                    var scriptsPath = new ScriptFile(site, "");
                    fileVirtualPath = UrlUtility.Combine(scriptsPath.VirtualPath, relativeScriptFilePath);
                    var physicalPath = UrlUtility.MapPath(fileVirtualPath);
                    if (File.Exists(physicalPath))
                    {
                        break;
                    }
                    else
                    {
                        site = site.Parent;
                    }
                } while (site != null);
            }
            if (withCDNResolving)
            {
                return ResourceCDNUrl(fileVirtualPath);
            }
            else
            {
                return new HtmlString(Url.Content(fileVirtualPath));
            }
        }
Esempio n. 7
0
 protected void Save(ScriptFile item)
 {
     item.Save();
 }
Esempio n. 8
0
 public void Update(ScriptFile @new, ScriptFile old)
 {
     Save(@new);
 }
Esempio n. 9
0
 public void Localize(ScriptFile file, Site targetSite)
 {
     var targetFile = new ScriptFile(targetSite, file.FileName);
     targetFile.Body = file.Read();
     targetFile.Save();
 }
Esempio n. 10
0
 public ScriptFile Get(ScriptFile dummy)
 {
     throw new NotImplementedException();
 }
Esempio n. 11
0
 public void Add(ScriptFile item)
 {
     Save(item);
 }