Пример #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);
        }
Пример #2
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;
        }
Пример #3
0
        public static SensorDataContract AddIPToLocation(SensorDataContract data, string gatewayIPAddressString)
        {
            if (data == null)
            {
                return(null);
            }

            SensorDataContract result = data;

            if (result.Location == null)
            {
                result.Location = "Unknown" + '\n';
            }
            else
            {
                result.Location = result.Location + '\n';
            }

            if (gatewayIPAddressString != null)
            {
                result.Location += gatewayIPAddressString;
            }

            return(result);
        }
Пример #4
0
        public static SensorDataContract SensorDataContractFromQueuedItem(QueuedItem data, ILogger logger = null)
        {
            if (data == null)
            {
                return(null);
            }

            SensorDataContract result = SensorDataContractFromString(data.JsonData);

            return(result);
        }
Пример #5
0
        public static SensorDataContract AddTimeCreated(SensorDataContract data)
        {
            if (data == null)
            {
                return(null);
            }

            SensorDataContract result = data;

            if (result.TimeCreated == default(DateTime))
            {
                var creationTime = DateTime.UtcNow;
                result.TimeCreated = creationTime;
            }

            return(result);
        }
        public static SensorDataContract Generate( )
        {
            int device = _Random.Next( ) % DEVICE_COUNT;

            SensorDataContract sensorData = new SensorDataContract
            {
                MeasureName = _MeasureName[ device ],
                UnitOfMeasure = _UnitOfMeasure[ device ],
                DisplayName = _DisplayName[ device ],
                Guid = _Guids[ device ],
                Value = _Random.Next( ) % 1000 - 500,
                Location = "here",
                Organization = "contoso",
                TimeCreated = DateTime.UtcNow
            };
            return sensorData;
        }
Пример #7
0
        public static SensorDataContract AddTimeCreated( SensorDataContract data )
        {
            if( data == null )
            {
                return null;
            }

            SensorDataContract result = data;
            if( result.TimeCreated == default( DateTime ) )
            {
                var creationTime = DateTime.UtcNow;
                result.TimeCreated = creationTime;
            }

            return result;
        }
Пример #8
0
        public static SensorDataContract AddIPToLocation( SensorDataContract data, string gatewayIPAddressString )
        {
            if( data == null )
            {
                return null;
            }

            SensorDataContract result = data;
            if( result.Location == null )
            {
                result.Location = "Unknown" + '\n';
            }
            else
            {
                result.Location = result.Location + '\n';
            }

            if( gatewayIPAddressString != null )
            {
                result.Location += gatewayIPAddressString;
            }

            return result;
        }