diff --git a/Maestro.MapViewer/MapViewer.cs b/Maestro.MapViewer/MapViewer.cs index 963e48eb9..8691954a9 100644 --- a/Maestro.MapViewer/MapViewer.cs +++ b/Maestro.MapViewer/MapViewer.cs @@ -2791,21 +2791,21 @@ public MapActiveTool ActiveTool switch (value) { case MapActiveTool.Pan: - using (var ms = new MemoryStream(Properties.Resources.grab)) + using (var ms = MemoryStreamPool.GetStream("ActiveTool", Properties.Resources.grab)) { this.Cursor = new Cursor(ms); } break; case MapActiveTool.ZoomIn: - using (var ms = new MemoryStream(Properties.Resources.zoomin)) + using (var ms = MemoryStreamPool.GetStream("ActiveTool", Properties.Resources.zoomin)) { this.Cursor = new Cursor(ms); } break; case MapActiveTool.ZoomOut: - using (var ms = new MemoryStream(Properties.Resources.zoomout)) + using (var ms = MemoryStreamPool.GetStream("ActiveTool", Properties.Resources.zoomout)) { this.Cursor = new Cursor(ms); } diff --git a/OSGeo.MapGuide.MaestroAPI.IntegrationTests/HttpConnectionTests.cs b/OSGeo.MapGuide.MaestroAPI.IntegrationTests/HttpConnectionTests.cs index d938b2bf4..53367425e 100644 --- a/OSGeo.MapGuide.MaestroAPI.IntegrationTests/HttpConnectionTests.cs +++ b/OSGeo.MapGuide.MaestroAPI.IntegrationTests/HttpConnectionTests.cs @@ -60,7 +60,7 @@ protected override string GetTestPrefix() return "Http"; } - //[Fact] + //[SkippableFact] public override void TestEncryptedFeatureSourceCredentials() { base.TestEncryptedFeatureSourceCredentials(); diff --git a/OSGeo.MapGuide.MaestroAPI.Tests/GdalConfigurationDocumentTests.cs b/OSGeo.MapGuide.MaestroAPI.Tests/GdalConfigurationDocumentTests.cs new file mode 100644 index 000000000..bbb13c309 --- /dev/null +++ b/OSGeo.MapGuide.MaestroAPI.Tests/GdalConfigurationDocumentTests.cs @@ -0,0 +1,84 @@ +#region Disclaimer / License + +// Copyright (C) 2017, Jackie Ng +// https://github.com/jumpinjackie/mapguide-maestro +// +// 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 OSGeo.MapGuide.MaestroAPI.SchemaOverrides; +using Xunit; + +namespace OSGeo.MapGuide.MaestroAPI.Tests +{ + public class GdalConfigurationDocumentTests + { + [Fact] + public void GdalDocument_AddLocationDeDupes() + { + var doc = new GdalConfigurationDocument(); + var loc = new GdalRasterLocationItem { Location = "C:\\temp\\location_1" }; + doc.AddLocation(loc); + Assert.Equal(1, doc.RasterLocations.Length); + var loc2 = new GdalRasterLocationItem { Location = "C:\\temp\\location_1" }; + doc.AddLocation(loc2); + Assert.Equal(1, doc.RasterLocations.Length); + var loc3 = new GdalRasterLocationItem { Location = "C:\\temp\\location_2" }; + doc.AddLocation(loc3); + Assert.Equal(2, doc.RasterLocations.Length); + } + + [Fact] + public void GdalDocument_Remove() + { + var doc = new GdalConfigurationDocument(); + var loc = new GdalRasterLocationItem { Location = "C:\\temp\\location_1" }; + Assert.False(doc.RemoveLocation(loc)); + doc.AddLocation(loc); + var loc2 = new GdalRasterLocationItem { Location = "C:\\temp\\location_1" }; + Assert.True(doc.RemoveLocation(loc2)); + } + + [Fact] + public void GdalDocument_CalculateExtents() + { + var doc = new GdalConfigurationDocument(); + Assert.Null(doc.CalculateExtent()); + var loc = new GdalRasterLocationItem { Location = "C:\\temp\\location_1" }; + loc.AddItem(new GdalRasterItem { FileName = "1_1.tif", MinX = 1, MinY = 1, MaxX = 2, MaxY = 2 }); + doc.AddLocation(loc); + var ext = doc.CalculateExtent(); + Assert.Equal(1, ext.MinX); + Assert.Equal(1, ext.MinY); + Assert.Equal(2, ext.MaxX); + Assert.Equal(2, ext.MaxY); + var loc2 = new GdalRasterLocationItem { Location = "C:\\temp\\location_2" }; + loc2.AddItem(new GdalRasterItem { FileName = "2_1.tif", MinX = -1, MinY = -1, MaxX = 2, MaxY = 2 }); + doc.AddLocation(loc2); + ext = doc.CalculateExtent(); + Assert.Equal(-1, ext.MinX); + Assert.Equal(-1, ext.MinY); + Assert.Equal(2, ext.MaxX); + Assert.Equal(2, ext.MaxY); + loc2.AddItem(new GdalRasterItem { FileName = "1_2.tif", MinX = 2, MinY = 1, MaxX = 3, MaxY = 3 }); + ext = doc.CalculateExtent(); + Assert.Equal(-1, ext.MinX); + Assert.Equal(-1, ext.MinY); + Assert.Equal(3, ext.MaxX); + Assert.Equal(3, ext.MaxY); + } + } +} diff --git a/OSGeo.MapGuide.MaestroAPI.Tests/KeyValueCollectionTests.cs b/OSGeo.MapGuide.MaestroAPI.Tests/KeyValueCollectionTests.cs new file mode 100644 index 000000000..0e475129f --- /dev/null +++ b/OSGeo.MapGuide.MaestroAPI.Tests/KeyValueCollectionTests.cs @@ -0,0 +1,117 @@ +#region Disclaimer / License + +// Copyright (C) 2017, Jackie Ng +// https://github.com/jumpinjackie/mapguide-maestro +// +// 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 OSGeo.MapGuide.MaestroAPI.Exceptions; +using OSGeo.MapGuide.MaestroAPI.Mapping; +using System.Collections; +using Xunit; + +namespace OSGeo.MapGuide.MaestroAPI.Tests +{ + public abstract class KeyValueCollectionTests + where TValue : class + where TCollection : KeyValueCollection + { + protected abstract TCollection CreateCollection(); + + protected abstract TValue CreateTestValue1(string desiredKey = null); + + protected abstract TValue CreateTestValue2(string desiredKey = null); + + public virtual void Collection_BasicManipulation() + { + var collection = CreateCollection(); + var val1 = CreateTestValue1(); + Assert.True(collection.IndexOf(val1) < 0); + Assert.False(collection.Contains(val1)); + collection.Add(val1); + Assert.True(collection.IndexOf(val1) >= 0); + Assert.True(collection.Contains(val1)); + + collection.Clear(); + Assert.Equal(0, collection.Count); + + var val2 = CreateTestValue2(); + collection.Insert(0, val1); + collection.Insert(0, val2); + + Assert.Equal(2, collection.Count); + Assert.False(collection.IsReadOnly); + } + + public virtual void Collection_BasicManipulation_AsIList() + { + IList collection = CreateCollection(); + var val1 = CreateTestValue1(); + Assert.True(collection.IndexOf(val1) < 0); + Assert.False(collection.Contains(val1)); + collection.Add(val1); + Assert.True(collection.IndexOf(val1) >= 0); + Assert.True(collection.Contains(val1)); + + collection.Clear(); + Assert.Equal(0, collection.Count); + + var val2 = CreateTestValue2(); + collection.Insert(0, val1); + collection.Insert(0, val2); + + Assert.Equal(2, collection.Count); + Assert.False(collection.IsReadOnly); + Assert.False(collection.IsFixedSize); + } + + public virtual void Collection_IsEnumerable() + { + var collection = CreateCollection(); + var val1 = CreateTestValue1(); + var val2 = CreateTestValue2(); + collection.Add(val1); + collection.Add(val2); + foreach (var v in collection) + { + Assert.True(v == val1 || v == val2); + } + } + + public virtual void Collection_IsEnumerable_AsIList() + { + IList collection = CreateCollection(); + var val1 = CreateTestValue1(); + var val2 = CreateTestValue2(); + collection.Add(val1); + collection.Add(val2); + foreach (var v in collection) + { + Assert.True(v == val1 || v == val2); + } + } + + public virtual void Collection_InsertDuplicateKeyThrows() + { + var collection = CreateCollection(); + var val1 = CreateTestValue1("Key1"); + var val2 = CreateTestValue2("Key1"); + collection.Insert(0, val1); + Assert.Throws(() => collection.Insert(0, val2)); + } + } +} diff --git a/OSGeo.MapGuide.MaestroAPI.Tests/Mapping/CollectionTests.cs b/OSGeo.MapGuide.MaestroAPI.Tests/Mapping/CollectionTests.cs new file mode 100644 index 000000000..263b5dddc --- /dev/null +++ b/OSGeo.MapGuide.MaestroAPI.Tests/Mapping/CollectionTests.cs @@ -0,0 +1,144 @@ +#region Disclaimer / License + +// Copyright (C) 2017, Jackie Ng +// https://github.com/jumpinjackie/mapguide-maestro +// +// 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 Moq; +using OSGeo.MapGuide.MaestroAPI.Mapping; +using System; +using Xunit; + +namespace OSGeo.MapGuide.MaestroAPI.Tests.Mapping +{ + public class LayerCollectionTests : KeyValueCollectionTests + { + protected override RuntimeMapLayerCollection CreateCollection() + { + var type = typeof(RuntimeMapLayerCollection); + var ctor = type.GetInternalConstructor(new[] { typeof(RuntimeMap) }); + + var map = Mock.Of(); + return ctor.Invoke(new[] { map }) as RuntimeMapLayerCollection; + } + + protected override RuntimeMapLayer CreateTestValue1(string desiredKey = null) + { + var id = Guid.NewGuid().ToString(); + var layer = new Mock(); + layer.Setup(l => l.Name).Returns(desiredKey ?? "TestValue1"); + layer.Setup(l => l.ObjectId).Returns(id); + return layer.Object; + } + + protected override RuntimeMapLayer CreateTestValue2(string desiredKey = null) + { + var id = Guid.NewGuid().ToString(); + var layer = new Mock(); + layer.Setup(l => l.Name).Returns(desiredKey ?? "TestValue2"); + layer.Setup(l => l.ObjectId).Returns(id); + return layer.Object; + } + + [Fact] + public override void Collection_BasicManipulation() + { + base.Collection_BasicManipulation(); + } + + [Fact] + public override void Collection_InsertDuplicateKeyThrows() + { + base.Collection_InsertDuplicateKeyThrows(); + } + + [Fact] + public override void Collection_BasicManipulation_AsIList() + { + base.Collection_BasicManipulation_AsIList(); + } + + [Fact] + public override void Collection_IsEnumerable() + { + base.Collection_IsEnumerable(); + } + + [Fact] + public override void Collection_IsEnumerable_AsIList() + { + base.Collection_IsEnumerable_AsIList(); + } + } + + public class GroupCollectionTests : KeyValueCollectionTests + { + protected override RuntimeMapGroupCollection CreateCollection() + { + var type = typeof(RuntimeMapGroupCollection); + var ctor = type.GetInternalConstructor(new[] { typeof(RuntimeMap) }); + + var map = Mock.Of(); + return ctor.Invoke(new[] { map }) as RuntimeMapGroupCollection; + } + + protected override RuntimeMapGroup CreateTestValue1(string desiredKey = null) + { + var layer = new Mock(); + layer.Setup(l => l.Name).Returns(desiredKey ?? "TestValue1"); + return layer.Object; + } + + protected override RuntimeMapGroup CreateTestValue2(string desiredKey = null) + { + var layer = new Mock(); + layer.Setup(l => l.Name).Returns(desiredKey ?? "TestValue2"); + return layer.Object; + } + + [Fact] + public override void Collection_BasicManipulation() + { + base.Collection_BasicManipulation(); + } + + [Fact] + public override void Collection_InsertDuplicateKeyThrows() + { + base.Collection_InsertDuplicateKeyThrows(); + } + + [Fact] + public override void Collection_BasicManipulation_AsIList() + { + base.Collection_BasicManipulation_AsIList(); + } + + [Fact] + public override void Collection_IsEnumerable() + { + base.Collection_IsEnumerable(); + } + + [Fact] + public override void Collection_IsEnumerable_AsIList() + { + base.Collection_IsEnumerable_AsIList(); + } + } +} diff --git a/OSGeo.MapGuide.MaestroAPI.Tests/ResourceTests.cs b/OSGeo.MapGuide.MaestroAPI.Tests/ResourceTests.cs index 9e9793c5d..14967779c 100644 --- a/OSGeo.MapGuide.MaestroAPI.Tests/ResourceTests.cs +++ b/OSGeo.MapGuide.MaestroAPI.Tests/ResourceTests.cs @@ -21,13 +21,17 @@ #endregion Disclaimer / License using Moq; using OSGeo.MapGuide.MaestroAPI.Resource.Conversion; +using OSGeo.MapGuide.MaestroAPI.Services; using OSGeo.MapGuide.ObjectModels; +using OSGeo.MapGuide.ObjectModels.Common; +using OSGeo.MapGuide.ObjectModels.FeatureSource; using OSGeo.MapGuide.ObjectModels.LayerDefinition; using OSGeo.MapGuide.ObjectModels.LoadProcedure; using OSGeo.MapGuide.ObjectModels.MapDefinition; using OSGeo.MapGuide.ObjectModels.SymbolDefinition; using OSGeo.MapGuide.ObjectModels.WebLayout; using System; +using System.IO; using System.Linq; using Xunit; @@ -35,6 +39,31 @@ namespace OSGeo.MapGuide.MaestroAPI.Tests { public class ResourceTests { + [Fact] + public void TestCredentialWriter() + { + var conn = new Mock(); + var mockRs = new Mock(); + conn.Setup(c => c.ResourceService).Returns(mockRs.Object); + + var fs = new Mock(); + Assert.Throws(() => fs.Object.SetEncryptedCredentials(conn.Object, "Foo", "bar")); + var fs2 = new Mock(); + fs2.Setup(f => f.ResourceID).Returns("Library://Test.FeatureSource"); + fs2.Object.SetEncryptedCredentials(conn.Object, "Foo", "bar"); + + mockRs.Verify(r => r.SetResourceData("Library://Test.FeatureSource", StringConstants.MgUserCredentialsResourceData, ResourceDataType.String, It.IsAny()), Times.Once); + } + + [Fact] + public void TestDeserializeEmbeddedFlexLayout() + { + var flex1 = ObjectFactory.DeserializeEmbeddedFlexLayout(new Version(2, 3, 0)); + Assert.NotNull(flex1); + var flex2 = ObjectFactory.DeserializeEmbeddedFlexLayout(new Version(2, 3, 0)); + Assert.NotNull(flex2); + } + [Fact] public void TestWebLayout() { diff --git a/OSGeo.MapGuide.MaestroAPI.Tests/UtilityTests.cs b/OSGeo.MapGuide.MaestroAPI.Tests/UtilityTests.cs index d50af5c7d..26f69ad39 100644 --- a/OSGeo.MapGuide.MaestroAPI.Tests/UtilityTests.cs +++ b/OSGeo.MapGuide.MaestroAPI.Tests/UtilityTests.cs @@ -28,15 +28,16 @@ namespace OSGeo.MapGuide.MaestroAPI.Tests { public class UtilityTests { - [Fact] - public void Utility_IsZero() + [Theory] + [InlineData(0.0, true)] + [InlineData(0.0f, true)] + [InlineData(0.1, false)] + [InlineData(0.1f, false)] + [InlineData(-0.1, false)] + [InlineData(-0.1f, false)] + public void Utility_IsZero(double val, bool expected) { - Assert.True(Utility.IsZero(0.0)); - Assert.True(Utility.IsZero(0.0f)); - Assert.False(Utility.IsZero(0.1)); - Assert.False(Utility.IsZero(0.1f)); - Assert.False(Utility.IsZero(-0.1)); - Assert.False(Utility.IsZero(-0.1f)); + Assert.Equal(expected, Utility.IsZero(val)); } [Fact] @@ -81,12 +82,14 @@ public void Utility_ToConnectionString() Assert.Equal("Foo=Bar;Baz=Snafu", Utility.ToConnectionString(nvc)); } - [Fact] - public void Utility_StripVersionFromProviderName() + [Theory] + [InlineData("OSGeo.SDF.4.0", "OSGeo.SDF")] + [InlineData("OSGeo.SDF.4", "OSGeo.SDF")] + [InlineData("OSGeo.SDF", "OSGeo.SDF")] + [InlineData("InvalidProviderName", "InvalidProviderName")] + public void Utility_StripVersionFromProviderName(string qualified, string expected) { - Assert.Equal("OSGeo.SDF", Utility.StripVersionFromProviderName("OSGeo.SDF.4.0")); - Assert.Equal("OSGeo.SDF", Utility.StripVersionFromProviderName("OSGeo.SDF.4")); - Assert.Equal("OSGeo.SDF", Utility.StripVersionFromProviderName("OSGeo.SDF")); + Assert.Equal(expected, Utility.StripVersionFromProviderName(qualified)); } [Fact] @@ -123,5 +126,72 @@ public void Utility_ParseQueryString() Assert.Equal("b ", param["a"]); Assert.Equal("d", param["c"]); } + + [Theory] + [InlineData("FF00FF", false)] + [InlineData("FF00FF12", false)] + [InlineData("123", true)] + [InlineData("123ADEF", true)] + public void Utility_ParseHTMLColor(string color, bool expectThrow) + { + try + { + var c = Utility.ParseHTMLColor(color); + if (expectThrow) + Assert.True(false, "This was supposed to throw"); + } + catch (Exception ex) + { + if (!expectThrow) + Assert.True(false, ex.Message); + } + } + + [Theory] + [InlineData("FF00FF", false)] + [InlineData("FF00FF12", false)] + [InlineData("123", true)] + [InlineData("123ADEF", true)] + public void Utility_ParseHTMLColorARGB(string color, bool expectThrow) + { + try + { + var c = Utility.ParseHTMLColorARGB(color); + if (expectThrow) + Assert.True(false, "This was supposed to throw"); + } + catch (Exception ex) + { + if (!expectThrow) + Assert.True(false, ex.Message); + } + } + + [Theory] + [InlineData("FF00FF", false)] + [InlineData("FF00FF12", false)] + [InlineData("123", true)] + [InlineData("123ADEF", true)] + public void Utility_ParseHTMLColorRGBA(string color, bool expectThrow) + { + try + { + var c = Utility.ParseHTMLColorRGBA(color); + if (expectThrow) + Assert.True(false, "This was supposed to throw"); + } + catch (Exception ex) + { + if (!expectThrow) + Assert.True(false, ex.Message); + } + } + + [Fact] + public void Utility_SerializeDigit() + { + Assert.Equal("1.1", Utility.SerializeDigit(1.1)); + Assert.Equal("1.1", Utility.SerializeDigit(1.1f)); + } } } diff --git a/OSGeo.MapGuide.MaestroAPI/CredentialWriter.cs b/OSGeo.MapGuide.MaestroAPI/CredentialWriter.cs index d5113a333..2f78d787c 100644 --- a/OSGeo.MapGuide.MaestroAPI/CredentialWriter.cs +++ b/OSGeo.MapGuide.MaestroAPI/CredentialWriter.cs @@ -115,7 +115,7 @@ public static Stream Write(string username, string password) { string credentials; EncryptStrings(username, password, out credentials, RESERVED_CHARACTERS_CREDENTIALS); - return new MemoryStream(ASCIIEncoding.Default.GetBytes(credentials)); + return MemoryStreamPool.GetStream("CredentialWriter.Write", ASCIIEncoding.Default.GetBytes(credentials)); } private static void EncryptStrings(string plainText1, string plainText2, out string cipherText, string reservedCharacters) diff --git a/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs b/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs index ded46df74..376fab529 100644 --- a/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs +++ b/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs @@ -173,6 +173,8 @@ public class RuntimeMap : MapObservable /// public virtual bool SupportsMutableMetersPerUnit => true; + protected internal RuntimeMap() { } //For mock support + /// /// Initializes this instance /// @@ -1213,10 +1215,13 @@ public RuntimeMapLayer[] GetLayersOfGroup(string groupName) { Check.ArgumentNotEmpty(groupName, nameof(groupName)); List layers = new List(); - foreach (var lyr in this.Layers) + if (this.Layers != null) { - if (groupName.Equals(lyr.Group)) - layers.Add(lyr); + foreach (var lyr in this.Layers) + { + if (groupName.Equals(lyr.Group)) + layers.Add(lyr); + } } return layers.ToArray(); } diff --git a/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapGroup.cs b/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapGroup.cs index 6f6e57590..65b2ae515 100644 --- a/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapGroup.cs +++ b/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapGroup.cs @@ -48,7 +48,7 @@ public static class RuntimeMapGroupType /// public class RuntimeMapGroup : MapObservable { - internal RuntimeMapGroup() + protected internal RuntimeMapGroup() { _disableChangeTracking = true; this.Group = string.Empty; diff --git a/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs b/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs index 50e66953a..b725f1cfb 100644 --- a/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs +++ b/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs @@ -188,6 +188,8 @@ protected void Initialize(ILayerDefinition ldf, bool suppressErrors) _visible = true; } + protected internal RuntimeMapLayer() { } //For mock support + /// /// Initializes this instance /// diff --git a/OSGeo.MapGuide.MaestroAPI/Utility.cs b/OSGeo.MapGuide.MaestroAPI/Utility.cs index f032fcd8d..4217ab000 100644 --- a/OSGeo.MapGuide.MaestroAPI/Utility.cs +++ b/OSGeo.MapGuide.MaestroAPI/Utility.cs @@ -306,13 +306,6 @@ public static IDictionary ParseQueryString(string queryString) .ToDictionary(s => s[0], s => s.Length > 1 ? s[1] : ""); } - /// - /// Parses a string with a decimal value in EN-US format - /// - /// The string value - /// The parsed value - public static float ParseDigit(string digit) => (float)double.Parse(digit, m_enCI); - /// /// Turns a decimal value into a string representation in EN-US format /// @@ -451,6 +444,7 @@ public static object XmlDeepCopy(object source) } } + /* /// /// Makes a deep copy of an object, by copying all the public properties. /// This overload tries to maintain object references by assigning properties @@ -539,6 +533,7 @@ public static object DeepCopy(object source) return target; } + */ /// /// Reads all data from a stream, and returns it as a single array. @@ -570,6 +565,7 @@ public static byte[] StreamAsArray(Stream s) } } + /* /// /// Serializes the given object as a UTF-8 encoded XML string. Any BOM is stripped from the XML string /// @@ -593,6 +589,7 @@ public static string NormalizedSerialize(XmlSerializer serializer, object o) } } } + */ /// /// Creates a copy of the stream, with removed Utf8 BOM, if any @@ -939,6 +936,7 @@ public static List> GetResourceIdPointers(System.X return res; } + /* /// /// Enumerates all objects by reflection, returns the list of referenced objects /// @@ -1023,6 +1021,7 @@ public static void EnumerateObjects(object obj, EnumerateObjectCallback c) } } } + */ /// /// Transforms the envelope. diff --git a/OSGeo.MapGuide.ObjectModels/IResource.cs b/OSGeo.MapGuide.ObjectModels/IResource.cs index e39050ff4..96b94f663 100644 --- a/OSGeo.MapGuide.ObjectModels/IResource.cs +++ b/OSGeo.MapGuide.ObjectModels/IResource.cs @@ -79,7 +79,7 @@ public static class ResourceExtensions public static Stream SerializeToStream(this IResource res) { string str = res.Serialize(); - return new MemoryStream(Encoding.UTF8.GetBytes(str)); + return MemoryStreamPool.GetStream("ResourceExtensions.SerializeToStream", Encoding.UTF8.GetBytes(str)); } /// diff --git a/OSGeo.MapGuide.ObjectModels/ResourceContentVersionChecker.cs b/OSGeo.MapGuide.ObjectModels/ResourceContentVersionChecker.cs index 067924d8f..ca816caf9 100644 --- a/OSGeo.MapGuide.ObjectModels/ResourceContentVersionChecker.cs +++ b/OSGeo.MapGuide.ObjectModels/ResourceContentVersionChecker.cs @@ -44,7 +44,7 @@ public sealed class ResourceContentVersionChecker : IDisposable /// The resource content stream. Inspection is done on a copy of this stream public ResourceContentVersionChecker(Stream stream) { - var ms = new MemoryStream(); + var ms = MemoryStreamPool.GetStream("ResourceContentVersionChecker.ctor"); Utils.CopyStream(stream, ms); ms.Position = 0L; //Rewind _stream = ms; @@ -57,7 +57,7 @@ public ResourceContentVersionChecker(Stream stream) /// public ResourceContentVersionChecker(string xmlContent) { - _stream = new MemoryStream(Encoding.UTF8.GetBytes(xmlContent)); + _stream = MemoryStreamPool.GetStream("ResourceContentVersionChecker.ctor", Encoding.UTF8.GetBytes(xmlContent)); } private ResourceTypeDescriptor _rtd; diff --git a/OSGeo.MapGuide.ObjectModels/ResourceTypeRegistry.cs b/OSGeo.MapGuide.ObjectModels/ResourceTypeRegistry.cs index 0e28e7929..ac2e7dd9d 100644 --- a/OSGeo.MapGuide.ObjectModels/ResourceTypeRegistry.cs +++ b/OSGeo.MapGuide.ObjectModels/ResourceTypeRegistry.cs @@ -213,7 +213,7 @@ public static IResource Deserialize(string resourceType, Stream stream) //UGLY: We have to peek inside the stream to determine the version number //House the stream inside a rewindable memory stream - using (var ms = new MemoryStream()) + using (var ms = MemoryStreamPool.GetStream("ResourceTypeRegistry.Deserialize")) { Utils.CopyStream(stream, ms); ms.Position = 0L; //Rewind