コード例 #1
0
        public override IValueSet GetValues(ITime time, string LinkID)
        {
            if (!initializeWasInvoked)
            {
                throw new Exception("Method \"GetValues\" in LinkableTimeSeriesGroup class was invoked before the Initialize method was invoked");
            }

            ILink link = this.GetLink(LinkID);
            SendSourceAfterGetValuesCallEvent(time, link);

            // -- handle incoming links (where this component is the target)
            if (!isBusy) //avoiding deadlocks 
            {
                isBusy = true;
                foreach (ILink acceptingLink in _acceptingLinks)
                {
                    if (((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries is TimestampSeries)
                    {
                        TimestampSeries timestampSeries = (TimestampSeries)((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries;
                        foreach (TimestampValue timestampValue in timestampSeries.Items)
                        {
                            TimeStamp getValuesTime = new TimeStamp(timestampValue.Time);
                            SendTargetBeforeGetValuesCall(getValuesTime, acceptingLink);
                            IValueSet valueSet = acceptingLink.SourceComponent.GetValues(getValuesTime, acceptingLink.ID);
                            timestampValue.Value = ((IScalarSet)valueSet).GetScalar(0);
                            SendTargetAfterGetValuesReturn(timestampValue.Value, acceptingLink);
                        }
                    }
                    else if (((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries is TimespanSeries)
                    {
                        TimespanSeries timespanSeries = (TimespanSeries)((TsQuantity)acceptingLink.TargetQuantity).BaseTimeSeries;
                        foreach (TimespanValue timespanValue in timespanSeries.Items)
                        {
                            HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan timeSpan = new HydroNumerics.OpenMI.Sdk.Backbone.TimeSpan(new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(timespanValue.StartTime), new HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp(timespanValue.EndTime));
                            SendTargetBeforeGetValuesCall(timeSpan, acceptingLink);
                            IValueSet valueSet = acceptingLink.SourceComponent.GetValues(timeSpan, acceptingLink.ID);
                            timespanValue.Value = ((IScalarSet)valueSet).GetScalar(0);
                            SendTargetAfterGetValuesReturn(timespanValue.Value, acceptingLink);
                        }
                    }
                    else
                    {
                        throw new Exception("Unexpected exception : Undefined timeseries type (occured in HydroNumerics.Time.OpenMI.LinkableTimeSeriesGroup class)");
                    }
                }
                isBusy = false;
            }

            // -- handle outgoing links (where this component is the source)
            HydroNumerics.Core.Unit toUnit = new HydroNumerics.Core.Unit();
            toUnit.ConversionFactorToSI = link.TargetQuantity.Unit.ConversionFactorToSI;
            toUnit.OffSetToSI = link.TargetQuantity.Unit.OffSetToSI;

            if (time is ITimeStamp)
            {
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp t = new TimeStamp((ITimeStamp)time);

                double x = ((TsQuantity)link.SourceQuantity).BaseTimeSeries.GetValue(t.ToDateTime(), toUnit);
                ScalarSet scalarSet = new ScalarSet(new double[] { x });
                SendSourceBeforeGetValuesReturn(x, link);
                return scalarSet;
            }
            else
            {
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp start = new TimeStamp(((ITimeSpan)time).Start);
                HydroNumerics.OpenMI.Sdk.Backbone.TimeStamp end = new TimeStamp(((ITimeSpan)time).End);

                double x = ((TsQuantity)link.SourceQuantity).BaseTimeSeries.GetValue(start.ToDateTime(), end.ToDateTime(), toUnit);
                ScalarSet scalarSet = new ScalarSet(new double[] { x });
                SendSourceBeforeGetValuesReturn(x, link);
                return scalarSet;
            }
        }
コード例 #2
0
 public void ToDateTime()
 {
     DateTime testDate = new DateTime(2008, 12, 31);
     TimeStamp timeStamp = new TimeStamp(testDate);
     Assert.AreEqual(testDate, timeStamp.ToDateTime());
 }