// private static dynamic ConvertReadData(AccessItemRegistration registerInfo, dynamic data) // { // return data; // } /* public static ReadData ToReadData(this ReadValue readData) * { * dynamic data = readData.DataValue.Value; * * var readData1 = new ReadData * { * Value = data, * ClientAlias = readData.ClientAlias, * }; * return readData1; * }*/ public static ReadData ToReadData(this ReadValue readData, IAccessItemRegistration reg) { dynamic data = readData.DataValue.Value; var readData1 = new ReadData { Value = DeviceConfigExtensions.Convert(data, reg), ClientAlias = readData.ClientAlias }; return(readData1); }
private static dynamic ConvertValueToServerType(IAccessItemRegistration reg, dynamic data) { var convertedValue = DeviceConfigExtensions.Convert(data, reg); var type1 = reg.Config.DataType.ToAccessDataType().ToString(); var type2 = reg.ServerDataType; if (type2 == null) { throw new Exception("registerInfo.ServerDataType==null"); } if (type2 == "System.Void") { throw new InvalidOperationException(string.Format("Device:{0}, registerInfo.ServerDataType is void", type2)); } if (type1 == type2) { return(convertedValue); } string converterTypeName = type1 + type2; if (!TypeInstances.ContainsKey(type1 + type2)) { var converterGenericType = typeof(IDataConverter <,>); var t1 = Type.GetType(type1); var t2 = Type.GetType(type2); var converterType = converterGenericType.MakeGenericType(t1, t2); TypeInstances.Add(converterTypeName, converterType); } var converterType2 = TypeInstances[converterTypeName]; dynamic converterInstance = ServiceLocator.GetInstance(converterType2); return(converterInstance.Convert(convertedValue)); }