Exemple #1
0
        public static QueuedItem QueuedItemFromSensorDataContract( SensorDataContract sensorData, ILogger logger = null )
        {
            if( sensorData == null )
            {
                return null;
            }

            QueuedItem result = null;
            try
            {
                result = new QueuedItem
                {
                    JsonData = JsonConvert.SerializeObject( sensorData )
                };
            }
            catch( Exception ex )
            {
                if( logger != null )
                {
                    logger.LogError( "Error on serialize item: " + ex.Message );
                }
            }

            return result;
        }
        public static QueuedItem QueuedItemFromSensorDataContract(SensorDataContract sensorData, ILogger logger = null)
        {
            if (sensorData == null)
            {
                return(null);
            }

            QueuedItem result = null;

            try
            {
                result = new QueuedItem
                {
                    JsonData = JsonConvert.SerializeObject(sensorData)
                };
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger.LogError("Error on serialize item: " + ex.Message);
                }
            }

            return(result);
        }
        public static SensorDataContract SensorDataContractFromQueuedItem(QueuedItem data, ILogger logger = null)
        {
            if (data == null)
            {
                return(null);
            }

            SensorDataContract result = SensorDataContractFromString(data.JsonData);

            return(result);
        }
Exemple #4
0
        public int Enqueue(string jsonData)
        {
            if (jsonData != null) //not filling a queue by empty items
            {
                QueuedItem sensorData = _dataTransform(jsonData);

                if (sensorData != null)
                {
                    //TODO: we can check status of BatchSender and indicate error on request if needed
                    _queue.Push(sensorData);

                    DataInQueue(sensorData);
                }
            }

            return(_queue.Count);
        }
Exemple #5
0
        protected virtual void DataInQueue(QueuedItem data)
        {
            DataInQueueEventHandler newData = OnDataInQueue;

            if (newData != null)
            {
                var sh = new SafeAction <QueuedItem>(d => newData(d), Logger);

                TaskWrapper.Run(() => sh.SafeInvoke(data));
            }

            //
            // NO logging on production code, enable for diagnostic purposes for debugging
            //
#if DEBUG_LOG
            LogMessageReceived( );
#endif
        }
 protected virtual void OnData( QueuedItem data )
 {
     // LORENZO: test behaviours such as accumulating data an processing in batch
     _batchSenderThread.Process( );
 }
        protected virtual void DataInQueue( QueuedItem data )
        {
            DataInQueueEventHandler newData = OnDataInQueue;

            if( newData != null )
            {
                var sh = new SafeAction<QueuedItem>( d => newData( d ), Logger );

                TaskWrapper.Run( ( ) => sh.SafeInvoke( data ) );
            }

            //
            // NO logging on production code, enable for diagnostic purposes for debugging 
            //
#if DEBUG_LOG
            LogMessageReceived( );
#endif
        }
Exemple #8
0
        protected virtual void DataInQueue( QueuedItem data )
        {
            // LORENZO: test behaviours such as accumulating data an processing in batch
            // as it stands, we are processing every event as it comes in

            _batchSenderThread.Process( );
        }
Exemple #9
0
        public static SensorDataContract SensorDataContractFromQueuedItem( QueuedItem data, ILogger logger = null )
        {
            if( data == null )
            {
                return null;
            }

            SensorDataContract result = SensorDataContractFromString( data.JsonData );
            return result;
        }