/// <summary> /// Update Arguments to include OpenMI V1 arguments defined by OMI Uri /// </summary> /// <param name="uriOmiV1">Uri of OpenMI v1 OMI XML</param> /// <param name="xLinkableComponent">XML Contents of OMI Uri</param> /// <param name="args1">OpenMI V1 arguments constructed from xLinkableComponent</param> /// <param name="reports">Details about method success</param> /// <returns>True if successful</returns> public static bool UpdateArgumentsFromOmiV1(Uri uriOmiV1, out XElement xLinkableComponent, out List<Utilities.Standard1.Argument1> args1, List<IReport> reports) { Contract.Requires(reports != null, "reports != null"); xLinkableComponent = null; args1 = null; if (uriOmiV1 == null) { var id = GetArgumentIdentity(Args.V1Omi); reports.Add(Report.Error(Report.ResourceIds.InvalidUri, id.Caption, "URI argument for OMI V1 not specified")); return false; } if (!File.Exists(uriOmiV1.LocalPath)) { var id = GetArgumentIdentity(Args.V1Omi); reports.Add(Report.Error(Report.ResourceIds.FileMissing, id.Caption, uriOmiV1.LocalPath)); return false; } var omiFile = new DocumentExistingFile(uriOmiV1); var xOmi = omiFile.Open(); xLinkableComponent = xOmi.Root; if (!Omi.Component.Validates(xLinkableComponent, Xsd.ComponentV1, reports)) return false; var ns1 = Omi.Component.NamespaceOpenMIv1; var xArguments = xOmi .Element(ns1.GetName("LinkableComponent")) .Elements(ns1.GetName("Arguments")) .SingleOrDefault(); if (xArguments != null) args1 = Utilities.Standard1.Arguments1( xArguments, ns1, omiFile.Uri); return true; }
/// <summary> /// Initialisation specific to Pond /// </summary> /// <param name="reinitialising">True if previously been through here before</param> protected override void DoInitialise(bool reinitialising) { ComponentState state = null; if (!reinitialising) { var stateUri = ArgumentStateUri; if (stateUri != null && stateUri.IsFile && File.Exists(stateUri.LocalPath)) { var accessor = new DocumentExistingFile(stateUri); var document = XDocument.Load(stateUri.LocalPath); state = new ComponentState(); state.Initialise(document.Root, accessor); SetIdentity(state); Caption = state.Caption; // as modified via argument EngineType = new ExternalType(state.EngineType); UseNativeDll = state.UseNativeEngine; } } base.DoInitialise(reinitialising); if (reinitialising || state == null) return; foreach (var arg in state.Arguments) Arguments.Add(arg); foreach (var input in state.Inputs) Add(input as BaseInput); foreach (var putput in state.Outputs) Add(putput as BaseOutput); }
/// <summary> /// Create an instance of OpenMI.Standard.ILinkableComponent /// </summary> /// <param name="uriOmiV1">Uri of OMI XML</param> /// <param name="component1">Instance of OpenMI.Standard.ILinkableComponent</param> /// <param name="reports">Details about method success</param> /// <returns>True if successful</returns> public static bool InstantiateComponent1(Uri uriOmiV1, out OpenMI.Standard.ILinkableComponent component1, List<IReport> reports) { component1 = null; XElement xLinkableComponent; List<Utilities.Standard1.Argument1> args1; if (!UpdateArgumentsFromOmiV1(uriOmiV1, out xLinkableComponent, out args1, reports)) return false; var assembly = Utilities.Xml.GetAttribute(xLinkableComponent, "Assembly"); var type = Utilities.Xml.GetAttribute(xLinkableComponent, "Type"); var omiFile = new DocumentExistingFile(uriOmiV1); var assemblyUri = new Uri(uriOmiV1, assembly); var typeV1 = new ExternalType(omiFile); typeV1.Initialise(assemblyUri.LocalPath, type); Type tComponentV1; component1 = typeV1.CreateInstance(out tComponentV1) as OpenMI.Standard.ILinkableComponent; if (component1 == null) { reports.Add(Report.Error(Report.ResourceIds.Instantiation, tComponentV1.ToString(), string.Empty)); return false; } return true; }