Example #1
0
        /// <summary>
        /// Converts the serializable named value into a normal named value
        /// </summary>
        /// <param name="serializableNamedValue">The serializable named value</param>
        /// <returns>The value, but in types common to the rest of Taupo</returns>
        public NamedValue Convert(SerializableNamedValue serializableNamedValue)
        {
            ExceptionUtilities.CheckArgumentNotNull(serializableNamedValue, "serializableNamedValue");
            var value = serializableNamedValue.Value;

#if WIN8
            var dateTimeOffsetValue = value as Microsoft.Test.Taupo.Astoria.Contracts.WebServices.DataOracleService.Win8.DateTimeOffset;
            if (dateTimeOffsetValue != null)
            {
                value = new System.DateTimeOffset(dateTimeOffsetValue.DateTime.Year,
                                                  dateTimeOffsetValue.DateTime.Month,
                                                  dateTimeOffsetValue.DateTime.Day,
                                                  dateTimeOffsetValue.DateTime.Hour,
                                                  dateTimeOffsetValue.DateTime.Minute,
                                                  dateTimeOffsetValue.DateTime.Second,
                                                  TimeSpan.FromMinutes(dateTimeOffsetValue.OffsetMinutes));
            }
#endif
            var spatialValue = value as SerializableSpatialData;
            if (spatialValue != null)
            {
                ExceptionUtilities.CheckObjectNotNull(this.SpatialFormatter, "Cannot convert spatial data without SpatialFormatter dependency being set");

                var spatialTypeKind = SpatialUtilities.InferSpatialTypeKind(spatialValue.BaseTypeName);
                value = this.SpatialFormatter.Parse(spatialTypeKind, spatialValue.WellKnownTextRepresentation);
            }
            else if (value is SerializableEmptyData)
            {
                value = EmptyData.Value;
            }

            return(new NamedValue(serializableNamedValue.Name, value));
        }
        /// <summary>
        /// Handles spatial primitives before delegating to the base type
        /// </summary>
        /// <param name="value">The primitive value to serialize</param>
        /// <param name="capitalizeIdentifiers">if set to <c>true</c> then identifiers for decimal, double, etc should be capitalized.</param>
        /// <returns>
        /// The wire representation of the primitive
        /// </returns>
        public string SerializePrimitive(object value, bool capitalizeIdentifiers)
        {
            if (value == null)
            {
                return(this.SerializeNull());
            }

            string wellKnownText = null;

            if (this.SpatialFormatter.IfValid(false, f => this.SpatialFormatter.TryConvert(value, out wellKnownText)))
            {
                var    kind = SpatialUtilities.InferSpatialTypeKind(value.GetType());
                string prefix;
                ExceptionUtilities.Assert(spatialLiteralPrefixMap.TryGetValue(kind, out prefix), "Could not find prefix for spatial type kind '{0}'", kind);
                return(prefix + '\'' + wellKnownText + '\'');
            }

            bool oldCapitalizeValue = this.shouldCapitalizeIdentifiers;

            try
            {
                this.shouldCapitalizeIdentifiers = capitalizeIdentifiers;
                return(base.SerializePrimitive(value));
            }
            finally
            {
                this.shouldCapitalizeIdentifiers = oldCapitalizeValue;
            }
        }
Example #3
0
        /// <summary>
        /// Converts the serializable named value into a normal named value
        /// </summary>
        /// <param name="serializableNamedValue">The serializable named value</param>
        /// <returns>The value, but in types common to the rest of Taupo</returns>
        public NamedValue Convert(SerializableNamedValue serializableNamedValue)
        {
            ExceptionUtilities.CheckArgumentNotNull(serializableNamedValue, "serializableNamedValue");
            var value        = serializableNamedValue.Value;
            var spatialValue = value as SerializableSpatialData;

            if (spatialValue != null)
            {
                ExceptionUtilities.CheckObjectNotNull(this.SpatialFormatter, "Cannot convert spatial data without SpatialFormatter dependency being set");

                var spatialTypeKind = SpatialUtilities.InferSpatialTypeKind(spatialValue.BaseTypeName);
                value = this.SpatialFormatter.Parse(spatialTypeKind, spatialValue.WellKnownTextRepresentation);
            }
            else if (value is SerializableEmptyData)
            {
                value = EmptyData.Value;
            }

            return(new NamedValue(serializableNamedValue.Name, value));
        }