/// <summary>
        /// Compared to <see cref="GetValues(IBaseExchangeItem)"/>,
        /// this version adds the values to the targetSet (for reuse or adding to a targetSet)
        /// </summary>
        public void GetValues(ITimeSpaceValueSet <double> targetSet, IBaseExchangeItem querySpecifier2)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier2 as ITimeSpaceExchangeItem;

            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            if (!(timeSpaceQuery is ITimeSpaceInput))
            {
                throw new OpenMIException("Get Values can only be called with an Input as argument")
                      {
                          Component = Adaptee.Component, Output = this
                      };
            }

            // Set query time to internal query item
            _query.TimeSet = timeSpaceQuery.TimeSet;

            ITimeSpaceValueSet incomingValues = _adaptee.GetValues(_query);

            // Transform the values from the adaptee
            _elementMapper.MapValues(targetSet, incomingValues);
        }
Exemple #2
0
        public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
        {
            // Note (SH): shouldn't a copy be made here?
            // Reply (ADH): In EngineWrapper2 I effectivly clone via the Values attribute
            // Suggest that standard should require GetValues to return
            // cloned IValueSet.
            // Maybe, more simply, IVAlueSet should implement IClonable
            ITimeSpaceValueSet values = base.GetValues(querySpecifier);

            if (values == null)
            {
                return(values);
            }

            if (!_initialisedFromArgs)
            {
                InitialiseFromArgs();
            }

            for (int m = 0; m < values.Values2D.Count; ++m)
            {
                for (int n = 0; n < values.Values2D[m].Count; ++n)
                {
                    if (values.Values2D[m][n] is double)
                    {
                        values.Values2D[m][n] = _a * (double)values.Values2D[m][n] + _b;
                    }
                }
            }

            return(values);
        }
Exemple #3
0
 public ExchangeItem(IBaseExchangeItem openMIItem, bool useBufferedValues)
 {
     if (openMIItem is ITimeSpaceOutput)
     {
         _openMIItem = _openMIOutputItem = (ITimeSpaceOutput)openMIItem;
     }
     else if (openMIItem is ITimeSpaceInput)
     {
         _openMIItem = _openMIInputItem = (ITimeSpaceInput)openMIItem;
     }
     else
     {
         throw new Exception("Unknown exchange item type: " + openMIItem.GetType());
     }
     if (_openMIItem.TimeSet != null && _openMIItem.TimeSet.HasDurations)
     {
         throw new Exception("\"" + Id + ": OpenDA Time Spans not covered by OpenDA Exchange items");
     }
     _useBufferedValues = useBufferedValues;
     if (_useBufferedValues)
     {
         _bufferedValues = new List <List <double> > {
             new List <double>()
         };
         _bufferedTimes = new List <double>();
     }
 }
        public ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;

            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("Must be an ITimeSpaceExchangeItem, add an adaptor", "querySpecifier");
            }

            if (_children.Count == 0)
            {
                return(null); // TODO: Or throw an exception?
            }
            TimeSpaceValueSet <double> resultSet = ElementMapper.CreateResultValueSet(timeSpaceQuery.TimeSet.Times.Count, this.ElementSet().ElementCount);

            // Get values from all adaptees/children, and add them together
            for (int i = 0; i < _children.Count; i++)
            {
                ITimeSpaceOutputAdder addingChild = _children[i] as ITimeSpaceOutputAdder;
                if (addingChild != null)
                {
                    addingChild.GetValues(resultSet, querySpecifier);
                }
                else
                {
                    ITimeSpaceValueSet values = _children[i].GetValues(querySpecifier);
                    AddSourceToTarget(resultSet, values);
                }
            }
            return(resultSet);
        }
Exemple #5
0
 public void AddOut(IBaseExchangeItem openMIo)
 {
     if (openMIo is ITimeSpaceOutput)
     {
         _openMIItem = _openMIOutputItem = (ITimeSpaceOutput)openMIo;
     }
 }
Exemple #6
0
 public void AddIn(IBaseExchangeItem openMIo)
 {
     if (openMIo is ITimeSpaceInput)
     {
         _openMIItem = _openMIInputItem = (ITimeSpaceInput)openMIo;
     }
 }
