Esempio n. 1
0
        public static void Write(IGISAttributes attributes, JsonTextWriter jwriter, string[] nonSerializedFields)
        {
            if (attributes == null)
            {
                return;
            }
            if (jwriter == null)
            {
                throw new ArgumentNullException("jwriter", "A valid JSON writer object is required.");
            }

            jwriter.WriteStartObject();

            IEnumerable <string> names = attributes.GetKeys();

            foreach (string name in names)
            {
                if (nonSerializedFields != null && Contains(nonSerializedFields, name))
                {
                    continue;
                }
                jwriter.WriteMember(name);
                jwriter.WriteString(attributes.GetValue(name).ToString());
            }

            jwriter.WriteEndObject();
        }
Esempio n. 2
0
        // Creates a SqlCommand for inserting a DataRow
        public static SqlCommand CreateInsertCommand(string tableName, string shapeFieldName, IEnumerator <DataColumn> columns, IGISAttributes feature)
        {
            if (string.IsNullOrEmpty(tableName))
            {
                throw new ArgumentNullException("tableName");
            }
            if (columns == null)
            {
                throw new ArgumentNullException("columns");
            }
            if (feature == null)
            {
                throw new ArgumentNullException("feature");
            }

            string     sql     = BuildInsertSQL(tableName, columns, shapeFieldName);
            SqlCommand command = new SqlCommand(sql);

            command.CommandType = System.Data.CommandType.Text;

            columns.Reset();
            while (columns.MoveNext())
            {
                DataColumn column = columns.Current;
                if (!column.AutoIncrement)
                {
                    string parameterName = "@" + column.ColumnName;
                    if (column.DataType == typeof(SqlGeography))
                    {
                        SqlGeography geog = feature.GetValue(column.ColumnName) as SqlGeography;
                        InsertGeographyParameter(command, parameterName, column.ColumnName, geog);
                    }
                    else if (column.DataType == typeof(SqlGeometry))
                    {
                        SqlGeometry geom = feature.GetValue(column.ColumnName) as SqlGeometry;
                        InsertGeometryParameter(command, parameterName, column.ColumnName, geom);
                    }
                    else
                    {
                        object val = feature.GetValue(column.ColumnName);
                        InsertParameter(command, parameterName, column.ColumnName, val, GetSqlDbType(column.DataType));
                    }
                }
            }

            return(command);
        }
Esempio n. 3
0
        public static void Write(IGISAttributes attributes, XmlWriter xwriter)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }
            if (xwriter == null)
            {
                throw new ArgumentNullException("xwriter");
            }

            xwriter.WriteStartElement("Attributes");

            IEnumerable <string> names = attributes.GetKeys();

            foreach (string name in names)
            {
                xwriter.WriteStartElement("item");
                //write the key
                xwriter.WriteElementString("key", name);
                //write the qualified type name of the value
                //write the value
                object value = attributes.GetValue(name);
                if (value == null)
                {
                    xwriter.WriteElementString("type", null);
                    xwriter.WriteElementString("value", null);
                }
                else
                {
                    TypeConverter typeConverter = TypeDescriptor.GetConverter(value.GetType());
                    xwriter.WriteElementString("type", value.GetType().AssemblyQualifiedName);
                    xwriter.WriteElementString("value", typeConverter.ConvertToString(value));
                }
                xwriter.WriteEndElement();
            }

            xwriter.WriteEndElement();
        }
Esempio n. 4
0
        public static void Write(IGISAttributes attributes, JsonTextWriter jwriter, string[] nonSerializedFields)
        {
            if (attributes == null)
                return;
            if (jwriter == null)
                throw new ArgumentNullException("jwriter", "A valid JSON writer object is required.");

            jwriter.WriteStartObject();

            IEnumerable<string> names = attributes.GetKeys();
            foreach (string name in names)
            {
                if (nonSerializedFields != null && Contains(nonSerializedFields, name))
                    continue;
                jwriter.WriteMember(name);
                jwriter.WriteString(attributes.GetValue(name).ToString());
            }

            jwriter.WriteEndObject();
        }