#region Disclaimer / License
// Copyright (C) 2013, Jackie Ng
// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie@gmail.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion Disclaimer / License
using Maestro.Editors.SymbolDefinition;
using Maestro.Shared.UI;
using OSGeo.MapGuide.MaestroAPI;
using OSGeo.MapGuide.MaestroAPI.Services;
using OSGeo.MapGuide.ObjectModels;
using OSGeo.MapGuide.ObjectModels.LayerDefinition;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace Maestro.Editors.Preview
{
///
/// The default resource previewer implementation
///
public class DefaultResourcePreviewer : IResourcePreviewer
{
private IUrlLauncherService _launcher;
///
/// Initializes a new instance of the DefaultResourcePreviewer class
///
///
public DefaultResourcePreviewer(IUrlLauncherService launcher)
{
_launcher = launcher;
}
internal abstract class PreviewResult
{
}
internal class UrlPreviewResult : PreviewResult
{
public string Url { get; set; }
}
internal class ImagePreviewResult : PreviewResult
{
public Image ImagePreview { get; set; }
}
///
/// Previews the specified resource
///
/// The resource to be previewed
/// The editor service
public void Preview(IResource res, IEditorService edSvc)
{
Preview(res, edSvc, edSvc.PreviewLocale);
}
///
/// Previews the specified resource
///
/// The resource to be previewed
/// The editor service
/// The locale to use if launching a viewer-based preview
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