Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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");
            }

            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));
        }