Exemple #7
0
        /// <summary>
        /// Get the value definition as a quality, throwing an
        /// exception if it is not a quality
        /// </summary>
        public static IQuality Quality(this IBaseExchangeItem item)
        {
            IQuality quality = item.ValueDefinition as IQuality;

            if (quality == null)
            {
                throw new Exception("ValueDefinition is not a quality");
            }
            return(quality);
        }
Exemple #8
0
        /// <summary>
        /// Get the <see cref="IElementSet"/> from the <paramref name="baseitem"/>,
        /// assuming it is a <see cref="ITimeSpaceExchangeItem"/> with an <see cref="IElementSet"/>
        /// as its <see cref="ITimeSpaceExchangeItem.SpatialDefinition"/>. If not, exceptions
        /// are thrown.
        /// </summary>
        public static IElementSet ElementSet(this IBaseExchangeItem baseitem)
        {
            ITimeSpaceExchangeItem item = baseitem as ITimeSpaceExchangeItem;

            if (item == null)
            {
                throw new Exception("base item is not an ITimeSpaceExchangeItem");
            }
            return(item.ElementSet());
        }
Exemple #9
0
        public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;

            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            CheckSpecificationAndTryUpdateIfRequired(timeSpaceQuery);
            return(Values);
        }
        public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier2)
        {
            CheckBuffer();
            List <IList <double> > valuesList = new List <IList <double> >();

            for (int i = 0; i < ((ITimeSpaceInput)Consumers[0]).TimeSet.Times.Count; i++)
            {
                ITime time = ((ITimeSpaceInput)Consumers[0]).TimeSet.Times[i];
                valuesList.Add(_buffer.GetValues(time));
            }
            return(new TimeSpaceValueSet <double>(valuesList));
        }
