public static void SetIntValue(this DatasourceRecord record, int value)
        {
            ThrowExceptionOnInvalidConversion(record.DataType, DatasourceRecord.DataTypeEnum.Integer);

            record.Value    = BitConverter.GetBytes(value);
            record.DataType = DatasourceRecord.DataTypeEnum.Integer;
        }
        public void Equivalent_SameValues()
        {
            var dr = new DatasourceRecord
            {
                DatasourceId    = 5,
                DataType        = DatasourceRecord.DataTypeEnum.Integer,
                IntervalSeconds = 6,
                Timestamp       = DateTime.Parse("2013-01-01 5:00am")
            };

            dr.SetIntValue(7);

            var dr2 = new DatasourceRecord
            {
                DatasourceId    = 5,
                DataType        = DatasourceRecord.DataTypeEnum.Integer,
                IntervalSeconds = 6,
                Timestamp       = DateTime.Parse("2013-01-01 5:00am")
            };

            dr2.SetIntValue(7);

            Assert.IsTrue(dr.Equivalent(dr2));
            Assert.IsTrue(dr2.Equivalent(dr));
        }
        /// <summary>
        ///     Receives a value posted to it, and saves that value to a local MessageQueue
        /// </summary>
        /// <param name="value"></param>
        public HttpResponseMessage Post([FromBody] DatasourceRecord value)
        {
            Log.DebugFormat("Received record ID '{0}'", value.DatasourceId);
            _recordRepository.Push(value);

            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
        public void Notify(DatasourceRecord message)
        {
            // TODO: FILTER! Might be able to do group subscriptions instead of channel resolvers
            //var id = _channelResolver.GetChannelId(message);

            //_log.DebugFormat("Received a message from {0} with an ID of {1}", message.DatasourceId, id);

            //if(id == null)
            //{
            //    // log or something
            //    return;
            //}

            //Clients.Client(id).notify(message);

            // Convert to DataRecord (type mismatch???)
            var dataRecord = new DataRecord
            {
                DatasourceId = message.DatasourceId,
                EncodedDataType = message.EncodedDataType,
                IntervalSeconds = message.IntervalSeconds,
                Timestamp = message.Timestamp,
                Value = message.Value,
                Id = message.Id
            };

            Clients.All.notify(dataRecord);
        }
        public void GetIntValue_DontAllowTypeToChange()
        {
            var dr = new DatasourceRecord();

            dr.SetDoubleValue(123);
            dr.GetIntValue();
        }
        public static void SetStringValue(this DatasourceRecord record, string value)
        {
            ThrowExceptionOnInvalidConversion(record.DataType, DatasourceRecord.DataTypeEnum.String);

            record.Value    = Encoding.UTF8.GetBytes(value);
            record.DataType = DatasourceRecord.DataTypeEnum.String;
        }
        public void SetDecimalValue_DontAllowTypeToChange()
        {
            var dr = new DatasourceRecord();

            dr.SetDoubleValue(123);
            dr.SetDecimalValue(123M);
        }
        public void SetStringValue_DontAllowTypeToChange()
        {
            var dr = new DatasourceRecord();

            dr.SetDoubleValue(123);
            dr.SetStringValue("hi");
        }
        public static void SetDoubleValue(this DatasourceRecord record, double value)
        {
            ThrowExceptionOnInvalidConversion(record.DataType, DatasourceRecord.DataTypeEnum.Double);

            record.Value    = BitConverter.GetBytes(value);
            record.DataType = DatasourceRecord.DataTypeEnum.Double;
        }
Example #10
0
 public void Push(DatasourceRecord record)
 {
     lock (Records)
     {
         Records.Add(record);
     }
 }
        public void Equivalent_BothHaveNullValue()
        {
            var dr  = new DatasourceRecord();
            var dr2 = new DatasourceRecord();

            Assert.IsTrue(dr.Equivalent(dr2));
            Assert.IsTrue(dr2.Equivalent(dr));
        }
        public void GetSetIntValue()
        {
            var dr = new DatasourceRecord();

            dr.SetIntValue(4);
            Assert.AreEqual(4, dr.GetIntValue());
            Assert.AreEqual(DatasourceRecord.DataTypeEnum.Integer, dr.DataType);
        }
        public void GetSetDoubleValue()
        {
            var dr = new DatasourceRecord();

            dr.SetDoubleValue(4.5);
            Assert.AreEqual(4.5, dr.GetDoubleValue());
            Assert.AreEqual(DatasourceRecord.DataTypeEnum.Double, dr.DataType);
        }
        public void GetSetStringValue()
        {
            var dr = new DatasourceRecord();

            dr.SetStringValue("hi there");
            Assert.AreEqual("hi there", dr.GetStringValue());
            Assert.AreEqual(DatasourceRecord.DataTypeEnum.String, dr.DataType);
        }
        public void EncodedDataType_GetSet()
        {
            var dr = new DatasourceRecord {
                EncodedDataType = 4
            };

            Assert.AreEqual(4, dr.EncodedDataType);
        }
        public void Equivalent_SourceIsNull()
        {
            var dr  = new DatasourceRecord();
            var dr2 = new DatasourceRecord();

            dr2.SetDoubleValue(5.6);

            Assert.IsFalse(dr.Equivalent(dr2));
            Assert.IsFalse(dr2.Equivalent(dr));
        }
        public void GetSetDecimalValue()
        {
            var dr = new DatasourceRecord();

            dr.SetDecimalValue(123456789M);
            var dv = dr.GetDecimalValue();

            Assert.AreEqual(123456789M, dv);
            Assert.AreEqual(DatasourceRecord.DataTypeEnum.Decimal, dr.DataType);
        }
        public void OnDataReceived(object sender, DataReceivedEventArgs <decimal> dataReceivedEventArgs)
        {
            var record = new DatasourceRecord
            {
                Timestamp    = dataReceivedEventArgs.Timestamp,
                DatasourceId = dataReceivedEventArgs.DeviceID,
            };

            record.SetDecimalValue(dataReceivedEventArgs.Value);
            _recordRepository.Push(record);
        }
        public static decimal GetDecimalValue(this DatasourceRecord record)
        {
            ThrowExceptionOnInvalidConversion(record.DataType, DatasourceRecord.DataTypeEnum.Decimal);

            using (var memoryStream = new MemoryStream(record.Value))
            {
                using (var binaryReader = new BinaryReader(memoryStream))
                {
                    return(binaryReader.ReadDecimal());
                }
            }
        }
        public static void SetDecimalValue(this DatasourceRecord record, decimal value)
        {
            ThrowExceptionOnInvalidConversion(record.DataType, DatasourceRecord.DataTypeEnum.Decimal);

            using (var memoryStream = new MemoryStream())
            {
                using (var binaryWriter = new BinaryWriter(memoryStream))
                {
                    binaryWriter.Write(value);
                    record.Value = memoryStream.ToArray();
                }
            }
            record.DataType = DatasourceRecord.DataTypeEnum.Decimal;
        }
        public static IEnumerable <DatasourceRecord> GenerateDummyData(int records)
        {
            var rand = new Random();

            for (var i = 0; i < records; i++)
            {
                var dr = new DatasourceRecord
                {
                    DatasourceId    = _datasources[rand.Next(0, 2)],
                    IntervalSeconds = rand.Next(60, 3600),
                    Timestamp       = DateTime.UtcNow.AddMilliseconds(i * 10),
                    DataType        = DatasourceRecord.DataTypeEnum.Double
                };
                dr.SetDoubleValue(rand.NextDouble() * 100000);
                yield return(dr);
            }
        }
 public DataRecord(DatasourceRecord datasourceRecord)
 {
     Mapper.CreateMap<DatasourceRecord, DataRecord>();
     Mapper.Map(datasourceRecord, this);
 }
        public static double GetDoubleValue(this DatasourceRecord record)
        {
            ThrowExceptionOnInvalidConversion(record.DataType, DatasourceRecord.DataTypeEnum.Double);

            return(BitConverter.ToDouble(record.Value, 0));
        }
        public static int GetIntValue(this DatasourceRecord record)
        {
            ThrowExceptionOnInvalidConversion(record.DataType, DatasourceRecord.DataTypeEnum.Integer);

            return(BitConverter.ToInt32(record.Value, 0));
        }
        public void Equivalent_SameInstances()
        {
            var dr = new DatasourceRecord();

            Assert.IsTrue(dr.Equivalent(dr));
        }
        public void Equivalent_CompareWithNull_NotEquivalent()
        {
            var dr = new DatasourceRecord();

            Assert.IsFalse(dr.Equivalent(null));
        }
        public static string GetStringValue(this DatasourceRecord record)
        {
            ThrowExceptionOnInvalidConversion(record.DataType, DatasourceRecord.DataTypeEnum.String);

            return(Encoding.UTF8.GetString(record.Value));
        }
Example #28
0
 public void Push(DatasourceRecord record)
 {
     Push(new List <DatasourceRecord> {
         record
     });
 }