Exemplo n.º 1
0
        private IEnumerable <DeviceDetails> GetDeviceData(List <string> assetUids, DeviceConfigRequestBase requestBase, CommonModels.DeviceConfigMessage configMessage)
        {
            var deviceDatas = _deviceService.GetDeviceData(assetUids, requestBase.DeviceType);

            if (deviceDatas.Any() && assetUids.Count() > deviceDatas.Count())
            {
                var noAssetDeviceList = assetUids.Except(deviceDatas.Select(x => x.AssetUid));
                if (noAssetDeviceList.Any())
                {
                    _loggingService.Info("Unable to find the device for the asset : " + string.Join(",", noAssetDeviceList), "MessageConstructor.GetDeviceData");
                    throw new MessageConstructorException("Unable to find the device for the asset : " + string.Join(",", noAssetDeviceList));
                }
            }
            var deviceDetails = deviceDatas.Select(x => new DeviceDetails
            {
                AssetUid     = new Guid(x.AssetUid),
                DeviceUid    = new Guid(x.DeviceUid),
                EventUtc     = configMessage.Timestamp.EventUtc,
                DeviceType   = requestBase.DeviceType,
                Group        = configMessage.Group,
                SerialNumber = x.SerialNumber,
                UserUid      = requestBase.UserUID.HasValue ? requestBase.UserUID.Value : default(Guid)
            });

            return(deviceDetails);
        }
Exemplo n.º 2
0
        public Tuple <bool, List <DeviceConfigMsg> > ProcessMessage(DeviceConfigRequestBase requestBase, CommonModels.DeviceConfigMessage configMessage)
        {
            var failedAssets = String.Empty;

            try
            {
                _loggingService.Debug("Device Request Message : " + JsonConvert.SerializeObject(requestBase), "MessageConstructor.ProcessMessage");
                _loggingService.Debug("Device Config Message : " + JsonConvert.SerializeObject(configMessage), "MessageConstructor.ProcessMessage");
                if (requestBase == null || configMessage == null || !_groupContainer.ContainsKey(configMessage.Group.GroupName) || !_deviceTypeFamilyContainer.ContainsKey(requestBase.DeviceType))
                {
                    _loggingService.Info("Device Message Group Name / Device Type is invalid !!", "MessageConstructor.ProcessMessage");
                    return(Tuple.Create <bool, List <DeviceConfigMsg> >(false, null));
                }
                var deviceDetails     = new List <DeviceDetails>();
                var kafkaObjects      = new List <object>();
                var groupBuilder      = _groupContainer[configMessage.Group.GroupName];
                var deviceTypeFamily  = _deviceTypeFamilyContainer[requestBase.DeviceType];
                var failedAssetsList  = new List <string>();
                var deviceDataDetails = this.GetDeviceData(requestBase.AssetUIDs, requestBase, configMessage);
                switch (deviceTypeFamily.FamilyName)
                {
                case "DataOut":
                    failedAssetsList.AddRange(this.ProcessDataOutMessage(groupBuilder, requestBase, deviceDetails, kafkaObjects, configMessage, deviceDataDetails));
                    break;

                case "MTS":
                    failedAssetsList.AddRange(this.ProcessMtsOutMessage(groupBuilder, requestBase, deviceDetails, kafkaObjects, configMessage, deviceDataDetails));
                    break;

                case "PL":
                    failedAssetsList.AddRange(this.ProcessPLOutMessage(groupBuilder, requestBase, deviceDetails, kafkaObjects, configMessage, deviceDataDetails));
                    break;
                }
                var deviceConfigMsgs = GetDeviceConfigMsg(deviceDetails).ToList();
                if (!(failedAssets.Any() || !PersistPublish(deviceConfigMsgs, kafkaObjects)))
                {
                    return(Tuple.Create(true, deviceConfigMsgs));
                }
                else
                {
                    Exception ex = new MessageConstructorException("Unable to Complete Device Configuration for assetuid " + failedAssets);
                    _loggingService.Error("Unable to Complete Device Configuration for assetuid " + failedAssets, "MessageConstructor.ProcessMessage", ex);
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                _loggingService.Error("Unable to Complete Device Configuration for assetuid " + failedAssets, "MessageConstructor.ProcessMessage", ex);
                throw new MessageConstructorException("Unable to Complete Device Configuration for assetuid " + failedAssets);
            }
        }
Exemplo n.º 3
0
        private List <string> ProcessPLOutMessage(IGroupMessageEventBuilder groupBuilder, DeviceConfigRequestBase requestBase, List <DeviceDetails> deviceDetails, List <object> kafkaObjects, CommonModels.DeviceConfigMessage configMessage, IEnumerable <DeviceDetails> deviceDataDetails)
        {
            var failedAssets       = new List <string>();
            var plOutEvents        = new List <object>();
            var plOutDeviceDetails = new List <DeviceDetails>();

            foreach (var assetuid in requestBase.AssetUIDs)
            {
                var deviceData = deviceDataDetails.First(x => x.AssetUid == Guid.Parse(assetuid));
                _loggingService.Info("Processing Message Started : " + JsonConvert.SerializeObject(deviceData), "MessageConstructor.ProcessPLOutMessage");
                var dataOutObj = groupBuilder.GetPlOutMessageEvent(requestBase, deviceData);
                if (!_dataValidator.TryParseEventMessage(dataOutObj, ref plOutEvents, ref plOutDeviceDetails))
                {
                    failedAssets.Add(assetuid);
                }
            }
            kafkaObjects.AddRange(plOutEvents);
            deviceDetails.AddRange(plOutDeviceDetails);
            return(failedAssets);
        }