WspBuffer v SerializedData

Sep 3, 2011 at 8:06 PM

Hi Keith,

I realise I am a little behind the game here, but I've just migrated to a new box and upgraded to 64 bit.  Inevitably nothing works.  Historically I used Dictionarys to transfer more complex data around and now I find the migration to WspBuffer seems to broad brush the underlying <value> types to only strings and objects.  I use mostly doubles.

Is there a paper describing the move from SerializedData to WspBuffer in more detail?  After so long away from this code I'm nervous about ripping it all up again.

Hope you are well,
DS

Coordinator
Sep 3, 2011 at 10:13 PM

Serializing a Dictionary<string, object> where the values are Double should work fine. Are you sure this is the issue and not something like the firewall? If you think it's because of serialization, can you send your class?

Keith

Sep 4, 2011 at 11:09 AM
Edited Sep 4, 2011 at 11:42 AM
You can see the issue in the following class. Ticks is Dictionary<string, Double> which generates the following errors:
The best overloaded method match for 'Microsoft.WebSolutionsPlatform.Event.WspBuffer.AddElement(string, string)' has some invalid arguments
Argument 2: cannot convert from 'System.Collections.Generic.Dictionary' to 'string'
There are similar issues around the TimeStamps, but I'm assuming a quick fix for doubles could be reused.
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.WebSolutionsPlatform.Event;
using Microsoft.WebSolutionsPlatform.Event.PubSubManager;

namespace DynamicalSystem.MarketData
{
    public abstract class MarketDataEvent : Event
    {

        private Dictionary<string, DateTime> TimeStampsField;
        public Dictionary<string, DateTime> TimeStamps
        {
            get { return TimeStampsField; }
            set { TimeStampsField = value; }
        }

        private DateTime sourceTimeStamp;
            public DateTime SourceTimeStamp
            {
                get { return sourceTimeStamp; }
                set { sourceTimeStamp = value; }
            }

        private Dictionary<string, Double> ticks;
        public Dictionary<string, Double> Ticks
        {
            get { return ticks; }
            set { ticks = value; }
        }

        private string units = "";
            public string Units
            {
                get { return units; }
                set { units = value; }
            }

        private string market;
            public string Market
            {
                get { return market; }
                set { market = value; }
            }

        private string source;
            public string Source
            {
                get { return source; }
                set { source = value; }
            }

        private UInt64 eventNum;
            public UInt64 EventNum
            {
                get { return eventNum; }
                set { eventNum = value; }
            }

        private Guid instanceId;
        public Guid InstanceId
        {
            get{ return instanceId; }
            set{ instanceId = value; }
        }

        private PublishManager Publisher;

        /// <summary>
        /// Base constructor to create a new event
        /// </summary>
        /// <param name="serializationData">Serialized event data</param>
        public MarketDataEvent() : base()
        {
            Ticks = new Dictionary<string,Double>();
            TimeStamps = new Dictionary<string, DateTime>();
            Market = "";
        }

        /// <summary>
        /// Base constructor to create a new event from a serialized event
        /// </summary>
        /// <param name="serializationData">Serialized event data</param>
        public MarketDataEvent(byte[] serializationData) : base(serializationData)
        {
        }

        /// <summary>
        /// Used for event serialization.
        /// </summary>
        /// <param name="data">SerializationData object passed to store serialized object</param>
        public override void GetObjectData(WspBuffer data)
        {
            data.AddElement(@"TimeStamps", TimeStamps);
            data.AddElement(@"Ticks", Ticks);
            data.AddElement(@"Units", Units);
            data.AddElement(@"Market", Market);
            data.AddElement(@"Source", Source);
            data.AddElement(@"EventNum", EventNum);
            data.AddElement(@"InstanceId", InstanceId);
        }

        public void Post()
        {
            try
            {
                if (Publisher == null)
                    Publisher = new PublishManager();
            }
            catch (Exception e)
            {
                Console.WriteLine("MarketData.MarketDataEvent\t: " + e.Message);
                return;
            }

            try
            {
                Publisher.Publish(this.Serialize());
            }
            catch (Exception e)
            {
                Console.WriteLine("MarketData.MarketDataEvent\t: " + e.Message);
                return;
            }
        }
    }
}

Coordinator
Sep 4, 2011 at 4:32 PM

If you change your dictionaries to Dictionary <string, object>, I think things should work fine. You could also cast the AddElement to (Dictionary <string, object>) but you then need to handle the deserialization to do the reverse.

Coordinator
Sep 8, 2011 at 6:22 AM

Did you get things working? Or shall I add the deserialization logic to your class so your types can remain as-is?