Exemple #11
0
        public static bool Update(ITimeSpaceOutput output, IBaseExchangeItem basequerySpecifier)
        {
            ITimeSpaceExchangeItem querySpecifier = basequerySpecifier as ITimeSpaceExchangeItem;

            if (querySpecifier == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            // Time set of query must be defined and have at least 1 time
            if (querySpecifier.TimeSet == null ||
                querySpecifier.TimeSet.Times == null ||
                querySpecifier.TimeSet.Times.Count == 0)
            {
                throw new Exception("Given the TimeSet of output item \"" + output.Id +
                                    "\", it can not produce one set of values for \"" + querySpecifier.Id + "\"");
            }

            // Output time set must be defined
            if (output.TimeSet == null || output.TimeSet.Times == null)
            {
                throw new Exception("Invalid time specifier in output item \"" + output.Id +
                                    "\" for in updating according to a time specification" + querySpecifier.Id);
            }

            // Compute until this time is available
            double queryTimeMjd = querySpecifier.TimeSet.Times[0].End().StampAsModifiedJulianDay;

            // The current available time from the output item
            double availableTimeMjd = Double.NegativeInfinity;

            if (output.TimeSet.Times.Count > 0)
            {
                availableTimeMjd = output.TimeSet.Times[output.TimeSet.Times.Count - 1].End().StampAsModifiedJulianDay;
            }

            // Update component until querytime is available
            // If component is "busy" (LinkableComponentStatus.Updating), the
            // component will not be updated.
            IBaseLinkableComponent component = output.Component;

            while ((component.Status == LinkableComponentStatus.Valid ||
                    component.Status == LinkableComponentStatus.Updated) &&
                   availableTimeMjd + Time.EpsilonForTimeCompare < queryTimeMjd)
            {
                component.Update();
                availableTimeMjd = output.TimeSet.Times[output.TimeSet.Times.Count - 1].End().StampAsModifiedJulianDay;
            }

            // Return true if component was updated up until queryTimeMjd
            return(availableTimeMjd + Time.EpsilonForTimeCompare >= queryTimeMjd);
        }
            public void GetValues(ITimeSpaceValueSet <double> targetSet, IBaseExchangeItem querySpecifier)
            {
                // Copy values from the adaptee to the targetSet
                ITimeSpaceValueSet sourceValues = _adaptee.GetValues(querySpecifier);

                for (int i = 0; i < targetSet.TimesCount(); i++)
                {
                    double[] sourceTimeValues = sourceValues.GetElementValuesForTime <double>(i);
                    for (int j = 0; j < targetSet.ElementCount(); j++)
                    {
                        targetSet.Values2D[i][j] += sourceTimeValues[j];
                    }
                }
            }
        bool TreeNodeContains(IBaseExchangeItem item, TreeNode node, out TreeNode outnode)
        {
            outnode = null;

            foreach (TreeNode n  in node.Nodes)
            {
                if (n.Tag != null && n.Tag is IBaseExchangeItem && ((item == (IBaseExchangeItem)n.Tag) || item.Id == ((IBaseExchangeItem)node.Tag).Id))
                {
                    outnode = n;
                    return(true);
                }
            }

            return(false);
        }
        public BaseExchangeItem(IBaseExchangeItem item)
            : base(item)
        {
            //            _componentId = _component != null ? _component.Id : string.Empty;

            BaseExchangeItem e = item as BaseExchangeItem;

            if (e != null)
            {
                // Need to clone e._valueSetConverter?

                _valueSetConverter = e._valueSetConverter;

                if (_valueSetConverter != null)
                    _valueSetConverter.ExchangeItem = this;
            }
        }
Exemple #15
0
            public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
            {
                ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;

                if (timeSpaceQuery == null)
                {
                    throw new ArgumentException("Query is not an ITimeSpaceExchangeItem - you may need to add an adaptor");
                }
                if (timeSpaceQuery.TimeSet != null && timeSpaceQuery.TimeSet.Times.Count == 1)
                {
                    double[] valuesForTimeStep = _timeSeriesComponent.Buffer.GetValues(timeSpaceQuery.TimeSet.Times[0]);
                    return(new ValueSet(new List <IList> {
                        valuesForTimeStep
                    }));
                }
                throw new Exception("Invalid time specification in querying exchange item \"" + querySpecifier.Id + "\"");
            }
        public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier2)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier2 as ITimeSpaceExchangeItem;

            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            if (!(timeSpaceQuery is ITimeSpaceInput))
            {
                throw new OpenMIException("Get Values can only be called with an Input as argument")
                      {
                          Component = Adaptee.Component, Output = this
                      };
            }


            /// Using a _query item in the
            ///     _adaptee.GetValues(_query)
            /// instead of
            ///     _adaptee.GetValues(this)
            ///
            /// Reason:
            /// If using the latter, it would be required to set the internal
            ///     TimeSet = timeSpaceQuery.TimeSet;
            /// but then internal Values (retrieved from adaptee) does not match TimeSet.
            /// And also:
            /// - the TimeSet is set to override and return _adaptee.TimeSet
            /// - the spatial definition would not match the adaptee

            // If uncommenting this, comment out also the overidden TimeSet property above
            //TimeSet = timeSpaceQuery.TimeSet;

            // Set query time to internal query item
            _query.TimeSet = timeSpaceQuery.TimeSet;

            ITimeSpaceValueSet          incomingValues = _adaptee.GetValues(_query);
            ITimeSpaceValueSet <double> resultValues   = ElementMapper.CreateResultValueSet(incomingValues.TimesCount(), SpatialDefinition.ElementCount);

            // Transform the values from the adaptee
            _elementMapper.MapValues(ref resultValues, ref incomingValues);

            return(resultValues);
        }
Exemple #17
0
        // Called from source
        public ITimeSpaceValueSet GetValues(IBaseExchangeItem exchange)
        {
            if (!(exchange is ITimeSpaceInput))
            {
                throw new InvalidOperationException();
            }

            ITimeSpaceInput source = (ITimeSpaceInput)exchange;

            ValidTimeSet(source.TimeSet);

            // TODO Check Component.Status befor update ? gridlock issues?
            // this.GetValues(source) should

            bool unavailable      = false;
            bool forceCacheUpdate = false;

            while (!CacheUpdateSource(source, forceCacheUpdate))
            {
                // TODO Multithreading sleep and retry
                unavailable
                    = Component.Status != LinkableComponentStatus.Initialized &&
                      Component.Status != LinkableComponentStatus.Updated &&
                      Component.Status != LinkableComponentStatus.Valid;

                if (unavailable)
                {
                    forceCacheUpdate = true;
                }
                else
                {
                    Component.Update(new ITimeSpaceOutput[] { this });
                }
            }

            if (ItemChanged != null)
            {
                ItemChanged(this, new ExchangeItemChangeEventArgs {
                    ExchangeItem = this, Message = CurrentState()
                });
            }

            return(((ITimeSpaceInput)source).Values);
        }
