147 lines
4.7 KiB
C#
147 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml;
|
|
|
|
namespace XYLEM.Device.Value
|
|
{
|
|
public static class ValueDescriptionFunc
|
|
{
|
|
/// <summary>
|
|
/// Is data a text
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static Boolean IsText(this ValueDataType DataType)
|
|
{
|
|
switch (DataType)
|
|
{
|
|
case ValueDataType._Empty:
|
|
case ValueDataType.B8:
|
|
case ValueDataType.S8:
|
|
case ValueDataType.U8:
|
|
case ValueDataType.Bool:
|
|
case ValueDataType.U16:
|
|
case ValueDataType.U16MJK_SN:
|
|
case ValueDataType.U16MJK_BRAND_ID:
|
|
case ValueDataType.B16:
|
|
case ValueDataType.S16:
|
|
case ValueDataType.B32:
|
|
case ValueDataType.U32:
|
|
case ValueDataType.U32MJK_SN:
|
|
case ValueDataType.S32:
|
|
case ValueDataType.F32:
|
|
case ValueDataType.B64:
|
|
case ValueDataType.U64:
|
|
case ValueDataType.S64:
|
|
case ValueDataType.F64:
|
|
case ValueDataType.U128:
|
|
case ValueDataType.U16TEXTID:
|
|
case ValueDataType.U16UNIT:
|
|
case ValueDataType.U16UNITGROUP:
|
|
case ValueDataType.U32TIME_Y2000:
|
|
case ValueDataType.U32TIME_Y1970:
|
|
case ValueDataType.U32TIME_Y1970_UTC:
|
|
case ValueDataType.TIME_ASCII_12B:
|
|
case ValueDataType.TIME_ymdhms:
|
|
case ValueDataType.Array6B:
|
|
case ValueDataType.Array10B:
|
|
case ValueDataType.Array12B:
|
|
case ValueDataType.Array64B:
|
|
case ValueDataType.Array128B:
|
|
case ValueDataType.Array136B:
|
|
case ValueDataType.Array250B:
|
|
return false;
|
|
default:
|
|
if (DataType.ToString().StartsWith("STR"))
|
|
{
|
|
return true; // Is text
|
|
}
|
|
throw (new Exception("No known tag = " + DataType.ToString()));
|
|
}
|
|
}
|
|
|
|
public static bool IsSMSText(this ValueDataType DataType)
|
|
{
|
|
if (DataType.IsText())
|
|
{
|
|
var typeAsText = DataType.ToString();
|
|
if (typeAsText.EndsWith("S"))
|
|
{ // is Email
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static bool IsEmailText(this ValueDataType DataType)
|
|
{
|
|
if (DataType.IsText())
|
|
{
|
|
var typeAsText = DataType.ToString();
|
|
if (typeAsText.EndsWith("E"))
|
|
{ // is Email
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Conversion has to be for string Quoted Printable Text
|
|
/// </summary>
|
|
/// <param name="DataType"></param>
|
|
/// <returns></returns>
|
|
public static bool IsEmailQuotedPrintableText(this ValueDataType DataType)
|
|
{
|
|
if (DataType.IsText())
|
|
{
|
|
var typeAsText = DataType.ToString();
|
|
if (typeAsText.EndsWith("Q"))
|
|
{ // is Email
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Conversion type for string is Windows 1252
|
|
/// </summary>
|
|
/// <param name="DataType"></param>
|
|
/// <returns></returns>
|
|
public static bool IsWindows1252Text(this ValueDataType DataType)
|
|
{
|
|
if (DataType.IsText())
|
|
{
|
|
var typeAsText = DataType.ToString();
|
|
if (typeAsText.EndsWith("W1252"))
|
|
{ // is Email
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Conversion type for string is Windows 1252 and for the email recipient address that needs special handling
|
|
/// Needs to have "<>" in frond and end
|
|
/// </summary>
|
|
/// <param name="DataType"></param>
|
|
/// <returns></returns>
|
|
public static bool IsWindows1252TextRecipient(this ValueDataType DataType)
|
|
{
|
|
if (DataType.IsText())
|
|
{
|
|
var typeAsText = DataType.ToString();
|
|
if (typeAsText.EndsWith("W1252rec"))
|
|
{ // is Email
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|