Ejemplo n.º 1
0
        public static void SerializeData(SensorDataModel sensorDataModel, string outputFilePath)
        {
            var ms = new MemoryStream();

            ProtoBuf.Serializer.Serialize<SensorDataModel>(ms, sensorDataModel);

            ms.Position = 0;
            using (ms)
            {
                Cryptographer.WriteEnCryptedMemoryStream(ms, outputFilePath);
            }
        }
Ejemplo n.º 2
0
        public static bool IsValid(SensorDataModel sensorDataModel)
        {
            var enumerator = sensorDataModel.SensorCollection.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (int.Parse(enumerator.Current.Sensor2) < 20
                    || int.Parse(enumerator.Current.Sensor2) > 80)
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 3
0
        public bool GetGenerateBarCodeText(SensorDataModel sensorDataModel, out string generatedText)
        {
            generatedText = string.Empty;

            var barCodeString = BarcodeManager.GenerateBarCodeString(sensorDataModel);

            if (string.IsNullOrEmpty(barCodeString))
                return false;

            Code128Content content = new Code128Content(barCodeString);
            generatedText = string.Join(string.Empty, content.Codes);

            return true;
        }
Ejemplo n.º 4
0
        public SensorDataModel CreateSensorDataModel()
        {
            SensorDataModel sensorDataModel = new SensorDataModel();
            sensorDataModel.DetailsName = "Test Details Name";
            sensorDataModel.StartDateTime = DateTime.Now;

            for (int i = 0; i < 10; i++)
                sensorDataModel.SensorCollection.Add(CreateSensorModel(i.ToString()));

            var startSensorModel = CreateSensorModel("26");
            startSensorModel.DateTime = new DateTime(2014, 04, 26, 14, 14, 14);
            sensorDataModel.SensorCollection.Add(startSensorModel);

            for (int i = 27; i < 36; i++)
                sensorDataModel.SensorCollection.Add(CreateSensorModel(i.ToString()));

            var endSensorModel = CreateSensorModel("81");
            endSensorModel.DateTime = new DateTime(2014, 04, 26, 15, 15, 15);
            sensorDataModel.SensorCollection.Add(endSensorModel);

            return sensorDataModel;
        }
Ejemplo n.º 5
0
        public static string GenerateBarCodeString(SensorDataModel sensorDataModel)
        {
            if (!IsValid(sensorDataModel))
                return string.Empty;

            const string startThreshold = "25";
            const string endThreshold = "80";

            DateTime startTime = default(DateTime);
            DateTime endTime = default(DateTime);

            bool computeStartTime=true;
            bool computeEndTime = false;

            var enumerator = sensorDataModel.SensorCollection.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (computeStartTime)
                {
                    if (int.Parse(enumerator.Current.Sensor1) > int.Parse(startThreshold))
                    {
                        startTime = enumerator.Current.DateTime;
                        computeStartTime = false;
                        computeEndTime = true;
                    }
                }
                if (computeEndTime)
                {
                    if (int.Parse(enumerator.Current.Sensor1) > int.Parse(endThreshold))
                    {
                        endTime = enumerator.Current.DateTime;
                    }
                }
            }

            return string.Format("{0}{1}{2}{3}",
                startTime.Hour.ToString(), startTime.Minute,
                endTime.Hour, endTime.Minute);
        }
Ejemplo n.º 6
0
        public void SerializeAndDeSerialize_SensorDataModel_Test()
        {
            var outputFile = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());

            var sensorDataModelExpected = new SensorDataModel();
            sensorDataModelExpected.DetailsName = "Details Name";
            sensorDataModelExpected.DetailsDesc = "DetailsDesc";

            for (int i = 0; i < 100; i++ )
                sensorDataModelExpected.SensorCollection.Add(new SensorModel(){Sensor1 = i.ToString()});

            Randmfun.Archiver.Serializer.SerializeData(sensorDataModelExpected, outputFile);

            var sensorDataModelActual = Randmfun.Archiver.Serializer.DeSerializeData(outputFile);

            Assert.AreEqual(sensorDataModelActual.DetailsDesc, sensorDataModelActual.DetailsDesc);
            Assert.AreEqual(sensorDataModelActual.DetailsName, sensorDataModelActual.DetailsName);
            Assert.AreEqual(sensorDataModelExpected.SensorCollection.Count, sensorDataModelActual.SensorCollection.Count);

            for (int i = 0; i < 100; i++)
                Assert.AreEqual(sensorDataModelActual.SensorCollection[i].Sensor1, sensorDataModelExpected.SensorCollection[i].Sensor1);
        }
