[mapguide-commits] r5425 - in sandbox/maestro-3.0:
OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI/Services
OSGeo.MapGuide.MaestroAPI.Http OSGeo.MapGuide.MaestroAPI.Native
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Wed Dec 1 06:01:21 EST 2010
Author: jng
Date: 2010-12-01 03:01:20 -0800 (Wed, 01 Dec 2010)
New Revision: 5425
Modified:
sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Enums.cs
sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs
sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Services/IResourceService.cs
Log:
3.0 sandbox changes:
- #1504: Add resource added, deleted, updated events to IResourceService and implementations
- #1536: Add a Touch() API to IResourceService to force timestamp updates.
Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Enums.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Enums.cs 2010-12-01 10:26:47 UTC (rev 5424)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Enums.cs 2010-12-01 11:01:20 UTC (rev 5425)
@@ -76,6 +76,15 @@
SymbolLibrary
}
+ public delegate void ResourceEventHandler(object sender, ResourceEventArgs e);
+
+ public class ResourceEventArgs : EventArgs
+ {
+ public ResourceEventArgs(string resourceID) { this.ResourceID = resourceID; }
+
+ public string ResourceID { get; set; }
+ }
+
/// <summary>
/// Helper class to filter <see cref="ResourceTypes"/> into the ones that are
/// editable
Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs 2010-12-01 10:26:47 UTC (rev 5424)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs 2010-12-01 11:01:20 UTC (rev 5425)
@@ -277,6 +277,55 @@
}
+ /// <summary>
+ /// Raised when a resource is added
+ /// </summary>
+ public event ResourceEventHandler ResourceAdded;
+ /// <summary>
+ /// Raised when a resource is deleted. Note if a folder is deleted, this will
+ /// only be raised for the folder and not its children. Also note that this is
+ /// raised on any move operations as the original source is for all intents and
+ /// purposes, deleted.
+ /// </summary>
+ public event ResourceEventHandler ResourceDeleted;
+ /// <summary>
+ /// Raised when a resource is updated
+ /// </summary>
+ public event ResourceEventHandler ResourceUpdated;
+
+ /// <summary>
+ /// Raises the <see cref="ResourceAdded"/> event
+ /// </summary>
+ /// <param name="resId"></param>
+ protected void OnResourceAdded(string resId)
+ {
+ var handler = this.ResourceAdded;
+ if (handler != null)
+ handler(this, new ResourceEventArgs(resId));
+ }
+
+ /// <summary>
+ /// Raises the <see cref="ResourceDeleted"/> event
+ /// </summary>
+ /// <param name="resId"></param>
+ protected void OnResourceDeleted(string resId)
+ {
+ var handler = this.ResourceDeleted;
+ if (handler != null)
+ handler(this, new ResourceEventArgs(resId));
+ }
+
+ /// <summary>
+ /// Raises the <see cref="ResourceUpdated"/> event
+ /// </summary>
+ /// <param name="resId"></param>
+ protected void OnResourceUpdated(string resId)
+ {
+ var handler = this.ResourceUpdated;
+ if (handler != null)
+ handler(this, new ResourceEventArgs(resId));
+ }
+
/// <summary>
/// Gets or sets the collection of cached schemas. Use the object type for key, and an XmlSchema instance for value.
/// </summary>
@@ -462,6 +511,19 @@
abstract public ObjCommon.ResourceList GetRepositoryResources(string startingpoint, string type, int depth, bool computeChildren);
/// <summary>
+ /// Forces a timestamp update of the specified resource. This is akin to
+ /// setting the resource's content using its existing content.
+ /// </summary>
+ /// <param name="resourceId"></param>
+ public virtual void Touch(string resourceId)
+ {
+ if (!ResourceIdentifier.IsFolderResource(resourceId))
+ {
+ SetResourceXmlData(resourceId, GetResourceXmlData(resourceId));
+ }
+ }
+
+ /// <summary>
/// Returns a boolean indicating if a given resource exists
/// </summary>
/// <param name="resourceid">The resource to look for</param>
Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Services/IResourceService.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Services/IResourceService.cs 2010-12-01 10:26:47 UTC (rev 5424)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Services/IResourceService.cs 2010-12-01 11:01:20 UTC (rev 5425)
@@ -33,6 +33,22 @@
public interface IResourceService : IService
{
/// <summary>
+ /// Raised when a resource is added
+ /// </summary>
+ event ResourceEventHandler ResourceAdded;
+ /// <summary>
+ /// Raised when a resource is deleted. Note if a folder is deleted, this will
+ /// only be raised for the folder and not its children. Also note that this is
+ /// raised on any move operations as the original source is for all intents and
+ /// purposes, deleted.
+ /// </summary>
+ event ResourceEventHandler ResourceDeleted;
+ /// <summary>
+ /// Raised when a resource is updated
+ /// </summary>
+ event ResourceEventHandler ResourceUpdated;
+
+ /// <summary>
/// Gets a listing of resources in this repository. This performs a full listing
/// </summary>
/// <returns></returns>
@@ -139,6 +155,13 @@
IResource GetResource(string resourceID);
/// <summary>
+ /// Forces a timestamp update of the specified resource. This is akin to
+ /// setting the resource's content using its existing content.
+ /// </summary>
+ /// <param name="resourceID"></param>
+ void Touch(string resourceID);
+
+ /// <summary>
/// Sets the resource data of a specified resource
/// </summary>
/// <param name="resourceid"></param>
Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs 2010-12-01 10:26:47 UTC (rev 5424)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs 2010-12-01 11:01:20 UTC (rev 5425)
@@ -442,6 +442,8 @@
public override void SetResourceXmlData(string resourceid, System.IO.Stream content, System.IO.Stream header)
{
+ bool exists = ResourceExists(resourceid);
+
System.IO.MemoryStream outStream = new System.IO.MemoryStream();
#if DEBUG_LASTMESSAGE
try
@@ -496,6 +498,11 @@
throw;
}
#endif
+
+ if (exists)
+ OnResourceUpdated(resourceid);
+ else
+ OnResourceAdded(resourceid);
}
private void LogResponse(HttpWebResponse resp)
@@ -672,6 +679,8 @@
using (System.IO.Stream resp = this.OpenRead(req))
resp.ReadByte();
//Do nothing... there is no return value
+
+ OnResourceDeleted(resourceID);
}
@@ -756,12 +765,22 @@
public override void CopyResource(string oldpath, string newpath, bool overwrite)
{
+ bool exists = ResourceExists(newpath);
+
string req = m_reqBuilder.CopyResource(oldpath, newpath, overwrite);
using (System.IO.Stream resp = this.OpenRead(req))
resp.ReadByte();
//Do nothing... there is no return value
+ if (exists)
+ OnResourceUpdated(newpath);
+ else
+ OnResourceAdded(newpath);
+
+ //HACK: the COPYRESOURCE call does not update timestamps of the target
+ //if it already exists.
+ Touch(newpath);
}
public override void CopyFolder(string oldpath, string newpath, bool overwrite)
@@ -769,20 +788,35 @@
oldpath = FixAndValidateFolderPath(oldpath);
newpath = FixAndValidateFolderPath(newpath);
+ bool exists = ResourceExists(newpath);
+
string req = m_reqBuilder.CopyResource(oldpath, newpath, overwrite);
using (System.IO.Stream resp = this.OpenRead(req))
resp.ReadByte();
//Do nothing... there is no return value
+
+ if (exists)
+ OnResourceUpdated(newpath);
+ else
+ OnResourceAdded(newpath);
}
public override void MoveResource(string oldpath, string newpath, bool overwrite)
{
+ bool exists = ResourceExists(newpath);
+
string req = m_reqBuilder.MoveResource(oldpath, newpath, overwrite);
using (System.IO.Stream resp = this.OpenRead(req))
resp.ReadByte();
//Do nothing... there is no return value
+
+ OnResourceDeleted(oldpath);
+ if (exists)
+ OnResourceUpdated(newpath);
+ else
+ OnResourceAdded(newpath);
}
public override void MoveFolder(string oldpath, string newpath, bool overwrite)
@@ -790,11 +824,19 @@
oldpath = FixAndValidateFolderPath(oldpath);
newpath = FixAndValidateFolderPath(newpath);
+ bool exists = ResourceExists(newpath);
+
string req = m_reqBuilder.MoveResource(oldpath, newpath, overwrite);
using (System.IO.Stream resp = this.OpenRead(req))
resp.ReadByte();
//Do nothing... there is no return value
+
+ OnResourceDeleted(oldpath);
+ if (exists)
+ OnResourceUpdated(newpath);
+ else
+ OnResourceAdded(newpath);
}
public override System.IO.Stream RenderDynamicOverlay(RuntimeMap map, MapSelection selection, string format, bool keepSelection)
Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs 2010-12-01 10:26:47 UTC (rev 5424)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs 2010-12-01 11:01:20 UTC (rev 5425)
@@ -197,6 +197,8 @@
public override void SetResourceXmlData(string resourceid, System.IO.Stream content, System.IO.Stream header)
{
+ bool exists = ResourceExists(resourceid);
+
MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
byte[] bufHeader = header == null ? new byte[0] : Utility.StreamAsArray(header);
@@ -204,6 +206,11 @@
MgByteReader rH = bufHeader.Length == 0 ? null : new MgByteReader(bufHeader, bufHeader.Length, "text/xml");
MgByteReader rC = bufContent.Length == 0 ? null : new MgByteReader(bufContent, bufContent.Length, "text/xml");
res.SetResource(new MgResourceIdentifier(resourceid), rC, rH);
+
+ if (exists)
+ OnResourceUpdated(resourceid);
+ else
+ OnResourceAdded(resourceid);
}
public FeatureSetReader ExecuteSqlQuery(string featureSourceID, string sql)
@@ -389,6 +396,8 @@
{
MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
res.DeleteResource(new MgResourceIdentifier(resourceID));
+
+ OnResourceDeleted(resourceID);
}
public override Version SiteVersion
@@ -465,12 +474,21 @@
public override void CopyResource(string oldpath, string newpath, bool overwrite)
{
+ bool exists = ResourceExists(newpath);
+
MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
res.CopyResource(new MgResourceIdentifier(oldpath), new MgResourceIdentifier(newpath), overwrite);
+
+ if (exists)
+ OnResourceUpdated(newpath);
+ else
+ OnResourceAdded(newpath);
}
public override void CopyFolder(string oldpath, string newpath, bool overwrite)
{
+ bool exists = ResourceExists(newpath);
+
if (!oldpath.EndsWith("/"))
oldpath += "/";
if (!newpath.EndsWith("/"))
@@ -478,16 +496,31 @@
MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
res.CopyResource(new MgResourceIdentifier(oldpath), new MgResourceIdentifier(newpath), overwrite);
+
+ if (exists)
+ OnResourceUpdated(newpath);
+ else
+ OnResourceAdded(newpath);
}
public override void MoveResource(string oldpath, string newpath, bool overwrite)
{
+ bool exists = ResourceExists(newpath);
+
MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
res.MoveResource(new MgResourceIdentifier(oldpath), new MgResourceIdentifier(newpath), overwrite);
+
+ OnResourceDeleted(oldpath);
+ if (exists)
+ OnResourceUpdated(newpath);
+ else
+ OnResourceAdded(newpath);
}
public override void MoveFolder(string oldpath, string newpath, bool overwrite)
{
+ bool exists = ResourceExists(newpath);
+
if (!oldpath.EndsWith("/"))
oldpath += "/";
if (!newpath.EndsWith("/"))
@@ -495,6 +528,12 @@
MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
res.MoveResource(new MgResourceIdentifier(oldpath), new MgResourceIdentifier(newpath), overwrite);
+
+ OnResourceDeleted(oldpath);
+ if (exists)
+ OnResourceUpdated(newpath);
+ else
+ OnResourceAdded(newpath);
}
public override System.IO.Stream RenderRuntimeMap(string resourceId, double x, double y, double scale, int width, int height, int dpi, string format, bool clip)
@@ -702,17 +741,16 @@
public override bool ResourceExists(string resourceid)
{
- try
+ //API is safe to call in MG 2.1 and newer
+ if (this.SiteVersion >= new Version(2, 1))
{
MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
return res.ResourceExists(new MgResourceIdentifier(resourceid));
}
- catch (Exception ex)
+ else
{
- try { return base.ResourceExists(resourceid); }
- catch { throw ex; } //Throw original error
+ return base.ResourceExists(resourceid);
}
-
}
public string[] GetConnectionPropertyValues(string providerName, string propertyName, string partialConnectionString)
More information about the mapguide-commits
mailing list