public void AddConnection(UIConnection connection) { if (connection.SourceModel == connection.TargetModel) { throw (new Exception("Cannot connect model with itself.")); } // Check whether both models exist bool providingFound = false, acceptingFound = false; foreach (UIModel model in _models) { if (model == connection.SourceModel) { providingFound = true; } if (model == connection.TargetModel) { acceptingFound = true; } } if (!providingFound || !acceptingFound) { throw (new Exception("Cannot find providing or accepting.")); } // check whether this link isn't already here (if yes, replace) foreach (UIConnection uiConnection in _connections) { if (uiConnection.SourceModel == connection.SourceModel && uiConnection.TargetModel == connection.TargetModel) { _connections.Remove(uiConnection); } } _connections.Add(connection); _oprUnsaved = true; }
/// <summary> /// Removes connection between two models. /// </summary> /// <param name="connection">Connection to be removed.</param> public void RemoveConnection(UIConnection connection) { // remove ILinks from both connected components if (!_runPrepareForComputationStarted) { foreach (ILink link in connection.Links) { string linkID = link.ID; ILinkableComponent sourceComponent = link.SourceComponent, targetComponent = link.TargetComponent; sourceComponent.RemoveLink(linkID); targetComponent.RemoveLink(linkID); } } _connections.Remove(connection); _shouldBeSaved = true; }
static oprConnectionDecorator[] Decorators(UIConnection connection, DirectoryInfo oprPath, out List <UIAdaptedOutputItem> allAdaptersInConnection) { allAdaptersInConnection = new List <UIAdaptedOutputItem>(); UIOutputItem adapter = null; foreach (Link link in connection.Links) { foreach (UIOutputItem source in link.Sources) { adapter = source; while (adapter != null && adapter is UIAdaptedOutputItem) { if (!allAdaptersInConnection.Contains((UIAdaptedOutputItem)adapter)) { allAdaptersInConnection.Add((UIAdaptedOutputItem)adapter); } adapter = adapter.Parent; } } } oprConnectionDecorator[] oprDecorators = new oprConnectionDecorator[allAdaptersInConnection.Count]; for (int n = 0; n < allAdaptersInConnection.Count; ++n) { oprDecorators[n] = new oprConnectionDecorator(); oprDecorators[n].item_id = allAdaptersInConnection[n].Id; oprDecorators[n].factory = allAdaptersInConnection[n].Factory.Persist(oprPath); IList <IArgument> ars = ((ITimeSpaceAdaptedOutput)allAdaptersInConnection[n].TimeSpaceOutput).Arguments; oprDecorators[n].arguments = DecoratorArgs(new List <IArgument>(ars).ToArray()); } return(oprDecorators); }
static oprConnection[] Connections(List <UIModel> models, UIConnection[] connections, DirectoryInfo oprPath) { oprConnection[] oprConnections = new oprConnection[connections.Length]; for (int n = 0; n < connections.Length; ++n) { UIConnection uiconn = connections[n]; oprConnection conn = new oprConnection(); conn.source_model_indexSpecified = true; conn.target_model_indexSpecified = true; conn.source_model_index = models.IndexOf(uiconn.SourceModel); conn.target_model_index = models.IndexOf(uiconn.TargetModel); List <UIAdaptedOutputItem> allAdaptersInConnection; conn.decorators = Decorators(uiconn, oprPath, out allAdaptersInConnection); conn.links = Links(uiconn, allAdaptersInConnection); oprConnections[n] = conn; } return(oprConnections); }
/// <summary> /// Loads composition from XML document. /// </summary> /// <param name="omiRelativeDirectory">Directory the OMI files are relative to.</param> /// <param name="xmlDocument">XML document</param> private void LoadFromXmlDocument(string omiRelativeDirectory, XmlDocument xmlDocument) { // once you choose to load new file, all previously opened models are closed Release(); CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo(""); XmlElement xmlRoot = (XmlElement)xmlDocument.ChildNodes[0]; XmlElement xmlModels = (XmlElement)xmlRoot.ChildNodes[0]; XmlElement xmlLinks = (XmlElement)xmlRoot.ChildNodes[1]; // run properties aren't mandatory XmlElement xmlRunProperties = null; if (xmlRoot.ChildNodes.Count > 2) { xmlRunProperties = (XmlElement)xmlRoot.ChildNodes[2]; } // check if (xmlRoot.GetAttribute("version") != "1.0") { throw (new FormatException("Version of file not supported. Currently supported only version '1.0'")); } if (xmlModels.Name != "models" || xmlLinks.Name != "links") { throw (new FormatException("Unknown file format ('models' or 'links' tag not present where expected).")); } if (xmlRunProperties != null) { if (xmlRunProperties.Name != "runproperties") { throw (new FormatException("Unknown file format ('runproperties' tag not present where expected).")); } } // read UIModels foreach (XmlElement xmlUiModel in xmlModels.ChildNodes) { try { UIModel uiModel = AddModel(omiRelativeDirectory, xmlUiModel.GetAttribute("omi")); uiModel.Rect.X = Int32.Parse(xmlUiModel.GetAttribute("rect_x")); uiModel.Rect.Y = Int32.Parse(xmlUiModel.GetAttribute("rect_y")); uiModel.Rect.Width = Int32.Parse(xmlUiModel.GetAttribute("rect_width")); uiModel.Rect.Height = Int32.Parse(xmlUiModel.GetAttribute("rect_height")); } catch (Exception e) { throw (new Exception( "Model cannot be added to composition due to exception.\n" + "OMI filename: " + xmlUiModel.GetAttribute("omi") + "\n" + "Exception: " + e.ToString())); } } // read UILinks foreach (XmlElement xmlUiLink in xmlLinks.ChildNodes) { // find models corresponding to this UIConnection UIModel providingModel = null, acceptingModel = null; foreach (UIModel uiModel in _models) { if (uiModel.ModelID == xmlUiLink.GetAttribute("model_providing")) { providingModel = uiModel; break; } } foreach (UIModel uiModel in _models) { if (uiModel.ModelID == xmlUiLink.GetAttribute("model_accepting")) { acceptingModel = uiModel; break; } } if (providingModel == null || acceptingModel == null) { throw (new Exception( "One model (or both) corresponding to this link cannot be found...\n" + "Providing model: " + xmlUiLink.GetAttribute("model_providing") + "\n" + "Accepting model: " + xmlUiLink.GetAttribute("model_accepting"))); } // construct UIConnection UIConnection uiLink = new UIConnection(providingModel, acceptingModel); // read OpenMI Links foreach (XmlElement xmlLink in xmlUiLink.ChildNodes) { // find corresponding exchange items IOutputExchangeItem outputExchangeItem = null; IInputExchangeItem inputExchangeItem = null; int count = providingModel.LinkableComponent.OutputExchangeItemCount; string sourceElementSetID = xmlLink.GetAttribute("source_elementset"); string sourceQuantityID = xmlLink.GetAttribute("source_quantity"); for (int i = 0; i < count; i++) { if (sourceElementSetID == providingModel.LinkableComponent.GetOutputExchangeItem(i).ElementSet.ID && sourceQuantityID == providingModel.LinkableComponent.GetOutputExchangeItem(i).Quantity.ID) { outputExchangeItem = providingModel.LinkableComponent.GetOutputExchangeItem(i); break; } } for (int i = 0; i < acceptingModel.LinkableComponent.InputExchangeItemCount; i++) { if (xmlLink.GetAttribute("target_elementset") == acceptingModel.LinkableComponent.GetInputExchangeItem(i).ElementSet.ID && xmlLink.GetAttribute("target_quantity") == acceptingModel.LinkableComponent.GetInputExchangeItem(i).Quantity.ID) { inputExchangeItem = acceptingModel.LinkableComponent.GetInputExchangeItem(i); break; } } if (outputExchangeItem == null || inputExchangeItem == null) { throw (new Exception( "Cannot find exchange item\n" + "Providing model: " + providingModel.ModelID + "\n" + "Accepting model: " + acceptingModel.ModelID + "\n" + "Source ElementSet: " + xmlLink.GetAttribute("source_elementset") + "\n" + "Source Quantity: " + xmlLink.GetAttribute("source_quantity") + "\n" + "Target ElementSet: " + xmlLink.GetAttribute("target_elementset") + "\n" + "Target Quantity: " + xmlLink.GetAttribute("target_quantity"))); } // read selected DataOperation's IDs, find their equivalents // in outputExchangeItem, and add these to link ArrayList dataOperationsToAdd = new ArrayList(); foreach (XmlElement xmlDataOperation in xmlLink.ChildNodes) { for (int i = 0; i < outputExchangeItem.DataOperationCount; i++) { IDataOperation dataOperation = outputExchangeItem.GetDataOperation(i); if (dataOperation.ID == xmlDataOperation.GetAttribute("id")) { // set data operation's arguments if any foreach (XmlElement xmlArgument in xmlDataOperation.ChildNodes) { string argumentKey = xmlArgument.GetAttribute("key"); for (int j = 0; j < dataOperation.ArgumentCount; j++) { IArgument argument = dataOperation.GetArgument(j); if (argument.Key == argumentKey && !argument.ReadOnly) { argument.Value = xmlArgument.GetAttribute("value"); } } } dataOperationsToAdd.Add(dataOperation); break; } } } // now construct the Link... Link link = new Link( providingModel.LinkableComponent, outputExchangeItem.ElementSet, outputExchangeItem.Quantity, acceptingModel.LinkableComponent, inputExchangeItem.ElementSet, inputExchangeItem.Quantity, "No description available.", xmlLink.GetAttribute("id"), dataOperationsToAdd); // ...add the link to the list uiLink.Links.Add(link); // and add it to both LinkableComponents uiLink.AcceptingModel.LinkableComponent.AddLink(link); uiLink.ProvidingModel.LinkableComponent.AddLink(link); } // add new UIConnection to list of connections _connections.Add(uiLink); } // read run properties (if present) if (xmlRunProperties != null) { string str = xmlRunProperties.GetAttribute("listenedeventtypes"); if (str.Length != (int)EventType.NUM_OF_EVENT_TYPES) { throw (new FormatException("Invalid number of event types in 'runproperties' tag, expected " + EventType.NUM_OF_EVENT_TYPES + ", but only " + str.Length + " found.")); } for (int i = 0; i < (int)EventType.NUM_OF_EVENT_TYPES; i++) { switch (str[i]) { case '1': _listenedEventTypes[i] = true; break; case '0': _listenedEventTypes[i] = false; break; default: throw (new FormatException("Unknown format of 'listenedeventtypes' attribute in 'runproperties' tag.")); } } _triggerInvokeTime = DateTime.Parse(xmlRunProperties.GetAttribute("triggerinvoke")); _logFileName = xmlRunProperties.GetAttribute("logfilename"); if (_logFileName != null) { _logFileName = _logFileName.Trim(); if (_logFileName == "") { _logFileName = null; // if not set, logfile isn't used } } str = xmlRunProperties.GetAttribute("showeventsinlistbox"); if (str == null || str == "" || str == "1") { _showEventsInListbox = true; // if not set, value is true } else { _showEventsInListbox = false; } str = xmlRunProperties.GetAttribute("runinsamethread"); if (str == "1") { _runInSameThread = true; } } Thread.CurrentThread.CurrentCulture = currentCulture; }
/// <summary> /// Removes connection between two models. /// </summary> /// <param name="connection">Connection to be removed.</param> public void RemoveConnection(UIConnection connection) { _connections.Remove(connection); _oprUnsaved = true; }
private void ShowLinkDialog( UIConnection link ) { // find maximum link ID of all existing links int maxID = 0; foreach( UIConnection uiLink in _composition.Connections ) foreach( ILink iLink in uiLink.Links ) maxID = Math.Max( int.Parse(iLink.ID), maxID ); _connectionDialog.PopulateDialog( link, maxID+1 ); if( _connectionDialog.ShowDialog(this) == DialogResult.OK ) _composition.ShouldBeSaved = true; UpdateTitle(); }
/// <summary> /// Loads composition from XML document. /// </summary> /// <param name="omiRelativeDirectory">Directory the OMI files are relative to.</param> /// <param name="xmlDocument">XML document</param> private void LoadFromXmlDocument(string omiRelativeDirectory, XmlDocument xmlDocument) { // once you choose to load new file, all previously opened models are closed Release(); CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo(""); XmlElement xmlRoot = (XmlElement)xmlDocument.ChildNodes[0]; XmlElement xmlModels = (XmlElement)xmlRoot.ChildNodes[0]; XmlElement xmlLinks = (XmlElement)xmlRoot.ChildNodes[1]; // run properties aren't mandatory XmlElement xmlRunProperties = null; if (xmlRoot.ChildNodes.Count > 2) xmlRunProperties = (XmlElement)xmlRoot.ChildNodes[2]; // check if (xmlRoot.GetAttribute("version") != "1.0") throw (new FormatException("Version of file not supported. Currently supported only version '1.0'")); if (xmlModels.Name != "models" || xmlLinks.Name != "links") throw (new FormatException("Unknown file format ('models' or 'links' tag not present where expected).")); if (xmlRunProperties != null) if (xmlRunProperties.Name != "runproperties") throw (new FormatException("Unknown file format ('runproperties' tag not present where expected).")); // read UIModels foreach (XmlElement xmlUiModel in xmlModels.ChildNodes) { try { UIModel uiModel = AddModel(omiRelativeDirectory, xmlUiModel.GetAttribute("omi")); uiModel.Rect.X = Int32.Parse(xmlUiModel.GetAttribute("rect_x")); uiModel.Rect.Y = Int32.Parse(xmlUiModel.GetAttribute("rect_y")); uiModel.Rect.Width = Int32.Parse(xmlUiModel.GetAttribute("rect_width")); uiModel.Rect.Height = Int32.Parse(xmlUiModel.GetAttribute("rect_height")); } catch (Exception e) { throw (new Exception( "Model cannot be added to composition due to exception.\n" + "OMI filename: " + xmlUiModel.GetAttribute("omi") + "\n" + "Exception: " + e.ToString())); } } // read UILinks foreach (XmlElement xmlUiLink in xmlLinks.ChildNodes) { // find models corresponding to this UIConnection UIModel providingModel = null, acceptingModel = null; foreach (UIModel uiModel in _models) if (uiModel.ModelID == xmlUiLink.GetAttribute("model_providing")) { providingModel = uiModel; break; } foreach (UIModel uiModel in _models) if (uiModel.ModelID == xmlUiLink.GetAttribute("model_accepting")) { acceptingModel = uiModel; break; } if (providingModel == null || acceptingModel == null) { throw (new Exception( "One model (or both) corresponding to this link cannot be found\n" + "Providing model: " + xmlUiLink.GetAttribute("model_providing") + "\n" + "Accepting model: " + xmlUiLink.GetAttribute("model_accepting"))); } // construct UIConnection UIConnection uiLink = new UIConnection(providingModel, acceptingModel); // read OpenMI Links foreach (XmlElement xmlLink in xmlUiLink.ChildNodes) { // find corresponding exchange items IOutputExchangeItem outputExchangeItem = null; IInputExchangeItem inputExchangeItem = null; int count = providingModel.LinkableComponent.OutputExchangeItemCount; string sourceElementSetID = xmlLink.GetAttribute("source_elementset"); string sourceQuantityID = xmlLink.GetAttribute("source_quantity"); for (int i = 0; i < count; i++) if (sourceElementSetID == providingModel.LinkableComponent.GetOutputExchangeItem(i).ElementSet.ID && sourceQuantityID == providingModel.LinkableComponent.GetOutputExchangeItem(i).Quantity.ID) { outputExchangeItem = providingModel.LinkableComponent.GetOutputExchangeItem(i); break; } for (int i = 0; i < acceptingModel.LinkableComponent.InputExchangeItemCount; i++) if (xmlLink.GetAttribute("target_elementset") == acceptingModel.LinkableComponent.GetInputExchangeItem(i).ElementSet.ID && xmlLink.GetAttribute("target_quantity") == acceptingModel.LinkableComponent.GetInputExchangeItem(i).Quantity.ID) { inputExchangeItem = acceptingModel.LinkableComponent.GetInputExchangeItem(i); break; } if (outputExchangeItem == null || inputExchangeItem == null) throw (new Exception( "Cannot find exchange item\n" + "Providing model: " + providingModel.ModelID + "\n" + "Accepting model: " + acceptingModel.ModelID + "\n" + "Source ElementSet: " + xmlLink.GetAttribute("source_elementset") + "\n" + "Source Quantity: " + xmlLink.GetAttribute("source_quantity") + "\n" + "Target ElementSet: " + xmlLink.GetAttribute("target_elementset") + "\n" + "Target Quantity: " + xmlLink.GetAttribute("target_quantity"))); // read selected DataOperation's IDs, find their equivalents // in outputExchangeItem, and add these to link ArrayList dataOperationsToAdd = new ArrayList(); foreach (XmlElement xmlDataOperation in xmlLink.ChildNodes) for (int i = 0; i < outputExchangeItem.DataOperationCount; i++) { IDataOperation dataOperation = outputExchangeItem.GetDataOperation(i); if (dataOperation.ID == xmlDataOperation.GetAttribute("id")) { // set data operation's arguments if any foreach (XmlElement xmlArgument in xmlDataOperation.ChildNodes) { string argumentKey = xmlArgument.GetAttribute("key"); for (int j = 0; j < dataOperation.ArgumentCount; j++) { IArgument argument = dataOperation.GetArgument(j); if (argument.Key == argumentKey && !argument.ReadOnly) argument.Value = xmlArgument.GetAttribute("value"); } } dataOperationsToAdd.Add(dataOperation); break; } } // now construct the Link Link link = new Link( providingModel.LinkableComponent, outputExchangeItem.ElementSet, outputExchangeItem.Quantity, acceptingModel.LinkableComponent, inputExchangeItem.ElementSet, inputExchangeItem.Quantity, "No description available.", xmlLink.GetAttribute("id"), dataOperationsToAdd); // add the link to the list uiLink.Links.Add(link); // and add it to both LinkableComponents uiLink.AcceptingModel.LinkableComponent.AddLink(link); uiLink.ProvidingModel.LinkableComponent.AddLink(link); } // add new UIConnection to list of connections _connections.Add(uiLink); } // read run properties (if present) if (xmlRunProperties != null) { string str = xmlRunProperties.GetAttribute("listenedeventtypes"); if (str.Length != (int)EventType.NUM_OF_EVENT_TYPES) throw (new FormatException("Invalid number of event types in 'runproperties' tag, expected " + EventType.NUM_OF_EVENT_TYPES + ", but only " + str.Length + " found.")); for (int i = 0; i < (int)EventType.NUM_OF_EVENT_TYPES; i++) switch (str[i]) { case '1': _listenedEventTypes[i] = true; break; case '0': _listenedEventTypes[i] = false; break; default: throw (new FormatException("Unknown format of 'listenedeventtypes' attribute in 'runproperties' tag.")); } _triggerInvokeTime = DateTime.Parse(xmlRunProperties.GetAttribute("triggerinvoke")); _logFileName = xmlRunProperties.GetAttribute("logfilename"); if (_logFileName != null) { _logFileName = _logFileName.Trim(); if (_logFileName == "") _logFileName = null; // if not set, logfile isn't used } str = xmlRunProperties.GetAttribute("showeventsinlistbox"); if (str == null || str == "" || str == "1") _showEventsInListbox = true; // if not set, value is true else _showEventsInListbox = false; str = xmlRunProperties.GetAttribute("runinsamethread"); if (str == "1") _runInSameThread = true; } Thread.CurrentThread.CurrentCulture = currentCulture; }
/// <summary> /// Removes connection between two models. /// </summary> /// <param name="connection">Connection to be removed.</param> public void RemoveConnection(UIConnection connection) { // remove ILinks from both connected components if (!_runPrepareForComputationStarted) foreach (ILink link in connection.Links) { string linkID = link.ID; ILinkableComponent sourceComponent = link.SourceComponent, targetComponent = link.TargetComponent; sourceComponent.RemoveLink(linkID); targetComponent.RemoveLink(linkID); } _connections.Remove(connection); _shouldBeSaved = true; }
/// <summary> /// Creates a new instance of <see cref="ConnectionDialog">ConnectionDialog</see> dialog. /// </summary> public ConnectionDialog() { InitializeComponent(); _uilink = null; _propertyManagerCache = new Hashtable(); _startingLinkID = 0; _shouldBeSaved = false; _elementSetViewer = new ElementSetViewer(); }
/// <summary> /// Populates this <see cref="ConnectionDialog">ConnectionDialog</see> with specific connection. /// </summary> /// <param name="uilink"></param> /// <param name="startingLinkID"></param> public void PopulateDialog( UIConnection uilink, int startingLinkID ) { _uilink = uilink; _startingLinkID = startingLinkID; _propertyManagerCache = new Hashtable(); _shouldBeSaved = false; ElementTypeFilterCheckBox.Checked = false; DimensionFilterCheckBox.Checked = false; int count; ILinkableComponent component; component = uilink.ProvidingModel.LinkableComponent; IExchangeItem[] outputExchangeItems = new IExchangeItem[ component.OutputExchangeItemCount ]; count = component.OutputExchangeItemCount; for( int i = 0; i < count; i++ ) outputExchangeItems[i] = component.GetOutputExchangeItem(i); providerExchangeItemSelector.PopulateExchangeItemTree( outputExchangeItems, true ); component = uilink.AcceptingModel.LinkableComponent; IExchangeItem[] inputExchangeItems = new IExchangeItem[ component.InputExchangeItemCount ]; count = component.InputExchangeItemCount; for( int i = 0; i < count; i++ ) inputExchangeItems[i] = component.GetInputExchangeItem(i); acceptorExchangeItemSelector.PopulateExchangeItemTree( inputExchangeItems, true ); UpdateListLinks(); labelInfo.Text = "Connection "+uilink.ProvidingModel.ModelID+" => "+uilink.AcceptingModel.ModelID; }
// TODO Wrap Arguments so that exception thrown to indicate invalid value // can be caught and presented to the user. // e.g. valueA now = fred, valueB can only be ethal or freda // // Arguments list members (count as well as values) can change depending on // values of other arguments. // So say, 1 argument firstly which is file name to another list of // arguments to then display. // OpenWEB // model file change throws exception saying reload required // pipistrelle reconises exception_openweb type and reloads automatically static List <UIConnection> DeserializeConnectionsV2(opr opr, List <UIModel> models, DirectoryInfo oprPath) { List <UIConnection> connections = new List <UIConnection>(); if (opr.connections == null) { return(connections); } Dictionary <string, UIAdaptedOutputItem> adaptedOutputs = new Dictionary <string, UIAdaptedOutputItem>(); UIInputItem target; UIModel uiSourceModel, uiTargetModel; UIConnection uiConnection; Dictionary <string, UIOutputItem> sources = new Dictionary <string, UIOutputItem>(); Dictionary <string, UIInputItem> targets = new Dictionary <string, UIInputItem>(); List <Link> links = new List <Link>(); foreach (oprConnection connection in opr.connections) { if (!connection.source_model_indexSpecified || !connection.target_model_indexSpecified) { throw new NotImplementedException("Incompletly specified connections"); } uiSourceModel = models[connection.source_model_index]; uiTargetModel = models[connection.target_model_index]; uiConnection = new UIConnection(uiSourceModel, uiTargetModel); connections.Add(uiConnection); sources.Clear(); targets.Clear(); foreach (ITimeSpaceOutput item in uiSourceModel.LinkableComponent.Outputs) { sources.Add(item.Id, new UIOutputItem(item)); } foreach (ITimeSpaceInput item in uiTargetModel.LinkableComponent.Inputs) { targets.Add(item.Id, new UIInputItem(item)); } # region delete later //nDecorators = connection.decorators != null ? connection.decorators.Length : 0; //ids = new string[nDecorators]; //oprFactories = new oprConnectionDecoratorFactory[nDecorators]; //oprArguments = new oprConnectionDecoratorArgument[nDecorators][]; //for (int n = 0; n < nDecorators; ++n) //{ // ids[n] = connection.decorators[n].item_id; // oprFactories[n] = connection.decorators[n].factory; // oprArguments[n] = connection.decorators[n].arguments; //} #endregion links = new List <Link>(); foreach (oprConnectionLink oprLink in connection.links) { target = targets[oprLink.target_item_id]; oprSourceItem srcItem = oprLink.source_item_id; List <UIOutputItem> sourcesm = new List <UIOutputItem>(); UIOutputItem source = BuildOutputItemChain(uiSourceModel.LinkableComponent, srcItem, connection.decorators, sources, adaptedOutputs, oprPath, target); foreach (oprSourceItem item in oprLink.source_item_ids) { UIOutputItem tempSrc = BuildOutputItemChain(uiSourceModel.LinkableComponent, item, connection.decorators, sources, adaptedOutputs, oprPath, target); sourcesm.Add(tempSrc); } // Just telling target about most decorated source, // not the intermediates (& visa versa). // Probably the safest option re ensuring UI works // in maximum number of cases. // Thats what the UIOuputItem.Parent attribute is for! // TODO ADH: However, might want // to make explicit in Standard? if (target.ExchangeItem is IBaseMultiInput) { IBaseMultiInput mtarget = (IBaseMultiInput)target.ExchangeItem; foreach (UIOutputItem tempout in sourcesm) { mtarget.AddProvider(tempout); tempout.AddConsumer(mtarget); } } else { target.Provider = source; source.AddConsumer(target); } Link tempLink = new Link(sourcesm, target); //tempLink.Source = source; links.Add(tempLink); } uiConnection.Links = links; }
static oprConnectionLink[] Links(UIConnection connection, List <UIAdaptedOutputItem> allAdaptersInConnection) { oprConnectionLink[] links = new oprConnectionLink[connection.Links.Count]; UIOutputItem source; for (int n = 0; n < connection.Links.Count; ++n) { Link link = connection.Links[n]; source = link.Source; oprConnectionLink oprLink = new oprConnectionLink() { target_item_id = link.Target.Id }; oprSourceItem source_item = new oprSourceItem() { source_item_id = source.Id, source_item_is_adaptedoutput = source is UIAdaptedOutputItem, source_item_adpatedoutput_index = source is UIAdaptedOutputItem?allAdaptersInConnection.IndexOf(source as UIAdaptedOutputItem) : -1, }; oprLink.source_item_id = source_item; source = source.Parent; while (source != null) { oprSourceItem tempItem = new oprSourceItem() { source_item_id = source.Id, source_item_is_adaptedoutput = source is UIAdaptedOutputItem, source_item_adpatedoutput_index = source is UIAdaptedOutputItem?allAdaptersInConnection.IndexOf(source as UIAdaptedOutputItem) : -1, }; source_item.parent_item_id = tempItem; source_item = tempItem; source = source.Parent; } oprSourceItem[] source_items = new oprSourceItem[link.Sources.Count]; for (int i = 0; i < source_items.Length; i++) { source = link.Sources[i]; source_item = new oprSourceItem() { source_item_id = source.Id, source_item_is_adaptedoutput = source is UIAdaptedOutputItem, source_item_adpatedoutput_index = source is UIAdaptedOutputItem?allAdaptersInConnection.IndexOf(source as UIAdaptedOutputItem) : -1, }; source = source.Parent; source_items[i] = source_item; while (source != null) { oprSourceItem tempItem = new oprSourceItem() { source_item_id = source.Id, source_item_is_adaptedoutput = source is UIAdaptedOutputItem, source_item_adpatedoutput_index = source is UIAdaptedOutputItem?allAdaptersInConnection.IndexOf(source as UIAdaptedOutputItem) : -1, }; source_item.parent_item_id = tempItem; source_item = tempItem; source = source.Parent; } } oprLink.source_item_ids = source_items; links[n] = oprLink; } return(links); }