Exemple #18
0
      public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
      {
        ITimeSpaceExchangeItem item = (ITimeSpaceExchangeItem)querySpecifier;

        TimeSet.SetSingleTime(item.TimeSet.Times[0]);

        int count = item.ElementSet().ElementCount;

        double[] vals = new double[count];
        for (int i = 0; i < count; i++)
        {
          vals[i] = ConstOutput;
        }

        ValueSetArray<double> valueset = new ValueSetArray<double>(vals);

        return valueset;

      }
Exemple #19
0
        public virtual ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;

            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("Must be an ITimeSpaceExchangeItem - an adaptor may be required");
            }
            if (!ExchangeItemHelper.OutputAndInputElementSetsFit(this, timeSpaceQuery))
            {
                throw new Exception("ElementSet of output item \"" + Id +
                                    "\" does not fit the ElementSet of requesting item \"" + querySpecifier.Id);
            }

            if (!ExchangeItemHelper.OutputAndInputTimeSetsFit(this, timeSpaceQuery))
            {
                throw new Exception("TimeSet of output item \"" + Id +
                                    "\" does not fit the TimeSet of requesting item \"" + querySpecifier.Id);
            }

            return(Values);
        }
Exemple #20
0
 ITimeSpaceValueSet ITimeSpaceOutput.GetValues(IBaseExchangeItem querySpecifier)
 {
     throw new NotImplementedException();
 }
Exemple #21
0
 public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
 {
     return(Convert((ITimeSpaceValueSet)Adaptee.GetValues(querySpecifier)));
 }
Exemple #22
0
 /// <summary>
 /// Constructor that also initializes the <see cref="ExchangeItem"/>
 /// and the <see cref="Message"/> property
 /// </summary>
 public ExchangeItemChangeEventArgs(IBaseExchangeItem exchangeItem, string message)
 {
     ExchangeItem = exchangeItem;
     Message      = message;
 }
 public abstract override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier);
 public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
 {
     return(CreateValues());
 }
            /// <summary>
            /// Overridden to call convertor.GetValues(...) directly without any calls to Engine.Update()
            /// </summary>
            /// <param name="querySpecifier"></param>
            /// <returns></returns>
            protected override ITimeSpaceValueSet GetValuesTimeImplementation(IBaseExchangeItem querySpecifier)
            {
                var convertor = ValueSetConverter as IValueSetConverterTime;

                if (convertor == null)
                    throw new Exception("ValueSetConverter not a IValueSetConverterTime");

                // Non OpenMI special case, handy for checking current values without changing engine state

                if (querySpecifier == null)
                    convertor.GetValueSetLatest();

                if (querySpecifier is IBaseInput && !Consumers.Any(c => c.Id == querySpecifier.Id))
                    throw new Exception("GetValues request from an unregistered Input Item: " + querySpecifier.Id);
                else if (querySpecifier is IBaseOutput && !AdaptedOutputs.Any(c => c.Id == querySpecifier.Id))
                    throw new Exception("GetValues request from an unregistered Adapted Output Item: " + querySpecifier.Id);

                if (querySpecifier is IBaseOutput)
                    throw new NotImplementedException();

                if (!(querySpecifier is ITimeSpaceExchangeItem))
                    return convertor.GetValueSetLatest() as ITimeSpaceValueSet;

                ITimeSet requestTimeSet = ((ITimeSpaceExchangeItem)querySpecifier).TimeSet;

                return convertor.GetValueSetAt(requestTimeSet) as ITimeSpaceValueSet;
            }
 /// <summary>
 /// Constructor that also initializes the <see cref="ExchangeItem"/>
 /// and the <see cref="Message"/> property
 /// </summary>
 public ExchangeItemChangeEventArgs(IBaseExchangeItem exchangeItem, string message)
 {
   ExchangeItem = exchangeItem;
   Message = message;
 }
 public virtual ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
 {
     return(_adaptee.GetValues(querySpecifier));
 }
