Exemplo n.º 1
0
        private async Task TimeSeriesCapabilityChanged(Climate.ITimeSeries timeSeries)
        {
            if (timeSeries == null)
            {
                return;
            }

            if (TimeSeriesCap != timeSeries)
            {
                TimeSeriesCap?.Dispose();
            }
            TimeSeriesCap = timeSeries;
        }
Exemplo n.º 2
0
        public override void Execute()
        {
            Climate.ITimeSeries timeSeries = null;
            bool   disposeTS = true;
            Packet p         = _timeSeriesPort.Receive();

            if (p != null)
            {
                timeSeries = p.Content as Climate.ITimeSeries;
                Drop(p);
            }

            IEnumerable <Mgmt.Event> mgmtEvents = null;

            p = _mgmtEventsPort.Receive();
            if (p != null)
            {
                mgmtEvents = p.Content as IEnumerable <Mgmt.Event>;
                Drop(p);
            }

            Soil.Profile soilProfile = null;
            p = _soilProfilePort.Receive();
            if (p != null)
            {
                soilProfile = p.Content as Soil.Profile;
                Drop(p);
            }

            p = _restPort.Receive();
            if (p != null)
            {
                object rest = p.Content;
                Drop(p);
                if (rest != null)
                {
                    var     restType = rest.GetType();
                    var     envType  = typeof(Model.Env <>).MakeGenericType(restType);
                    dynamic env      = Activator.CreateInstance(envType);
                    if (env != null)
                    {
                        disposeTS = false;
                        if (rest is ST rst)
                        {
                            env.Rest = rst;
                        }
                        if (timeSeries != null)
                        {
                            env.TimeSeries = timeSeries;
                        }
                        if (soilProfile != null)
                        {
                            env.SoilProfile = soilProfile;
                        }
                        if (mgmtEvents != null)
                        {
                            env.MgmtEvents = mgmtEvents;
                        }
                        _outPort.Send(Create(env));
                    }
                }
            }

            // if there was no REST or no env could be created dispose potential timeSeries cap
            if (disposeTS)
            {
                timeSeries?.Dispose();
            }
        }