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; } }
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 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 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 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 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); }