public void PrePrepare( LinkableComponentV1OpenMI component2, OpenMI.Standard.ILinkableComponent component1, double startTime, double updateLinkTimeIncrement, List<IBaseInput> activeInputs, List<IBaseOutput> activeOutputs) { Contract.Requires(component1 != null, "component1 != null"); Contract.Requires(component2 != null, "component2 != null"); Component1 = component1; Component1.Initialize(component2.Arguments.Select(a => new Utilities.Standard1.Argument1(a)).ToArray()); _currentTime = startTime; _updateLinkTimeIncrement = updateLinkTimeIncrement; // Create internal links between components 1 and 2 // T2 --> T1 // S1 --> S2 Utilities.Standard1.TimeSpan timeHorizon1 = new Utilities.Standard1.TimeSpan(component2.TimeExtent.TimeHorizon); OpenMI.Standard.IInputExchangeItem input; OpenMI.Standard.IOutputExchangeItem output; OpenMI.Standard.ILink internalLink; ITimeSpaceExchangeItem itemTimeSpace; string idQuantity, idElementSet; activeInputs.ForEach(i => { idQuantity = i.ValueDefinition.Caption; itemTimeSpace = i as ITimeSpaceExchangeItem; idElementSet = itemTimeSpace == null ? i.Caption // what else? : itemTimeSpace.SpatialDefinition.Caption; internalLink = null; for (int n = 0; n < _component1.InputExchangeItemCount; ++n) { input = _component1.GetInputExchangeItem(n); if (input.Quantity.ID != idQuantity || input.ElementSet.ID != idElementSet) continue; var isVector = input.Quantity.ValueType == OpenMI.Standard.ValueType.Vector; // Get providers convertor to use directly Contract.Requires(i.Provider is IHasValueSetConvertor, "i.Provider is IHasValueSetConvertor"); var convertorProvider = ((IHasValueSetConvertor)i.Provider).ValueSetConverter as IValueSetConverterTime; Contract.Requires(convertorProvider != null, "i.Provider.ValueSetConverter is IValueSetConverterTime"); internalLink = new Utilities.Standard1.InternalLink( _component1, input, timeHorizon1, convertorProvider, isVector); _linksIn.Add(internalLink); _component1.AddLink(internalLink); break; } if (internalLink == null) throw new Exception(string.Format( "OpenMI.Standard.IOutputExchangeItem not found with Quality,ElementSet ids if \"{0}\",\"{1}\"", idQuantity, idElementSet)); }); activeOutputs.ForEach(o => { idQuantity = o.ValueDefinition.Caption; itemTimeSpace = o as ITimeSpaceExchangeItem; idElementSet = itemTimeSpace == null ? o.Caption // what else? : itemTimeSpace.SpatialDefinition.Caption; internalLink = null; for (int n = 0; n < _component1.OutputExchangeItemCount; ++n) { output = _component1.GetOutputExchangeItem(n); if (output.Quantity.ID != idQuantity || output.ElementSet.ID != idElementSet) continue; internalLink = new Utilities.Standard1.InternalLink(_component1, output, timeHorizon1); _linksOut.Add(internalLink); _component1.AddLink(internalLink); if (((IHasValueSetConvertor)o).ValueSetConverter is ValueSetConverterTimeEngineDoubleStandard1) { var convertor = (ValueSetConverterTimeEngineDoubleStandard1)((IHasValueSetConvertor)o).ValueSetConverter; convertor.SetRuntime(this, internalLink); } else if (((IHasValueSetConvertor)o).ValueSetConverter is ValueSetConverterTimeEngineDoubleVector3dStandard1) { var convertor = (ValueSetConverterTimeEngineDoubleVector3dStandard1)((IHasValueSetConvertor)o).ValueSetConverter; convertor.SetRuntime(this, internalLink); } else throw new Exception("o.ValueSetConverter as ValueSetConverterTimeEngineDouble?"); break; } if (internalLink == null) throw new Exception(string.Format( "OpenMI.Standard.IInputExchangeItem not found with Quality,ElementSet ids if \"{0}\",\"{1}\"", idQuantity, idElementSet)); }); if (_linksOut.Count < 1) throw new Exception("At least one output link must be specified"); }
/// <summary> /// Initialise unpersisted variables /// </summary> /// <param name="engineProxy"></param> /// <param name="link"></param> public void SetRuntime(LinkableComponentV1OpenMI.EngineProxy engineProxy, ILink link) { _engineProxy = engineProxy; _link = link; }
public static LinkableComponentV1Base CreateWrappedComponent(ExternalType component, IEnumerable<Argument1> arguments) { var ns = Omi.Component.NamespaceOpenMIv1; var omi = new XElement( ns + "LinkableComponent", new XAttribute("Type", component.TypeName), new XAttribute("Assembly", component.Url.LocalPath), new XElement(ns + "Arguments", arguments.Select(a => new XElement(ns + "Argument", new XAttribute("Key", a.Key), new XAttribute("Value", a.Value)))) ); var version = Omi.Component.Version.One; if (arguments.Any(a => a.Key.Contains("FluidEarth") || a.Key.Contains("OpenWEB"))) version = Omi.Component.Version.OneFluidEarth; LinkableComponentV1Base c = null; if (version == Omi.Component.Version.One) c = new LinkableComponentV1OpenMI(); else c = new LinkableComponentV1FluidEarth(); throw new NotImplementedException(); // c.ArgumentV1Omi = ??; }