Exemple #1
0
        private string MakeAbsolute(string templateHtmlFile)
        {
            if (templateHtmlFile == null)
            {
                return(null);
            }

            if (!Path.IsPathRooted(templateHtmlFile))
            {
                templateHtmlFile = Path.Combine(BlogEditingTemplate.GetBlogTemplateDir(_blogId), templateHtmlFile);
            }
            return(templateHtmlFile);
        }
Exemple #2
0
        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);
            }
        }
        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);
                }
            }
        }