예제 #1
0
        public static NpgsqlPath Parse(string s)
        {
            bool open;

            switch (s[0])
            {
            case '[':
                open = true;
                break;

            case '(':
                open = false;
                break;

            default:
                throw new Exception("Invalid path string: " + s);
            }
            Contract.Assume(s[s.Length - 1] == (open ? ']' : ')'));
            var result = new NpgsqlPath(open);
            var i      = 1;

            while (true)
            {
                var i2 = s.IndexOf(')', i);
                result.Add(NpgsqlPoint.Parse(s.Substring(i, i2 - i + 1)));
                if (s[i2 + 1] != ',')
                {
                    break;
                }
                i = i2 + 2;
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Path.
        /// </summary>
        internal static Object ToPath(NpgsqlBackendTypeInfo TypeInfo, String BackendData, Int16 TypeSize, Int32 TypeModifier)
        {
            Match     m      = pathpolygonRegex.Match(BackendData);
            Boolean   open   = (BackendData[0] == '[');
            ArrayList points = new ArrayList();

            while (m.Success)
            {
                if (open)
                {
                    points.Add(new NpgsqlPoint(
                                   Single.Parse(m.Groups[1].ToString(), NumberStyles.Any,
                                                CultureInfo.InvariantCulture.NumberFormat),
                                   Single.Parse(m.Groups[2].ToString(), NumberStyles.Any,
                                                CultureInfo.InvariantCulture.NumberFormat)));
                }
                else
                {
                    // Here we have to do a little hack, because as of 2004-08-11 mono cvs version, the last group is returned with
                    // a trailling ')' only when the last character of the string is a ')' which is the case for closed paths
                    // returned by backend. This gives parsing exception when converting to single.
                    // I still don't know if this is a bug in mono or in my regular expression.
                    // Check if there is this character and remove it.

                    String group2 = m.Groups[2].ToString();
                    if (group2.EndsWith(")"))
                    {
                        group2 = group2.Remove(group2.Length - 1, 1);
                    }

                    points.Add(new NpgsqlPoint(
                                   Single.Parse(m.Groups[1].ToString(), NumberStyles.Any,
                                                CultureInfo.InvariantCulture.NumberFormat),
                                   Single.Parse(group2, NumberStyles.Any,
                                                CultureInfo.InvariantCulture.NumberFormat)));
                }

                m = m.NextMatch();
            }

            NpgsqlPath result = new NpgsqlPath((NpgsqlPoint[])points.ToArray(typeof(NpgsqlPoint)));

            result.IsOpen = open;
            return(result);
        }
예제 #3
0
 public bool Equals(NpgsqlPath other)
 {
     if (Open != other.Open || Count != other.Count)
     {
         return(false);
     }
     else if (ReferenceEquals(_points, other._points))//Short cut for shallow copies.
     {
         return(true);
     }
     for (int i = 0; i != Count; ++i)
     {
         if (this[i] != other[i])
         {
             return(false);
         }
     }
     return(true);
 }
예제 #4
0
        public void Path()
        {
            var expectedOpen = new NpgsqlPath(new[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }, true);
            var expectedClosed = new NpgsqlPath(new[] { new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4) }, false);
            var cmd = new NpgsqlCommand("SELECT @p1, @p2, @p3", Conn);
            var p1 = new NpgsqlParameter("p1", NpgsqlDbType.Path) { Value = expectedOpen };
            var p2 = new NpgsqlParameter("p2", NpgsqlDbType.Path) { Value = expectedClosed };
            var p3 = new NpgsqlParameter { ParameterName = "p3", Value = expectedClosed };
            Assert.That(p3.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Path));
            cmd.Parameters.Add(p1);
            cmd.Parameters.Add(p2);
            cmd.Parameters.Add(p3);
            var reader = cmd.ExecuteReader();
            reader.Read();

            for (var i = 0; i < cmd.Parameters.Count; i++)
            {
                var expected = i == 0 ? expectedOpen : expectedClosed;
                Assert.That(reader.GetFieldType(i), Is.EqualTo(typeof(NpgsqlPath)));
                Assert.That(reader[i], Is.EqualTo(expected));
            }
        }
        /// <summary>
        /// Path.
        /// </summary>
        internal static Object ToPath(NpgsqlBackendTypeInfo TypeInfo, byte[] bBackendData, Int16 TypeSize, Int32 TypeModifier)
        {
            string BackendData = BackendEncoding.UTF8Encoding.GetString(bBackendData);
            Match m = pathpolygonRegex.Match(BackendData);
            Boolean open = (BackendData[0] == '[');
            List<NpgsqlPoint> points = new List<NpgsqlPoint>();

            while (m.Success)
            {
                if (open)
                {
                    points.Add(
                        new NpgsqlPoint(
                            Single.Parse(m.Groups[1].ToString(), NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat),
                            Single.Parse(m.Groups[2].ToString(), NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat)));
                }
                else
                {
                    // Here we have to do a little hack, because as of 2004-08-11 mono cvs version, the last group is returned with
                    // a trailling ')' only when the last character of the string is a ')' which is the case for closed paths
                    // returned by backend. This gives parsing exception when converting to single.
                    // I still don't know if this is a bug in mono or in my regular expression.
                    // Check if there is this character and remove it.

                    String group2 = m.Groups[2].ToString();
                    if (group2.EndsWith(")"))
                    {
                        group2 = group2.Remove(group2.Length - 1, 1);
                    }

                    points.Add(
                        new NpgsqlPoint(
                            Single.Parse(m.Groups[1].ToString(), NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat),
                            Single.Parse(group2, NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat)));
                }

                m = m.NextMatch();
            }

            NpgsqlPath result = new NpgsqlPath(points.ToArray());
            result.Open = open;
            return result;
        }
