Ejemplo n.º 1
0
        public override FunctionHandlerResult Handle(FunctionHandlerContext context, Packet packet, ref HubMessageQueue hubMessageQueue)
        {
            var queryableFunctionPairs = FunctionHandlerHelper.SplitPairs(packet.Text, context.ModuleConfiguration.FunctionResultDelimiter, context.ModuleConfiguration.FunctionResultNameDelimiter);
            var module          = packet.Module;
            var moduleFunctions = context.DatabaseContext.ModuleFunctions
                                  .AsNoTracking()
                                  .Where(i => i.ModuleID == module.ID)
                                  .Select(i => i.FunctionID)
                                  .ToHashSet();

            foreach (var queryableFunctionPair in queryableFunctionPairs)
            {
                var functionName = queryableFunctionPair.Key;
                var functionID   = context.FunctionNames.Forward.GetValueOrNullable(functionName);
                if (!functionID.HasValue)
                {
                    Log(context, packet,
                        MethodBase.GetCurrentMethod().GetFullName(),
                        $"Unrecognized function '{functionName}' received in the report.");

                    continue;
                }

                if (!moduleFunctions.Contains(functionID.Value))
                {
                    Log(context, packet,
                        MethodBase.GetCurrentMethod().GetFullName(),
                        $"Unbound function '{functionName}' received in the report.");

                    continue;
                }

                var functionType = context.FunctionTypes.Reverse[functionID.Value];
                var handler      = context.QueryableFunctionHandlers.GetValueOrDefault(functionType);
                if (handler == null)
                {
                    Log(context, packet,
                        MethodBase.GetCurrentMethod().GetFullName(),
                        $"No handler found for function '{functionName}' received in the report.");

                    continue;
                }

                handler.Handle(context, packet, queryableFunctionPair.Value, hubMessageQueue);
            }

            return(PacketStateEnum.Handled);
        }
Ejemplo n.º 2
0
 protected override IReadOnlyCollection <KeyValuePair <string, string> > GetItems(IpiSensorNetConfiguration moduleConfiguration, Packet packet)
 => FunctionHandlerHelper.SplitPairs(packet.Text, moduleConfiguration.FunctionResultDelimiter, moduleConfiguration.FunctionResultValueDelimiter);