public static WebDataField GetOneDataField(WebDataType dataType) { WebDataField dataField; dataField = new WebDataField(); dataField.Name = "Test"; dataField.Type = dataType; switch (dataType) { case WebDataType.Boolean: dataField.Value = true.WebToString(); break; case WebDataType.DateTime: dataField.Value = DateTime.Now.WebToString(); break; case WebDataType.Float64: dataField.Value = Math.PI.WebToString(); break; case WebDataType.Int32: dataField.Value = Int32.MaxValue.WebToString(); break; case WebDataType.Int64: dataField.Value = Int64.MaxValue.WebToString(); break; case WebDataType.String: dataField.Value = "Testing"; break; } return(dataField); }
/// <summary> /// Get a DataField with the specified name. /// </summary> /// <param name='dataFields'>The WebDataField list.</param> /// <param name='fieldName'>Name of field to get.</param> /// <param name='create'>If true, DataField is created if it was not found.</param> /// <param name='dataType'>Data type of the field. This parameter is only used if a field is created.</param> /// <exception cref="ArgumentException">Thrown if no field was found.</exception> private static WebDataField GetDataField(this List <WebDataField> dataFields, String fieldName, Boolean create, WebDataType dataType) { if (dataFields.IsNotEmpty()) { foreach (WebDataField dataField in dataFields) { if (dataField.Name == fieldName) { return(dataField); } } } if (create) { WebDataField dataField; dataField = new WebDataField(); dataField.Name = fieldName; dataField.Type = dataType; dataFields.Add(dataField); return(dataField); } else { // No field with specified name. throw new ArgumentException("No data field with name " + fieldName + "!"); } }
public void Type() { const WebDataType dataType = WebDataType.Boolean; GetObject(true).Type = dataType; Assert.AreEqual(GetObject().Type, dataType); }
/// <summary> /// Create a SpeciesFactFieldCondition instance. /// </summary> public SpeciesFactFieldCondition() { _operator = DataConditionOperatorId.Equal; FactorField = null; IsEnumAsString = false; _type = WebDataType.String; _value = null; }
/// <summary> /// Check if the WebDataField is of the expected type. /// </summary> /// <param name='dataField'>Data field object.</param> /// <param name='type'>Expected data type.</param> private static void CheckDataType(this WebDataField dataField, WebDataType type) { if (dataField.Type != type) { throw new ArgumentException("Wrong data type in WebDataField " + dataField.Name + ". " + "Expected data type = " + type + ". Actual data type = " + dataField.Type + "."); } }
/// <summary> /// Set Double value. /// </summary> /// <param name="value">A Double value.</param> public void SetValue(Double value) { _type = WebDataType.Float; _value = value.WebToString(); }
/// <summary> /// Set DateTime value. /// </summary> /// <param name="value">A DateTime value.</param> public void SetValue(DateTime value) { _type = WebDataType.DateTime; _value = value.WebToString(); }
/// <summary> /// Set Boolean value. /// </summary> /// <param name="value">A Boolean value.</param> public void SetValue(Boolean value) { _type = WebDataType.Boolean; _value = value.WebToString(); }
/// <summary> /// Set String value. /// </summary> /// <param name="value">A String value.</param> public void SetValue(String value) { _type = WebDataType.String; _value = value; }
/// <summary> /// Set Int64 value. /// </summary> /// <param name="value">A Int32 value.</param> public void SetValue(Int64 value) { _type = WebDataType.Int64; _value = value.WebToString(); }
/// <summary> /// Convert one species observation field value from JSON to /// class WebSpeciesObservationField. /// </summary> /// <param name="value">Field value is returned in this parameter.</param> /// <param name="type">Field value is of this type.</param> /// <param name="speciesObservationsJson">Species observation field in JSON format.</param> /// <param name="startIndex">Current position in the species observation JSON string.</param> /// <returns>Updated current position in the species observation JSON string.</returns> private Int32 GetSpeciesObservationFieldValue(out String value, WebDataType type, String speciesObservationsJson, Int32 startIndex) { Boolean stringEndFound; Int32 stopIndex; switch (type) { case WebDataType.Boolean: switch (speciesObservationsJson.Substring(startIndex, 4)) { case "fals": value = Boolean.FalseString; startIndex += 6; break; case "true": value = Boolean.TrueString; startIndex += 5; break; default: throw new Exception("Not handled boolean data type value = " + speciesObservationsJson.Substring(startIndex, 4)); } break; case WebDataType.DateTime: stopIndex = speciesObservationsJson.IndexOf('\"', startIndex + 1); value = speciesObservationsJson.Substring(startIndex + 1, stopIndex - startIndex - 1); startIndex = stopIndex + 2; break; case WebDataType.Float64: stopIndex = speciesObservationsJson.IndexOfAny(new[] { ',', '}' }, startIndex); value = speciesObservationsJson.Substring(startIndex, stopIndex - startIndex); // Convert float value from Elasticsearch // format to SOAP web service format. value = value.WebParseDouble().WebToString(); startIndex = stopIndex + 1; break; case WebDataType.Int32: case WebDataType.Int64: stopIndex = speciesObservationsJson.IndexOfAny(new[] { ',', '}' }, startIndex); value = speciesObservationsJson.Substring(startIndex, stopIndex - startIndex); startIndex = stopIndex + 1; break; case WebDataType.String: stopIndex = startIndex + 1; stringEndFound = false; while (!stringEndFound) { stringEndFound = (speciesObservationsJson[stopIndex] == '"') && (speciesObservationsJson[stopIndex - 1] != '\\'); if (!stringEndFound) { stopIndex++; } } value = speciesObservationsJson.Substring(startIndex + 1, stopIndex - startIndex - 1); startIndex = stopIndex + 2; // Remove escape of special characters. value = value.Replace("\\\"", "\""); value = value.Replace("\\\\", "\\"); break; default: throw new Exception("Not handled data type = " + type); } return(startIndex); }