예제 #6
0
        public void Path()
        {
            using (var conn = OpenConnection())
            {
                var expectedOpen = new NpgsqlPath(new[] {new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4)}, true);
                var expectedClosed = new NpgsqlPath(new[] {new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4)}, false);
                var cmd = new NpgsqlCommand("SELECT @p1, @p2, @p3", conn);
                var p1 = new NpgsqlParameter("p1", NpgsqlDbType.Path) {Value = expectedOpen};
                var p2 = new NpgsqlParameter("p2", NpgsqlDbType.Path) {Value = expectedClosed};
                var p3 = new NpgsqlParameter {ParameterName = "p3", Value = expectedClosed};
                Assert.That(p3.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Path));
                cmd.Parameters.Add(p1);
                cmd.Parameters.Add(p2);
                cmd.Parameters.Add(p3);
                using (var reader = cmd.ExecuteReader())
                {
                    reader.Read();

                    for (var i = 0; i < cmd.Parameters.Count; i++)
                    {
                        var expected = i == 0 ? expectedOpen : expectedClosed;
                        Assert.That(reader.GetFieldType(i), Is.EqualTo(typeof(NpgsqlPath)));
                        var actual = reader.GetFieldValue<NpgsqlPath>(i);
                        Assert.That(actual.Open, Is.EqualTo(expected.Open));
                        Assert.That(actual, Has.Count.EqualTo(expected.Count));
                        for (var j = 0; j < actual.Count; j++)
                            AssertPointsEqual(actual[j], expected[j]);
                    }
                }
            }
        }
        /// <summary>
        /// Path.
        /// </summary>
        internal static Object ToPath(NpgsqlBackendTypeInfo TypeInfo, String BackendData, Int16 TypeSize, Int32 TypeModifier)
        {
        	   	
        	Match m = pathpolygonRegex.Match(BackendData);
        	Boolean open = (BackendData[0] == '['); 
        	ArrayList points = new ArrayList();
        	    	
        	while (m.Success)
        	{
        		
        		if (open)
        			points.Add(new NpgsqlPoint(Single.Parse(m.Groups[1].ToString()), Single.Parse(m.Groups[2].ToString())));
        		else
        		{
        			// Here we have to do a little hack, because as of 2004-08-11 mono cvs version, the last group is returned with
        			// a trailling ')' only when the last character of the string is a ')' which is the case for closed paths
					// returned by backend. This gives parsing exception when converting to single. 
					// I still don't know if this is a bug in mono or in my regular expression.
        			// Check if there is this character and remove it.
        			
        			String group2 = m.Groups[2].ToString();
        			if (group2.EndsWith(")"))
        				group2 = group2.Remove(group2.Length - 1, 1);
        				
        			points.Add(new NpgsqlPoint(Single.Parse(m.Groups[1].ToString()), Single.Parse(group2)));
        		}
        			
        		m = m.NextMatch();
        		
        	}
        	
        	NpgsqlPath result = new NpgsqlPath((NpgsqlPoint[]) points.ToArray(typeof(NpgsqlPoint)));
			result.IsOpen = open; 
        	return result;
        	
            
        }