public void GeographyCollection_Serialize()
        {
            Dictionary <Type, object> data = new Dictionary <Type, object>();

            foreach (var sample in testData)
            {
                data.Add(SpatialTestUtil.GeographyTypeFor(sample.Key), sample.Value.Select(wkt => wktFormatter.Read <Geography>(new StringReader(wkt))).ToList());
            }

            using (TestWebRequest request = CreateCollectionReadService(data).CreateForInProcess())
            {
                System.Data.Test.Astoria.TestUtil.RunCombinations(UnitTestsUtil.ResponseFormats, (format) =>
                {
                    var response = UnitTestsUtil.GetResponseAsAtomXLinq(request, "/Entities", format);

                    // feed/entry/content/properties/CollectionGeographyPoint[@type = \"Collection(Edm.Point)\"]"
                    UnitTestsUtil.VerifyXPaths(response,
                                               testData.Keys.Select(type =>
                                                                    String.Format("atom:feed/atom:entry/atom:content/adsm:properties/ads:Collection{0}[@adsm:type = \"#Collection({1})\"]",
                                                                                  SpatialTestUtil.GeographyTypeFor(type).Name, SpatialTestUtil.GeographyEdmNameFor(type))).ToArray());

                    UnitTestsUtil.VerifyXPaths(response,
                                               testData.Select(d =>
                                                               String.Format("count(atom:feed/atom:entry/atom:content/adsm:properties/ads:Collection{0}/adsm:element) = {1}",
                                                                             SpatialTestUtil.GeographyTypeFor(d.Key).Name, d.Value.Length)).ToArray());
                });
            }
        }
示例#2
0
        private static bool TryParseSpatialLiteral <T>(string literalText, string prefix, WellKnownTextSqlFormatter formatter, out T literalValue) where T : class, ISpatial
        {
            string str;
            bool   flag2;

            if (!TryExtractWellKnownTextSqlFromSpatialLiteral(literalText, prefix, out str))
            {
                literalValue = default(T);
                return(false);
            }
            StringReader input = new StringReader(str);

            try
            {
                literalValue = formatter.Read <T>(input);
                flag2        = true;
            }
            catch (Exception exception)
            {
                if (!CommonUtil.IsCatchableExceptionType(exception))
                {
                    throw;
                }
                literalValue = default(T);
                flag2        = false;
            }
            finally
            {
                if (input != null)
                {
                    input.Dispose();
                }
            }
            return(flag2);
        }
示例#3
0
        private static bool TryParseSpatialLiteral <T>(string literalText, string prefix, WellKnownTextSqlFormatter formatter, out T literalValue) where T : class, ISpatial
        {
            string text;
            var    worked = TryExtractWellKnownTextSqlFromSpatialLiteral(literalText, prefix, out text);

            if (!worked)
            {
                literalValue = null;
                return(false);
            }

            using (var reader = new StringReader(text))
            {
                try
                {
                    literalValue = formatter.Read <T>(reader);
                    return(true);
                }
                catch (Exception e)
                {
                    if (CommonUtil.IsCatchableExceptionType(e))
                    {
                        literalValue = null;
                        return(false);
                    }

                    throw;
                }
            }
        }
示例#4
0
        internal static T ParseSpatialLiteral <T>(string literalText, string prefix, WellKnownTextSqlFormatter formatter) where T : class, ISpatial
        {
            string str;

            if (!TryExtractWellKnownTextSqlFromSpatialLiteral(literalText, prefix, out str))
            {
                str = literalText;
            }
            using (StringReader reader = new StringReader(str))
            {
                return(formatter.Read <T>(reader));
            }
        }
        /// <summary>
        /// Создаёт объект Geography.
        /// </summary>
        /// <param name="wkt">Строка в формате WKT или EWKT.</param>
        /// <returns>Объект Geography.</returns>
        public static Geography CreateGeography(this string wkt)
        {
            WellKnownTextSqlFormatter wktFormatter = WellKnownTextSqlFormatter.Create();

            return(wktFormatter.Read <Geography>(new StringReader(wkt)));
        }