Author |
Topic: Persisting Fonts, Colors and Custom Data Objects (4 messages, Page 1 of 1) |
||||
---|---|---|---|---|---|
Moderators: VPfau | |||||
PDavies541 Posts: 21 Joined: Feb 01, 2013 |
Hi
I'm having trouble saving fonts, colors and custom data objects into an OEC workspace file as XML. I have tried and tested classes that can serialize fonts, colors and custom data objects that I've successfully used on many other projects but I seem to be having trouble using these in OEC. My simple test indicator code is below. I would be grateful if you could tell me what I'm going wrong or the preferred way of saving fonts, colors and custom data objects into an OEC workspace. P.S. I don't get any compile or run time errors with this code. Thanks in advance public sealed class JTPersistenceTest : OEC.Chart.Custom.CustomIndicator, IOECPersistence { private OECMainForm form = null; //class to XML srialize colors private JTSerializableColor testColor = null; //class to XML serialize data objects private OECData theData = null; private int theInt; protected override void Refresh(DataChangedMode mode) { if (form == null) { //above variables changed in here form = new OECMainForm(this); form.Show(); } } public override void Delete() { Print("Calling Overriden Delete()"); form.Close(); base.Delete(); } //this won't save [XmlSerializable] public OECData TestData { get { return theData; } set { theData = value;} } //this will save [XmlSerializable] public int TheInt { get { return theInt; } set { theInt = value; } } //this won't save [XmlSerializable] public JTSerializableColor TestColor { get { return testColor; } set { testColor = value; } } } } Peter Davies |
||||
VictorV Posts: 746 Joined: May 08, 2007 |
Hello. To reproduce it, I've added the next implementation of OECData and JTSerializableColor:
public class OECData { [XmlSerializable] public int TheIntInData { get { return theInt; } set { theInt = value; } } private int theInt = 10; } public class JTSerializableColor { [XmlSerializable] public int TheIntInColor { get { return theInt; } set { theInt = value; } } private int theInt = 100; } then, initialized private members: private JTSerializableColor testColor = new JTSerializableColor(); //class to XML serialize data objects private OECData theData = new OECData(); private int theInt = 15; and found out serialized data in XML file: <TestData> <TheIntInData>10</TheIntInData> </TestData> <TheInt>15</TheInt> <TestColor> <TheIntInColor>100</TheIntInColor> </TestColor> </JTPersistenceTest> Could you provide more details how to reproduce the issue? Victor Vins Lead Software Developer |
||||
PDavies541 Posts: 21 Joined: Feb 01, 2013 |
Hi Victor
Thanks for the reply. I can see what you did to make it work but what I didn't send you was my definition of the Serializable color class or OEC Data class. They are below. I use these classes because I sometimes need to save data into my own XML file and also in the OEC workspace. When I use the files as listed below they are not recognized in the OEC XML file but save fine to local storage. Thanks again [Serializable()] /// <summary> /// JTSerializableColor /// </summary> /// <remaks> /// Wrapper clas to serialize and deserialize /// the Color structure. Color structure can not be XML /// serialized because it does not have any public /// fields and can't be serialized directly. /// </remaks> public class JTSerializableColor : ICloneable { #region Public Variables //the ARGB name of the color public int colorARGB { get; set; } //color name public string colorName; #endregion #region Constructors #region Default /// <summary> /// JTSerializableColor /// </summary> /// <remarks> /// Default constructor for XML serialization /// </remarks> public JTSerializableColor() { //do nothing } #endregion #region Normal /// <summary> /// JTSerializableColor /// </summary> /// <remarks> /// Constructor used when creating objects /// </remarks> /// <param name="name"></param> public JTSerializableColor(Color name) { //set ARGB value colorARGB = name.ToArgb(); //set name colorName = name.Name; } #endregion #endregion #region Public Methods #region Get Color /// <summary> /// GetColor /// </summary> /// <remarks> /// Returns the color from the /// stored name. /// </remarks> /// <returns></returns> public Color GetColor() { //return the color return Color.FromArgb(colorARGB); } #endregion #region Set Color /// <summary> /// SetColor /// </summary> /// <remarks> /// Sets the name from the color /// </remarks> /// <param name="color"></param> public void SetColor(Color color) { //set the name colorARGB = color.ToArgb(); } #endregion #region Clone /// <summary> /// Clone /// </summary> /// <remarks> /// Shallow copy of this object /// </remarks> /// <returns></returns> public JTSerializableColor Clone() { //clone return (JTSerializableColor)this.MemberwiseClone(); } #endregion #endregion #region IClonable Members /// <summary> /// ICloneable.Clone() /// </summary> /// <remarks> /// Interface implementation /// </remarks> /// <returns></returns> object ICloneable.Clone() { return Clone(); } #endregion } [Serializable()] public class OECData : ISerializable { private int testInt = 10; /// <summary> /// Constructor /// </summary> public OECData() { } /// <summary> /// Constructor /// </summary> /// <param name="info"></param> /// <param name="context"></param> public OECData(SerializationInfo info, StreamingContext context) { testInt = (int)info.GetValue("TestInt", typeof(int)); } /// <summary> /// /// </summary> /// <param name="info"></param> /// <param name="context"></param> public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("TestInt", testInt); } public int TestInt { get { return testInt; } set { testInt = value; } } } Peter Davies |
||||
VictorV Posts: 746 Joined: May 08, 2007 |
We are using xml serialization (System.Xml.Serialization), not runtime one (System.Runtime.Serialization). You code will start working with OEC indicators, if it will support xml serialization. For example, public properties can be marked with XmlSerializable attribute.
Victor Vins Lead Software Developer |
||||