/// <summary> /// Returns an existing unbound ClientProperty with the corresponding name /// or creates a new one if not found. /// </summary> /// <param name="name"></param> /// <param name="type"></param> /// <param name="readOnly"> /// null means we don't care and want to get back the existing property if any. /// if none is available, a read/write property is then returned. /// </param> /// <returns></returns> public WoopsaClientProperty GetProperty(string name, WoopsaValueType type, bool?readOnly = null) { WoopsaProperty result = Properties.ByNameOrNull(name); if (result != null) { if (result.Type != type) { throw new Exception(string.Format( "A property with then name '{0}' exists, but with the type {1} instead of {2}", name, result.Type, type)); } else if (readOnly != null && result.IsReadOnly != readOnly) { throw new Exception(string.Format( "A property with then name '{0}' exists, but with the readonly flag {1} instead of {2}", name, result.IsReadOnly, readOnly)); } else if (!(result is WoopsaClientProperty)) { throw new Exception(string.Format( "A property with then name '{0}' exists, but it is not of the type WoopsaClientProperty", name)); } else { return(result as WoopsaClientProperty); } } else { return(base.CreateProperty(name, type, readOnly ?? true)); } }
public WoopsaAdsProperty(WoopsaObject container, string name, WoopsaValueType type, WoopsaPropertyGet get, WoopsaPropertySet set, TcAdsSymbolInfo adsInfo) : base(container, name, type, get, set) { string[] path = adsInfo.Name.Split('.'); RootName = path[0]; AdsInfo = adsInfo; }
protected WoopsaClientProperty CreateProperty(string name, WoopsaValueType type, bool readOnly) { if (readOnly) return new WoopsaClientProperty(this, name, type, GetProperty); else return new WoopsaClientProperty(this, name, type, GetProperty, SetProperty); }
protected virtual WoopsaPropertyGet CreateWoopsaPropertyGetDelegate( WoopsaValueType publishedWoopsaPropertyType, PropertyDescription propertyDescription) { return((sender) => (propertyDescription.Converter.ToWoopsaValue( propertyDescription.PropertyInfo.GetValue(TargetObject, EmptyParameters), publishedWoopsaPropertyType, GetTimeStamp()))); }
public WoopsaMethod GetMethod(string name, WoopsaValueType returnType, WoopsaMethodArgumentInfo[] argumentInfos) { WoopsaMethod result = Methods.ByNameOrNull(name); if (result != null) { if (result.ReturnType != returnType) { throw new Exception(string.Format( "A method with then name {0} exists, but with the return type {1} instead of {2}", name, result.ReturnType, returnType)); } else if (result.ArgumentInfos.IsSame(argumentInfos)) { throw new Exception(string.Format( "A method with then name {0} exists, but with different arguments", name)); } else { return(result); } } else { return(base.CreateMethod(name, argumentInfos, returnType)); } }
/// <summary> /// Determines the WoopsaValueType based on a .NET type. /// </summary> /// <param name="targetType">The .NET type to try to get the WoopsaValueType from</param> /// <param name="resultType">The inferred WoopsaValueType. If the type cannot be inferred, this value will be WoopsaValueType.Null</param> /// <returns>true if the type could be inferred, false otherwise. A return value of false will also result in WoopsaValueType.Null</returns> public static bool InferWoopsaType(Type targetType, out WoopsaValueType resultType) { if (targetType == typeof(void)) { resultType = WoopsaValueType.Null; return(true); } else if (targetType.IsEnum) { resultType = WoopsaValueType.Text; return(true); } else { switch (System.Type.GetTypeCode(targetType)) { case TypeCode.Boolean: resultType = WoopsaValueType.Logical; return(true); case TypeCode.Byte: case TypeCode.SByte: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: resultType = WoopsaValueType.Integer; return(true); case TypeCode.Decimal: case TypeCode.Double: case TypeCode.Single: resultType = WoopsaValueType.Real; return(true); case TypeCode.DateTime: resultType = WoopsaValueType.DateTime; return(true); case TypeCode.String: resultType = WoopsaValueType.Text; return(true); default: if (targetType == typeof(TimeSpan)) { resultType = WoopsaValueType.TimeSpan; return(true); } else { resultType = WoopsaValueType.Null; return(false); } } } }
public MethodDescription(WoopsaValueType returnType, ArgumentDescriptions arguments, MethodInfo methodInfo, WoopsaConverter converter) { WoopsaReturnType = returnType; Arguments = arguments; MethodInfo = methodInfo; Converter = converter; }
public PropertyDescription(WoopsaValueType type, PropertyInfo propertyInfo, bool isReadOnly, WoopsaConverter converter) { WoopsaType = type; PropertyInfo = propertyInfo; IsReadOnly = isReadOnly; Converter = converter; }
public void RegisterConverter(Type type, WoopsaConverter converter, WoopsaValueType woopsaValueType) { _converterDescriptions[type] = new WoopsaConverterDescription() { Converter = converter, WoopsaValueType = woopsaValueType }; }
private WoopsaValue(string text, WoopsaValueType type, DateTime? timestamp) { _text = text; _type = type; _timestamp = timestamp; if (type == WoopsaValueType.JsonData) _jsonData = Woopsa.WoopsaJsonData.CreateFromText(text); }
protected virtual WoopsaPropertySet CreateWoopsaPropertySetDelegate( WoopsaValueType publishedWoopsaPropertyType, PropertyDescription propertyDescription) { return((sender, value) => propertyDescription.PropertyInfo.SetValue( TargetObject, propertyDescription.Converter.FromWoopsaValue(value, propertyDescription.PropertyInfo.PropertyType), null)); }
public WoopsaClientProperty(WoopsaBaseClientObject container, string name, WoopsaValueType type, WoopsaPropertyGet get, WoopsaPropertySet set) : base(container, name, type, get, set) { if (container == null) { throw new ArgumentNullException("container", string.Format("The argument '{0}' of the WoopsaClientProperty constructor cannot be null!", "container")); } }
private static bool MustQuote(WoopsaValueType type) { return (type != WoopsaValueType.JsonData && type != WoopsaValueType.Real && type != WoopsaValueType.Integer && type != WoopsaValueType.Logical && type != WoopsaValueType.TimeSpan); }
protected WoopsaMethod CreateMethod(string name, WoopsaMethodArgumentInfo[] argumentInfos, WoopsaValueType returnType) { return new WoopsaMethod(this, name, returnType, argumentInfos, args => Invoke(args, argumentInfos, name)); }
protected WoopsaMethod CreateMethod(string name, WoopsaMethodArgumentInfo[] argumentInfos, WoopsaValueType returnType) { return(new WoopsaMethod(this, name, returnType, argumentInfos, args => Invoke(args, argumentInfos, name))); }
public static WoopsaValue ToWoopsaValue(object value, WoopsaValueType type, DateTime?timeStamp = null) { try { switch (type) { case WoopsaValueType.Logical: return(new WoopsaValue((bool)value, timeStamp)); case WoopsaValueType.Integer: return(new WoopsaValue(Convert.ToInt64(value), timeStamp)); case WoopsaValueType.Real: return(new WoopsaValue(Convert.ToDouble(value), timeStamp)); case WoopsaValueType.DateTime: return(new WoopsaValue((DateTime)value, timeStamp)); case WoopsaValueType.TimeSpan: if (value is TimeSpan) { return(new WoopsaValue((TimeSpan)value, timeStamp)); } else { return(new WoopsaValue(TimeSpan.FromSeconds(Convert.ToDouble(value)), timeStamp)); } case WoopsaValueType.Text: if (value == null) { return(new WoopsaValue(string.Empty, timeStamp)); } else if (value.GetType().IsEnum) { return(new WoopsaValue(value.ToString(), timeStamp)); } else if (string.IsNullOrEmpty((string)value)) { return(new WoopsaValue(string.Empty, timeStamp)); } else { return(new WoopsaValue(WoopsaFormat.ToStringWoopsa(value), timeStamp)); } default: return(WoopsaValue.CreateUnchecked(WoopsaFormat.ToStringWoopsa(value), type, timeStamp)); } } catch (InvalidCastException) { throw new WoopsaException(String.Format("Cannot typecast object of type {0} to Woopsa Type {1}", value.GetType(), type.ToString())); } }
private WoopsaValue(string text, WoopsaValueType type, DateTime?timestamp) { _text = text; _type = type; _timestamp = timestamp; if (type == WoopsaValueType.JsonData) { _jsonData = Woopsa.WoopsaJsonData.CreateFromText(text); } }
protected WoopsaClientProperty CreateProperty(string name, WoopsaValueType type, bool readOnly) { if (readOnly) { return(new WoopsaClientProperty(this, name, type, GetProperty)); } else { return(new WoopsaClientProperty(this, name, type, GetProperty, SetProperty)); } }
public WoopsaMethod(WoopsaObject container, string name, WoopsaValueType returnType, IEnumerable <WoopsaMethodArgumentInfo> argumentInfos, WoopsaMethodInvoke methodInvoke) : base(container, name) { ReturnType = returnType; ArgumentInfos = argumentInfos; _methodInvoke = methodInvoke; if (container != null) { container.Add(this); } }
public bool BeckhoffToWoopsaValueType(string beckhoffType, out WoopsaValueType woopsaType) { switch (beckhoffType) { case BeckhoffValueType.BOOL: woopsaType = WoopsaValueType.Logical; break; case BeckhoffValueType.BYTE: case BeckhoffValueType.WORD: case BeckhoffValueType.DWORD: case BeckhoffValueType.SINT: case BeckhoffValueType.INT: case BeckhoffValueType.DINT: case BeckhoffValueType.LINT: case BeckhoffValueType.USINT: case BeckhoffValueType.UINT: case BeckhoffValueType.UDINT: case BeckhoffValueType.ULINT: woopsaType = WoopsaValueType.Integer; break; case BeckhoffValueType.REAL: case BeckhoffValueType.LREAL: woopsaType = WoopsaValueType.Real; break; case BeckhoffValueType.STRING: woopsaType = WoopsaValueType.Text; break; case BeckhoffValueType.TIME: woopsaType = WoopsaValueType.TimeSpan; break; case BeckhoffValueType.TIME_OF_DAY: case BeckhoffValueType.DATE: case BeckhoffValueType.DATE_AND_TIME: woopsaType = WoopsaValueType.DateTime; break; default: // specific length string in TwinCAT for example : STRING(63) if (beckhoffType.Contains("STRING(") && beckhoffType.Contains(")")) { woopsaType = WoopsaValueType.Text; return(true); } woopsaType = WoopsaValueType.Null; return(false); } return(true); }
public static WoopsaValue DeserializedJsonToWoopsaValue(object deserializedJson, WoopsaValueType type, DateTime?timeStamp = null) { if (type == WoopsaValueType.JsonData) { return(new WoopsaValue(Woopsa.WoopsaJsonData.CreateFromDeserializedData(deserializedJson))); } else { return(ToWoopsaValue(deserializedJson, type, timeStamp)); } }
public virtual bool InferWoopsaType(Type type, out WoopsaValueType woopsaValueType, out WoopsaConverter converter) { if (ConverterDescriptions.TryGetValue(type, out WoopsaConverterDescription converterDescription)) { woopsaValueType = converterDescription.WoopsaValueType; converter = converterDescription.Converter; return(true); } else { converter = WoopsaConverterDefault.Default; return(WoopsaTypeUtils.InferWoopsaType(type, out woopsaValueType)); } }
public WoopsaProperty(WoopsaObject container, string name, WoopsaValueType type, WoopsaPropertyGet get, WoopsaPropertySet set) : base(container, name) { Type = type; _get = get; IsReadOnly = set == null; if (!IsReadOnly) { _set = set; } if (container != null) { container.Add(this); } }
public bool BeckhoffToWoopsaValueType(string beckhoffType, out WoopsaValueType woopsaType) { switch (beckhoffType) { case BeckhoffValueType.BOOL: woopsaType = WoopsaValueType.Logical; break; case BeckhoffValueType.BYTE: case BeckhoffValueType.WORD: case BeckhoffValueType.DWORD: case BeckhoffValueType.SINT: case BeckhoffValueType.INT: case BeckhoffValueType.DINT: case BeckhoffValueType.LINT: case BeckhoffValueType.USINT: case BeckhoffValueType.UINT: case BeckhoffValueType.UDINT: case BeckhoffValueType.ULINT: woopsaType = WoopsaValueType.Integer; break; case BeckhoffValueType.REAL: case BeckhoffValueType.LREAL: woopsaType = WoopsaValueType.Real; break; case BeckhoffValueType.STRING: woopsaType = WoopsaValueType.Text; break; case BeckhoffValueType.TIME: woopsaType = WoopsaValueType.TimeSpan; break; case BeckhoffValueType.TIME_OF_DAY: case BeckhoffValueType.DATE: case BeckhoffValueType.DATE_AND_TIME: woopsaType = WoopsaValueType.DateTime; break; default: // specific length string in TwinCAT for example : STRING(63) if (beckhoffType.Contains("STRING(") && beckhoffType.Contains(")")) { woopsaType = WoopsaValueType.Text; return true; } woopsaType = WoopsaValueType.Null; return false; } return true; }
/// <summary> /// Determines the WoopsaValueType based on a .NET type. /// </summary> /// <param name="targetType">The .NET type to try to get the WoopsaValueType from</param> /// <param name="resultType">The inferred WoopsaValueType. If the type cannot be inferred, this value will be WoopsaValueType.Null</param> /// <returns>true if the type could be inferred, false otherwise. A return value of false will also result in WoopsaValueType.Null</returns> public static bool InferWoopsaType(Type targetType, out WoopsaValueType resultType) { if (targetType == typeof(void)) { resultType = WoopsaValueType.Null; return true; } else switch (System.Type.GetTypeCode(targetType)) { case TypeCode.Boolean: resultType = WoopsaValueType.Logical; return true; case TypeCode.Byte: case TypeCode.SByte: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: resultType = WoopsaValueType.Integer; return true; case TypeCode.Decimal: case TypeCode.Double: case TypeCode.Single: resultType = WoopsaValueType.Real; return true; case TypeCode.DateTime: resultType = WoopsaValueType.DateTime; return true; case TypeCode.String: resultType = WoopsaValueType.Text; return true; default: if (targetType == typeof(TimeSpan)) { resultType = WoopsaValueType.TimeSpan; return true; } else { resultType = WoopsaValueType.Null; return false; } } }
protected void AddWoopsaProperty(PropertyDescription propertyDescription) { WoopsaValueType publishedWoopsaPropertyType = PublishedWoopsaPropertyType(propertyDescription); if (propertyDescription.IsReadOnly) { new WoopsaProperty(this, propertyDescription.PropertyInfo.Name, publishedWoopsaPropertyType, CreateWoopsaPropertyGetDelegate(publishedWoopsaPropertyType, propertyDescription) ); } else { new WoopsaProperty(this, propertyDescription.PropertyInfo.Name, publishedWoopsaPropertyType, CreateWoopsaPropertyGetDelegate(publishedWoopsaPropertyType, propertyDescription), CreateWoopsaPropertySetDelegate(publishedWoopsaPropertyType, propertyDescription) ); } }
public static WoopsaValue CreateChecked(string text, WoopsaValueType type, DateTime?timestamp = null) { try { // Sanity check for the value passed in argument switch (type) { case WoopsaValueType.Integer: Int64.Parse(text, CultureInfo.InvariantCulture); break; case WoopsaValueType.Real: Double.Parse(text, CultureInfo.InvariantCulture); break; case WoopsaValueType.Logical: Boolean.Parse(text); text = text.ToLower(); // .NET and JSON serialize booleans differently (.NET uses a capital first letter) :/ break; case WoopsaValueType.Text: if (text == null) { text = string.Empty; } break; case WoopsaValueType.DateTime: DateTime.Parse(text, CultureInfo.InvariantCulture); break; case WoopsaValueType.TimeSpan: Double.Parse(text, CultureInfo.InvariantCulture); break; } } catch (Exception) { throw new WoopsaException(String.Format("Cannot create a WoopsaValue of type {0} from string \"{1}\"", type.ToString(), text)); } return(CreateUnchecked(text, type, timestamp)); }
/// <summary> /// Returns an existing unbound ClientProperty with the corresponding path /// or creates a new one if not found. /// </summary> /// <param name="path"></param> /// <param name="type"></param> /// <param name="readOnly"> /// null means we don't care and want to get back the existing property if any. /// if none is available, a read/write property is then returned. /// </param> /// <returns></returns> public WoopsaClientProperty GetPropertyByPath(string path, WoopsaValueType type, bool?readOnly = null) { WoopsaUnboundClientObject container; string[] pathParts = path.Split(WoopsaConst.WoopsaPathSeparator); if (pathParts.Length > 0) { container = this; for (int i = 0; i < pathParts.Length - 1; i++) { container = container.GetUnboundItem(pathParts[i]); } return(container.GetProperty(pathParts[pathParts.Length - 1], type, readOnly)); } else { throw new Exception( string.Format("The path '{0}' is not valid to referemce a property", path)); } }
public override WoopsaValue ToWoopsaValue(object value, WoopsaValueType woopsaValueType, DateTime?timeStamp) { return(WoopsaValue.ToWoopsaValue(value, woopsaValueType, timeStamp)); }
public WoopsaAdsProperty(WoopsaObject container, string name, WoopsaValueType type, WoopsaPropertyGet get, TcAdsSymbolInfo adsInfo) : this(container, name, type, get, null, adsInfo) { }
public WoopsaClientProperty(WoopsaBaseClientObject container, string name, WoopsaValueType type, WoopsaPropertyGet get, WoopsaPropertySet set) : base(container, name, type, get, set) { if (container == null) throw new ArgumentNullException("container", string.Format("The argument '{0}' of the WoopsaClientProperty constructor cannot be null!", "container")); }
public WoopsaClientProperty(WoopsaBaseClientObject container, string name, WoopsaValueType type, WoopsaPropertyGet get) : this(container, name, type, get, null) { }
/// <summary> /// Returns an existing unbound ClientProperty with the corresponding path /// or creates a new one if not found. /// </summary> /// <param name="path"></param> /// <param name="type"></param> /// <param name="readOnly"> /// null means we don't care and want to get back the existing property if any. /// if none is available, a read/write property is then returned. /// </param> /// <returns></returns> public WoopsaClientProperty GetPropertyByPath(string path, WoopsaValueType type, bool? readOnly = null) { WoopsaUnboundClientObject container; string[] pathParts = path.Split(WoopsaConst.WoopsaPathSeparator); if (pathParts.Length > 0) { container = this; for (int i = 0; i < pathParts.Length - 1; i++) container = container.GetUnboundItem(pathParts[i]); return container.GetProperty(pathParts[pathParts.Length - 1], type, readOnly); } else throw new Exception( string.Format("The path '{0}' is not valid to referemce a property", path)); }
public WoopsaValueTypeAttribute(WoopsaValueType valueType) { ValueType = valueType; }
private WoopsaValue(string text, WoopsaValueType type) : this(text, type, null) { }
internal static WoopsaValue CreateUnchecked(string text, WoopsaValueType type, DateTime?timestamp = null) { return(new WoopsaValue(text, type, timestamp)); }
public static WoopsaValue ToWoopsaValue(object value, WoopsaValueType type, DateTime? timeStamp = null) { try { switch (type) { case WoopsaValueType.Logical: return new WoopsaValue((bool)value, timeStamp); case WoopsaValueType.Integer: return new WoopsaValue(Convert.ToInt64(value), timeStamp); case WoopsaValueType.Real: return new WoopsaValue(Convert.ToDouble(value), timeStamp); case WoopsaValueType.DateTime: return new WoopsaValue((DateTime)value, timeStamp); case WoopsaValueType.TimeSpan: if (value is TimeSpan) return new WoopsaValue((TimeSpan)value, timeStamp); else return new WoopsaValue(TimeSpan.FromSeconds(Convert.ToDouble(value)), timeStamp); case WoopsaValueType.Text: if (string.IsNullOrEmpty((string)value)) return new WoopsaValue(string.Empty, timeStamp); else return new WoopsaValue(WoopsaFormat.ToStringWoopsa(value), timeStamp); default: return WoopsaValue.CreateUnchecked(WoopsaFormat.ToStringWoopsa(value), type, timeStamp); } } catch (InvalidCastException) { throw new WoopsaException(String.Format("Cannot typecast object of type {0} to Woopsa Type {1}", value.GetType(), type.ToString())); } }
public static WoopsaValue DeserializedJsonToWoopsaValue(object deserializedJson, WoopsaValueType type, DateTime? timeStamp = null) { if (type == WoopsaValueType.JsonData) return new WoopsaValue(Woopsa.WoopsaJsonData.CreateFromDeserializedData(deserializedJson)); else return ToWoopsaValue(deserializedJson, type, timeStamp); }
public static WoopsaValue CreateChecked(string text, WoopsaValueType type, DateTime? timestamp = null) { try { // Sanity check for the value passed in argument switch (type) { case WoopsaValueType.Integer: Int64.Parse(text, CultureInfo.InvariantCulture); break; case WoopsaValueType.Real: Double.Parse(text, CultureInfo.InvariantCulture); break; case WoopsaValueType.Logical: Boolean.Parse(text); text = text.ToLower(); // .NET and JSON serialize booleans differently (.NET uses a capital first letter) :/ break; case WoopsaValueType.Text: if (text == null) text = string.Empty; break; case WoopsaValueType.DateTime: DateTime.Parse(text, CultureInfo.InvariantCulture); break; case WoopsaValueType.TimeSpan: Double.Parse(text, CultureInfo.InvariantCulture); break; } } catch (Exception) { throw new WoopsaException(String.Format("Cannot create a WoopsaValue of type {0} from string \"{1}\"", type.ToString(), text)); } return CreateUnchecked(text, type, timestamp); }
public WoopsaValue(WoopsaJsonData jsonData, DateTime? timestamp = null) { _jsonData = jsonData; _type = WoopsaValueType.JsonData; _timestamp = timestamp; }
/// <summary> /// Returns an existing unbound ClientProperty with the corresponding name /// or creates a new one if not found. /// </summary> /// <param name="name"></param> /// <param name="type"></param> /// <param name="readOnly"> /// null means we don't care and want to get back the existing property if any. /// if none is available, a read/write property is then returned. /// </param> /// <returns></returns> public WoopsaClientProperty GetProperty(string name, WoopsaValueType type, bool? readOnly = null) { WoopsaProperty result = Properties.ByNameOrNull(name); if (result != null) { if (result.Type != type) throw new Exception(string.Format( "A property with then name '{0}' exists, but with the type {1} instead of {2}", name, result.Type, type)); else if (readOnly != null && result.IsReadOnly != readOnly) throw new Exception(string.Format( "A property with then name '{0}' exists, but with the readonly flag {1} instead of {2}", name, result.IsReadOnly, readOnly)); else if (!(result is WoopsaClientProperty)) throw new Exception(string.Format( "A property with then name '{0}' exists, but it is not of the type WoopsaClientProperty", name)); else return result as WoopsaClientProperty; } else return base.CreateProperty(name, type, readOnly ?? true); }
public abstract WoopsaValue ToWoopsaValue(object value, WoopsaValueType woopsaValueType, DateTime?timeStamp);
private static bool MustQuote(WoopsaValueType type) { return type != WoopsaValueType.JsonData && type != WoopsaValueType.Real && type != WoopsaValueType.Integer && type != WoopsaValueType.Logical && type != WoopsaValueType.TimeSpan; }
internal static WoopsaValue CreateUnchecked(string text, WoopsaValueType type, DateTime? timestamp = null) { return new WoopsaValue(text, type, timestamp); }
public WoopsaMethod GetMethod(string name, WoopsaValueType returnType, WoopsaMethodArgumentInfo[] argumentInfos) { WoopsaMethod result = Methods.ByNameOrNull(name); if (result != null) { if (result.ReturnType != returnType) throw new Exception(string.Format( "A method with then name {0} exists, but with the return type {1} instead of {2}", name, result.ReturnType, returnType)); else if (result.ArgumentInfos.IsSame(argumentInfos)) throw new Exception(string.Format( "A method with then name {0} exists, but with different arguments", name)); else return result; } else return base.CreateMethod(name, argumentInfos, returnType); }
public WoopsaMethodArgumentInfo(string name, WoopsaValueType type) { Name = name; Type = type; }