Class Utility
Various helper functions
Inheritance
Inherited Members
Namespace: OSGeo.MapGuide.MaestroAPI
Assembly: OSGeo.MapGuide.MaestroAPI.dll
Syntax
public static class Utility
Fields
| Improve this Doc View SourceXML_EXCEPTION_KEY
The exception data key that hints that an System.Exception thrown is related to XML content errors
Declaration
public const string XML_EXCEPTION_KEY = "XmlError"
Field Value
Type | Description |
---|---|
System.String |
Methods
| Improve this Doc View SourceChangeColorBrightness(Color, Single)
Creates color with corrected brightness.
Declaration
public static Color ChangeColorBrightness(Color color, float correctionFactor)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | Color to correct. |
System.Single | correctionFactor | The brightness correction factor. Must be between -1 and 1. Negative values produce darker colors. |
Returns
Type | Description |
---|---|
System.Drawing.Color | Corrected System.Drawing.Color structure. |
CleanUpFeatureSet(String)
Removes the outer <FeatureInformation> tag, and returns a blank string for empty sets. This eases the use of SelectionXml, because different parts of MapGuide represents it differently.
Declaration
public static string CleanUpFeatureSet(string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | The string to clean |
Returns
Type | Description |
---|---|
System.String | The cleaned string |
CopyStream(Stream, Stream)
Copies the content of a stream into another stream. Automatically attempts to rewind the source stream.
Declaration
public static void CopyStream(Stream source, Stream target)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | source | The source stream |
System.IO.Stream | target | The target stream |
CopyStream(Stream, Stream, Utility.StreamCopyProgressDelegate, Int64)
Copies the content of a stream into another stream, with callbacks.
Declaration
public static void CopyStream(Stream source, Stream target, Utility.StreamCopyProgressDelegate callback, long updateFrequence)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | source | The source stream |
System.IO.Stream | target | The target stream |
Utility.StreamCopyProgressDelegate | callback | An optional callback delegate, may be null. |
System.Int64 | updateFrequence | The number of bytes to copy before calling the callback delegate, set to 0 to get every update |
CopyStream(Stream, Stream, Boolean)
Copies the content of a stream into another stream.
Declaration
public static void CopyStream(Stream source, Stream target, bool rewind)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | source | The source stream |
System.IO.Stream | target | The target stream |
System.Boolean | rewind | True if the source stream should be rewound before being copied |
CreateDefaultLayer(IServerConnection, LayerType)
Creates a layer definition at the highest supported resource version
Declaration
public static ILayerDefinition CreateDefaultLayer(IServerConnection conn, LayerType layerType)
Parameters
Type | Name | Description |
---|---|---|
IServerConnection | conn | |
LayerType | layerType |
Returns
Type | Description |
---|---|
ILayerDefinition |
CreateDefaultLayer(IServerConnection, String, ClassDefinition, String)
Creates a default Layer Definition from the given Class Definition
Declaration
public static string CreateDefaultLayer(IServerConnection conn, string fsId, ClassDefinition clsDef, string targetFolder)
Parameters
Type | Name | Description |
---|---|---|
IServerConnection | conn | |
System.String | fsId | |
ClassDefinition | clsDef | |
System.String | targetFolder |
Returns
Type | Description |
---|---|
System.String |
CreateFlexibleLayout(IServerConnection, String, Boolean)
Creates a flexible layout
Declaration
public static IApplicationDefinition CreateFlexibleLayout(IServerConnection conn, string templateName, bool statelessMode = false)
Parameters
Type | Name | Description |
---|---|---|
IServerConnection | conn | |
System.String | templateName | |
System.Boolean | statelessMode | If true, the widget set will only be populated with widgets that can work without a running MapGuide Server |
Returns
Type | Description |
---|---|
IApplicationDefinition |
CreateMapDefinition(IServerConnection, String)
Creates a map definition at the highest supported resource version
Declaration
public static IMapDefinition CreateMapDefinition(IServerConnection conn, string name)
Parameters
Type | Name | Description |
---|---|---|
IServerConnection | conn | |
System.String | name |
Returns
Type | Description |
---|---|
IMapDefinition |
CreateMapDefinition(IServerConnection, String, String, IEnvelope)
Creates a map definition at the highest supported resource version
Declaration
public static IMapDefinition CreateMapDefinition(IServerConnection conn, string name, string csWkt, IEnvelope extent)
Parameters
Type | Name | Description |
---|---|---|
IServerConnection | conn | |
System.String | name | |
System.String | csWkt | |
IEnvelope | extent |
Returns
Type | Description |
---|---|
IMapDefinition |
CreateSimpleSymbol(IServerConnection, String, String)
Creates a simple symbol definition at the highest supported resource version
Declaration
public static ISimpleSymbolDefinition CreateSimpleSymbol(IServerConnection conn, string name, string description)
Parameters
Type | Name | Description |
---|---|---|
IServerConnection | conn | |
System.String | name | |
System.String | description |
Returns
Type | Description |
---|---|
ISimpleSymbolDefinition |
CreateWatermarkPreviewMapDefinition(IWatermarkDefinition)
Creates a preview map definition for the given watermark
Declaration
public static IMapDefinition2 CreateWatermarkPreviewMapDefinition(IWatermarkDefinition wmd)
Parameters
Type | Name | Description |
---|---|---|
IWatermarkDefinition | wmd |
Returns
Type | Description |
---|---|
IMapDefinition2 |
DecodeFDOName(String)
Converts FDO encoded characters into their original character.
Declaration
public static string DecodeFDOName(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The FDO encoded string |
Returns
Type | Description |
---|---|
System.String | The unencoded version of the string |
Remarks
FDO names must always be encoded when writing back to attributes in XML configuration documents as it may contain reserved characters that would render the final XML attribute content invalid.
Consequently, such names must always be decoded when reading from XML configuration documents otherwise these escape characters may still be present after reading
EncodeFDOName(String)
FDO encodes a string
Declaration
public static string EncodeFDOName(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Returns
Type | Description |
---|---|
System.String |
Remarks
FDO names must always be encoded when writing back to attributes in XML configuration documents as it may contain reserved characters that would render the final XML attribute content invalid.
Consequently, such names must always be decoded when reading from XML configuration documents otherwise these escape characters may still be present after reading
ExplodeThemeIntoFilteredLayers(IServerConnection, ExplodeThemeOptions, LengthyOperationProgressCallBack)
Explodes a themed layer into filtered sub-layers where each sub-layer is filtered on the individual theme rule's filter
Declaration
public static void ExplodeThemeIntoFilteredLayers(IServerConnection conn, ExplodeThemeOptions options, LengthyOperationProgressCallBack progress)
Parameters
Type | Name | Description |
---|---|---|
IServerConnection | conn | |
ExplodeThemeOptions | options | |
LengthyOperationProgressCallBack | progress |
FdoStringifiyLiteral(String)
Surrounds the given string with single-quotes. Mainly used for FDO expressions where string literals are required as un-quoted strings will trigger the FDO expression engine.
Declaration
public static string FdoStringifiyLiteral(string str)
Parameters
Type | Name | Description |
---|---|---|
System.String | str |
Returns
Type | Description |
---|---|
System.String |
FormatSizeString(Int64)
Formats a number of bytes to a human readable format, ea.: 2.56 Kb
Declaration
public static string FormatSizeString(long size)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | size | The size in bytes |
Returns
Type | Description |
---|---|
System.String | The human readable string |
GenerateLayerName(String, String, String, Int32, IVectorRule)
Generates a unique layer name for a given vector rule
Declaration
public static string GenerateLayerName(string layerFormat, string layerName, string scaleRange, int i, IVectorRule rule)
Parameters
Type | Name | Description |
---|---|---|
System.String | layerFormat | |
System.String | layerName | |
System.String | scaleRange | |
System.Int32 | i | |
IVectorRule | rule |
Returns
Type | Description |
---|---|
System.String |
GetResourceIdPointers(XmlNode)
Enumerates all xml nodes in the document, and looks for tags or attributes named ResourceId
Declaration
public static List<KeyValuePair<XmlNode, string>> GetResourceIdPointers(XmlNode item)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlNode | item | The xml item to examine |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.Xml.XmlNode, System.String>> | A list with all found elements |
GetScaleRangeStr(IVectorScaleRange)
String-ifies a scale range
Declaration
public static string GetScaleRangeStr(IVectorScaleRange parentRange)
Parameters
Type | Name | Description |
---|---|---|
IVectorScaleRange | parentRange |
Returns
Type | Description |
---|---|
System.String |
GetStylizationFunctions()
Returns the list of known FDO stylization expression functions
Declaration
public static IEnumerable<IFdoFunctionDefintion> GetStylizationFunctions()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IFdoFunctionDefintion> |
HasOriginalXml(Exception)
Gets whether the given exception has original xml content attached
Declaration
public static bool HasOriginalXml(Exception ex)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | ex |
Returns
Type | Description |
---|---|
System.Boolean |
InRange<T>(T, T, T, Boolean)
Returns true if the given value is in range
Declaration
public static bool InRange<T>(T val, T min, T max, bool bInclusive = true)
where T : IComparable
Parameters
Type | Name | Description |
---|---|---|
T | val | |
T | min | |
T | max | |
System.Boolean | bInclusive |
Returns
Type | Description |
---|---|
System.Boolean |
Type Parameters
Name | Description |
---|---|
T |
IsDbXmlError(Exception)
Gets whether the thrown exception is related to DBXML
Declaration
public static bool IsDbXmlError(Exception ex)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | ex |
Returns
Type | Description |
---|---|
System.Boolean |
IsSessionExpiredException(Exception)
Helper to determine if the given exception is related to session expiry
Declaration
public static bool IsSessionExpiredException(Exception ex)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | ex |
Returns
Type | Description |
---|---|
System.Boolean |
IsSuccessfulConnectionTestResult(String)
Checks if the given result is a successful test connection result
Declaration
public static bool IsSuccessfulConnectionTestResult(string sResult)
Parameters
Type | Name | Description |
---|---|---|
System.String | sResult |
Returns
Type | Description |
---|---|
System.Boolean |
IsZero(Double)
Returns true if this value is zero for all intents and purposes
Declaration
public static bool IsZero(this double val)
Parameters
Type | Name | Description |
---|---|---|
System.Double | val |
Returns
Type | Description |
---|---|
System.Boolean |
IsZero(Single)
Returns true if this value is zero for all intents and purposes
Declaration
public static bool IsZero(this float val)
Parameters
Type | Name | Description |
---|---|---|
System.Single | val |
Returns
Type | Description |
---|---|
System.Boolean |
MakeWktCircle(Double, Double, Double)
Creates the WKT for the given circle
Declaration
public static string MakeWktCircle(double x, double y, double r)
Parameters
Type | Name | Description |
---|---|---|
System.Double | x | |
System.Double | y | |
System.Double | r |
Returns
Type | Description |
---|---|
System.String |
MakeWktPolygon(Double, Double, Double, Double)
Creates the polygon WKT for the given bounding box
Declaration
public static string MakeWktPolygon(double x1, double y1, double x2, double y2)
Parameters
Type | Name | Description |
---|---|---|
System.Double | x1 | |
System.Double | y1 | |
System.Double | x2 | |
System.Double | y2 |
Returns
Type | Description |
---|---|
System.String |
ParseHTMLColor(String)
Parses a color in HTML notation (ea. #ffaabbff)
Declaration
public static Color ParseHTMLColor(string color)
Parameters
Type | Name | Description |
---|---|---|
System.String | color | The HTML representation of the color |
Returns
Type | Description |
---|---|
System.Drawing.Color | The .Net color structure that matches the color |
ParseHTMLColorARGB(String)
Parses a color in HTML notation (ea. #ffaabbff)
Declaration
public static Color ParseHTMLColorARGB(string color)
Parameters
Type | Name | Description |
---|---|---|
System.String | color | The HTML representation of the color |
Returns
Type | Description |
---|---|
System.Drawing.Color | The .Net color structure that matches the color |
ParseHTMLColorRGBA(String)
Parses a color in HTML notation (ea. #ffaabbff)
Declaration
public static Color ParseHTMLColorRGBA(string color)
Parameters
Type | Name | Description |
---|---|---|
System.String | color | The HTML representation of the color |
Returns
Type | Description |
---|---|
System.Drawing.Color | The .Net color structure that matches the color |
ParseQueryString(String)
Parses the given query string to a dictionary
Declaration
public static IDictionary<string, string> ParseQueryString(string queryString)
Parameters
Type | Name | Description |
---|---|---|
System.String | queryString |
Returns
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, System.String> |
RemoveUTF8BOM(MemoryStream)
Creates a copy of the stream, with removed Utf8 BOM, if any
Declaration
public static MemoryStream RemoveUTF8BOM(MemoryStream ms)
Parameters
Type | Name | Description |
---|---|---|
System.IO.MemoryStream | ms | The stream to fix |
Returns
Type | Description |
---|---|
System.IO.MemoryStream | A stream with no Utf8 BOM |
ReplaceResourceIds(XmlDocument, String, String)
Replaces all references of the given resource id.
Declaration
public static bool ReplaceResourceIds(XmlDocument doc, string srcId, string dstId)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlDocument | doc | A resource document. Any replacements will modify the XmlDocument that is passed in |
System.String | srcId | The resource id to replace |
System.String | dstId | The resource id to replace with |
Returns
Type | Description |
---|---|
System.Boolean | true if a replacement was made. false if no replacements were made |
SerializeDigit(Double)
Turns a decimal value into a string representation in EN-US format
Declaration
public static string SerializeDigit(double digit)
Parameters
Type | Name | Description |
---|---|---|
System.Double | digit | The value to encode |
Returns
Type | Description |
---|---|
System.String | The encoded value |
SerializeDigit(Single)
Turns a decimal value into a string representation in EN-US format
Declaration
public static string SerializeDigit(float digit)
Parameters
Type | Name | Description |
---|---|---|
System.Single | digit | The value to encode |
Returns
Type | Description |
---|---|
System.String | The encoded value |
SerializeHTMLColor(Color, Boolean)
Returns the HTML ARGB representation of an .Net color structure
Declaration
public static string SerializeHTMLColor(Color color, bool includeAlpha)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to encode |
System.Boolean | includeAlpha | A flag indicating if the color structures alpha value should be included |
Returns
Type | Description |
---|---|
System.String | The HTML representation of the color structure |
SerializeHTMLColorARGB(Color, Boolean)
Returns the HTML ARGB representation of an .Net color structure
Declaration
public static string SerializeHTMLColorARGB(Color color, bool includeAlpha)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to encode |
System.Boolean | includeAlpha | A flag indicating if the color structures alpha value should be included |
Returns
Type | Description |
---|---|
System.String | The HTML representation of the color structure |
SerializeHTMLColorRGBA(Color, Boolean)
Returns the HTML RGBA representation of an .Net color structure
Declaration
public static string SerializeHTMLColorRGBA(Color color, bool includeAlpha)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to encode |
System.Boolean | includeAlpha | A flag indicating if the color structures alpha value should be included |
Returns
Type | Description |
---|---|
System.String | The HTML representation of the color structure |
StreamAsArray(Stream)
Reads all data from a stream, and returns it as a single array. Note that this is very inefficient if the stream is several megabytes long.
Declaration
public static byte[] StreamAsArray(Stream s)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | s | The stream to exhaust |
Returns
Type | Description |
---|---|
System.Byte[] | The streams content as an array |
StripVersionFromProviderName(String)
Strips the version component from provider name
Declaration
public static string StripVersionFromProviderName(string providername)
Parameters
Type | Name | Description |
---|---|---|
System.String | providername | The provider name. |
Returns
Type | Description |
---|---|
System.String |
StripWmsMetadata(ResourceDocumentHeaderType)
Strips known WMS metadata from the given resource document header
Declaration
public static void StripWmsMetadata(ResourceDocumentHeaderType header)
Parameters
Type | Name | Description |
---|---|---|
ResourceDocumentHeaderType | header |
ThrowAsWebException(Exception)
This method tries to extract the html content of a WebException. If succesfull, it will return an exception with an error message corresponding to the html text. If not, it will return the original exception object.
Declaration
public static Exception ThrowAsWebException(Exception ex)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | ex | The exception object to extract from |
Returns
Type | Description |
---|---|
System.Exception | A potentially better exeception |
ToConnectionString(NameValueCollection)
Converts the specified name value collection into a connection string
Declaration
public static string ToConnectionString(NameValueCollection values)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Specialized.NameValueCollection | values |
Returns
Type | Description |
---|---|
System.String |
TransformEnvelope(ICoordinateSystemCatalog, IEnvelope, String, String)
Transforms the envelope from the given source coordinate system to the given target coordinate system
Declaration
public static IEnvelope TransformEnvelope(ICoordinateSystemCatalog csCatalog, IEnvelope env, string srcCsWkt, string dstCsWkt)
Parameters
Type | Name | Description |
---|---|---|
ICoordinateSystemCatalog | csCatalog | The connection's associated coordinate system catalog |
IEnvelope | env | The envelope. |
System.String | srcCsWkt | The source coordinate system WKT. |
System.String | dstCsWkt | The destination coordinate system WKT. |
Returns
Type | Description |
---|---|
IEnvelope |
XmlDeepCopy(Object)
Builds a copy of the object by serializing it to xml, and then deserializing it. Please note that this function is has a large overhead.
Declaration
public static object XmlDeepCopy(object source)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | The object to copy |
Returns
Type | Description |
---|---|
System.Object | A copy of the object |