Ejemplo n.º 7
0
        private void StoreToDb(byte[] byteStream, SensorDataModel sensorDataModel, string generateBarCode)
        {
            // Get the UserId of the just-added user
            var newUser = Membership.GetUser();
            var newUserId = newUser.ProviderUserKey.ToString();

            //' Insert a new record into UserProfiles
            var connectionString =
                ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;

            string binFileId = Guid.NewGuid().ToString();

            var insertSql =
                "Insert into BinFileStore VALUES(@UserId, @BinFileId, @DetailsName, @DetailsDesc, @UploadedTime, @GeneratedBarCode, @BinFile)";
            using (var myConnection = new SqlConnection(connectionString))
            {
                myConnection.Open();
                var myCommand = new SqlCommand(insertSql, myConnection);
                myCommand.Parameters.AddWithValue("@UserId", newUserId);
                myCommand.Parameters.AddWithValue("@BinFileId", binFileId);
                myCommand.Parameters.AddWithValue("@DetailsName", sensorDataModel.DetailsName);
                myCommand.Parameters.AddWithValue("@DetailsDesc", sensorDataModel.DetailsDesc);
                myCommand.Parameters.AddWithValue("@UploadedTime", DateTime.Now);
                myCommand.Parameters.AddWithValue("@GeneratedBarCode", generateBarCode);
                myCommand.Parameters.AddWithValue("@BinFile", byteStream);

                myCommand.ExecuteNonQuery();
                myConnection.Close();
            }
        }
Ejemplo n.º 8
0
        private void StartClick(object sender, RoutedEventArgs e)
        {
            try
            {
                var sensorDataModel = new SensorDataModel();

                ThirdEyeApplicationContext.SetCurrentSensorModel(sensorDataModel);

                var comunicationModel = ThirdEyeApplicationContext.GetCommunicationConfigViewModel();

                this.currentGlobalSerialPort = new SerialPort();

                currentGlobalSerialPort.PortName = comunicationModel.SelectedComPort;
                currentGlobalSerialPort.Parity = (Parity)Enum.Parse(typeof(Parity), comunicationModel.SelectedParity);
                currentGlobalSerialPort.BaudRate = int.Parse(comunicationModel.SelectedBaudRate);
                currentGlobalSerialPort.DataBits = int.Parse(comunicationModel.SelectedDataBit);
                currentGlobalSerialPort.StopBits = (StopBits)Enum.Parse(typeof(StopBits), comunicationModel.SelectedStopBit);

                this.currentGlobalSerialIO = new SerialIoLayer(currentGlobalSerialPort);
                currentGlobalSerialIO.LogData += (serialIo_LogData);

                currentGlobalSerialIO.Start();

                this.lblArchive.Visibility = System.Windows.Visibility.Collapsed;
                this.lblDetail.Visibility = System.Windows.Visibility.Collapsed;
                this.lblDetailName.Visibility = System.Windows.Visibility.Collapsed;
                this.lblFilePath.Visibility = System.Windows.Visibility.Visible;
                this.lblFilePath.Content = string.Format("Reading from {0}, at {1} baudrate", currentGlobalSerialPort.PortName, currentGlobalSerialPort.BaudRate.ToString());

                currentCommunicationState = CommunicationState.Reading;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message + exception.InnerException);
            }
        }
Ejemplo n.º 9
0
        private void LoadDummyDataClick(object sender, RoutedEventArgs e)
        {
            var _sensorDataModel = new SensorDataModel();
            _sensorDataModel.SensorCollection = new ObservableCollection<SensorModel>();
            for (int i = 20, j=21, k=22; i < 90; i++, j++, k++)
            {
                int year = 1870 + i;
                int month = i%10 + 1;
                int day = i%28 + 1;
                _sensorDataModel.SensorCollection.Add(new SensorModel()
                                                          {
                                                              DateTime = new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day)),
                                                              Sensor1 = i.ToString(),
                                                              Sensor2 = j.ToString(),
                                                              Sensor3 = k.ToString()
                                                          });
            }

            ThirdEyeApplicationContext.SetCurrentSensorModel(_sensorDataModel);
        }
Ejemplo n.º 10
0
 public static void SetCurrentSensorModel(SensorDataModel sensorDataModel)
 {
     currentSensorDataModel = sensorDataModel;
 }