private void UpdateIsSetDisplay() { if (m_isNullable) { if (m_value == null) { chkIsNull.Checked = true; txtValue.Text = string.Empty; chkIsNull.Enabled = true; txtValue.ReadOnly = true; } else { chkIsNull.Checked = false; txtValue.Text = TypeXmlConvert.ToString(m_value); chkIsNull.Enabled = true; txtValue.ReadOnly = false; } } else { chkIsNull.Visible = false; txtValue.Text = TypeXmlConvert.ToString(m_value); txtValue.ReadOnly = false; } }
private string GetErrorMessage() { // Check required. if (m_required && (m_value == null || m_value == string.Empty)) { return("A value is required."); } if (!TypeXmlConvert.CanConvert(m_value, m_primitiveType)) { return("The text cannot be converted to the '" + m_primitiveType.ToString() + "' type."); } // Check the regular expression if there is one. if (m_regularExpression != string.Empty && m_regex != null) { if (!m_regex.IsMatch(m_value == null ? string.Empty : m_value.ToString())) { return("The value does not match the regular expression '" + m_regularExpression + "'."); } } // All is OK. return(string.Empty); }
protected override void WriteContents(XmlWriteAdaptor adaptor) { adaptor.WriteStartElement(Constants.Xml.Exception.PropertiesElement); // Write out all properties. foreach (PropertyInfo propertyInfo in PropertyInfos) { // Write an element for each property, indicating whether it is null or not. adaptor.WriteStartElement(propertyInfo.Name); object value = m_properties[propertyInfo.Name]; if (value == null) { adaptor.WriteAttribute(Constants.Xsi.Prefix, Constants.Xsi.NilAttribute, Constants.Xsi.Namespace, XmlConvert.ToString(true)); } else { adaptor.WriteElementValue(TypeXmlConvert.ToString(m_properties[propertyInfo.Name], propertyInfo.Type)); } adaptor.WriteEndElement(); } adaptor.WriteEndElement(); }
protected override bool Commit(CurrencyManager currencyManager, int rowNum) { if (m_textbox.IsInEditOrNavigateMode) { // Read only mode so remove the text box. m_textbox.Bounds = Rectangle.Empty; } else { // Hide the control because it is no longer needed. HideControl(); // Only continue if in fact editing is still happening. if (m_inEdit) { // Base the value on the validity of the control value. object value = m_control.IsValid ? m_control.Value : m_originalValue; SetColumnValueAtRow(currencyManager, rowNum, TypeXmlConvert.ToString(value)); EndEdit(); } } return(true); }
private void UpdateGuidDisplay() { EnsureVisible(guidEditor); if (TypeXmlConvert.CanConvert(m_value, PrimitiveType.Guid)) { guidEditor.Value = TypeXmlConvert.ToGuid(m_value); } }
public bool EqualsValue(object value) { if (!IsValid) { return(false); } return(Object.Equals(TypeXmlConvert.ToType(m_value, m_primitiveType), value)); }
private void UpdateBooleanDisplay() { EnsureVisible(booleanEditor); if (TypeXmlConvert.CanConvert(m_value, PrimitiveType.Boolean)) { booleanEditor.Value = TypeXmlConvert.ToBoolean(m_value); } else { booleanEditor.Value = true; } }
private void UpdateDateDisplay() { EnsureVisible(datePicker); if (TypeXmlConvert.CanConvert(m_value, PrimitiveType.Date)) { datePicker.Value = TypeXmlConvert.ToDate(m_value); } else { datePicker.Value = DatePicker.MinDate; } }
private void UpdateTimeSpanDisplay() { EnsureVisible(timeSpanPicker); if (TypeXmlConvert.CanConvert(m_value, PrimitiveType.TimeSpan)) { timeSpanPicker.Value = TypeXmlConvert.ToTimeSpan(m_value); } else { timeSpanPicker.Value = new LinkMe.Framework.Type.TimeSpan(); } }
private static EventParameter ReadPrimitiveTypeParameter(XmlReadAdaptor adaptor, string name) { // Look for a primitive type. PrimitiveTypeInfo primitiveTypeInfo = PrimitiveTypeInfo.ReadXsiTypeAttribute(adaptor); if (primitiveTypeInfo == null) { return(null); } return(new EventParameter(name, TypeXmlConvert.ToType(adaptor.ReadInnerXml(), primitiveTypeInfo.PrimitiveType))); }
private void UpdateDefaultDisplay() { EnsureVisible(txtValue); if (TypeXmlConvert.CanConvert(m_value, m_primitiveType)) { object value = TypeXmlConvert.ToType(m_value, m_primitiveType); txtValue.Text = TypeXmlConvert.ToString(value); } else { txtValue.Text = m_value; } }
private bool CanConvertToSelectedType() { if (m_value == null) { return(true); } else if (m_value is string) { return(TypeXmlConvert.CanConvert((string)m_value, m_primitiveType)); } else { return(TypeConvert.CanConvert(m_value, m_primitiveType)); } }
private void m_control_Leave(object sender, System.EventArgs e) { if (m_inEdit && !m_firstEdit) { if (m_control.IsValid) { SetColumnValueAtRow(m_currencyManager, m_currentRow, TypeXmlConvert.ToString(m_control.Value)); } m_inEdit = false; m_firstEdit = true; Invalidate(); } HideControl(); }
private string GetText(object value) { if (value == System.DBNull.Value) { return(NullText); } if (value != null && TypeXmlConvert.CanConvert((string)value, m_control.PrimitiveType)) { return(TypeXmlConvert.ToType((string)value, m_control.PrimitiveType).ToString()); } else { return(string.Empty); } }
private void booleanEditor_ValueChanged(object sender, System.EventArgs e) { if (!m_isChanging) { m_isChanging = true; try { m_value = TypeXmlConvert.ToString(booleanEditor.Value); CheckIsValid(); OnValueChanged(EventArgs.Empty); } finally { m_isChanging = false; } } }
private void WriteXml(XmlWriteAdaptor adaptor) { // Source. adaptor.WriteStartElement(Constants.Xml.SourceElement); adaptor.WriteName(_source); adaptor.WriteEndElement(); // Event. adaptor.WriteStartElement(Constants.Xml.EventElement); adaptor.WriteName(_event); adaptor.WriteEndElement(); // Type, Method, Message, Time, Sequence. adaptor.WriteElement(Constants.Xml.TypeElement, _type); adaptor.WriteElement(Constants.Xml.MethodElement, _method); adaptor.WriteElement(Constants.Xml.MessageElement, _message); // The message time is in UTC, but System.Xml.XmlConvert assumes it's local time and writes // the local timezone. Use LinkMe.Framework.Type.DateTime to avoid this. DateTime time = DateTime.FromSystemDateTime(_time, TimeZone.UTC); adaptor.WriteElement(Constants.Xml.TimeElement, TypeXmlConvert.ToString(time)); if (_sequence != 0) { adaptor.WriteElement(Constants.Xml.SequenceElement, TypeXmlConvert.ToString(_sequence)); } // Exception. if (_exception != null) { adaptor.WriteStartElement(Constants.Xml.ExceptionElement); _exception.WriteXml(adaptor.XmlWriter); adaptor.WriteEndElement(); } // Details and Parameters. WriteDetails(adaptor); WriteParameters(adaptor); }
private bool WritePrimitiveTypeParameter(XmlWriteAdaptor adaptor) { // Get the info. PrimitiveTypeInfo primitiveTypeInfo = PrimitiveTypeInfo.GetPrimitiveTypeInfo(m_value.GetType()); if (primitiveTypeInfo == null) { return(false); } // Apply the appropriate xsi:type attribute. primitiveTypeInfo.WriteXsiTypeAttribute(adaptor); // Write the value itself. adaptor.WriteElementValue(TypeXmlConvert.ToString(m_value)); return(true); }
private void ReadStandard(XmlReadAdaptor adaptor) { // Source. if (adaptor.ReadElement(Constants.Xml.SourceElement)) { _source = adaptor.ReadName(); adaptor.ReadEndElement(); } // Event. if (adaptor.ReadElement(Constants.Xml.EventElement)) { _event = adaptor.ReadName(); adaptor.ReadEndElement(); } // Type, Method, Message, Time, Sequence. _type = adaptor.ReadElementString(Constants.Xml.TypeElement, string.Empty); _method = adaptor.ReadElementString(Constants.Xml.MethodElement, string.Empty); _message = adaptor.ReadElementString(Constants.Xml.MessageElement, string.Empty); string timeXml = adaptor.ReadElementString(Constants.Xml.TimeElement, string.Empty); // The time is in the LinkMe.Framework.Type.DateTime format and should always be in UTC. DateTime time = TypeXmlConvert.ToDateTime(timeXml); Debug.Assert(time.TimeZone == TimeZone.UTC, "time.TimeZone == TimeZone.UTC"); _time = time.ToSystemDateTime(); string sequence = adaptor.ReadElementString(Constants.Xml.SequenceElement, string.Empty); _sequence = (sequence.Length == 0 ? 0 : TypeXmlConvert.ToInt32(sequence)); // Exception. _exception = ExceptionInfo.FromXml(adaptor, Constants.Xml.ExceptionElement); }
private static EventParameter CreateFromXml(string name, string className, ValueFormat format, string xml) { System.Type type = ClassInfo.GetTypeFromAssemblyQualifiedName(className); Debug.Assert(type != null, "type != null"); // Is it a primitive type? If so, the data is the raw XML value, no elements, etc. so convert it // to an object. PrimitiveTypeInfo primitiveInfo = PrimitiveTypeInfo.GetPrimitiveTypeInfo(type, false); if (primitiveInfo != null) { return(new EventParameter(name, TypeXmlConvert.ToType(xml, primitiveInfo.PrimitiveType))); } if (format == ValueFormat.SystemXml) { if (type == typeof(ulong)) { return(new EventParameter(name, XmlConvert.ToUInt64(xml))); } else if (type == typeof(uint)) { return(new EventParameter(name, XmlConvert.ToUInt32(xml))); } else if (type == typeof(ushort)) { return(new EventParameter(name, XmlConvert.ToUInt16(xml))); } else if (type == typeof(sbyte)) { return(new EventParameter(name, XmlConvert.ToSByte(xml))); } } // Not a primitive type, so the XML string is the full serialized representation. Don't deserialize it // until needed. return(new EventParameter(name, className, xml, format)); }
private object GetValue(CurrencyManager currencyManager, int row) { DataView dataView = currencyManager.List as DataView; if (dataView != null) { if (row < dataView.Count) { string value = (string)dataView[row][MappingName]; if (value != string.Empty) { return(TypeXmlConvert.ToType(value, m_control.PrimitiveType)); } } return(PrimitiveTypeInfo.GetPrimitiveTypeInfo(m_control.PrimitiveType).Default); } else { return(null); } }
protected override void ReadContents(XmlReadAdaptor adaptor) { // Read all properties. m_properties.Clear(); if (adaptor.ReadElement(Constants.Xml.Exception.PropertiesElement)) { while (adaptor.ReadElement()) { string name = adaptor.Name; // Determine whether the value is null or not. bool isNil = adaptor.ReadAttributeBoolean(Constants.Xsi.NilAttribute, Constants.Xsi.Namespace, false); if (isNil) { m_properties[name] = null; } else { string value = adaptor.GetValue(); foreach (PropertyInfo propertyInfo in PropertyInfos) { if (propertyInfo.Name == name) { SetPropertyValue(name, TypeXmlConvert.ToType(value, propertyInfo.Type)); break; } } } adaptor.ReadEndElement(); } adaptor.ReadEndElement(); } }
private ValueFormat GetDataFromBinary(out string stringValue, out byte[] binaryValue) { // We already have the binary data, but for a primitive type we want to store only the XML. In that // case unpack the value (deserialize from binary) and serialize to XML. System.Type type = ClassInfo.GetTypeFromAssemblyQualifiedName(m_class); Debug.Assert(type != null, "type != null"); if (PrimitiveTypeInfo.GetPrimitiveTypeInfo(type, false) != null) { stringValue = TypeXmlConvert.ToString(Value); binaryValue = null; return(type.Namespace == m_systemNamespace ? ValueFormat.SystemXml : ValueFormat.LinkMeXml); } else if (type == typeof(ulong) || type == typeof(uint) || type == typeof(ushort) || type == typeof(sbyte)) { stringValue = ((System.IFormattable)Value).ToString(null, NumberFormatInfo.InvariantInfo); binaryValue = null; return(ValueFormat.SystemXml); } // Not a primitive type - store the binary data. stringValue = null; binaryValue = (byte[])m_value; ValueFormat format = m_valueFormat; // Do we want the string representation as well? if (type.IsSubclassOf(typeof(System.Exception)) || type == typeof(System.Exception)) { stringValue = Value.ToString(); } return(format); }
private ValueFormat GetDataFromRawValue(out string stringValue, out byte[] binaryValue) { Debug.Assert(m_value != null, "m_value != null"); // Do we need the binary value, the string value or both? System.Type type = m_value.GetType(); PrimitiveTypeInfo primitiveTypeInfo = PrimitiveTypeInfo.GetPrimitiveTypeInfo(type, false); if (primitiveTypeInfo != null) { // Primitive type - store only the XML. stringValue = TypeXmlConvert.ToString(m_value); binaryValue = null; return(type.Namespace == m_systemNamespace ? ValueFormat.SystemXml : ValueFormat.LinkMeXml); } // Also check for the types that are not LinkMe primtive types, but can still be stored as a string // and searched. if (m_value is ulong || m_value is uint || m_value is ushort || m_value is sbyte) { stringValue = ((System.IFormattable)m_value).ToString(null, NumberFormatInfo.InvariantInfo); binaryValue = null; return(ValueFormat.SystemXml); } // Try to write to binary. Try system serialization first, then LinkMe IBinarySerializable. // DataObject fails to deserialize when user code directly calls IBinarySerializable. // The byte stream will be read by UnpackSystemBinaryParameter() or UnpackLinkMeBinaryParameter(). ValueFormat format = ValueFormat.Raw; binaryValue = null; IBinarySerializable serializable; if (type.IsSerializable) { using (MemoryStream stream = new MemoryStream()) { try { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, m_value); binaryValue = stream.ToArray(); format = ValueFormat.SystemBinary; } catch (System.Exception) { } } } else if ((serializable = m_value as IBinarySerializable) != null) { using (MemoryStream stream = new MemoryStream()) { try { BinaryWriter writer = new BinaryWriter(stream); serializable.Write(writer); binaryValue = stream.ToArray(); format = ValueFormat.LinkMeBinary; } catch (System.Exception) { } } } if (format != ValueFormat.Raw) { // All details should be in the binary data, but write the string as well for certain types, // so that they can be searched. if (m_value is System.Exception) { stringValue = m_value.ToString(); } else { stringValue = null; } } else { // We don't have the binary data, so export XML or at least the ToString() value. try { stringValue = XmlSerializer.Serialize(m_value); format = ValueFormat.LinkMeXml; // May actually be SystemXml, but doesn't matter in this case. } catch (System.Exception) { stringValue = m_value.ToString(); format = ValueFormat.String; } } Debug.Assert(format != ValueFormat.Raw, "format != ValueFormat.Raw"); return(format); }