예제 #1
0
        private static string GetChannelName(NameOrScriptBlock name, Sensor sensor)
        {
            string finalName;

            if (name.IsScriptBlock)
            {
                if (sensor != null)
                {
                    finalName = name.ScriptBlock.InvokeWithDollarUnder(sensor)?.FirstOrDefault()?.ToString();
                }
                else
                {
                    finalName = name.ScriptBlock.InvokeWithVariables()?.FirstOrDefault()?.ToString();
                }
            }
            else
            {
                finalName = name.Name;
            }

            if (string.IsNullOrWhiteSpace(finalName))
            {
                throw new InvalidOperationException($"'{finalName}' is not a valid channel name. Name must not be null, empty or whitespace.");
            }

            return(finalName);
        }
예제 #2
0
        private void ProcessAggregatorEnd(NameOrScriptBlock name, Sensor sensor, ScriptBlock finalizer)
        {
            if (finalizer != null)
            {
                accumulation.Value = finalizer.InvokeWithVariables(accumulation).FirstOrDefault();
            }

            var tuple = MakeChannel(name, sensor, accumulation.Value?.ToString()); //todo: try and break this by returning null to the accumulator...in fact, do that on every script block

            WriteObject(tuple.Item1);
            WriteObject(tuple.Item2);
        }
예제 #3
0
        private Tuple <string, string> MakeChannel(NameOrScriptBlock name, Sensor sensor, string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new InvalidOperationException($"'{value}' is not a valid channel expression. Expression must not be null, empty or whitespace.");
            }

            var processedName = GetChannelName(name, sensor);

            var tuple = Tuple.Create($"#{id}:{processedName}", value);

            id++;

            return(tuple);
        }
예제 #4
0
        private void ProcessAggregator(NameOrScriptBlock name, EnumOrScriptBlock <FactorySummaryMode> aggregator, ScriptBlock finalizer)
        {
            if (summarySensors.Count == 0)
            {
                return;
            }

            var blocks = GetScriptBlockFromSummaryMode(aggregator, finalizer);

            foreach (var sensor in summarySensors)
            {
                ProcessAggregatorInternal(sensor, blocks.Item1);
            }

            ProcessAggregatorEnd(name, summarySensors.LastOrDefault(), blocks.Item2);
        }