internal static void UpdateMapImage(ISmartContent content, MapSettings settings, Size newSize)
        {
            if (settings.MapImageInvalidated)
            {
                settings.MapImageInvalidated = false;
                float           latitude   = settings.Latitude;
                float           longitude  = settings.Longitude;
                string          reserved   = settings.Reserved;
                int             zoomLevel  = settings.ZoomLevel;
                string          style      = settings.MapStyle;
                string          sceneId    = settings.BirdseyeSceneId;
                VEBirdseyeScene scene      = sceneId != null ? new VEBirdseyeScene(sceneId, settings.BirdseyeOrientation) : null;
                string          previewUrl = MapUrlHelper.CreateMapUrl(LocalMapPreviewUrl, latitude, longitude, reserved, style, zoomLevel, settings.Pushpins, scene);

#pragma warning disable 612,618
                HtmlScreenCapture screenCapture = new HtmlScreenCapture(new Uri(previewUrl, true), newSize.Width);
#pragma warning restore 612,618

                screenCapture.HtmlDocumentAvailable += new OpenLiveWriter.Api.HtmlDocumentAvailableHandler(screenCapture_HtmlDocumentAvailable);
                screenCapture.MaximumHeight          = newSize.Height;
                Bitmap bitmap = screenCapture.CaptureHtml(45000);
                if (bitmap != null)
                {
                    try
                    {
                        if (content.Files.Contains(settings.ImageFileId))
                        {
                            content.Files.Remove(settings.ImageFileId);
                        }
                    }
                    catch (Exception e) { Debug.Fail(e.ToString()); }

                    //add the new map image (note that we use a new name to a bug in IE7 that prevents the editor
                    //from refreshing the image displayed in the browser (bug 287563)
                    string newGuid        = Guid.NewGuid().ToString();
                    string newImageFileId = "map-" + newGuid.Substring(newGuid.LastIndexOf("-", StringComparison.OrdinalIgnoreCase) + 1) + ".jpg";
                    settings.ImageFileId = newImageFileId;
                    content.Files.AddImage(settings.ImageFileId, bitmap, ImageFormat.Jpeg);
                }
                else
                {
                    Debug.WriteLine("Map image could not be regenerated.");
                }
            }
        }
Ejemplo n.º 2
0
        public Bitmap GetVideoSnapshot(VideoProvider provider, string embedHtml, Size videoSize)
        {
            try
            {
                string videoHtml = GenerateEmbedHtml(embedHtml, videoSize);
                if (provider != null && provider.UseBackgroundColor != String.Empty)
                {
                    videoHtml = String.Format(CultureInfo.InvariantCulture, "<div style=\"background-color:{0};\">{1}</div>", provider.UseBackgroundColor, videoHtml);
                }
                HtmlScreenCapture htmlScreenCapture = new HtmlScreenCapture(videoHtml, videoSize.Width);

                if (provider != null && provider.RectangleTest != null)
                {
                    rectTest = provider.RectangleTest;
                    htmlScreenCapture.HtmlScreenCaptureAvailable += new HtmlScreenCaptureAvailableHandler(htmlScreenCapture_HtmlScreenCaptureAvailable_RectangleTest);
                }
                else if (provider != null && provider.SnapshotLoadedOrigColor != Color.Empty)
                {
                    testColor = provider.SnapshotLoadedOrigColor;
                    testPct = provider.SnapshotLoadedColorPct;
                    htmlScreenCapture.HtmlScreenCaptureAvailable +=new HtmlScreenCaptureAvailableHandler(htmlScreenCapture_HtmlScreenCaptureAvailable_ColorTest);
                }
                else
                {
                    testBitmap = null;
                    htmlScreenCapture.HtmlScreenCaptureAvailable +=new HtmlScreenCaptureAvailableHandler(htmlScreenCapture_HtmlScreenCaptureAvailable_ChangeTest);
                }

                htmlScreenCapture.MaximumHeight = videoSize.Height;
                //we set our own limit to ensure a snapshot is always getting returned
                SetTimeout(DEFAULT_TIMEOUT_MS);
                Bitmap videoSnapshot = htmlScreenCapture.CaptureHtml(2 * DEFAULT_TIMEOUT_MS);

                // return the video
                return videoSnapshot ;
            }
            catch(Exception ex)
            {
                Trace.WriteLine(ex.ToString());
                throw new VideoPluginException(Res.Get(StringId.Plugin_Video_Snapshot_Error_Title), String.Format(Res.Get(StringId.Plugin_Video_Snapshot_Error_Message), ex.Message)) ;
            }
        }
        internal static void UpdateMapImage(ISmartContent content, MapSettings settings, Size newSize)
        {
            if (settings.MapImageInvalidated)
            {
                settings.MapImageInvalidated = false;
                float latitude = settings.Latitude;
                float longitude = settings.Longitude;
                string reserved = settings.Reserved;
                int zoomLevel = settings.ZoomLevel;
                string style = settings.MapStyle;
                string sceneId = settings.BirdseyeSceneId;
                VEBirdseyeScene scene = sceneId != null ? new VEBirdseyeScene(sceneId, settings.BirdseyeOrientation) : null;
                string previewUrl = MapUrlHelper.CreateMapUrl(LocalMapPreviewUrl, latitude, longitude, reserved, style, zoomLevel, settings.Pushpins, scene);

#pragma warning disable 612, 618
                HtmlScreenCapture screenCapture = new HtmlScreenCapture(new Uri(previewUrl, true), newSize.Width);
#pragma warning restore 612, 618

                screenCapture.HtmlDocumentAvailable += new OpenLiveWriter.Api.HtmlDocumentAvailableHandler(screenCapture_HtmlDocumentAvailable);
                screenCapture.MaximumHeight = newSize.Height;
                Bitmap bitmap = screenCapture.CaptureHtml(45000);
                if (bitmap != null)
                {
                    try
                    {
                        if (content.Files.Contains(settings.ImageFileId))
                            content.Files.Remove(settings.ImageFileId);
                    }
                    catch (Exception e) { Debug.Fail(e.ToString()); }

                    //add the new map image (note that we use a new name to a bug in IE7 that prevents the editor
                    //from refreshing the image displayed in the browser (bug 287563)
                    string newGuid = Guid.NewGuid().ToString();
                    string newImageFileId = "map-" + newGuid.Substring(newGuid.LastIndexOf("-", StringComparison.OrdinalIgnoreCase) + 1) + ".jpg";
                    settings.ImageFileId = newImageFileId;
                    content.Files.AddImage(settings.ImageFileId, bitmap, ImageFormat.Jpeg);
                }
                else
                {
                    Debug.WriteLine("Map image could not be regenerated.");
                }
            }
        }