/// <summary>
        /// Previews the specified resource
        /// </summary>
        /// <param name="res">The resource to be previewed</param>
        /// <param name="edSvc">The editor service</param>
        /// <param name="locale">The locale to use if launching a viewer-based preview</param>
        public void Preview(IResource res, IEditorService edSvc, string locale)
        {
            //TODO: Prompt for symbol parameters if there are any, as these can affect the rendered output
            //and it is a nice way to test symbol parameters wrt to rendering

            IServerConnection conn   = edSvc.CurrentConnection;
            BusyWaitDelegate  worker = () =>
            {
                //Save the current resource to another session copy
                string resId = "Session:" + edSvc.SessionID + "//" + res.ResourceType.ToString() + "Preview" + Guid.NewGuid() + "." + res.ResourceType.ToString(); //NOXLATE

                var resSvc = edSvc.CurrentConnection.ResourceService;
                resSvc.SaveResourceAs(res, resId);
                resSvc.CopyResource(res.ResourceID, resId, true);
                var previewCopy = resSvc.GetResource(resId);

                if (previewCopy.ResourceType == ResourceTypes.SymbolDefinition.ToString() && conn.SiteVersion >= new Version(2, 0))
                {
                    return(GenerateSymbolDefinitionPreview(conn, previewCopy, 100, 100));
                }
                else
                {
                    //Now feed it to the preview engine
                    var url = new ResourcePreviewEngine(edSvc).GeneratePreviewUrl(previewCopy, locale);
                    return(new UrlPreviewResult()
                    {
                        Url = url
                    });
                }
            };
            Action <object, Exception> onComplete = (result, ex) =>
            {
                if (ex != null)
                {
                    ErrorDialog.Show(ex);
                }
                else
                {
                    var urlResult = result as UrlPreviewResult;
                    var imgResult = result as ImagePreviewResult;
                    if (urlResult != null)
                    {
                        var url = urlResult.Url;
                        _launcher.OpenUrl(url);
                    }
                    else if (imgResult != null)
                    {
                        new SymbolPreviewDialog(imgResult.ImagePreview).Show(null);
                    }
                }
            };

            BusyWaitDialog.Run(Strings.PrgPreparingResourcePreview, worker, onComplete);
        }
        /// <summary>
        /// Previews the specified resource
        /// </summary>
        /// <param name="res">The resource to be previewed</param>
        /// <param name="edSvc">The editor service</param>
        public void Preview(IResource res, IEditorService edSvc, string locale)
        {
            //TODO: Prompt for symbol parameters if there are any, as these can affect the rendered output
            //and it is a nice way to test symbol parameters wrt to rendering

            IServerConnection conn = res.CurrentConnection;
            BusyWaitDelegate worker = () =>
            {
                string mapguideRootUrl = (string)conn.GetCustomProperty("BaseUrl"); //NOXLATE
                //Save the current resource to another session copy
                string resId = "Session:" + edSvc.SessionID + "//" + res.ResourceType.ToString() + "Preview" + Guid.NewGuid() + "." + res.ResourceType.ToString(); //NOXLATE

                edSvc.ResourceService.SaveResourceAs(res, resId);
                edSvc.ResourceService.CopyResource(res.ResourceID, resId, true);
                var previewCopy = edSvc.ResourceService.GetResource(resId);

                if (previewCopy.ResourceType == ResourceTypes.SymbolDefinition && conn.SiteVersion >= new Version(2, 0))
                {
                    //For Symbol Definition previews, we make a placeholder Layer Definition with the
                    ILayerDefinition layerDef = ObjectFactory.CreateDefaultLayer(conn, LayerType.Vector);
                    IVectorLayerDefinition2 vl = layerDef.SubLayer as IVectorLayerDefinition2;
                    if (vl != null)
                    {
                        //HACK-ish: We are flubbing a completely invalid Layer Definition under normal circumstances,
                        //but one that has the minimum required content model to generate an appropriate GETLEGENDIMAGE preview for
                        vl.FeatureName = string.Empty;
                        vl.ResourceId = string.Empty;
                        vl.Geometry = string.Empty;
                        vl.ToolTip = string.Empty;
                        var vsr = vl.GetScaleRangeAt(0) as IVectorScaleRange2;
                        if (vsr != null)
                        {
                            vsr.AreaStyle = null;
                            vsr.LineStyle = null;
                            vsr.PointStyle = null;
                            var cs = layerDef.CreateDefaultCompositeStyle();
                            var cr = cs.GetRuleAt(0);
                            var csym = cr.CompositeSymbolization;
                            var si = csym.CreateSymbolReference(previewCopy.ResourceID);
                            csym.AddSymbolInstance(si);
                            vsr.CompositeStyle = new List<ICompositeTypeStyle>() { cs };

                            var ldfId = "Session:" + edSvc.SessionID + "//" + res.ResourceType.ToString() + "Preview" + Guid.NewGuid() + ".LayerDefinition"; //NOXLATE
                            edSvc.ResourceService.SaveResourceAs(layerDef, ldfId);

                            var mappingSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);
                            var img = mappingSvc.GetLegendImage(42, ldfId, 0, 4, 100, 100, "PNG"); //NOXLATE
                            return new ImagePreviewResult() { ImagePreview = img };
                        }
                    }

                    return null;
                }
                else
                {
                    //Now feed it to the preview engine
                    var url = new ResourcePreviewEngine(mapguideRootUrl, edSvc).GeneratePreviewUrl(previewCopy, locale);
                    return new UrlPreviewResult() { Url = url };
                }
            };
            Action<object, Exception> onComplete = (result, ex) =>
            {
                if (ex != null)
                {
                    ErrorDialog.Show(ex);
                }
                else
                {
                    var urlResult = result as UrlPreviewResult;
                    var imgResult = result as ImagePreviewResult;
                    if (urlResult != null)
                    {
                        var url = urlResult.Url;
                        _launcher.OpenUrl(url);
                    }
                    else if (imgResult != null)
                    {
                        new SymbolPreviewDialog(imgResult.ImagePreview).Show(null);
                    }
                }
            };
            BusyWaitDialog.Run(Strings.PrgPreparingResourcePreview, worker, onComplete);
        }
