Exemple #1
0
        public void Process(MessageReceivedArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));
            Assert.ArgumentNotNull(args.EventData, nameof(args.EventData));
            Assert.ArgumentNotNull(args.Database, nameof(args.Database));

            var eventData = args.EventData;

            if (eventData?.Body.Array == null)
            {
                return;
            }

            var data = Encoding.UTF8.GetString(eventData.Body.Array);

            Log.Info($"Message received on partition {args.Partition}: {data}", args.EventData);

            // Find the key that brings the method reference - won't handle the message if this is not found
            var methodKey = eventData.Properties.Keys.FirstOrDefault(p => p.ToLower() == MethodProperyName.ToLower());

            if (string.IsNullOrEmpty(methodKey))
            {
                return;
            }
            var methodNameOrPath = eventData.Properties[methodKey].ToString();
            var method           = _hubRepository.GetMethodByName(methodNameOrPath, args.Database);
            var device           = _hubRepository.GetDeviceByName(methodNameOrPath, args.Database);

            if (method == null || device == null)
            {
                return;
            }

            // Get payload from device (if any)
            var payloadKey = eventData.Properties.Keys.FirstOrDefault(p => p.ToLower() == PayloadProperyName.ToLower());
            var payload    = string.IsNullOrEmpty(payloadKey) ? string.Empty : eventData.Properties[payloadKey].ToString();

            // Store results on cache
            _methodCacheManager.SaveResponseToCache(device, method, payload, data);
        }
Exemple #2
0
        /// <summary>
        /// Parameters accepts string separated by ','
        /// Position 0 = Sitecore ID, Sitecore Path or dot separated string Eg: "HubName.DeviceName.MethodName"
        /// Position 1 = PropertyName
        /// Position 2 = Payload
        /// </summary>
        /// <param name="strParameters"></param>
        /// <returns></returns>
        public object GetValue(string strParameters)
        {
            if (string.IsNullOrEmpty(strParameters) || !strParameters.Contains(","))
            {
                return(string.Empty);
            }

            var parameters = strParameters.Split(',');

            if (parameters.Length < 2)
            {
                return(string.Empty);
            }

            var methodPart   = parameters[0].Trim();
            var propertyPart = parameters[1].Trim();
            var payloadPart  = parameters.Length > 2 ? parameters[2].Trim() : string.Empty;

            if (string.IsNullOrEmpty(methodPart) || string.IsNullOrEmpty(propertyPart))
            {
                return(string.Empty);
            }

            // Get method and device
            var device = _hubRepository.GetDeviceByName(methodPart);
            var method = _hubRepository.GetMethodByName(methodPart);

            if (method == null || device == null)
            {
                return(string.Empty);
            }

            // Invoke method and get result
            var result        = method.Invoke(device, payloadPart);
            var propertyValue = result.GetValue(propertyPart);

            return(propertyValue);
            //return propertyValue==null ? string.Empty : propertyValue.ToString();
        }
 public SmartDisplayController(IIoTHubRepository ioTHubRepository)
 {
     _method = ioTHubRepository.GetMethodByName(MethodPath);
     _device = ioTHubRepository.GetDeviceByName(MethodPath);
 }