Exemple #28
0
        private static double _lastOutputTime; // HACK, REMOVE

        public ExchangeItem(IBaseExchangeItem openMIItem) : this(openMIItem, false)
        {
        }
Exemple #29
0
 IBaseValueSet IBaseOutput.GetValues(IBaseExchangeItem querySpecifier)
 {
     return GetValues(querySpecifier);
 }
        protected override IBaseValueSet GetValuesImplementation(IBaseExchangeItem querySpecifier)
        {
            // Here as non spatial and not temporal

            // Special case, handy for checking current values without changing engine state
            if (querySpecifier == null)
                ValueSetConverter.GetValueSetLatest();

            if (querySpecifier is IBaseInput && !Consumers.Any(c => c.Id == querySpecifier.Id))
                throw new Exception("GetValues request from an unregistered Input Item: " + querySpecifier.Id);
            else if (querySpecifier is IBaseOutput && !AdaptedOutputs.Any(c => c.Id == querySpecifier.Id))
                throw new Exception("GetValues request from an unregistered Adapted Output Item: " + querySpecifier.Id);

            if (querySpecifier is IBaseOutput)
                throw new NotImplementedException();

            // Not a time based request just update and return latest

            Component.Update(this);

            return ValueSetConverter.GetValueSetLatest();
        }
        public static IValueSetConverter Convertor(IBaseExchangeItem item)
        {
            var has = item as IHasValueSetConvertor;

            if (has == null || has.ValueSetConverter == null)
                throw new Exception(item.Caption + " does not have a IValueSetConverter");

            return ((IHasValueSetConvertor)item).ValueSetConverter;
        }
Exemple #32
0
 public abstract override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier);