Beispiel #3
0
        /// <summary>
        /// Previews the given resource
        /// </summary>
        /// <param name="res"></param>
        /// <param name="edSvc"></param>
        /// <param name="locale"></param>
        public void Preview(IResource res, IEditorService edSvc, string locale)
        {
            IServerConnection conn = edSvc.CurrentConnection;

            if (this.UseLocal && IsLocalPreviewableType(res) && SupportsMappingService(conn))
            {
                BusyWaitDelegate worker = () =>
                {
                    IMappingService mapSvc     = (IMappingService)conn.GetService((int)ServiceType.Mapping);
                    IMapDefinition  previewMdf = null;
                    switch (res.ResourceType)
                    {
                    case "LayerDefinition":
                    {
                        ILayerDefinition ldf       = (ILayerDefinition)res;
                        string           layerName = string.Empty;
                        if (edSvc.IsNew)
                        {
                            layerName = ResourceIdentifier.GetName(ldf.SubLayer.ResourceId);
                        }
                        else
                        {
                            layerName = ResourceIdentifier.GetName(edSvc.ResourceID);
                        }
                        previewMdf = ResourcePreviewEngine.CreateLayerPreviewMapDefinition(ldf, edSvc.SessionID, layerName, conn);
                    }
                    break;

                    case "WatermarkDefinition":
                    {
                        previewMdf = Utility.CreateWatermarkPreviewMapDefinition((IWatermarkDefinition)res);
                    }
                    break;

                    case "MapDefinition":
                    {
                        previewMdf = (IMapDefinition)res;
                    }
                    break;
                    }

                    if (string.IsNullOrEmpty(previewMdf.ResourceID))
                    {
                        var sessionId = edSvc.SessionID;
                        var mdfId     = "Session:" + sessionId + "//" + Guid.NewGuid() + ".MapDefinition"; //NOXLATE

                        conn.ResourceService.SaveResourceAs(previewMdf, mdfId);
                        previewMdf.ResourceID = mdfId;
                    }

                    if (previewMdf != null)
                    {
                        return(mapSvc.CreateMap(previewMdf, false));
                    }
                    else
                    {
                        return(null);
                    }
                };
                Action <object, Exception> onComplete = (obj, ex) =>
                {
                    if (ex != null)
                    {
                        throw ex;
                    }

                    if (obj != null)
                    {
                        var rtMap = (RuntimeMap)obj;
                        if (_viewManager != null)
                        {
                            _viewManager.OpenContent(ViewRegion.Document, () => new MapPreviewViewContent(rtMap, _launcher, (edSvc.IsNew) ? null : edSvc.ResourceID));
                        }
                        else
                        {
                            var diag = new MapPreviewDialog(rtMap, _launcher, (edSvc.IsNew) ? null : edSvc.ResourceID);
                            diag.Show(null);
                        }
                    }
                    else //Fallback, shouldn't happen
                    {
                        _inner.Preview(res, edSvc, locale);
                    }
                };
                BusyWaitDialog.Run(Strings.PrgPreparingResourcePreview, worker, onComplete);
            }
            else
            {
                _inner.Preview(res, edSvc, locale);
            }
        }