public override async Task Execute()
        {
            var arv = new SyncReceiverMultiple(Receivers.Select(it => it.Value).ToArray());
            await arv.LoadData();

            IRow[] data = arv.valuesRead;
            await TransformAndSendData(association, data);
        }
예제 #2
0
        public override async Task Execute()
        {
            IReceive arv = null;

            if (Receivers?.Count == 1)
            {
                arv = Receivers[0];
            }
            if (arv == null)
            {
                if (AllReceiversAsync)
                {
                    arv = new AsyncReceiverMultiple(Receivers.Select(it => it.Value).ToArray());
                }
                else
                {
                    arv = new SyncReceiverMultiple(Receivers.Select(it => it.Value).ToArray());
                }
            }
            await arv.LoadData();

            bool existsVar = (RuntimeParameters?.Length ?? 0) > 0;

            string[] nameObjectsWithVariables = null;
            if (existsVar)
            {
                nameObjectsWithVariables = RuntimeParameters
                                           .SelectMany(it => it.NameObjectsToApplyTo)
                                           .Select(it => it.NameObjectToApplyTo.ToLowerInvariant())
                                           .Distinct()
                                           .ToArray();
            }
            IRow[] data = arv.valuesRead;
            foreach (var filterKV in FiltersAndTransformers)
            {
                var var = filterKV.Value as TransformIntoVariable;
                if (var != null)
                {
                    if (!existsVar)
                    {
                        //TODO:log
                        continue;
                    }
                    var param = RuntimeParameters.FirstOrDefault(it => it.VariableName == var.VariableName);
                    if (param == null)
                    {
                        throw new ArgumentException($"in runtime parameters I cannot find variable {var.VariableName}");
                    }
                    await var.Run();

                    variables[param] = var.Result;
                    continue;
                }
                bool hasVar = (nameObjectsWithVariables?.Length > 0) && (nameObjectsWithVariables.Contains(filterKV.Value.Name.ToLowerInvariant()));
                if (hasVar)
                {
                    TransformPropertyFromVar(filterKV.Value);
                }
                //TODO: see also IFilterTransformer
                var transform = filterKV.Value as ITransform;
                if (transform != null)
                {
                    transform.valuesRead = data;
                    await transform.Run();

                    data = transform.valuesTransformed;
                    continue;
                }
                var filter = filterKV.Value as IFilter;
                if (filter != null)
                {
                    filter.valuesRead = data;
                    await filter.Run();

                    data = filter.valuesTransformed;
                    continue;
                }
                Debug.Assert(false, "base object is not found");
                //@class.Log(LogLevel.Error,0,$"base object is not found",null,null);
                Debug.Assert(false, "filter is not found");
            }
            //await SenderData(data);
            if (Senders.Count == 0)
            {
                return;
            }

            ISend send = null;

            if (Senders.Count == 1)
            {
                send = Senders[0];
            }
            if (send == null)
            {
                if (AllSendersAsync)
                {
                    send = new ASyncSenderMultiple(Senders.Select(it => it.Value).ToArray());
                }
                else
                {
                    send = new SyncSenderMultiple(Senders.Select(it => it.Value).ToArray());
                }
            }
            send.valuesToBeSent = data;
            await send.Send();
        }