Esempio n. 1
0
        public void TransformTestWithoutUnit()
        {
            string jsonContent        = @"{
                  'gwy': 'b19IoTWorx',
                  'name': 'Device_190130_AV_67',
                  'value': '400.000000',
                  'timestamp': '2019-06-10T23:48:43.667Z',
                  'status': true
                }";
            var    telemetryDataPoint = JsonConvert.DeserializeObject <BACNetTelemetryMsg>(jsonContent, _jsonSerializerSettings);
            var    eventData          = new EventData(new byte[0]);
            BACNetIoTHubMessage bacNetIoTHubMessage = new BACNetIoTHubMessage(telemetryDataPoint, eventData.SystemProperties, eventData.Properties);

            DeviceDocument inputDeviceDocument = new DeviceDocument()
            {
                id = telemetryDataPoint.name
            };
            DeviceDocument output = IoTWorxBuildingDataProcessingFunction.ApplyTelemetryToDeviceDoc(bacNetIoTHubMessage, inputDeviceDocument);

            output.EventEnqueuedUtcTime.ShouldBe(DateTime.UtcNow, TimeSpan.FromMilliseconds(1000));
            output.PresentValue.ShouldBe("400.000000");
            output.ValueUnits.ShouldBeEmpty();
            output.DeviceTimestamp.ShouldBe(DateTime.Parse("2019-06-10T23:48:43.667Z"));
            output.DeviceStatus.ToLower().ShouldBe(bool.TrueString.ToLower());
        }
        DeviceDocument GetModelDatas(DeviceDocumentViewModel _viewModel)
        {
            DeviceDocument _model = new DeviceDocument()
            {
                DeviceID = _viewModel.DeviceID,
                ActPuttingOperationFileName         = _viewModel.ActPuttingOperationFileName,
                ActPuttingOperationBinData          = _viewModel.ActPuttingOperationBinData,
                RegistrationCertificateFileName     = _viewModel.RegistrationCertificateFileName,
                RegistrationCertificateBinData      = _viewModel.RegistrationCertificateBinData,
                CertificateConformityDeviceFileName = _viewModel.CertificateConformityDeviceFileName,
                CertificateConformityDeviceBinData  = _viewModel.CertificateConformityDeviceBinData,
                Photo1FileName         = _viewModel.Photo1FileName,
                Photo1BinData          = _viewModel.Photo1BinData,
                Photo2FileName         = _viewModel.Photo2FileName,
                Photo2BinData          = _viewModel.Photo2BinData,
                Photo3FileName         = _viewModel.Photo3FileName,
                Photo3BinData          = _viewModel.Photo3BinData,
                ServiceManualFileName  = _viewModel.ServiceManualFileName,
                ServiceManualBinData   = _viewModel.ServiceManualBinData,
                UserManualFileName     = _viewModel.UserManualFileName,
                UserManualBinData      = _viewModel.UserManualBinData,
                PassportDeviceFileName = _viewModel.PassportDeviceFileName,
                PassportDeviceBinData  = _viewModel.PassportDeviceBinData,
                CreateDateTime         = _viewModel.CreateDateTime,
                ChangeDateTime         = _viewModel.ChangeDateTime
            };

            _viewModel.Device = new Device();
            _model.Device     = _viewModel.Device;

            return(_model);
        }
