public static void Initialise(Player p, Configuration c, ModelInterface m, MainFrame form) { if (INSTANCE == null) { INSTANCE = new Engine(p, c, m, form); } }
private Engine(Player p, Configuration c, ModelInterface m, MainFrame form) { this._player = p; this._configuration = c; this._model = m; form.Engine = this; this._timer = new System.Timers.Timer(DEFAULT_INTERVAL); this._timer.Elapsed += new ElapsedEventHandler(OnTimedEvent); this._timer.SynchronizingObject = form; }
private void RequestDiscovery(ModelInterface intfc) { if (_requestSvr != null) { _requestSvr.RequestDiscovery(intfc); } }
public InterfaceDataRecord CreateInterfaceRepresentation(ModelInterface intfc) { if (intfc == null) { return(null); } InterfaceDataRecord raw = new InterfaceDataRecord(intfc.PersistentId); if (intfc is ModelInterface) { // Common parameters AddCommonInterfacePropertiesAsNVPairs(intfc, raw); raw.AddProperty(AgentKeys.AgentName, AgentId); // mark it as mine raw.AddProperty(AgentKeys.VisaIntfType, VisaIntfTypeString); } // Unique parameters var specificIntfc = intfc as ModelInterfaceSample; if (specificIntfc != null) { AddInfoToInterface(raw, specificIntfc); } return(raw); }
private object GetModel(string name, ModelProperties properties) { ModelInterface model = Plugins.Instance.GetModel(name); PropertyTable propertyTable = new PropertyTable(model); Starter starter = Factory.Starter.DesignStarter(); starter.Run(model); starter.Wait(); propertyTable.UpdateAfterInitialize(); if (properties != null) { model.OnProperties(properties); propertyTable.UpdateAfterProjectFile(); string[] keys = properties.GetModelKeys(); for (int i = 0; i < keys.Length; i++) { ModelProperties nestedProperties = properties.GetModel(keys[i]); if (nestedProperties.ModelType == ModelType.Indicator) { Add(nestedProperties); } } } else { LoadIndicators(model); } return(propertyTable); }
public void Chain(string current, string previous) { ModelInterface currentStrategy = null; ModelInterface previousStrategy = null; for (int i = 0; i < models.Count; i++) { if (models[i].Name == current) { currentStrategy = models[i]; } if (models[i].Name == previous) { previousStrategy = models[i]; } } if (currentStrategy == null) { throw new ApplicationException("Child Strategy '" + current + "' was not found for AddDependency()"); } if (previousStrategy == null) { throw new ApplicationException("Parent Strategy '" + previous + "' was not found for AddDependency()"); } currentStrategy.Chain.Dependencies.Add(previousStrategy.Chain); }
public void WriteEngineResult(ModelLoaderInterface loader, TickEngine engine, Action <int, double> fitnessCallback) { try { loader.OptimizeOutput = new FileStream(fileName, FileMode.Append); using (StreamWriter fwriter = new StreamWriter(loader.OptimizeOutput)) { ModelInterface topModel = engine.Model; foreach (var chain in topModel.Chain.Dependencies) { var passModel = chain.Model as StrategyInterface; var strings = passModel.Name.Split(new char[] { '-' }); var passNumber = int.Parse(strings[2]); if (fitnessCallback != null) { fitnessCallback(passNumber, passModel.OnGetFitness()); } if (passModel == null) { log.Error("Model " + passModel + " must implement the StrategyInterface or PortfolioInterface for the optimizer statistics results to get recorded."); } else { WritePassStats(fwriter, passModel); } } } } catch (Exception ex) { log.Error("ERROR: Problem writing optimizer results.", ex); } }
public override void Run(ModelInterface model) { Factory.Parallel.SetMode(parallelMode); Factory.SysLog.ResetConfiguration(); engine = Factory.Engine.TickEngine("Design"); engine.MaxBarsBack = 2; engine.MaxTicksBack = 2; SymbolInfo symbolInfo = Factory.Symbol.LookupSymbol("Design"); engine.SymbolInfo = new SymbolInfo[] { symbolInfo }; engine.IntervalDefault = ProjectProperties.Starter.IntervalDefault; engine.DesiredRunMode = RunMode.Historical; engine.DataFolder = DataFolder; engine.EnableTickFilter = ProjectProperties.Engine.EnableTickFilter; if (CancelPending) { return; } engine.Model = model; engine.QueueTask(); engine.WaitTask(); var parallel = Factory.Parallel; parallel.Dispose(); }
public View(Form1 form, ModelInterface model) { this.form = form; this.model = model; model.subscribe(this); serialNumber = 0; }
public void TestOrder() { int i = 0; Chain current = chain.Root; do { ModelInterface formula = current.Model; i++; switch (i) { case 1: Assert.AreEqual("first", formula.Name); break; case 2: Assert.AreEqual("second", formula.Name); break; case 3: Assert.AreEqual("third", formula.Name); break; } current = current.Next; } while(current.Model != null); Assert.AreEqual(3, i); }
public TickEngine ProcessHistorical(ModelInterface topModel, bool quietMode) { var engine = SetupEngine(quietMode); engine.Model = topModel; return(engine); }
public virtual void Run(ModelInterface model) { Factory.Parallel.SetMode(parallelMode); try { engine = Factory.Engine.TickEngine("Starter"); if (ProjectProperties.Starter.SymbolProperties.Length == 0) { throw new TickZoomException("Please enter at least one symbol."); } ProjectProperties.Engine.CopyProperties(engine); // Chaining of models. engine.Model = model; engine.ChartProperties = ProjectProperties.Chart; engine.SymbolInfo = ProjectProperties.Starter.SymbolProperties; engine.IntervalDefault = ProjectProperties.Starter.IntervalDefault; engine.EnableTickFilter = ProjectProperties.Engine.EnableTickFilter; engine.BackgroundWorker = BackgroundWorker; engine.DesiredRunMode = runMode; if (runMode == RunMode.RealTime) { engine.Providers = SetupDataProviders(); } engine.StartCount = StartCount; engine.EndCount = EndCount; engine.DataFolder = dataFolder; engine.StartTime = ProjectProperties.Starter.StartTime; engine.EndTime = ProjectProperties.Starter.EndTime; engine.TestFinishedTimeout = ProjectProperties.Starter.TestFinishedTimeout; engine.PortfolioSyncInterval = ProjectProperties.Starter.PortfolioSyncInterval; if (CancelPending) { return; } engine.TickReplaySpeed = ProjectProperties.Engine.TickReplaySpeed; engine.BarReplaySpeed = ProjectProperties.Engine.BarReplaySpeed; engine.ShowChartCallback = ShowChartCallback; engine.CreateChartCallback = CreateChartCallback; log.Info("Setting engine create chart callback = " + engine.CreateChartCallback); engine.Run(); var parallel = Factory.Parallel; parallel.Dispose(); if (CancelPending) { return; } } finally { Factory.Parallel.ReleaseIOTasks(); Factory.Parallel.SetMode(ParallelMode.Normal); } }
public void AddDependency(ModelInterface model) { if (model == this) { throw new ApplicationException("Sorry, cannot add " + model.Name + " as a dependency on itself. This creates a circular dependency."); } chain.Dependencies.Add(model.Chain); }
private void LinkFormula(ModelInterface value) { formula = value; if (value != null) { value.Chain = this; } }
private void HandleServerMessage(ModelInterface msg) { PositionUpdate pu = msg as PositionUpdate; if (pu != null) { return; } }
void TreeViewAfterLabelEdit(object sender, NodeLabelEditEventArgs e) { if (e.Label != null) { ModelInterface model = Plugins.Instance.GetModel(e.Label); e.Node.Tag = model; projectDoc.MainForm.PropertyWindow.SelectedObject = e.Node.Tag; } }
public Model() { // instantiate a model interface for this model instance which takes care of all communication with the outside world modelInterface = new ModelInterface(this) { // first message stating the model instantiated StatusMessage = $"Neonatal Physiology Engine version 1.0." }; }
// Update is called once per frame void Update() { ModelInterface msg = server.GetMessage(); if (msg != null) { this.HandleServerMessage(msg); } }
private void LoadIndicators(ModelInterface model) { for (int i = 0; i < model.Chain.Dependencies.Count; i++) { IndicatorInterface indicator = model.Chain.Dependencies[i].Model as IndicatorInterface; if (indicator != null) { Add(indicator.GetType().Name); } } }
public ModelInterface[] GetAvailableInterfaces() { var result = new ModelInterface[] { }; var hwDetector = GenerateHardwareDetector(); if (hwDetector != null) { var intfcs = hwDetector.GetConnectedInterfaces(); result = intfcs.ToArray(); } return(result); }
public Portfolio GetPortfolio(string name) { ModelInterface model = GetModelInternal(name); if (model is Portfolio) { return((Portfolio)model); } else { throw new InvalidCastException("'" + name + "' is not a portfolio. Perhaps, try GetStrategy() method instead."); } }
public ModelInterface ProcessLoader(ModelLoaderInterface loader, int passNumber) { loader.OnClear(); loader.OnLoad(ProjectProperties); ModelInterface topModel = loader.TopModel; if (!SetOptimizeValues(loader)) { throw new ApplicationException("Error, setting optimize variables."); } topModel.Name += "-Pass-" + passNumber; return(topModel); }
public ModelInterface GetMessage() { ProcessEvent ev = this.PeekEvent(); NetworkPacket np = ev as NetworkPacket; if (np != null) { string msg = np.GetMessage(); ModelInterface model = ConvertStringToModel.ToModel(msg); return(model); } return(null); }
public override void OnLoad(ProjectProperties properties) { // Loop through and setup a default strategy to handle orders // for each symbol. for (int i = 0; i < properties.Starter.SymbolProperties.Length; i++) { string symbol = properties.Starter.SymbolInfo[i].Symbol; ModelInterface market = CreateStrategy("StrategyCommon", symbol + "Strategy"); market.SymbolDefault = symbol; AddDependency("ExampleScannerStrategy", symbol + "Strategy"); } TopModel = GetPortfolio("ExampleScannerStrategy"); TopModel.SymbolDefault = properties.Starter.SymbolInfo[0].Symbol; }
public void AddEventListener(EventType eventType, ModelInterface listener) { ActiveList <ModelInterface> listeners; if (!eventListeners.TryGetValue((int)eventType, out listeners)) { listeners = new ActiveList <ModelInterface>(); eventListeners.Add((int)eventType, listeners); } if (!listeners.Contains(listener)) { listeners.AddLast(listener); } }
public override void Run(ModelInterface model) { SetupProviderServiceConfig(); Factory.Provider.StartSockets(); runMode = RunMode.RealTime; try { base.Run(model); } finally { parallelMode = ParallelMode.Normal; Factory.Provider.ShutdownSockets(); } }
public ModelDevice[] GetAvailableDevices(ModelInterface modelInterface) { var result = new ModelDevice[] { }; var hwDetector = GenerateHardwareDetector(); if (hwDetector != null) { var intfc = modelInterface as ModelInterfaceSample; if (intfc != null) { var devices = hwDetector.GetConnectedInstruments(intfc); result = devices.ToArray(); } } return result; }
public ModelDevice[] GetAvailableDevices(ModelInterface modelInterface) { var result = new ModelDevice[] { }; var hwDetector = GenerateHardwareDetector(); if (hwDetector != null) { var intfc = modelInterface as ModelInterfaceSample; if (intfc != null) { var devices = hwDetector.GetConnectedInstruments(intfc); result = devices.ToArray(); } } return(result); }
public void InitialiseModel(ModelInterface m) { MapGenerator g = this.GameMode.Generator; m.SetStopped(false); m.SetLost(false); m.SetMapDimensions(new Vector2D(this.Width, this.Height)); this._ship.Position = new Vector2D((this.Width - this._ship.Dimension.X) / 2, 0); m.AddShip(this._ship); m.SetBricks(g.generateMap(m.GetLevel(), this.Width, this.LevelHeight, this.GameMode.MinSpeed)); m.RemoveBalls(); m.AddBall(); }
public static ModelInterface ToModel(String networkString) { ModelInterface mi = null; mi = PositionUpdate.ToModel(networkString); if (mi != null) { return(mi); } if (mi == null) { Debug.Log("FAILED! FAILED! FAILED! to add new network model: " + networkString); } return(mi); }
public virtual void Run(ModelLoaderInterface loader) { if (loader.Category == projectFileLoaderCategory && loader.Name == projectFileLoaderName) { log.Notice("Loading project from " + ProjectFile); projectProperties = ProjectPropertiesCommon.Create(new StreamReader(ProjectFile)); } loader.OnInitialize(ProjectProperties); loader.OnLoad(ProjectProperties); if (!SetOptimizeValues(loader)) { throw new ApplicationException("Error, setting optimize variables. See log file for details."); } ModelInterface model = loader.TopModel; Run(model); }
/// <summary> /// This method deserializes all child model elements. /// </summary> /// <remarks> /// The caller will position the reader at the open tag of the first child XML element to deserialized. /// This method will read as many child elements as it can. It returns under three circumstances: /// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the /// open tag of the unknown element. This implies the if the first child XML element is unknown, this method /// should return immediately and do nothing. /// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element. /// 3) EOF. /// </remarks> /// <param name="serializationContext">Serialization context.</param> /// <param name="reader">XmlReader to read serialized data from.</param> /// <param name="element">In-memory ModelInterface instance that will get the deserialized data.</param> private static void ReadChildElements(DslModeling::SerializationContext serializationContext, ModelInterface element, global::System.Xml.XmlReader reader) { while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { switch (reader.LocalName) { case "operations": // Relationship "InterfaceHasOperation" if (reader.IsEmptyElement) { // No instance of this relationship, just skip DslModeling::SerializationUtilities.Skip(reader); } else { DslModeling::SerializationUtilities.SkipToFirstChild(reader); // Skip the open tag of <operations> ReadInterfaceHasOperationInstances(serializationContext, element, reader); DslModeling::SerializationUtilities.Skip(reader); // Skip the close tag of </operations> } break; case "implementors": // Relationship "Implementation" if (reader.IsEmptyElement) { // No instance of this relationship, just skip DslModeling::SerializationUtilities.Skip(reader); } else { DslModeling::SerializationUtilities.SkipToFirstChild(reader); // Skip the open tag of <implementors> ReadImplementationInstances(serializationContext, element, reader); DslModeling::SerializationUtilities.Skip(reader); // Skip the close tag of </implementors> } break; default: return; // Don't know this element. } } }
private bool IsInterfacePresentProc(ModelInterfaceSample interfaceToCheck, ModelInterface[] availableInterfaces) { return interfaceToCheck.IsInterfacePresent(availableInterfaces); }
/// <summary> /// Reads all instances of relationship InterfaceHasOperation. /// </summary> /// <remarks> /// The caller will position the reader at the open tag of the first XML element inside the relationship tag, so it can be /// either the first instance, or a bogus tag. This method will deserialize all instances and ignore all bogus tags. When the /// method returns, the reader will be positioned at the end tag of the relationship (or EOF if somehow that happens). /// </remarks> /// <param name="serializationContext">Serialization context.</param> /// <param name="element">In-memory ModelInterface instance that will get the deserialized data.</param> /// <param name="reader">XmlReader to read serialized data from.</param> private static void ReadInterfaceHasOperationInstances(DslModeling::SerializationContext serializationContext, ModelInterface element, global::System.Xml.XmlReader reader) { while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { DslModeling::DomainClassXmlSerializer newInterfaceOperationOfInterfaceHasOperationSerializer = serializationContext.Directory.GetSerializer(InterfaceOperation.DomainClassId); global::System.Diagnostics.Debug.Assert(newInterfaceOperationOfInterfaceHasOperationSerializer != null, "Cannot find serializer for InterfaceOperation!"); InterfaceOperation newInterfaceOperationOfInterfaceHasOperation = newInterfaceOperationOfInterfaceHasOperationSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as InterfaceOperation; if (newInterfaceOperationOfInterfaceHasOperation != null) { element.Operations.Add(newInterfaceOperationOfInterfaceHasOperation); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newInterfaceOperationOfInterfaceHasOperation.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newInterfaceOperationOfInterfaceHasOperation.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newInterfaceOperationOfInterfaceHasOperation, reader); } else { global::System.Type typeofInterfaceHasOperation = typeof(InterfaceHasOperation); DslModeling::DomainRelationshipXmlSerializer newInterfaceHasOperationSerializer = serializationContext.Directory.GetSerializer(InterfaceHasOperation.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer; global::System.Diagnostics.Debug.Assert(newInterfaceHasOperationSerializer != null, "Cannot find serializer for InterfaceHasOperation!"); InterfaceHasOperation newInterfaceHasOperation = newInterfaceHasOperationSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as InterfaceHasOperation; if (newInterfaceHasOperation != null) { if (newInterfaceHasOperation.GetType() == typeofInterfaceHasOperation) { // The relationship should be serialized in short-form. FWK_DslSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(InterfaceHasOperation)); } DslModeling::DomainRoleInfo.SetRolePlayer (newInterfaceHasOperation, InterfaceHasOperation.InterfaceDomainRoleId, element); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newInterfaceHasOperation.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newInterfaceHasOperation.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newInterfaceHasOperation, reader); } else { // Unknown element, skip DslModeling::SerializationUtilities.Skip(reader); } } } }
public void SendMessage(ModelInterface msg) { this.SendMessage (msg.ToNetworkString()); }
private void HandleServerMessage(ModelInterface msg) { PositionUpdate pu = msg as PositionUpdate; if(pu != null) { this.HandlePositionUpdate(pu); return; } ActionUpdate au = msg as ActionUpdate; if(au != null) { this.HandleActionUpdate(au); return; } ServerSettingsUpdate ssu = msg as ServerSettingsUpdate; if(ssu != null) { Debug.Log ("Server Settings Update, ServerFPS: " + ssu.serverFps); Constants.SERVER_FPS = ssu.serverFps; return; } WorldUpdate wu = msg as WorldUpdate; if(wu != null) { this.world.HandleWorldUpdate(wu); return; } LoginSuccessfulResponse lsr = msg as LoginSuccessfulResponse; if(lsr != null) { Debug.Log ("Login Successfull!"); this.server.SendMessage(new CharacterInfoRequest()); return; } LoginFailedResponse lfr = msg as LoginFailedResponse; if(lfr != null) { Debug.Log ("Login Failed: " + lfr.errorMsg); return; } UnexpectedRequestResponse urr = msg as UnexpectedRequestResponse; if(urr != null) { Debug.Log ("UnexpectedRequestResponse: " + urr.request); return; } NoCharacterFoundResponse ncfr = msg as NoCharacterFoundResponse; if(ncfr != null) { Debug.Log ("NoCharacterFound"); return; } CharacterInfoResponse cir = msg as CharacterInfoResponse; if(cir != null) { Debug.Log ("Character Info received for: " + cir.ToNetworkString()); this.player.transform.position = new Vector3(cir.posx, cir.posy, cir.posz); this.player.GUID = cir.GUID; this.startSendingInputs = true; return; } }
public ModelInterface[] GetAvailableInterfaces() { var result = new ModelInterface[] { }; var hwDetector = GenerateHardwareDetector(); if (hwDetector != null) { var intfcs = hwDetector.GetConnectedInterfaces(); result = intfcs.ToArray(); } return result; }
public InterfaceDataRecord CreateInterfaceRepresentation(ModelInterface intfc) { if (intfc == null) return null; InterfaceDataRecord raw = new InterfaceDataRecord(intfc.PersistentId); if (intfc is ModelInterface) { // Common parameters AddCommonInterfacePropertiesAsNVPairs(intfc, raw); raw.AddProperty(AgentKeys.AgentName, AgentId); // mark it as mine raw.AddProperty(AgentKeys.VisaIntfType, VisaIntfTypeString); } // Unique parameters var specificIntfc = intfc as ModelInterfaceSample; if (specificIntfc != null) { AddInfoToInterface(raw, specificIntfc); } return raw; }
private static void ReadImplementationInstances(DslModeling::SerializationContext serializationContext, ModelInterface element, global::System.Xml.XmlReader reader) { while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element) { DslModeling::DomainClassXmlSerializer newModelTypeMonikerOfImplementationSerializer = serializationContext.Directory.GetSerializer(ModelType.DomainClassId); global::System.Diagnostics.Debug.Assert(newModelTypeMonikerOfImplementationSerializer != null, "Cannot find serializer for ModelType!"); DslModeling::Moniker newModelTypeMonikerOfImplementation = newModelTypeMonikerOfImplementationSerializer.TryCreateMonikerInstance(serializationContext, reader, element, Implementation.DomainClassId, element.Partition); if (newModelTypeMonikerOfImplementation != null) { new Implementation(element.Partition, new DslModeling::RoleAssignment(Implementation.ImplementDomainRoleId, element), new DslModeling::RoleAssignment(Implementation.ImplementorDomainRoleId, newModelTypeMonikerOfImplementation)); DslModeling::SerializationUtilities.Skip(reader); // Moniker contains no child XML elements, so just skip. } else { global::System.Type typeofImplementation = typeof(Implementation); DslModeling::DomainRelationshipXmlSerializer newImplementationSerializer = serializationContext.Directory.GetSerializer(Implementation.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer; global::System.Diagnostics.Debug.Assert(newImplementationSerializer != null, "Cannot find serializer for Implementation!"); Implementation newImplementation = newImplementationSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as Implementation; if (newImplementation != null) { if (newImplementation.GetType() == typeofImplementation) { // The relationship should be serialized in short-form. LinqToRdfSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(Implementation)); } DslModeling::DomainRoleInfo.SetRolePlayer (newImplementation, Implementation.ImplementDomainRoleId, element); DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newImplementation.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newImplementation.GetDomainClass().Name + "!"); targetSerializer.Read(serializationContext, newImplementation, reader); } else { // Unknown element, skip DslModeling::SerializationUtilities.Skip(reader); } } } }
private static void WriteChildElements(DslModeling::SerializationContext serializationContext, ModelInterface element, global::System.Xml.XmlWriter writer) { // InterfaceHasOperation global::System.Collections.ObjectModel.ReadOnlyCollection<InterfaceHasOperation> allInterfaceHasOperationInstances = InterfaceHasOperation.GetLinksToOperations(element); if (!serializationContext.Result.Failed && allInterfaceHasOperationInstances.Count > 0) { writer.WriteStartElement("operations"); global::System.Type typeofInterfaceHasOperation = typeof(InterfaceHasOperation); foreach (InterfaceHasOperation eachInterfaceHasOperationInstance in allInterfaceHasOperationInstances) { if (serializationContext.Result.Failed) break; if (eachInterfaceHasOperationInstance.GetType() != typeofInterfaceHasOperation) { // Derived relationships will be serialized in full-form. DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachInterfaceHasOperationInstance.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachInterfaceHasOperationInstance.GetDomainClass().Name + "!"); derivedRelSerializer.Write(serializationContext, eachInterfaceHasOperationInstance, writer); } else { // No need to serialize the relationship itself, just serialize the role-player directly. DslModeling::ModelElement targetElement = eachInterfaceHasOperationInstance.Operation; DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!"); targetSerializer.Write(serializationContext, targetElement, writer); } } writer.WriteEndElement(); } // Implementation global::System.Collections.ObjectModel.ReadOnlyCollection<Implementation> allImplementationInstances = Implementation.GetLinksToImplementors(element); if (!serializationContext.Result.Failed && allImplementationInstances.Count > 0) { DslModeling::DomainRelationshipXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(Implementation.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer; global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for Implementation!"); writer.WriteStartElement("implementors"); global::System.Type typeofImplementation = typeof(Implementation); foreach (Implementation eachImplementationInstance in allImplementationInstances) { if (serializationContext.Result.Failed) break; if (eachImplementationInstance.GetType() != typeofImplementation) { // Derived relationships will be serialized in full-form. DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachImplementationInstance.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachImplementationInstance.GetDomainClass().Name + "!"); derivedRelSerializer.Write(serializationContext, eachImplementationInstance, writer); } else { // No need to serialize the relationship itself, just serialize the role-player directly. DslModeling::ModelElement targetElement = eachImplementationInstance.Implementor; DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id); global::System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!"); targetSerializer.WriteMoniker(serializationContext, targetElement, writer, element, relSerializer); } } writer.WriteEndElement(); } }