oddin-gg / netcoresdk

BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

Event structure optimization and publication of raw data #7

Open lwasak opened 3 years ago

lwasak commented 3 years ago
    public class OddsChangeEventArgs<T> : EventArgs where T : ISportEvent
    {
        private readonly IFeedMessageMapper _messageMapper;
        private readonly odds_change _feedMessage;
        private readonly byte[] _rawMessage;
        private readonly IOddsChange<T> _oddsChange;

        internal OddsChangeEventArgs(IFeedMessageMapper messageMapper, odds_change feedMessage, byte[] rawMessage)
        {
            if (messageMapper is null)
                throw new ArgumentNullException(nameof(messageMapper));

            if (feedMessage is null)
                throw new ArgumentNullException(nameof(feedMessage));

            _messageMapper = messageMapper;
            _feedMessage = feedMessage;
            _rawMessage = rawMessage;

            _oddsChange = GetOddsChange();
        }

        public IOddsChange<T> GetOddsChange()
        {
            if ((_oddsChange is null) == false)
                return _oddsChange;

            return _messageMapper.MapOddsChange<T>(_feedMessage, _rawMessage);
        }
    }

usage

        private async void OnOddsChange(object sender, OddsChangeEventArgs<ISportEvent> e)
        {
              var oddsChangeEvent = e.GetOddsChange();
              (...)

The events args you guys created is overly complicated and can be simplified. In the current construct you have created GetOddsChange has to be called twice. _rawMessage is not used anywhere its only assigned from variable to variable.

To simplify thins and make this just a basic data object I suggest more optimal structure below

    public class OddsChangeEventArgs<T> : EventArgs where T : ISportEvent
    {
        public IOddsChange<T> OddsChange { get; }

        internal OddsChangeEventArgs(IFeedMessageMapper messageMapper, odds_change feedMessage, byte[] rawMessage)
        {
            if (messageMapper is null)
                throw new ArgumentNullException(nameof(messageMapper));

            if (feedMessage is null)
                throw new ArgumentNullException(nameof(feedMessage));

            OddsChange = messageMapper.MapOddsChange<T>(feedMessage, rawMessage);
        }
    }

Same goes for all other events you guys sent.

Additionally we need to have the raw message before you guys parsed it. Can you in similar scheme provide it for us in the event? Currently its locked under a private field.

Regards

michal-fuleky commented 3 years ago

This is an unfortunate mistake. Actually GetOddsChange() should have optional parameter for Culture so that SportEvents are build in that specific culture. This feature was/will be added in version v1.1.0.

When it comes to raw data you can already access them via: eventArgs.GetOddsChange().RawMessage then you can use: Encoding.UTF8.GetString(...) to get actual XML Body.