[mapguide-commits] r8456 - in trunk/Tools/Maestro: Maestro.Base/Commands Maestro.Editors/Fusion Maestro.Editors/Preview OSGeo.MapGuide.MaestroAPI/ObjectModels OSGeo.MapGuide.MaestroAPI.Rest
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Thu Nov 20 18:27:41 PST 2014
Author: jng
Date: 2014-11-20 18:27:41 -0800 (Thu, 20 Nov 2014)
New Revision: 8456
Added:
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Rest/RestResourcePreviewUrlGenerator.cs
Modified:
trunk/Tools/Maestro/Maestro.Base/Commands/StartupCommand.cs
trunk/Tools/Maestro/Maestro.Editors/Fusion/FlexLayoutSettingsCtrl.cs
trunk/Tools/Maestro/Maestro.Editors/Fusion/MapSettingsCtrl.cs
trunk/Tools/Maestro/Maestro.Editors/Fusion/WidgetSettingsCtrl.cs
trunk/Tools/Maestro/Maestro.Editors/Preview/DefaultResourcePreviewer.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Rest/OSGeo.MapGuide.MaestroAPI.Rest.csproj
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Rest/RestConnection.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/ApplicationDefinitionInterfaces.cs
Log:
#2506: Add resource preview support
Modified: trunk/Tools/Maestro/Maestro.Base/Commands/StartupCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/StartupCommand.cs 2014-11-21 01:30:19 UTC (rev 8455)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/StartupCommand.cs 2014-11-21 02:27:41 UTC (rev 8456)
@@ -49,6 +49,7 @@
var urlLauncher = ServiceRegistry.GetService<UrlLauncherService>();
ResourcePreviewerFactory.RegisterPreviewer("Maestro.Http", new LocalMapPreviewer(new DefaultResourcePreviewer(urlLauncher), urlLauncher)); //NOXLATE
+ ResourcePreviewerFactory.RegisterPreviewer("Maestro.Rest", new LocalMapPreviewer(new DefaultResourcePreviewer(urlLauncher), urlLauncher)); //NOXLATE
//A stub previewer does nothing, but will use local map previews for applicable resources if the configuration
//property is set
ResourcePreviewerFactory.RegisterPreviewer("Maestro.LocalNative", new LocalMapPreviewer(new StubPreviewer(), urlLauncher)); //NOXLATE
Modified: trunk/Tools/Maestro/Maestro.Editors/Fusion/FlexLayoutSettingsCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Fusion/FlexLayoutSettingsCtrl.cs 2014-11-21 01:30:19 UTC (rev 8455)
+++ trunk/Tools/Maestro/Maestro.Editors/Fusion/FlexLayoutSettingsCtrl.cs 2014-11-21 02:27:41 UTC (rev 8456)
@@ -56,10 +56,13 @@
try
{
_fsvc = (IFusionService)_edsvc.GetService((int)ServiceType.Fusion);
- _baseUrl = service.GetCustomProperty("BaseUrl").ToString(); //NOXLATE
+ if (service.CurrentConnection.ProviderName.ToUpper() == "MAESTRO.HTTP")
+ {
+ _baseUrl = service.GetCustomProperty("BaseUrl").ToString(); //NOXLATE
- if (!_baseUrl.EndsWith("/")) //NOXLATE
- _baseUrl += "/"; //NOXLATE
+ if (!_baseUrl.EndsWith("/")) //NOXLATE
+ _baseUrl += "/"; //NOXLATE
+ }
}
catch
{
Modified: trunk/Tools/Maestro/Maestro.Editors/Fusion/MapSettingsCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Fusion/MapSettingsCtrl.cs 2014-11-21 01:30:19 UTC (rev 8455)
+++ trunk/Tools/Maestro/Maestro.Editors/Fusion/MapSettingsCtrl.cs 2014-11-21 02:27:41 UTC (rev 8456)
@@ -53,10 +53,13 @@
try
{
_fsvc = (IFusionService)service.GetService((int)ServiceType.Fusion);
- _baseUrl = service.GetCustomProperty("BaseUrl").ToString(); //NOXLATE
+ if (service.CurrentConnection.ProviderName.ToUpper() == "MAESTRO.HTTP")
+ {
+ _baseUrl = service.GetCustomProperty("BaseUrl").ToString(); //NOXLATE
- if (!_baseUrl.EndsWith("/")) //NOXLATE
- _baseUrl += "/"; //NOXLATE
+ if (!_baseUrl.EndsWith("/")) //NOXLATE
+ _baseUrl += "/"; //NOXLATE
+ }
}
catch
{
Modified: trunk/Tools/Maestro/Maestro.Editors/Fusion/WidgetSettingsCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Fusion/WidgetSettingsCtrl.cs 2014-11-21 01:30:19 UTC (rev 8455)
+++ trunk/Tools/Maestro/Maestro.Editors/Fusion/WidgetSettingsCtrl.cs 2014-11-21 02:27:41 UTC (rev 8456)
@@ -58,10 +58,13 @@
_edsvc = service;
_fsvc = (IFusionService)_edsvc.GetService((int)ServiceType.Fusion);
_context = new FlexibleLayoutEditorContext(_fsvc);
- _baseUrl = service.GetCustomProperty("BaseUrl").ToString(); //NOXLATE
+ if (service.CurrentConnection.ProviderName.ToUpper() == "MAESTRO.HTTP")
+ {
+ _baseUrl = service.GetCustomProperty("BaseUrl").ToString(); //NOXLATE
- if (!_baseUrl.EndsWith("/")) //NOXLATE
- _baseUrl += "/"; //NOXLATE
+ if (!_baseUrl.EndsWith("/")) //NOXLATE
+ _baseUrl += "/"; //NOXLATE
+ }
}
catch
{
Modified: trunk/Tools/Maestro/Maestro.Editors/Preview/DefaultResourcePreviewer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Preview/DefaultResourcePreviewer.cs 2014-11-21 01:30:19 UTC (rev 8455)
+++ trunk/Tools/Maestro/Maestro.Editors/Preview/DefaultResourcePreviewer.cs 2014-11-21 02:27:41 UTC (rev 8456)
@@ -87,7 +87,6 @@
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
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/ApplicationDefinitionInterfaces.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/ApplicationDefinitionInterfaces.cs 2014-11-21 01:30:19 UTC (rev 8455)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/ObjectModels/ApplicationDefinitionInterfaces.cs 2014-11-21 02:27:41 UTC (rev 8456)
@@ -584,6 +584,18 @@
public static class ExtensionMethods
{
/// <summary>
+ /// Gets the name of the fusion template
+ /// </summary>
+ /// <param name="appDef"></param>
+ /// <returns></returns>
+ public static string GetTemplateName(this IApplicationDefinition appDef)
+ {
+ string[] tokens = appDef.TemplateUrl.Split('/');
+ // fusion/templates/mapguide/{templateName}/index.html
+ return tokens[tokens.Length - 2];
+ }
+
+ /// <summary>
/// Gets whether a widget with the specified name already exists
/// </summary>
/// <param name="appDef"></param>
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Rest/OSGeo.MapGuide.MaestroAPI.Rest.csproj
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Rest/OSGeo.MapGuide.MaestroAPI.Rest.csproj 2014-11-21 01:30:19 UTC (rev 8455)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Rest/OSGeo.MapGuide.MaestroAPI.Rest.csproj 2014-11-21 02:27:41 UTC (rev 8456)
@@ -49,6 +49,7 @@
<Compile Include="RestCoordinateSystemCategory.cs" />
<Compile Include="RestCoordinateSystemDefinition.cs" />
<Compile Include="RestException.cs" />
+ <Compile Include="RestResourcePreviewUrlGenerator.cs" />
<Compile Include="Strings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Rest/RestConnection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Rest/RestConnection.cs 2014-11-21 01:30:19 UTC (rev 8455)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Rest/RestConnection.cs 2014-11-21 02:27:41 UTC (rev 8456)
@@ -39,7 +39,9 @@
public class RestConnection : MgServerConnectionBase,
IServerConnection,
IFeatureService,
- IResourceService
+ IResourceService,
+ IMappingService,
+ IFusionService
{
public const string PARAM_URL = "Url";
public const string PARAM_USERNAME = "Username";
@@ -47,6 +49,8 @@
private string _restRootUrl;
+ internal string RestRootUrl { get { return _restRootUrl; } }
+
internal RestClient MakeClient()
{
return new RestClient(_restRootUrl);
@@ -1034,6 +1038,17 @@
});
}
+ public Stream RenderMapLegend(Mapping.RuntimeMap map, int width, int height, System.Drawing.Color backgroundColor, string format)
+ {
+ return FetchRuntimeMapRepresentationAsStream(map, "/legendimage.{type}", (req) =>
+ {
+ req.AddUrlSegment("type", format.ToLower());
+
+ req.AddParameter("width", width);
+ req.AddParameter("height", height);
+ });
+ }
+
public override Stream GetTile(string mapdefinition, string baselayergroup, int col, int row, int scaleindex, string format)
{
return FetchResourceRepresentationAsStream(mapdefinition, "/tile.{type}/{groupName}/{scale}/{col}/{row}", (req) =>
@@ -1055,6 +1070,10 @@
return this;
case ServiceType.Resource:
return this;
+ case ServiceType.Mapping:
+ return this;
+ case ServiceType.Fusion:
+ return this;
default:
throw new ArgumentException(string.Format(Strings.InvalidOrUnsupportedServiceType, serviceType), "serviceType");
}
@@ -1072,5 +1091,37 @@
return _restRootUrl + " (v" + this.SiteVersion.ToString() + ")";
}
}
+
+ public override Resource.Preview.IResourcePreviewUrlGenerator GetPreviewUrlGenerator()
+ {
+ return new RestResourcePreviewUrlGenerator(this);
+ }
+
+ public ObjectModels.ApplicationDefinition.IApplicationDefinitionTemplateInfoSet GetApplicationTemplates()
+ {
+ var client = MakeClient();
+ var req = MakeRequest("services/fusiontemplates.xml");
+ var resp = ExecuteRequest<OSGeo.MapGuide.ObjectModels.ApplicationDefinition_1_0_0.ApplicationDefinitionTemplateInfoSet>(client, req);
+ ValidateResponse(resp);
+ return GetData(resp);
+ }
+
+ public ObjectModels.ApplicationDefinition.IApplicationDefinitionWidgetInfoSet GetApplicationWidgets()
+ {
+ var client = MakeClient();
+ var req = MakeRequest("services/fusionwidgets.xml");
+ var resp = ExecuteRequest<OSGeo.MapGuide.ObjectModels.ApplicationDefinition_1_0_0.ApplicationDefinitionWidgetInfoSet>(client, req);
+ ValidateResponse(resp);
+ return GetData(resp);
+ }
+
+ public ObjectModels.ApplicationDefinition.IApplicationDefinitionContainerInfoSet GetApplicationContainers()
+ {
+ var client = MakeClient();
+ var req = MakeRequest("services/fusioncontainers.xml");
+ var resp = ExecuteRequest<OSGeo.MapGuide.ObjectModels.ApplicationDefinition_1_0_0.ApplicationDefinitionContainerInfoSet>(client, req);
+ ValidateResponse(resp);
+ return GetData(resp);
+ }
}
}
Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Rest/RestResourcePreviewUrlGenerator.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Rest/RestResourcePreviewUrlGenerator.cs (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Rest/RestResourcePreviewUrlGenerator.cs 2014-11-21 02:27:41 UTC (rev 8456)
@@ -0,0 +1,104 @@
+#region Disclaimer / License
+// Copyright (C) 2014, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at 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
+using OSGeo.MapGuide.MaestroAPI.Resource;
+using OSGeo.MapGuide.MaestroAPI.Resource.Preview;
+using OSGeo.MapGuide.ObjectModels.ApplicationDefinition;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OSGeo.MapGuide.MaestroAPI.Rest
+{
+ class RestResourcePreviewUrlGenerator : ResourcePreviewUrlGenerator
+ {
+ private RestConnection _conn;
+
+ public RestResourcePreviewUrlGenerator(RestConnection conn)
+ {
+ _conn = conn;
+ }
+
+ private string GetSuffix(string resourceID, string sessionID)
+ {
+ ResourceIdentifier ri = new ResourceIdentifier(resourceID);
+ if (ri.IsInLibrary)
+ {
+ return "/library/" + ri.Path + "." + ri.ResourceType;
+ }
+ else
+ {
+ return "/session/" + sessionID + "/" + ri.Path + "." + ri.ResourceType;
+ }
+ }
+
+ protected override string GenerateWatermarkPreviewUrl(ObjectModels.WatermarkDefinition.IWatermarkDefinition res, string locale, bool isNew, string sessionID)
+ {
+ var url = _conn.RestRootUrl + GetSuffix(res.ResourceID, sessionID) + "/preview";
+ return url;
+ }
+
+ protected override string GenerateWebLayoutPreviewUrl(Resource.IResource res, string locale, bool isNew, string sessionID)
+ {
+ var url = _conn.RestRootUrl + GetSuffix(res.ResourceID, sessionID) + "/preview";
+ return url;
+ }
+
+ protected override string GenerateMapPreviewUrl(Resource.IResource res, string locale, bool isNew, string sessionID)
+ {
+ var url = _conn.RestRootUrl + GetSuffix(res.ResourceID, sessionID) + "/preview";
+ return url;
+ }
+
+ protected override string GenerateLayerPreviewUrl(Resource.IResource res, string locale, bool isNew, string sessionID)
+ {
+ var url = _conn.RestRootUrl + GetSuffix(res.ResourceID, sessionID) + "/viewer";
+ return url;
+ }
+
+ protected override string GenerateFlexLayoutPreviewUrl(Resource.IResource res, string locale, bool isNew, string sessionID)
+ {
+ var flexLayout = (IApplicationDefinition)res;
+ var url = _conn.RestRootUrl + GetSuffix(res.ResourceID, sessionID) + "/viewer/" + flexLayout.GetTemplateName();
+ return url;
+ }
+
+ protected override string GenerateFeatureSourcePreviewUrl(Resource.IResource res, string locale, bool isNew, string sessionID)
+ {
+ var url = _conn.RestRootUrl + GetSuffix(res.ResourceID, sessionID) + "/preview";
+ return url;
+ }
+
+ private static string[] PREVIEWABLE_RESOURCE_TYPES = new string[]
+ {
+ ResourceTypes.FeatureSource.ToString(),
+ ResourceTypes.ApplicationDefinition.ToString(),
+ ResourceTypes.LayerDefinition.ToString(),
+ ResourceTypes.MapDefinition.ToString(),
+ ResourceTypes.WebLayout.ToString(),
+ ResourceTypes.WatermarkDefinition.ToString()
+ };
+
+ public override bool IsPreviewableType(string resourceType)
+ {
+ return Array.IndexOf(PREVIEWABLE_RESOURCE_TYPES, resourceType) >= 0;
+ }
+ }
+}
More information about the mapguide-commits
mailing list