/// <summary>
        /// Get web data field as string.
        /// </summary>
        /// <param name="dataField">Data field.</param>
        /// <returns>Web data field as string.</returns>
        public static String WebToString(this WebDataField dataField)
        {
            StringBuilder stringBuilder;

            if (dataField.IsNull())
            {
                return(String.Empty);
            }
            else
            {
                stringBuilder = new StringBuilder();
                stringBuilder.Append("Data field:");
                if (dataField.Information.IsNotEmpty())
                {
                    stringBuilder.Append(" Information = [" + dataField.Information + "],");
                }

                stringBuilder.Append(" Name = " + dataField.Name);
                stringBuilder.Append(", Type = " + dataField.Type);
                if (dataField.Unit.IsNotEmpty())
                {
                    stringBuilder.Append(", Unit = [" + dataField.Unit + "]");
                }

                stringBuilder.Append(", Value = [" + dataField.Value + "]");
                return(stringBuilder.ToString());
            }
        }
Exemple #2
0
        /// <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 + "!");
            }
        }
 /// <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 + ".");
     }
 }
Exemple #4
0
        /// <summary>
        /// Load all unread columns as WebDataFields into this WebData.
        /// </summary>
        /// <param name='data'>Data object.</param>
        /// <param name='dataReader'>An open DataReader.</param>
        public static void LoadData(this WebData data, DataReader dataReader)
        {
            WebDataField dataField;

            if (dataReader.NextUnreadColumn())
            {
                data.DataFields = new List <WebDataField>();
                do
                {
                    dataField = new WebDataField();
                    dataField.LoadData(dataReader);
                    data.DataFields.Add(dataField);
                }while (dataReader.NextUnreadColumn());
            }
        }
 /// <summary>
 /// Get an Int64 value from the data field.
 /// </summary>
 /// <param name='dataField'>Data field object.</param>
 /// <returns>An Int64 value</returns>
 public static Int64 GetInt64(this WebDataField dataField)
 {
     dataField.CheckDataType(WebDataType.Int64);
     return(dataField.Value.WebParseInt64());
 }
 /// <summary>
 /// Get a Double value from the data field.
 /// </summary>
 /// <param name='dataField'>Data field object.</param>
 /// <returns>An Double value</returns>
 public static Double GetFloat64(this WebDataField dataField)
 {
     dataField.CheckDataType(WebDataType.Float64);
     return(dataField.Value.WebParseDouble());
 }
 /// <summary>
 /// Get a DateTime value from the data field.
 /// </summary>
 /// <param name='dataField'>Data field object.</param>
 /// <returns>An DateTime value</returns>
 public static DateTime GetDateTime(this WebDataField dataField)
 {
     dataField.CheckDataType(WebDataType.DateTime);
     return(dataField.Value.WebParseDateTime());
 }
 /// <summary>
 /// Get a Boolean value from the data field.
 /// </summary>
 /// <param name='dataField'>Data field object.</param>
 /// <returns>An Boolean value</returns>
 public static Boolean GetBoolean(this WebDataField dataField)
 {
     dataField.CheckDataType(WebDataType.Boolean);
     return(dataField.Value.WebParseBoolean());
 }
 /// <summary>
 /// Check that data is valid.
 /// </summary>
 /// <param name='dataField'>Data field object.</param>
 public static void CheckData(this WebDataField dataField)
 {
     dataField.Name  = dataField.Name.CheckInjection();
     dataField.Unit  = dataField.Unit.CheckInjection();
     dataField.Value = dataField.Value.CheckInjection();
 }
        /// <summary>
        /// Load data into WebDataField.
        /// </summary>
        /// <param name='dataField'>Data field object.</param>
        /// <param name='dataReader'>An open data reader.</param>
        public static void LoadData(this WebDataField dataField,
                                    DataReader dataReader)
        {
            String type;

            dataField.Name  = dataReader.GetUnreadColumnName();
            dataField.Value = null;
            type            = dataReader.GetUnreadColumnType().ToString();
            switch (type)
            {
            case "System.Boolean":
                dataField.Type = WebDataType.Boolean;
                if (dataReader.IsNotDbNull(dataField.Name))
                {
                    dataField.Value = dataReader.GetBoolean(dataField.Name).WebToString();
                }
                break;

            case "System.DateTime":
                dataField.Type = WebDataType.DateTime;
                if (dataReader.IsNotDbNull(dataField.Name))
                {
                    dataField.Value = dataReader.GetDateTime(dataField.Name).WebToString();
                }
                break;

            case "System.Double":
            case "System.Single":
                dataField.Type = WebDataType.Float64;
                if (dataReader.IsNotDbNull(dataField.Name))
                {
                    dataField.Value = dataReader.GetDouble(dataField.Name).WebToString();
                }
                break;

            case "System.Byte":
            case "System.SByte":
            case "System.Int16":
            case "System.UInt16":
                dataField.Type = WebDataType.Int32;
                if (dataReader.IsNotDbNull(dataField.Name))
                {
                    dataField.Value = dataReader.GetInt16(dataField.Name).WebToString();
                }
                break;

            case "System.Int32":
            case "System.UInt32":
                dataField.Type = WebDataType.Int32;
                if (dataReader.IsNotDbNull(dataField.Name))
                {
                    dataField.Value = dataReader.GetInt32(dataField.Name).WebToString();
                }
                break;

            case "System.Int64":
            case "System.UInt64":
                dataField.Type = WebDataType.Int64;
                if (dataReader.IsNotDbNull(dataField.Name))
                {
                    dataField.Value = dataReader.GetInt64(dataField.Name).WebToString();
                }
                break;

            default:
                dataField.Type = WebDataType.String;
                if (dataReader.IsNotDbNull(dataField.Name))
                {
                    dataField.Value = dataReader.GetString(dataField.Name);
                }
                break;
            }
        }
 /// <summary>
 /// Get an String value from the data field with the specified name.
 /// </summary>
 /// <param name='dataField'>Data field object.</param>
 /// <returns>An String value</returns>
 public static String GetString(this WebDataField dataField)
 {
     dataField.CheckDataType(WebDataType.String);
     return(dataField.Value);
 }