Esempio n. 3
0
        public void TransformTestWithUnit()
        {
            string jsonContent =
                @"{
                    'gwy': 'b19IoTWorx',
                    'name': 'Device_190131_AV_90',
                    'value': '73.000000 DEGREES-FAHRENHEIT',
                    'timestamp': '2019-06-10T23:48:43.667Z',
                    'status': true
                }";
            var telemetryDataPoint = JsonConvert.DeserializeObject <BACNetTelemetryMsg>(jsonContent, _jsonSerializerSettings);
            var eventData          = new EventData(new byte[0]);
            BACNetIoTHubMessage bacNetIoTHubMessage = new BACNetIoTHubMessage(telemetryDataPoint, eventData.SystemProperties, eventData.Properties);

            DeviceDocument inputDeviceDocument = new DeviceDocument()
            {
                id         = telemetryDataPoint.name,
                DeviceName = "190131",
                ObjectType = "AnalogValue",
                Instance   = 90
            };
            DeviceDocument output = IoTWorxBuildingDataProcessingFunction.ApplyTelemetryToDeviceDoc(bacNetIoTHubMessage, inputDeviceDocument);

            //output.Gateway.ShouldBe("b19IoTWorx");
            output.id.ShouldBe((string)telemetryDataPoint.name);
            output.EventEnqueuedUtcTime.ShouldBe(DateTime.UtcNow, TimeSpan.FromMilliseconds(1000));
            output.DeviceName.ShouldBe("190131");
            output.ObjectType.ShouldBe("AnalogValue");
            output.Instance.ShouldBe(90);
            output.PresentValue.ShouldBe("73.000000");
            output.ValueUnits.ShouldBe("DEGREES-FAHRENHEIT");
            output.DeviceTimestamp.ShouldBe(DateTime.Parse("2019-06-10T23:48:43.667Z"));
            output.DeviceStatus.ToLower().ShouldBe(bool.TrueString.ToLower());
            Console.Write(JsonConvert.SerializeObject(output));
        }