Exemple #33
0
        public override ITimeSpaceValueSet GetValues(IBaseExchangeItem basequerySpecifier)
        {
            ITimeSpaceExchangeItem querySpecifier = basequerySpecifier as ITimeSpaceExchangeItem;

            if (querySpecifier == null)
            {
                throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");
            }

            //------------------------------------------------------
            // Check if we need to update the output component

            // Time set of query must be defined and have at least 1 time
            if (querySpecifier.TimeSet == null ||
                querySpecifier.TimeSet.Times == null ||
                querySpecifier.TimeSet.Times.Count == 0)
            {
                throw new Exception("Invalid query specifier \"" + querySpecifier.Id +
                                    "\" for in GetValues() call to time decorater " + Id);
            }

            // Determine query time
            double queryTimeMjd = querySpecifier.TimeSet.Times[querySpecifier.TimeSet.Times.Count - 1].End().StampAsModifiedJulianDay;

            // Determine the times available in the buffer
            double        availableTimeMjd = Double.NegativeInfinity;
            IList <ITime> currentTimes     = TimeSet.Times;

            if (currentTimes.Count > 0)
            {
                availableTimeMjd = currentTimes[currentTimes.Count - 1].End().StampAsModifiedJulianDay;
            }

            // Check if we need to update
            // In case the output component is "busy", this may not actually update values
            // up to queryTimeMjd, in which case the _buffer.GetValues below will extrapolate.
            if (availableTimeMjd < queryTimeMjd)
            {
                if (ComponentUpdater == null)
                {
                    throw new Exception("Failed when trying to update time buffer (no updater is specified)");
                }
                ComponentUpdater.Update(querySpecifier);
            }

            //------------------------------------------------------
            // Retrieve values from the buffer

            // Return the values for the required time(s)
            IList <IList <double> > resultValues = new List <IList <double> >();

            if (querySpecifier.TimeSet != null && querySpecifier.TimeSet.Times != null)
            {
                for (int t = 0; t < querySpecifier.TimeSet.Times.Count; t++)
                {
                    ITime    queryTime         = querySpecifier.TimeSet.Times[t];
                    double[] valuesForTimeStep = _buffer.GetValues(queryTime);
                    resultValues.Add(valuesForTimeStep);
                }
            }
            ITime earliestConsumerTime = ExchangeItemHelper.GetEarliestConsumerTime(this);

            if (earliestConsumerTime != null)
            {
                _buffer.ClearBefore(earliestConsumerTime);
            }
            return(new TimeSpaceValueSet <double>(resultValues));
        }
 public override bool CanConnect(IBaseExchangeItem proposed, out string whyNot)
 {
     whyNot = "Can connect to anything, but cannot be used at runtime.";
     return true;
 }
    public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
    {
      ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;
      if (timeSpaceQuery == null)
        throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor");

      if (timeSpaceQuery.TimeSet == null || timeSpaceQuery.TimeSet.Times == null ||
          timeSpaceQuery.TimeSet.Times.Count == 0)
      {
        throw new Exception("Invalid query specifier \"" + timeSpaceQuery.Id +
                            "\" for in GetValues() call to time decorater " + Id);
      }

      // Determinee query time and currently available time
      double queryTimeAsMJD =
          timeSpaceQuery.TimeSet.Times[timeSpaceQuery.TimeSet.Times.Count - 1].StampAsModifiedJulianDay +
          timeSpaceQuery.TimeSet.Times[timeSpaceQuery.TimeSet.Times.Count - 1].DurationInDays;

      double availableTimeAsMJD = Double.NegativeInfinity;
      IList<ITime> currentTimes = TimeSet.Times;
      if (currentTimes.Count > 0)
      {
        availableTimeAsMJD =
            currentTimes[currentTimes.Count - 1].StampAsModifiedJulianDay +
            currentTimes[currentTimes.Count - 1].DurationInDays;
      }

      // Check if we need to update
      if (availableTimeAsMJD < queryTimeAsMJD)
      {
        // TODO (JGr): output item should not do the actual update of the component?
        if (Adaptee == null)
        {
          throw new Exception("Can not update, no parent output defined, calling GetValues() of time bufferer " + Id);
        }
        if (_adaptee.TimeSet == null || _adaptee.TimeSet.Times == null)
        {
          throw new Exception("Invalid time specifier in decorated output item \"" + Adaptee.Id +
                              "\" for in GetValues() call to time decorater " + Id);
        }

        // Update as far as needed.
        IBaseLinkableComponent linkableComponent = Adaptee.Component;
        while ((linkableComponent.Status == LinkableComponentStatus.Valid ||
                linkableComponent.Status == LinkableComponentStatus.Updated) &&
               availableTimeAsMJD < queryTimeAsMJD)
        {
          linkableComponent.Update();
          // Determine newly available time
          IList<ITime> parentTimes = _adaptee.TimeSet.Times;
          availableTimeAsMJD =
              parentTimes[parentTimes.Count - 1].StampAsModifiedJulianDay +
              parentTimes[parentTimes.Count - 1].DurationInDays;
        }
      }

      // Return the values for the required time(s)
      IList<IList<double>> resultValues = new List<IList<double>>();
      if (timeSpaceQuery.TimeSet != null && timeSpaceQuery.TimeSet.Times != null)
      {
        for (int t = 0; t < timeSpaceQuery.TimeSet.Times.Count; t++)
        {
          resultValues.Add(new List<double>());
          ITime queryTime = timeSpaceQuery.TimeSet.Times[t];
          List<double> valuesForTimeStep = _buffer.GetValues(queryTime);
          foreach (double d in valuesForTimeStep)
          {
            resultValues[t].Add(d);
          }
        }
      }
      return new TimeSpaceValueSet<double>(resultValues);
    }
Exemple #36
0
 public new IBaseValueSet GetValues(IBaseExchangeItem querySpecifier)
 {
     return(((ITimeSpaceAdaptedOutput)_item).GetValues(querySpecifier));
 }
