public static string GetPreviewBitmapPath(string blogId, string elementId) { string blogTemplateDir = BlogEditingTemplate.GetBlogTemplateDir(blogId); string previewBitmapFilename = elementId.Replace(PreviewGuid, ".bmp"); return(Path.Combine(blogTemplateDir, previewBitmapFilename)); }
public string GetEditorTemplateHtml(BlogEditingTemplateType templateType, bool forceRTL) { SettingsPersisterHelper templates = _editorTemplateSettings.GetSubSettings(EDITOR_TEMPLATES_KEY); string templateHtmlFile = templates.GetString(templateType.ToString(), null); // Sometimes templateHtmlFile is relative, sometimes it is already absolute (from older builds). templateHtmlFile = MakeAbsolute(templateHtmlFile); if (templateHtmlFile != null && File.Exists(templateHtmlFile)) { string templateHtml; using (StreamReader reader = new StreamReader(templateHtmlFile, Encoding.UTF8)) templateHtml = reader.ReadToEnd(); if (File.Exists(templateHtmlFile + ".path")) { string origPath = File.ReadAllText(templateHtmlFile + ".path"); string newPath = Path.Combine(Path.GetDirectoryName(templateHtmlFile), Path.GetFileName(origPath)); string newUri = UrlHelper.SafeToAbsoluteUri(new Uri(newPath)); templateHtml = templateHtml.Replace(origPath, newUri); } return(templateHtml); } else { return(BlogEditingTemplate.GetDefaultTemplateHtml(forceRTL, templateType != BlogEditingTemplateType.Normal)); } }
private string MakeAbsolute(string templateHtmlFile) { if (templateHtmlFile == null) { return(null); } if (!Path.IsPathRooted(templateHtmlFile)) { templateHtmlFile = Path.Combine(BlogEditingTemplate.GetBlogTemplateDir(_blogId), templateHtmlFile); } return(templateHtmlFile); }
/// <summary> /// Loads the blog editing template. /// </summary> /// <param name="blogId"></param> /// <returns></returns> internal static string LoadBlogTemplate(string blogId, BlogEditingTemplateType templateType, bool forceRTL) { using (PostHtmlEditingSettings templateSettings = new PostHtmlEditingSettings(blogId)) { string html = templateSettings.GetEditorTemplateHtml(templateType, forceRTL); if (html == null || html == String.Empty || html.IndexOf(BlogEditingTemplate.POST_TITLE_MARKER) == -1 || html.IndexOf(BlogEditingTemplate.POST_BODY_MARKER) == -1) { html = BlogEditingTemplate.GetDefaultTemplateHtml(forceRTL, true); } return(html); } }
public string GetEditorTemplateHtml(BlogEditingTemplateType templateType, bool forceRTL) { SettingsPersisterHelper templates = _editorTemplateSettings.GetSubSettings(EDITOR_TEMPLATES_KEY); string templateHtmlFile = templates.GetString(templateType.ToString(), null); // Sometimes templateHtmlFile is relative, sometimes it is already absolute (from older builds). templateHtmlFile = MakeAbsolute(templateHtmlFile); if (templateHtmlFile != null && File.Exists(templateHtmlFile)) { string templateHtml; using (StreamReader reader = new StreamReader(templateHtmlFile, Encoding.UTF8)) templateHtml = reader.ReadToEnd(); if (File.Exists(templateHtmlFile + ".path")) { string origPath = File.ReadAllText(templateHtmlFile + ".path"); string newPath = Path.Combine(Path.GetDirectoryName(templateHtmlFile), Path.GetFileName(origPath)); string newUri = UrlHelper.SafeToAbsoluteUri(new Uri(newPath)); templateHtml = templateHtml.Replace(origPath, newUri); } /*Parse meta tags in order to set CSS3 compatibility*/ Regex metatag = new Regex(@"<(?i:meta)(\s)+(?i:http-equiv)(\s)*=""(?:X-UA-Compatible)""(\s)+(?i:content)(\s)*=""(?i:IE=edge)""(\s)*/>"); Match match = metatag.Match(templateHtml); if (!match.Success) { // prepend the metatag to make css3 compatible at least on edge (Windows 8+) int i = templateHtml.IndexOf("<HEAD>", StringComparison.OrdinalIgnoreCase); if (i > 0) { templateHtml = (templateHtml.Substring(0, i + 6) + "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />" + templateHtml.Substring(i + 6)); } } return(templateHtml); } else { return(BlogEditingTemplate.GetDefaultTemplateHtml(forceRTL, templateType != BlogEditingTemplateType.Normal)); } }
private string MakeRelative(string templateHtmlFile) { if (templateHtmlFile == null) { return(null); } if (!Path.IsPathRooted(templateHtmlFile)) { return(templateHtmlFile); } string filename = Path.GetFileName(templateHtmlFile); if (File.Exists(Path.Combine(BlogEditingTemplate.GetBlogTemplateDir(_blogId), filename))) { return(filename); } else { Trace.Fail("Failed to make relative path: " + templateHtmlFile); return(templateHtmlFile); } }
public void LoadHtmlFragment(string title, string postBodyHtml, string baseUrl, BlogEditingTemplate editingTemplate) { const int SPACE_BETWEEN_TITLE_AND_BODY = 4; if (editingTemplate.ContainsTitle) { // Make sure the title textbox is showing if there is a title. textBoxTitle.Visible = true; panelSourceEditor.Top = textBoxTitle.Bottom + SPACE_BETWEEN_TITLE_AND_BODY; panelSourceEditor.Height = Height - panelSourceEditor.Top; textBoxTitle.Text = title; } else { // We need to hide the title textbox if there is no title. textBoxTitle.Visible = false; panelSourceEditor.Top = textBoxTitle.Top; panelSourceEditor.Height = Height - panelSourceEditor.Top; } //make the post body HTML look pretty postBodyHtml = ApplyPostBodyFormatting(postBodyHtml); sourceControl.LoadHtmlFragment(postBodyHtml); sourceControl.Focus(); }
public string GetEditorTemplateHtml(BlogEditingTemplateType templateType, bool forceRTL) { SettingsPersisterHelper templates = _editorTemplateSettings.GetSubSettings(EDITOR_TEMPLATES_KEY); string templateHtmlFile = templates.GetString(templateType.ToString(), null); // Sometimes templateHtmlFile is relative, sometimes it is already absolute (from older builds). templateHtmlFile = MakeAbsolute(templateHtmlFile); if (templateHtmlFile != null && File.Exists(templateHtmlFile)) { string templateHtml; using (StreamReader reader = new StreamReader(templateHtmlFile, Encoding.UTF8)) templateHtml = reader.ReadToEnd(); if (File.Exists(templateHtmlFile + ".path")) { string origPath = File.ReadAllText(templateHtmlFile + ".path"); string newPath = Path.Combine(Path.GetDirectoryName(templateHtmlFile), Path.GetFileName(origPath)); string newUri = UrlHelper.SafeToAbsoluteUri(new Uri(newPath)); templateHtml = templateHtml.Replace(origPath, newUri); } /* Parse meta tags in order to set MSHTML emulation for IE9 * As of Internet Explorer 10, support for element behaviors have been removed. * Core OLW functionality, such as table management, currently rely on these mechanisms. * An alternative to Element Behaviors must be found before we can push the IE version forward to allow for newer web standards. */ // Search for an existing X-UA-Compatible tag in the template Regex metatag = new Regex(@"<(?i:meta)(?:\s)+(?i:http-equiv)(?:\s)*=""(?:X-UA-Compatible)""(?:\s)+(?i:content)(?:\s)*=""(\S*)""(?:\s)*/>"); Match match = metatag.Match(templateHtml); if (match.Success && match.Groups.Count > 1) { // There already exists a 'X-UA-Compatible' meta tag in the template, modify it // Grab info on the existing 'content' value var contentVal = match.Groups[1]; // Remove the content value from the template var templateContentRemoved = templateHtml.Remove(contentVal.Index, contentVal.Length); // Add the IE9 emulation string into the HTML template templateHtml = templateContentRemoved.Insert(contentVal.Index, UA_COMPATIBLE_STRING); } else { // Prepend meta tag for IE9 emulation int i = templateHtml.IndexOf("<HEAD>", StringComparison.OrdinalIgnoreCase); if (i > 0) { templateHtml = (templateHtml.Substring(0, i + 6) + $"<meta http-equiv=\"X-UA-Compatible\" content=\"{UA_COMPATIBLE_STRING}\" />" + templateHtml.Substring(i + 6)); } } return(templateHtml); } else { return(BlogEditingTemplate.GetDefaultTemplateHtml(forceRTL, templateType != BlogEditingTemplateType.Normal)); } }
private void screenCapture_HtmlScreenCaptureAvailable(object sender, HtmlScreenCaptureAvailableEventArgsCore e) { if (e.CaptureCompleted && e.Bitmap != null) { // Ensure that the path exists try { // Problem because this check is pumping messages on bg thread? string directory = BlogEditingTemplate.GetBlogTemplateDir(_blogId); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } } catch (Exception ex) { Trace.Fail(ex.ToString()); return; } // Now we should have all of the element images foreach (string elementId in _screenCapture.Ids) { using (Bitmap elementBitmap = _screenCapture.GetElementCaptureProperties(elementId).Bitmap) { // Warning. elementBitmap may be null. string path = SemanticHtmlPreviewManager.GetPreviewBitmapPath(_blogId, elementId); try { // We take the lock here to ensure that we don't try to read a halfway-written file on the UI thread. lock (_previewLock) { ElementCaptureProperties properties = _screenCapture.GetElementCaptureProperties(elementId); using (Bitmap previewBitmap = GetGalleryPreviewImageFromElementImage(elementBitmap, _previewImageWidth, _previewImageHeight, properties.BackgroundColor, properties.Padding, _isRtl)) { previewBitmap.Save(path); } } } catch (Exception ex) { Trace.WriteLine("Failed to get preview image for blog(" + _blogId + ") and element(" + elementId + "): " + ex); try { File.Delete(path); } catch (Exception ex2) { Trace.WriteLine("Failed to delete preview image after failing to get it:" + ex2); } return; } } } try { _editingSite.FrameWindow.Invoke(new ThreadStart(() => _editingSite.CommandManager.Invalidate( CommandId.SemanticHtmlGallery)), null); } catch (Exception ex) { Trace.WriteLine("NotifyWeblogStylePreviewChanged failed: " + ex.Message); } } }