Esempio n. 4
0
        public static IInputDocument LoadDocument(int docnum, IGlobalValues data)
        {
            var    sql    = new SqlConnection(data.ConnectionString);
            string sqlcmd = @"SELECT DocTypeID FROM " + data.ActiveSchema +
                            ".DocumentHead WHERE  DocumentHead.DocumentID = " + docnum.ToString();
            SqlCommand cmd = new SqlCommand(sqlcmd, sql);
            int        type;

            try
            {
                sql.Open();
                type = (int)cmd.ExecuteScalar();
                sql.Close();
            }
            catch (Exception exception)
            {
                //return null;
                throw new Exception("Ошибка загрузки свойств документа.", exception);
            }
            switch (type)
            {
            case 1:
            case 3:
                return(PlanDocument.LoadDocument(docnum, data.ActiveSchema + ".DocumentHead", data.ActiveSchema + ".DocumentBody", data.ConnectionString));

            case 2:
            case 4:
                return(DeviceDocument.LoadDocument(docnum, data.ActiveSchema + ".DocumentHead", data.ActiveSchema + ".DocumentBody", data.ConnectionString, new List <int>(data.ProductGroups[DEVICES].Keys)));

            default:
                throw new Exception("Неверный тип документа.");
            }
        }
        public async Task FlagsUnprovisionedDevicesTest()
        {
            BACNetTelemetryMsg ioTWorxBacNetMsg = new BACNetTelemetryMsg()
            {
                name      = "Device_190130_AV_67",
                value     = "180",
                status    = "",
                timestamp = DateTime.UtcNow.ToString("o")
            };
            BACNetIoTHubMessage iotBacNetEventHubMessage = new BACNetIoTHubMessage(
                ioTWorxBacNetMsg,
                ed.SystemProperties, new Dictionary <string, object>());

            var messages = new List <BACNetIoTHubMessage>()
            {
                { iotBacNetEventHubMessage }
            };

            await IoTWorxBuildingDataProcessingFunction.HandleMessageBatch(
                messages, provisionedDeviceDocuments, outputDeviceDocs, outputEvents, unprovisionedDeviceOutput,
                LoggerUtils.Logger <object>(), new CancellationToken());

            //Unprovisioned devices should be written to the DocDb and flagged accordingly
            outputDeviceDocs.Items.Count.ShouldBe(1);
            DeviceDocument deviceDocument = outputDeviceDocs.Items[0];

            deviceDocument.id.ShouldBe(ioTWorxBacNetMsg.name);
            deviceDocument.PresentValue.ShouldBe(ioTWorxBacNetMsg.value);
            deviceDocument.DeviceStatus.ShouldBe("Unprovisioned");

            unprovisionedDeviceOutput.Items.Count.ShouldBe(1);

            //Don't send Unprovisioned device events downstream
            outputEvents.Items.ShouldBeEmpty();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            DeviceDocument deviceDocument = db.DeviceDocuments.Find(id);

            db.DeviceDocuments.Remove(deviceDocument);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task OnlyProvisionedDeviceDataSentToEventHub()
        {
            //Create 2 messages, one for a provisioned and the other an unprovisioned device
            BACNetTelemetryMsg ioTWorxBacNetMsg = new BACNetTelemetryMsg()
            {
                name      = "Device_190130_AV_67",
                value     = "180",
                status    = "true",
                timestamp = DateTime.UtcNow.ToString("o")
            };
            BACNetIoTHubMessage provisionedIoTBacNetEventHubMessage = new BACNetIoTHubMessage(
                ioTWorxBacNetMsg,
                ed.SystemProperties, new Dictionary <string, object>());

            //Clone Provisioned into Unprovisioned and modify the name
            var unprovisionedIoTBacNetEventHubMessage =
                JsonConvert.DeserializeObject <BACNetIoTHubMessage>(JsonConvert.SerializeObject(provisionedIoTBacNetEventHubMessage));

            unprovisionedIoTBacNetEventHubMessage.BACNetMsg.name = "unprovisioned_device_name";

            var messages = new List <BACNetIoTHubMessage>()
            {
                { provisionedIoTBacNetEventHubMessage },
                { unprovisionedIoTBacNetEventHubMessage }
            };

            //Ensure device 1 is "Provisioned" (and 2 isn't)
            var provisionedDeviceDocuments = new List <DeviceDocument>()
            {
                { new DeviceDocument()
                  {
                      id = provisionedIoTBacNetEventHubMessage.BACNetMsg.name, DeviceStatus = "Provisioned"
                  } }
            };

            await IoTWorxBuildingDataProcessingFunction.HandleMessageBatch(
                messages, provisionedDeviceDocuments, outputDeviceDocs, outputEvents, unprovisionedDeviceOutput,
                LoggerUtils.Logger <object>(), new CancellationToken());

            //Unprovisioned devices should be written to the DocDb and flagged accordingly
            outputDeviceDocs.Items.Count.ShouldBe(2);
            unprovisionedDeviceOutput.Items.Count.ShouldBe(1);

            DeviceDocument deviceDocument = outputDeviceDocs.Items[0];

            deviceDocument.id.ShouldBe(provisionedIoTBacNetEventHubMessage.BACNetMsg.name);
            deviceDocument.PresentValue.ShouldBe(provisionedIoTBacNetEventHubMessage.BACNetMsg.value);
            deviceDocument.DeviceStatus.ShouldBe("true");

            DeviceDocument unprovisionedDeviceDocument = outputDeviceDocs.Items[1];

            unprovisionedDeviceDocument.id.ShouldBe(unprovisionedIoTBacNetEventHubMessage.BACNetMsg.name);
            unprovisionedDeviceDocument.PresentValue.ShouldBe(unprovisionedIoTBacNetEventHubMessage.BACNetMsg.value);
            unprovisionedDeviceDocument.DeviceStatus.ShouldBe("Unprovisioned");
        }
 public ActionResult Edit(DeviceDocumentViewModel _viewModel)
 {
     if (ModelState.IsValid)
     {
         DeviceDocument _model = GetModelDatas(_viewModel);
         db.Entry(_model).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DeviceID = new SelectList(db.Devices, "DeviceID", "DeviceType", _viewModel.DeviceID);
     return(View(_viewModel));
 }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DeviceDocument deviceDocument = db.DeviceDocuments.Find(id);

            if (deviceDocument == null)
            {
                return(HttpNotFound());
            }
            return(View(deviceDocument));
        }
Esempio n. 10
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DeviceDocument deviceDocument = db.DeviceDocuments.Find(id);

            if (deviceDocument == null)
            {
                //return HttpNotFound();
                return(View("ErrorView"));
            }
            return(View(deviceDocument));
        }
