/////////////////////////////////////////////////////////////////////// #region ICloneable Members /// <summary> /// Creates a deep copy of the object. /// </summary> public virtual object Clone() { TsCAeAttributeValue clone = (TsCAeAttributeValue)MemberwiseClone(); clone.Value = OpcConvert.Clone(Value); return(clone); }
/// <summary> /// Initializes object with the specified ItemValue object. /// </summary> public TsCDaItemValue(TsCDaItemValue item) : base(item) { if (item == null) { return; } Value = OpcConvert.Clone(item.Value); Quality = item.Quality; QualitySpecified = item.QualitySpecified; Timestamp = item.Timestamp; TimestampSpecified = item.TimestampSpecified; }
/// <summary> /// Initializes the object with the specified URL and COM server. /// </summary> internal Subscription(TsCAeSubscriptionState state, object subscription) { subscription_ = subscription; clientHandle_ = OpcConvert.Clone(state.ClientHandle); supportsAe11_ = true; callback_ = new Callback(state.ClientHandle); // check if the V1.1 interfaces are supported. try { IOPCEventSubscriptionMgt2 server = (IOPCEventSubscriptionMgt2)subscription_; } catch { supportsAe11_ = false; } }
/// <summary> /// Converts a value to the specified type using the specified locale. /// </summary> protected object ChangeType(object source, Type type, string locale) { CultureInfo culture = Thread.CurrentThread.CurrentCulture; // override the current thread culture to ensure conversions happen correctly. try { Thread.CurrentThread.CurrentCulture = new CultureInfo(locale); } catch { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); } try { object result = OpcConvert.ChangeType(source, type); // check for overflow converting to float. if (typeof(Single) == type) { if (Single.IsInfinity(Convert.ToSingle(result))) { throw new OverflowException(); } } return(result); } // restore the current thread culture after conversion. finally { Thread.CurrentThread.CurrentCulture = culture; } }
/////////////////////////////////////////////////////////////////////// #region Private Methods /// <summary> /// Reads an instance of a type from the buffer, /// </summary> private int ReadType(TsCCpxContext context, out TsCCpxComplexValue complexValue) { complexValue = null; TypeDescription type = context.Type; int startIndex = context.Index; byte bitOffset = 0; ArrayList fieldValues = new ArrayList(); for (int ii = 0; ii < type.Field.Length; ii++) { FieldType field = type.Field[ii]; TsCCpxComplexValue fieldValue = new TsCCpxComplexValue { Name = (field.Name != null && field.Name.Length != 0) ? field.Name : String.Format("[{0}]", ii), Type = null, Value = null }; // check if additional padding is required after the end of a bit field. if (bitOffset != 0) { if (field.GetType() != typeof(BitString)) { context.Index++; bitOffset = 0; } } int bytesRead = 0; if (IsArrayField(field)) { bytesRead = ReadArrayField(context, field, ii, fieldValues, out fieldValue.Value); } else if (field.GetType() == typeof(TypeReference)) { object typeValue = null; bytesRead = ReadField(context, (TypeReference)field, out typeValue); // assign a name appropriate for the current context. fieldValue.Name = field.Name; fieldValue.Type = ((TsCCpxComplexValue)typeValue).Type; fieldValue.Value = ((TsCCpxComplexValue)typeValue).Value; } else { bytesRead = ReadField(context, field, ii, fieldValues, out fieldValue.Value, ref bitOffset); } if (bytesRead == 0 && bitOffset == 0) { throw new TsCCpxInvalidDataInBufferException(String.Format("Could not read field '{0}' in type '{1}'.", field.Name, type.TypeID)); } context.Index += bytesRead; // assign a value for field type. if (fieldValue.Type == null) { fieldValue.Type = OpcConvert.ToString(fieldValue.Value.GetType()); } fieldValues.Add(fieldValue); } // skip padding bits at the end of a type. if (bitOffset != 0) { context.Index++; } complexValue = new TsCCpxComplexValue(); complexValue.Name = type.TypeID; complexValue.Type = type.TypeID; complexValue.Value = (TsCCpxComplexValue[])fieldValues.ToArray(typeof(TsCCpxComplexValue)); return(context.Index - startIndex); }
/// <summary> /// Returns a copy of the collection as an array. /// </summary> public new int[] ToArray() { return((int[])OpcConvert.Clone(Array)); }
/// <summary> /// Returns a copy of the collection as an array. /// </summary> public new string[] ToArray() { return((string[])OpcConvert.Clone(Array)); }
/// <summary> /// Returns a copy of the collection as an array. /// </summary> public new TsCAeItemUrl[] ToArray() { return((TsCAeItemUrl[])OpcConvert.Clone(Array)); }