Exemplo n.º 1
0
 private void _htmlScreenCapture_HtmlScreenCaptureAvailable(object sender, HtmlScreenCaptureAvailableEventArgsCore e)
 {
     if (HtmlScreenCaptureAvailable != null)
     {
         HtmlScreenCaptureAvailableEventArgs ea = new HtmlScreenCaptureAvailableEventArgs(e.Bitmap);
         HtmlScreenCaptureAvailable(this, ea);
         e.CaptureCompleted = ea.CaptureCompleted;
     }
 }
        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);
                }
            }
        }