Esempio n. 11
0
        public static IInputDocument CreateDocument(InputDocumentHead head, IGlobalValues data, int parent)
        {
            switch (head.DocType)
            {
            case 1:
            case 3:
                return(PlanDocument.CreateDocument(head, data.ActiveSchema + ".DocumentHead", data.ActiveSchema + ".DocumentBody", data.ConnectionString, parent));

            case 2:
            case 4:
                return(DeviceDocument.CreateDocument(head, data.ActiveSchema + ".DocumentHead", data.ActiveSchema + ".DocumentBody", data.ConnectionString, new List <int>(data.ProductGroups[DEVICES].Keys), parent));

            default:
                throw new Exception("Неверный тип документа.");
            }
        }
Esempio n. 12
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DeviceDocument _model     = db.DeviceDocuments.Find(id);
            var            _viewModel = DeviceDocumentViewModel.GetViewModelDatas(_model);

            if (_model == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DeviceID = new SelectList(db.Devices, "DeviceID", "InventoryNumber", _model.DeviceID);
            return(View(_viewModel));
        }
Esempio n. 13
0
        public async Task UnprovisionedRemainsTest()
        {
            BACNetTelemetryMsg ioTWorxBacNetMsg = new BACNetTelemetryMsg()
            {
                name      = "Device_190130_AV_67",
                value     = "180",
                status    = "true",
                timestamp = DateTime.UtcNow.ToString("o")
            };
            BACNetIoTHubMessage iotBacNetEventHubMessage = new BACNetIoTHubMessage(
                ioTWorxBacNetMsg,
                ed.SystemProperties, new Dictionary <string, object>());

            var messages = new List <BACNetIoTHubMessage>()
            {
                { iotBacNetEventHubMessage }
            };

            //Ensure this device is Provisioned as "Unprovisioned" and stays that way
            var provisionedDeviceDocuments = new List <DeviceDocument>()
            {
                { new DeviceDocument()
                  {
                      id = ioTWorxBacNetMsg.name, DeviceStatus = "Unprovisioned"
                  } }
            };

            await IoTWorxBuildingDataProcessingFunction.HandleMessageBatch(
                messages, provisionedDeviceDocuments, outputDeviceDocs, outputEvents, unprovisionedDeviceOutput,
                LoggerUtils.Logger <object>(), new CancellationToken());

            //Unprovisioned devices should be written to the DocDb and remain in Unprovisioned state
            outputDeviceDocs.Items.Count.ShouldBe(1);
            DeviceDocument outDeviceDocument = outputDeviceDocs.Items[0];

            outDeviceDocument.id.ShouldBe(ioTWorxBacNetMsg.name);
            outDeviceDocument.PresentValue.ShouldBe(ioTWorxBacNetMsg.value);
            outDeviceDocument.DeviceStatus.ShouldBe("Unprovisioned");

            unprovisionedDeviceOutput.Items.Count.ShouldBe(1);

            //Don't send Unprovisioned device events downstream
            outputEvents.Items.Count.ShouldBe(0);
        }
Esempio n. 14
0
        public ActionResult Create(DeviceDocument _model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    db.DeviceDocuments.Add(_model);
                    db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    //ViewBag.Error = ex.ToString();
                    throw new DbEntityValidationException(ex.ToString());
                    //return View("SaveError");
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.DeviceID = new SelectList(db.Devices, "DeviceID", "InventoryNumber", _model.DeviceID);
            return(View(_model));
        }