public virtual bool Reload()
        {
            if (!File.Exists(this.Location))
            {
                return(false);
            }

            this.Contents = () => new StreamReader(VirtualPathProviderHelper.Open(new FileInfo(this.Location).FullName));

            return(true);
        }
        public virtual bool Reload()
        {
            if (!VirtualPathProviderHelper.FileExists(this.Location))
            {
                return(false);
            }

            var file = VirtualPathProviderHelper.GetFile(this.Location);

            this.ContentsReader = () => new StreamReader(VirtualPathProviderHelper.Open(file));

            return(true);
        }
        private Template FindTemplate(string templatePath)
        {
            Template template        = null;
            string   contentTemplate = "";

            if (IsEditableTemplate(templatePath))
            {
                var themeAssetService = new ThemeAssetService();
                contentTemplate = themeAssetService.GetContent(templatePath);
            }
            else
            {
                contentTemplate = VirtualPathProviderHelper.Load(templatePath);
            }
            if (!string.IsNullOrEmpty(contentTemplate))
            {
                template = Template.Parse(contentTemplate);
            }
            if (template == null)
            {
                template = Template.Parse(string.Format("Không tìm thấy template '{0}'", templatePath));
            }
            return(template);
        }
 public FileViewLocationResult(VirtualFile file, string name) : base(file.VirtualPath, name, () => new StreamReader(VirtualPathProviderHelper.Open(file)))
 {
     //_fileHash = VirtualPathProviderHelper.GetFileHash(file.VirtualPath);
     //this._lastModifiedUtc = file.LastWriteTimeUtc;
 }
        private ViewLocationResult FindView(IEnumerable<string> locations, string viewName, string fileNameFormat = "{0}", bool throwException = false)
        {
            var checkedLocations = new List<string>();
            var viewFound = false;
            var context = new HttpContextWrapper(HttpContext.Current);

            var viewNameWithExtension = string.Format(fileNameFormat, viewName);

            ViewLocationResult foundView = null;

            var themeDirectory = ThemeDirectory;
            var cacheKey = string.Format("{0}-{1}", themeDirectory, viewNameWithExtension);

            if (!string.IsNullOrEmpty(themeDirectory))
            {
                // check cache first
                foundView = ViewLocationCache.GetViewLocation(context, cacheKey) as ViewLocationResult;
                if (foundView != null) return foundView;

                foreach (var fullPath in locations.Select(viewLocation => Combine(this._baseDirectoryPath, themeDirectory, viewLocation, viewNameWithExtension)))
                {
                    var file = VirtualPathProviderHelper.GetFile(fullPath);
                    if (file != null)
                    {
                        foundView = new FileViewLocationResult(file, file.VirtualPath);
                        viewFound = true;
                        break;
                    }

                    checkedLocations.Add(fullPath);
                }

                // now search in global location
                // App_Data/Themes/_Global
                if (!viewFound)
                {
                    foreach (var fullPath in
                        locations.Select(
                            viewLocation => Combine(this._baseDirectoryPath, "_global", viewLocation, viewNameWithExtension)))
                    {
                        var file = VirtualPathProviderHelper.GetFile(fullPath);
                        if (file != null)
                        {
                            foundView = new FileViewLocationResult(file, file.VirtualPath);
                            viewFound = true;
                            break;
                        }

                        checkedLocations.Add(Path.Combine(this._baseDirectoryPath, fullPath));
                    }
                }
            }

            if (foundView == null /*!viewFound && throwException*/)
            {
                foundView = new ViewLocationResult(checkedLocations.ToArray());
            }

            ViewLocationCache.InsertViewLocation(context, cacheKey, foundView);

            return foundView;
        }
 public FileViewLocationResult(FileInfo file, string name) : base(file.FullName, name, file.Extension, () => new StreamReader(VirtualPathProviderHelper.Open(file.FullName)))
 {
     this._lastModifiedUtc = file.LastWriteTimeUtc;
 }