Exemple #37
0
        public virtual ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
        {
            ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;
            if (timeSpaceQuery == null)
            {
                throw new ArgumentException("Must be an ITimeSpaceExchangeItem - an adaptor may be required");
            }
            if (!ExchangeItemHelper.OutputAndInputElementSetsFit(this, timeSpaceQuery))
            {
                throw new Exception("ElementSet of output item \"" + Id +
                                    "\" does not fit the ElementSet of requesting item \"" + querySpecifier.Id);
            }

            if (!ExchangeItemHelper.OutputAndInputTimeSetsFit(this, timeSpaceQuery))
            {
                throw new Exception("TimeSet of output item \"" + Id +
                                    "\" does not fit the TimeSet of requesting item \"" + querySpecifier.Id);
            }

            return Values;
        }
    public ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
    {
      ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem;
      if (timeSpaceQuery == null)
        throw new ArgumentException("Must be an ITimeSpaceExchangeItem, add an adaptor", "querySpecifier");

      if (_children.Count == 0)
        return (null); // TODO: Or throw an exception?
      
      TimeSpaceValueSet<double> resultSet = ElementMapper.CreateResultValueSet(timeSpaceQuery.TimeSet.Times.Count, this.ElementSet().ElementCount);

      // Get values from all adaptees/children, and add them together
      for (int i = 0; i < _children.Count; i++)
      {
        _children[i].GetValues(resultSet, querySpecifier);
      }
      return (resultSet);
    }
 public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
 {
     return(_tsadaptee.GetValues(querySpecifier).MultiplyElementValues(_factors));
 }
 public ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier)
 {
   return (_adaptee.GetValues(querySpecifier));
 }
 IBaseValueSet IBaseOutput.GetValues(IBaseExchangeItem querySpecifier)
 {
     return(GetValues(querySpecifier));
 }
      public void GetValues(ITimeSpaceValueSet<double> targetSet, IBaseExchangeItem querySpecifier)
      {
        // Copy values from the adaptee to the targetSet
        ITimeSpaceValueSet sourceValues = _adaptee.GetValues(querySpecifier);

        for (int i = 0; i < targetSet.TimesCount(); i++)
        {
          double[] sourceTimeValues = sourceValues.GetElementValuesForTime<double>(i);
          for (int j = 0; j < targetSet.ElementCount(); j++)
          {
            targetSet.Values2D[i][j] += sourceTimeValues[j];
          }
        }
      }
 protected override IBaseValueSet GetValuesImplementation(IBaseExchangeItem querySpecifier)
 {
     return GetValuesTimeImplementation(querySpecifier);
 }
Exemple #44
0
 public IBaseValueSet GetValues(IBaseExchangeItem querySpecifier)
 {
     throw new NotImplementedException();
 }
        public static IValueSetConverterTimeEngine EngineConvertor(IBaseExchangeItem item)
        {
            var convertor = Convertor(item) as IValueSetConverterTimeEngine;

            if (convertor == null)
                throw new Exception(item.Caption + " does not have a IValueSetConverterEngine");

            return convertor;
        }
        protected override ITimeSpaceValueSet GetValuesTimeImplementation(IBaseExchangeItem querySpecifier)
        {
            if (!(querySpecifier is ITimeSpaceExchangeItem))
                return _valueSetConverterTime.GetValueSetLatest() as ITimeSpaceValueSet;

            TimeSet = ((ITimeSpaceExchangeItem)querySpecifier).TimeSet;
            TimeSet queryTime = new TimeSet(((ITimeSpaceExchangeItem)querySpecifier).TimeSet);

            if (Component == null) // Orphaned Exchange item
                return _valueSetConverterTime.GetValueSetAt(TimeSet) as ITimeSpaceValueSet;

            int updateCount = 0;

            while (!_valueSetConverterTime.CanGetValueSetWithoutExtrapolationAt(queryTime))
            {
                if (Component.Status == LinkableComponentStatus.Updating)
                {
                    // Bidirectional link and component is busy

                    string warning = string.Format("WARNING: Component \"{0}\" busy extrapolated for required values", Component.Caption);

                    Trace.TraceWarning(warning);
                    SendItemChangedEvent(warning);

                    return _valueSetConverterTime.GetValueSetAt(queryTime) as ITimeSpaceValueSet;
                }
                else if (updateCount > _updatelimitBeforeExtrapolating)
                {
                    string error = string.Format(
                        "ERROR: Component \"{0}\" reached update limit of {1}, aborted updates and extrapolated for required values",
                        Component.Caption, _updatelimitBeforeExtrapolating);

                    Trace.TraceError(error);
                    SendItemChangedEvent(error);

                    return _valueSetConverterTime.GetValueSetAt(queryTime) as ITimeSpaceValueSet;
                }
                else
                {
                    Component.Update(this);
                    ++updateCount;
                }
            }

            return _valueSetConverterTime.GetValueSetAt(queryTime) as ITimeSpaceValueSet;
        }