/// <summary>
        /// Returns the html content to be injected into the page for the admin
        /// panel dashboard.
        /// </summary>
        public async Task <IHtmlContent> GetAsync()
        {
            const string CUSTOM_DASHBOARD_CONTENT_PATH = "/Cofoundry/Admin/Dashboard/Dashboard.html";
            const string DEFAULT_CONTENT = "<h2>{0}</h2><p>Welcome to the administration panel.</p> ";

            var    result = _resourceLocator.GetFile(CUSTOM_DASHBOARD_CONTENT_PATH);
            string html;

            if (!result.Exists)
            {
                var settings = await _queryExecutor.ExecuteAsync(new GetSettingsQuery <GeneralSiteSettings>());

                html = string.Format(DEFAULT_CONTENT, settings.ApplicationName);
            }
            else
            {
                using (var stream = result.CreateReadStream())
                    using (var reader = new StreamReader(stream))
                    {
                        html = await reader.ReadToEndAsync();
                    }
            }

            return(new HtmlString(html));
        }
        public string RenderSvgToString()
        {
            var virtualFile = _resourceLocator.GetFile(VisualEditorRouteLibrary.StaticContent.Url("svg-cache.html"));

            using (var stream = virtualFile.Open())
            {
                var reader = new StreamReader(stream);
                return(reader.ReadToEnd());
            }
        }
Esempio n. 3
0
        private async Task <string> RenderSvgIconsToStringAsync()
        {
            var    virtualFile = _resourceLocator.GetFile(_adminRouteLibrary.VisualEditor.StaticResource("svg-cache.html"));
            string result      = null;

            using (var stream = virtualFile.CreateReadStream())
            {
                var reader = new StreamReader(stream);
                result = await reader.ReadToEndAsync();
            }

            return(result);
        }
Esempio n. 4
0
        public string Read(string viewPath)
        {
            if (!_resourceLocator.FileExists(viewPath))
            {
                throw new InvalidOperationException(string.Format("Could not find template {0}", viewPath));
            }

            var    file     = _resourceLocator.GetFile(viewPath);
            string template = null;

            using (var stream = file.Open())
                using (var reader = new StreamReader(stream, Encoding.UTF8))
                {
                    template = reader.ReadToEnd();
                }

            return(template);
        }
Esempio n. 5
0
        /// <summary>
        /// Attempts to read a view file to a string, returning null if the file does not exist.
        /// </summary>
        /// <param name="path">The virtual path to the view file.</param>
        public async Task <string> ReadViewFileAsync(string path)
        {
            string result = null;

            if (!FileExists(path))
            {
                return(result);
            }

            var file = _resourceLocator.GetFile(path);

            if (file == null)
            {
                return(null);
            }

            using (var stream = file.Open())
                using (var reader = new StreamReader(stream))
                {
                    result = await reader.ReadToEndAsync();
                }

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Attempts to read a view file to a string, returning null if the file does not exist.
        /// </summary>
        /// <param name="path">The virtual path to the view file.</param>
        public virtual async Task <string> ReadViewFileAsync(string path)
        {
            string result = null;

            if (!FileExists(path))
            {
                return(result);
            }

            var file = _resourceLocator.GetFile(path);

            if (file == null || !file.Exists || file.IsDirectory)
            {
                return(null);
            }

            using (var stream = file.CreateReadStream())
                using (var reader = new StreamReader(stream))
                {
                    result = await reader.ReadToEndAsync();
                }

            return(result);
        }