예제 #1
0
        private void LoadComponentsCommand()
        {
            // reset component list, channel list and canvas
            deploymentComponentList.Clear();
            canvas.Children.Clear();
            deploymentChannelList.Clear();
            eventChannelLinesList.Clear();
            eventChannelList.Clear();
            groupsList.Clear();
            CleanGUICanvas();
            copyModel = null;

            // loading the components
            foreach (object o in deploymentModel.components) {
                componentType modelComp = (componentType)o;
                // check, if bundle is available
                if (componentList.ContainsKey(modelComp.type_id)) {

                    // init the ArrayLists containing the ports. Used for easier and faster access
                    modelComp.InitArrayLists();

                    foreach (propertyType p in modelComp.properties) {
                        modelComp.PropertyArrayList.Add(p);
                    }

                    // copy the property datatype and description from bundle_description
                    // also copy the port datatypes form the bundle_description
                    // works only, if bundle and deployment fits to each other

                    try {
                        // search for bundle component
                        Asterics.ACS2.componentTypesComponentType bundleComponent = (Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id];

                        // copy the ComponentType of the component
                        modelComp.ComponentType = bundleComponent.type.Value;

                        if (modelComp.properties != null) {
                            foreach (propertyType deploymentProperty in modelComp.properties) {
                                int index = 0;
                                // searching for the right component property
                                while (deploymentProperty.name != bundleComponent.properties[index].name) {
                                    index++;
                                }
                                // copy the properties of the component
                                deploymentProperty.DataType = bundleComponent.properties[index].type;

                                // check, if the property is a dynamic property
                                if (bundleComponent.properties[index].getStringList) {
                                    deploymentProperty.GetStringList = true;
                                }
                                else {
                                    deploymentProperty.GetStringList = false;
                                }

                                // check the value fitting to the datatype
                                if (!CheckPropertyDatatype(deploymentProperty.value, deploymentProperty.DataType)) {
                                    throw new LoadPropertiesException();
                                }

                                deploymentProperty.Description = bundleComponent.properties[index].description;
                                if (bundleComponent.properties[index].combobox != null) {
                                    deploymentProperty.ComboBoxStrings = bundleComponent.properties[index].combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                }
                                deploymentProperty.PropertyChanged += ComponentPropertyChanged;
                                deploymentProperty.PropertyChangeError += ComponentPropertyChangeError;
                            }
                            // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment
                            if ((bundleComponent.properties == null) && (modelComp.properties.Length != 0)) {
                                throw new LoadPropertiesException();
                            }
                            else if ((bundleComponent.properties != null) && (modelComp.properties.Length != bundleComponent.properties.Length)) {
                                throw new LoadPropertiesException();
                            }
                        }

                        foreach (object portObj in modelComp.PortsList.Values) {
                            // searching for the inPorts
                            if (portObj is inputPortType) {
                                int index = 0;
                                inputPortType deploymentInPort = (inputPortType)portObj;
                                ArrayList helperListInPort = new ArrayList(); // a list with all InPorts of a component for the bundel_description
                                foreach (object bundleInPort in bundleComponent.ports) {
                                    if (bundleInPort is ACS2.inputPortType) {
                                        helperListInPort.Add(bundleInPort);
                                    }
                                }
                                while (deploymentInPort.portTypeID != ((ACS2.inputPortType)helperListInPort[index]).id) {
                                    index++; // searching for the right input port
                                }
                                // copy the dataType of the port
                                deploymentInPort.PortDataType = ((Asterics.ACS2.inputPortType)helperListInPort[index]).dataType;
                                deploymentInPort.MustBeConnected = ((Asterics.ACS2.inputPortType)helperListInPort[index]).mustBeConnected;
                                deploymentInPort.Description = ((Asterics.ACS2.inputPortType)helperListInPort[index]).description;
                                deploymentInPort.ComponentId = ((Asterics.ACS2.inputPortType)helperListInPort[index]).ComponentId;
                                deploymentInPort.ComponentTypeId = ((Asterics.ACS2.inputPortType)helperListInPort[index]).id;

                                // update the alias for group ports via property changed listener
                                deploymentInPort.PropertyChanged += InputPortIntPropertyChanged;

                                ACS2.propertyType[] sourceProperties = ((Asterics.ACS2.inputPortType)helperListInPort[index]).properties;
                                if ((sourceProperties != null) && (sourceProperties.Length > 0)) {
                                    //if (deploymentInPort.PropertyArrayList.Count > 0) {
                                    foreach (propertyType deploymentProperty in deploymentInPort.properties) {
                                        int inPortIndex = 0;
                                        while (deploymentProperty.name != sourceProperties[inPortIndex].name) {
                                            inPortIndex++;
                                        }
                                        // copy the properties of the inPort
                                        deploymentProperty.DataType = sourceProperties[inPortIndex].type;
                                        deploymentProperty.Description = sourceProperties[inPortIndex].description;
                                        if (sourceProperties[inPortIndex].combobox != null) {
                                            deploymentProperty.ComboBoxStrings = sourceProperties[inPortIndex].combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                        }
                                        deploymentProperty.PropertyChanged += InPortPropertyChanged;
                                        deploymentProperty.PropertyChangeError += ComponentPropertyChangeError;
                                    }
                                    // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment
                                    if (deploymentInPort.properties.Length != sourceProperties.Length) {
                                        throw new LoadPropertiesException();
                                    }
                                }
                                deploymentInPort.properties = (propertyType[])deploymentInPort.PropertyArrayList.ToArray(typeof(propertyType));
                            }
                            else {
                                // comparing all outPports
                                int index = 0;
                                outputPortType outPort = (outputPortType)portObj;
                                ArrayList helperListOutPort = new ArrayList();
                                foreach (object origOutPort in bundleComponent.ports) {
                                    if (origOutPort is ACS2.outputPortType) {
                                        helperListOutPort.Add(origOutPort);
                                    }
                                }
                                while (outPort.portTypeID != ((Asterics.ACS2.outputPortType)helperListOutPort[index]).id) {
                                    index++;
                                }
                                // copy the dataType of the port
                                outPort.PortDataType = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).dataType;
                                outPort.Description = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).description;
                                outPort.ComponentId = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).ComponentId;
                                outPort.ComponentTypeId = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).id;

                                // update the alias for group ports via property changed listener
                                outPort.PropertyChanged += OutputPortIntPropertyChanged;

                                ACS2.propertyType[] sourceProperties = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).properties;
                                if ((sourceProperties != null) && (sourceProperties.Length > 0)) {
                                    //if (outPort.PropertyArrayList.Count > 0) {
                                    foreach (propertyType compProperty in outPort.properties) {
                                        int outPortIndex = 0;
                                        while (compProperty.name != sourceProperties[outPortIndex].name) {
                                            outPortIndex++;
                                        }
                                        // copy the properties of the outPort
                                        compProperty.DataType = sourceProperties[outPortIndex].type;
                                        compProperty.Description = sourceProperties[outPortIndex].description;
                                        if (sourceProperties[outPortIndex].combobox != null) {
                                            compProperty.ComboBoxStrings = sourceProperties[outPortIndex].combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                        }
                                        compProperty.PropertyChanged += OutPortPropertyChanged;
                                        compProperty.PropertyChangeError += ComponentPropertyChangeError;
                                    }
                                    // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment
                                    if (outPort.properties.Length != sourceProperties.Length) {
                                        throw new LoadPropertiesException();
                                    }
                                }
                                outPort.properties = (propertyType[])outPort.PropertyArrayList.ToArray(typeof(propertyType));
                            }
                        }
                        // check if the amount of ports is equal to the amount of ports in the bundle
                        foreach (object origPort in bundleComponent.ports) {
                            if (origPort is ACS2.outputPortType) {
                                if (!modelComp.PortsList.Contains(((ACS2.outputPortType)origPort).id)) {
                                    outputPortType outPort = new outputPortType();
                                    outPort.PortDataType = ((Asterics.ACS2.outputPortType)origPort).dataType;
                                    outPort.Description = ((Asterics.ACS2.outputPortType)origPort).description;
                                    outPort.ComponentId = ((Asterics.ACS2.outputPortType)origPort).ComponentId;
                                    outPort.ComponentTypeId = ((Asterics.ACS2.outputPortType)origPort).id;
                                    outPort.portTypeID = ((Asterics.ACS2.outputPortType)origPort).id;
                                    modelComp.PortsList.Add(outPort.portTypeID, outPort);
                                    modelComp.ports = new object[modelComp.PortsList.Count];
                                    modelComp.PortsList.Values.CopyTo(modelComp.ports, 0);
                                    throw new LoadPortsException(outPort.portTypeID);
                                }
                            } else if (origPort is ACS2.inputPortType) {
                                if (!modelComp.PortsList.Contains(((ACS2.inputPortType)origPort).id)) {
                                    inputPortType inPort = new inputPortType();
                                    inPort.PortDataType = ((Asterics.ACS2.inputPortType)origPort).dataType;
                                    inPort.MustBeConnected = ((Asterics.ACS2.inputPortType)origPort).mustBeConnected;
                                    inPort.Description = ((Asterics.ACS2.inputPortType)origPort).description;
                                    inPort.ComponentId = ((Asterics.ACS2.inputPortType)origPort).ComponentId;
                                    inPort.ComponentTypeId = ((Asterics.ACS2.inputPortType)origPort).id;
                                    inPort.portTypeID = ((Asterics.ACS2.inputPortType)origPort).id;
                                    modelComp.PortsList.Add(inPort.portTypeID, inPort);
                                    modelComp.ports = new object[modelComp.PortsList.Count];
                                    modelComp.PortsList.Values.CopyTo(modelComp.ports, 0);
                                    throw new LoadPortsException(inPort.portTypeID);
                                }
                            }
                        }

                    }
                    catch (LoadPortsException lPortEx) {
                        // HasVersionConflict indicates a version conflict between the component in a stored model and
                        // the component in the bundle descriptor
                        //modelComp.HasVersionConflict = true;
                        modelComp.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                        MessageBox.Show(Properties.Resources.CopyPortsErrorTextFormat(lPortEx.Message, modelComp.id), Properties.Resources.CopyPortsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                        traceSource.TraceEvent(TraceEventType.Error, 3, lPortEx.Message);

                    } catch (Exception lPropEx) { //LoadPropertiesException
                        MessageBox.Show(Properties.Resources.CopyPropertiesErrorTextFormat(modelComp.id), Properties.Resources.CopyPropertiesErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                        traceSource.TraceEvent(TraceEventType.Error, 3, lPropEx.Message);

                        //versionconflict
                        int posX;
                        int posY;
                        // set coordinates for the component in case there are not already set
                        if ((modelComp.layout.posX == null) || (modelComp.layout.posX == "") || (modelComp.layout.posY == null) || (modelComp.layout.posY == "")) {
                            posX = 40;
                            posY = 40;
                        }
                        else {
                            posX = Int32.Parse(modelComp.layout.posX);
                            posY = Int32.Parse(modelComp.layout.posY);
                        }

                        // backup component to load properties
                        componentType backupComp = modelComp;

                        modelComp = componentType.CopyFromBundleModel((Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id], modelComp.id);
                        modelComp.layout.posX = Convert.ToString(posX);
                        modelComp.layout.posY = Convert.ToString(posY);

                        //reload the GUIElemens form the backup
                        if (backupComp.gui != null) {
                            modelComp.gui = backupComp.gui;
                        }
                        // HasVersionConflict indicates a version conflict between the component in a stored model and
                        // the component in the bundle descriptor
                        modelComp.HasVersionConflict = true;
                        modelComp.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                        //break;

                        // new code, copy property values from invalid (version conflict) component
                        foreach (propertyType deploymentProperty in modelComp.properties) {
                            foreach (propertyType backupProperty in backupComp.properties) {
                                if (deploymentProperty.name == backupProperty.name) {
                                    if (CheckPropertyDatatype(backupProperty.value, deploymentProperty.DataType)) {
                                        deploymentProperty.value = backupProperty.value; // try-parse is missing
                                    }
                                    break;
                                }
                            }
                        }

                    } // end of LoadPropertiesException

                    // set coordinates for the component in case there are not already set
                    if ((modelComp.layout.posX == null) || (modelComp.layout.posX == "") || (modelComp.layout.posY == null) || (modelComp.layout.posY == "")) {
                        int[] pos = ProperComponentCoordinates(40, 40);
                        modelComp.layout.posX = Convert.ToString(pos[0]);
                        modelComp.layout.posY = Convert.ToString(pos[1]);
                    }

                    // Searching for the event triggers and event listeners of a component
                    Asterics.ACS2.componentTypesComponentType bundleComponentEvents = (Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id];
                    // If component has version conflict, the events are already set by 'CopyFromBundleModel'
                    if ((bundleComponentEvents.events != null) && !modelComp.HasVersionConflict) {
                        foreach (object eventO in bundleComponentEvents.events) {
                            if (eventO is ACS2.eventsTypeEventListenerPortType) {
                                ACS2.eventsTypeEventListenerPortType compEl = (ACS2.eventsTypeEventListenerPortType)eventO;
                                EventListenerPort el = new EventListenerPort();
                                el.EventListenerId = compEl.id;
                                el.ComponentId = modelComp.id;
                                el.EventDescription = compEl.description;
                                modelComp.EventListenerList.Add(el);
                            }
                            else if (eventO is ACS2.eventsTypeEventTriggererPortType) {
                                ACS2.eventsTypeEventTriggererPortType compEl = (ACS2.eventsTypeEventTriggererPortType)eventO;
                                EventTriggerPort el = new EventTriggerPort();
                                el.EventTriggerId = compEl.id;
                                el.ComponentId = modelComp.id;
                                el.EventDescription = compEl.description;
                                modelComp.EventTriggerList.Add(el);
                            }
                        }
                    }

                    // if the component has no version conflict, it will be pasted on the layout, otherwise, it is already on the
                    // canvas (done by 'CopyFromBundleModel')
                    if (!modelComp.HasVersionConflict) {
                        // setting the mainRectangle and the portRectangles on the canvas
                        modelComp.InitGraphLayout(modelComp.id);
                    }
                    else {
                        //deploymentModel.components = deploymentComponentList.Values.ToArray();
                    }

                    // check, if the component has a confilct marker, but the VersionConflict is not set. This happens,
                    // if the version conflict occurs bacause of new ports
                    if (!modelComp.HasVersionConflict && modelComp.ComponentCanvas.Background != null) {
                        modelComp.HasVersionConflict = true;
                    }

                    canvas.Children.Add(modelComp.ComponentCanvas);
                    KeyboardNavigation.SetTabIndex(modelComp.ComponentCanvas, canvas.Children.Count + 1);
                    deploymentComponentList.Add(modelComp.id, modelComp);
                    // adding context menu
                    modelComp.MainRectangle.ContextMenu = componentContextMenu;
                    // adding keyboard focus listener
                    modelComp.ComponentCanvas.KeyDown += Component_KeyDown;
                    modelComp.ComponentCanvas.KeyUp += Component_KeyUp;
                    modelComp.ComponentCanvas.Focusable = true;
                    modelComp.ComponentCanvas.GotKeyboardFocus += ComponentCanvas_GotKeyboardFocus;
                    modelComp.ComponentCanvas.LostKeyboardFocus += ComponentCanvas_LostKeyboardFocus;

                    // adding property changed listener
                    modelComp.PropertyChanged += ComponentIntPropertyChanged;
                    modelComp.TopGrid.ContextMenu = componentContextMenu;
                    modelComp.TopRectangle.ContextMenu = componentContextMenu;
                    // set position of component on the canvas
                    Canvas.SetLeft(modelComp.ComponentCanvas, Int32.Parse(modelComp.layout.posX));
                    Canvas.SetTop(modelComp.ComponentCanvas, Int32.Parse(modelComp.layout.posY));

                    // Adapt the size of MainRectangle, if more then MAINRECTANGLENUMBEROFPORTS are in a component
                    int numInPorts = 0;
                    int numOutPorts = 0;
                    foreach (object objPort in modelComp.PortsList.Values) {
                        if (objPort is inputPortType) {
                            numInPorts++;
                        }
                        else {
                            numOutPorts++;
                        }
                    }
                    if (numOutPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) {
                        modelComp.MainRectangle.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE);
                        modelComp.ComponentCanvas.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE);
                    }
                    else if (numInPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) {
                        modelComp.MainRectangle.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE);
                        modelComp.ComponentCanvas.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE);
                    }
                    // Adapt the position of event trigger and event listener port, if the component has more input/output ports
                    if (modelComp.EventListenerList.Count > 0) {
                        Canvas.SetTop(modelComp.EventListenerPolygon.InputEventPortCanvas, modelComp.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10);
                    }
                    if (modelComp.EventTriggerList.Count > 0) {
                        Canvas.SetTop(modelComp.EventTriggerPolygon.OutputEventPortCanvas, modelComp.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10);
                    }
                }
                else {
                    MessageBox.Show(Properties.Resources.LoadComponentNotFoundFormat(modelComp.type_id), Properties.Resources.CopyPropertiesErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                    // removing the channels
                    if (deploymentModel.channels != null) {
                        List<channel> tempChannelList = deploymentModel.channels.ToList();
                        foreach (object oChannel in deploymentModel.channels) {
                            channel modChannel = (channel)oChannel;
                            if ((modChannel.source.component.id == modelComp.id) || (modChannel.target.component.id == modelComp.id)) {
                                tempChannelList.Remove(modChannel);
                            }
                        }
                        deploymentModel.channels = tempChannelList.ToArray();
                    }
                    // removing the eventchannels
                    if (deploymentModel.eventChannels != null) {
                        List<eventChannel> tempEventChannelList = deploymentModel.eventChannels.ToList();
                        foreach (object oEventChannel in deploymentModel.eventChannels) {
                            eventChannel modEventChannel = (eventChannel)oEventChannel;
                            if ((modEventChannel.sources.source.component.id == modelComp.id) || (modEventChannel.targets.target.component.id == modelComp.id)) {
                                tempEventChannelList.Remove(modEventChannel);
                            }
                        }
                        deploymentModel.eventChannels = tempEventChannelList.ToArray();
                    }
                }

                // check, if component has a gui component, and load the gui component
                if (modelComp.gui != null && ((Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id]) != null) {
                    if (((Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id]).gui.IsExternalGUIElementSpecified && ((Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id]).gui.IsExternalGUIElement) {
                        modelComp.gui.IsExternalGUIElement = true;
                    } else {
                        modelComp.gui.IsExternalGUIElement = false;
                    }
                    AddGUIComponent(modelComp);
                }
            }
            deploymentModel.components = deploymentComponentList.Values.ToArray();

            // loading the channels
            if (deploymentModel.channels != null) {
                foreach (object o in deploymentModel.channels) {
                    channel modChannel = (channel)o;
                    // check versionconflict: add only channels to components without a conflict
                    if ((deploymentComponentList.ContainsKey(modChannel.source.component.id)) && (deploymentComponentList.ContainsKey(modChannel.target.component.id))) {

                        // one of the channels component has a conflict. Check, if port is available and datatype fits together
                        componentType tempCompOut = (componentType)deploymentComponentList[modChannel.source.component.id];
                        componentType tempCompIn = (componentType)deploymentComponentList[modChannel.target.component.id];
                        // try, if the ports are still available
                        if ((tempCompOut.PortsList.Contains(modChannel.source.port.id)) && (tempCompIn.PortsList.Contains(modChannel.target.port.id))) {
                            // check the datatypes of the ports, for the case, that they have been changed
                            if (CheckInteroperabilityOfPorts(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortDataType, ((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortDataType)) {
                                AddChannel(modChannel);
                                modChannel.Line.Y1 = Canvas.GetTop(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortRectangle) + Canvas.GetTop(tempCompOut.ComponentCanvas) + 5;
                                modChannel.Line.X1 = Canvas.GetLeft(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortRectangle) + Canvas.GetLeft(tempCompOut.ComponentCanvas) + 20;

                                modChannel.Line.Y2 = Canvas.GetTop(((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortRectangle) + Canvas.GetTop(tempCompIn.ComponentCanvas) + 5;
                                modChannel.Line.X2 = Canvas.GetLeft(((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortRectangle) + Canvas.GetLeft(tempCompIn.ComponentCanvas);
                                Canvas.SetZIndex(modChannel.Line, Canvas.GetZIndex(modChannel.Line) + 1000);
                            }
                            else {
                                // if no event listener Port can be found, the component has a version conflict
                                MessageBox.Show(Properties.Resources.CopyChannelsErrorTextFormat(tempCompOut.id, tempCompIn.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                tempCompIn.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                tempCompIn.HasVersionConflict = true;
                                tempCompOut.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                tempCompOut.HasVersionConflict = true;
                            }
                        }
                        else {
                            if (!tempCompOut.PortsList.Contains(modChannel.source.port.id)) {
                                MessageBox.Show(Properties.Resources.CopyChannelErrorNotFoundFormat(tempCompOut.id, tempCompIn.id, modChannel.source.port.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                tempCompOut.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                tempCompOut.HasVersionConflict = true;
                            }
                            else {
                                MessageBox.Show(Properties.Resources.CopyChannelErrorNotFoundFormat(tempCompOut.id, tempCompIn.id, modChannel.source.port.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                tempCompIn.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                tempCompIn.HasVersionConflict = true;
                            }
                        }

                    }
                }
            }

            // Loading the events and drawing the lines between the event ports
            if (deploymentModel.eventChannels != null) {
                bool foundLine = false;
                foreach (object o in deploymentModel.eventChannels) {
                    eventChannel evChannel = (eventChannel)o;
                    //if (!(((modelComponent)deploymentComponentList[evChannel.sources.source[0].component.id]).HasVersionConflict) && !(((modelComponent)deploymentComponentList[evChannel.targets.target[0].component.id]).HasVersionConflict)) {
                    bool foundTriggerPort = false;
                    bool foundListenerPort = false;
                    try {
                        foreach (EventTriggerPort checkEvent in ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).EventTriggerList) {
                            if (checkEvent.ComponentId == evChannel.sources.source.component.id && checkEvent.EventTriggerId == evChannel.sources.source.eventPort.id) {
                                foundTriggerPort = true;
                                break;
                            }
                        }
                        if (foundTriggerPort) {
                            foreach (EventListenerPort checkEvent in ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).EventListenerList) {
                                if (checkEvent.ComponentId == evChannel.targets.target.component.id && checkEvent.EventListenerId == evChannel.targets.target.eventPort.id) {
                                    foundListenerPort = true;
                                    break;
                                }
                            }
                            if (foundListenerPort) {
                                foreach (eventChannelLine channelLine in eventChannelLinesList) {
                                    if ((evChannel.sources.source.component.id == channelLine.TriggerComponentId) && (evChannel.targets.target.component.id == channelLine.ListenerComponentId)) {
                                        foundLine = true;
                                        break;
                                    }
                                }
                                if (!foundLine) {
                                    eventChannelLine eCL = new eventChannelLine();

                                    eCL.Line.X1 = Canvas.GetLeft(((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) + LayoutConstants.EVENTOUTPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5;
                                    //eCL.Line.Y1 = Canvas.GetTop(((modelComponent)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) + LayoutConstants.EVENTOUTPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3;
                                    eCL.Line.Y1 = Canvas.GetTop(((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) +
                                        ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).MainRectangle.Height + LayoutConstants.EVENTPORTHEIGHT + LayoutConstants.MAINRECTANGLEOFFSETY - 7;
                                    eCL.Line.X2 = Canvas.GetLeft(((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5;
                                    //eCL.Line.Y2 = Canvas.GetTop(((modelComponent)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3;
                                    eCL.Line.Y2 = Canvas.GetTop(((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) +
                                        ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).MainRectangle.Height + LayoutConstants.EVENTPORTHEIGHT + LayoutConstants.MAINRECTANGLEOFFSETY - 7;

                                    eCL.Line.Focusable = true;
                                    eCL.ListenerComponentId = evChannel.targets.target.component.id;
                                    eCL.TriggerComponentId = evChannel.sources.source.component.id;
                                    eCL.Line.GotKeyboardFocus += EventChannel_GotKeyboardFocus;
                                    eCL.Line.LostKeyboardFocus += EventChannel_LostKeyboardFocus;
                                    eCL.Line.KeyDown += EventChannel_KeyDown;
                                    eCL.Line.ContextMenu = eventChannelContextMenu;
                                    eventChannelLinesList.Add(eCL);
                                    canvas.Children.Add(eCL.Line);
                                    KeyboardNavigation.SetTabIndex(eCL.Line, canvas.Children.Count + 1);
                                    Canvas.SetZIndex(eCL.Line, Canvas.GetZIndex(eCL.Line) + 2000);
                                }
                                eventChannelList.Add(o);
                                foundLine = false;
                            }
                            else {
                                // if no event listener Port can be found, the component has a version conflict
                                MessageBox.Show(Properties.Resources.CopyEventsErrorTextFormat(evChannel.targets.target.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).HasVersionConflict = true;
                            }
                        }
                        else {
                            // if no event trigger Port can be found, the component has a version conflict
                            MessageBox.Show(Properties.Resources.CopyEventsErrorTextFormat(evChannel.sources.source.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                            ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                            ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).HasVersionConflict = true;
                        }
                    }
                    catch (Exception) {
                        MessageBox.Show(Properties.Resources.CopyEventsExceptionTextFormat(evChannel.sources.source.component.id, evChannel.sources.source.eventPort.id,
                            evChannel.targets.target.component.id, evChannel.targets.target.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
            }

            ClearSelectedChannelList();
            ClearSelectedEventChannelList();
            ClearSelectedComponentList();
            // loading the groups
            if (deploymentModel.groups != null) {
                foreach (group makeGroup in deploymentModel.groups) {
                    foreach (string id in makeGroup.componentId) {
                        AddSelectedComponent(deploymentComponentList[id]);
                    }
                    string groupName = DoGrouping(null, false, false);
                    componentType ct = deploymentComponentList[groupName];
                    backupIdForPropertyEditor = groupName;
                    ct.id = makeGroup.id;
                    // set the alias
                    if (makeGroup.portAlias != null) {
                        foreach (portAlias alias in makeGroup.portAlias) {
                            componentType groupToUpdate = deploymentComponentList[makeGroup.id];
                            foreach (object port in groupToUpdate.ports) {
                                if ((port is inputPortType) && (((inputPortType)port).portTypeID == alias.portId)) {
                                    ((inputPortType)port).PortAliasForGroups = alias.portAlias1;
                                    ((inputPortType)port).PortLabel.Text = alias.portAlias1;
                                    break;
                                }
                                else if ((port is outputPortType) && (((outputPortType)port).portTypeID == alias.portId)) {
                                    ((outputPortType)port).PortAliasForGroups = alias.portAlias1;
                                    ((outputPortType)port).PortLabel.Text = alias.portAlias1;
                                    break;
                                }
                            }
                        }
                    }
                    if (makeGroup.description != null) {
                        deploymentComponentList[makeGroup.id].description = makeGroup.description;
                    }
                    ClearSelectedChannelList();
                    ClearSelectedEventChannelList();
                    ClearSelectedComponentList();
                }
            }

            // clear the undo/redo stack
            undoStack.Clear();
            redoStack.Clear();

            // focus the first element
            if (canvas.Children.Count > 0) {
                Keyboard.Focus(canvas.Children[0]);
            }
            else {
                Keyboard.Focus(canvas);
            }
        }
예제 #2
0
        /// <summary>
        /// Copy alle Components of the copyModel to the actual model
        /// </summary>
        private void PasteCopiedModel(model modelToPaste, bool namesAreValid, bool addToUndoStack)
        {
            CommandObject co = new CommandObject("Delete");
            if (modelToPaste == null)
                return;
            // loading the components
            /*
             *  Create a list of lists which contain all elements which should be within a group
             *  after the paste method finishes
             */
            ArrayList groupComps = new ArrayList();
            ArrayList groups = new ArrayList();
            ArrayList groupNames = new ArrayList();
            foreach (componentType ct in modelToPaste.components) {
                if (ct.ComponentType != ACS2.componentTypeDataTypes.group)
                    continue;
                groups.Add(ct);
                groupComponent gc = groupsList[ct.id];
                ArrayList groupElems = new ArrayList();
                foreach (componentType child in gc.AddedComponentList) {
                    foreach (componentType child1 in modelToPaste.components) {
                        if (child1.id.Equals(child.id)) {
                            groupElems.Add(child1);
                        }
                    }
                }
                if (groupElems.Count > 0) {
                    groupComps.Add(groupElems);
                    bool namevalid = namesAreValid;
                    int i = 1;
                    while (namevalid == false) {
                        string modelID = ct.id + "." + i;
                        if (!deploymentComponentList.ContainsKey(modelID)) {
                            namevalid = true;
                            groupNames.Add(modelID);
                        }
                        else
                            i++;
                    }
                }
            }

            // Rename components and update all channels
            Dictionary<string, string> changedComponents = new Dictionary<string, string>();
            foreach (object o in modelToPaste.components) {
                componentType modelComp = (componentType)o;
                if (modelComp.ComponentType == ACS2.componentTypeDataTypes.group)
                    continue;
                // change id
                bool namevalid = namesAreValid;
                int i = 1;
                while (namevalid == false) {
                    string modelID = modelComp.id + "." + i;
                    if (!deploymentComponentList.ContainsKey(modelID)) {
                        if (modelToPaste.channels != null) {
                            foreach (channel c in modelToPaste.channels) {
                                if (c.source.component.id == modelComp.id)
                                    c.source.component.id = modelID;
                                if (c.target.component.id == modelComp.id)
                                    c.target.component.id = modelID;
                            }
                        }
                        if (modelToPaste.eventChannels != null) {
                            foreach (eventChannel ec in modelToPaste.eventChannels) {
                                if (ec.sources.source.component.id == modelComp.id)
                                    ec.sources.source.component.id = modelID;
                                if (ec.targets.target.component.id == modelComp.id)
                                    ec.targets.target.component.id = modelID;
                            }
                        }
                        changedComponents.Add(modelComp.id,modelID);
                        modelComp.id = modelID;
                        namevalid = true;
                    }
                    else
                        i++;
                }
                // check, if bundle is available
                if (componentList.ContainsKey(modelComp.type_id)) {

                    // init the ArrayLists containing the ports. Used for easier and faster access
                    modelComp.InitArrayLists();

                    foreach (propertyType p in modelComp.properties) {
                        modelComp.PropertyArrayList.Add(p);
                    }

                    // copy the property datatype and description from bundle_description
                    // also copy the port datatypes form the bundle_description
                    // works only, if bundle and deployment fits to each other

                    try {
                        // search for bundle component
                        Asterics.ACS2.componentTypesComponentType bundleComponent = (Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id];

                        // copy the ComponentType of the component
                        modelComp.ComponentType = bundleComponent.type.Value;

                        if (modelComp.properties != null) {
                            foreach (propertyType deploymentProperty in modelComp.properties) {
                                int index = 0;
                                // searching for the right component property
                                while (deploymentProperty.name != bundleComponent.properties[index].name) {
                                    index++;
                                }
                                // copy the properties of the component
                                deploymentProperty.DataType = bundleComponent.properties[index].type;

                                // check, if the property is a dynamic property
                                if (bundleComponent.properties[index].getStringList) {
                                    deploymentProperty.GetStringList = true;
                                } else {
                                    deploymentProperty.GetStringList = false;
                                }

                                // check the value fitting to the datatype
                                if (!CheckPropertyDatatype(deploymentProperty.value, deploymentProperty.DataType)) {
                                    throw new LoadPropertiesException();
                                }

                                deploymentProperty.Description = bundleComponent.properties[index].description;
                                if (bundleComponent.properties[index].combobox != null) {
                                    deploymentProperty.ComboBoxStrings = bundleComponent.properties[index].combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                }
                                deploymentProperty.PropertyChanged += ComponentPropertyChanged;
                                deploymentProperty.PropertyChangeError += ComponentPropertyChangeError;
                            }
                            // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment
                            if ((bundleComponent.properties == null) && (modelComp.properties.Length != 0)) {
                                throw new LoadPropertiesException();
                            }
                            else if ((bundleComponent.properties != null) && (modelComp.properties.Length != bundleComponent.properties.Length)) {
                                throw new LoadPropertiesException();
                            }
                        }

                        foreach (object portObj in modelComp.PortsList.Values) {
                            // searching for the inPorts
                            if (portObj is inputPortType) {
                                int index = 0;
                                inputPortType deploymentInPort = (inputPortType)portObj;
                                ArrayList helperListInPort = new ArrayList(); // a list with all InPorts of a component for the bundel_description
                                foreach (object bundleInPort in bundleComponent.ports) {
                                    if (bundleInPort is ACS2.inputPortType) {
                                        helperListInPort.Add(bundleInPort);
                                    }
                                }
                                while (deploymentInPort.portTypeID != ((ACS2.inputPortType)helperListInPort[index]).id) {
                                    index++; // searching for the right input port
                                }
                                // copy the dataType of the port
                                deploymentInPort.PortDataType = ((Asterics.ACS2.inputPortType)helperListInPort[index]).dataType;
                                deploymentInPort.MustBeConnected = ((Asterics.ACS2.inputPortType)helperListInPort[index]).mustBeConnected;
                                deploymentInPort.Description = ((Asterics.ACS2.inputPortType)helperListInPort[index]).description;
                                deploymentInPort.ComponentId = ((Asterics.ACS2.inputPortType)helperListInPort[index]).ComponentId;
                                deploymentInPort.ComponentTypeId = ((Asterics.ACS2.inputPortType)helperListInPort[index]).id;

                                // update the alias for group ports via property changed listener
                                deploymentInPort.PropertyChanged += InputPortIntPropertyChanged;

                                ACS2.propertyType[] sourceProperties = ((Asterics.ACS2.inputPortType)helperListInPort[index]).properties;
                                if ((sourceProperties != null) && (sourceProperties.Length > 0)) {
                                    //if (deploymentInPort.PropertyArrayList.Count > 0) {
                                    foreach (propertyType deploymentProperty in deploymentInPort.properties) {
                                        int inPortIndex = 0;
                                        while (deploymentProperty.name != sourceProperties[inPortIndex].name) {
                                            inPortIndex++;
                                        }
                                        // copy the properties of the inPort
                                        deploymentProperty.DataType = sourceProperties[inPortIndex].type;
                                        deploymentProperty.Description = sourceProperties[inPortIndex].description;
                                        if (sourceProperties[inPortIndex].combobox != null) {
                                            deploymentProperty.ComboBoxStrings = sourceProperties[inPortIndex].combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                        }
                                        deploymentProperty.PropertyChanged += InPortPropertyChanged;
                                        deploymentProperty.PropertyChangeError += ComponentPropertyChangeError;
                                    }
                                    // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment
                                    if (deploymentInPort.properties.Length != sourceProperties.Length) {
                                        throw new Exception();
                                    }
                                }
                                deploymentInPort.properties = (propertyType[])deploymentInPort.PropertyArrayList.ToArray(typeof(propertyType));
                            }
                            else {
                                // comparing all outPports
                                int index = 0;
                                outputPortType outPort = (outputPortType)portObj;
                                ArrayList helperListOutPort = new ArrayList();
                                foreach (object origOutPort in bundleComponent.ports) {
                                    if (origOutPort is ACS2.outputPortType) {
                                        helperListOutPort.Add(origOutPort);
                                    }
                                }
                                while (outPort.portTypeID != ((Asterics.ACS2.outputPortType)helperListOutPort[index]).id) {
                                    index++;
                                }
                                // copy the dataType of the port
                                outPort.PortDataType = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).dataType;
                                outPort.Description = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).description;
                                outPort.ComponentId = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).ComponentId;
                                outPort.ComponentTypeId = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).id;

                                // update the alias for group ports via property changed listener
                                outPort.PropertyChanged += OutputPortIntPropertyChanged;

                                ACS2.propertyType[] sourceProperties = ((Asterics.ACS2.outputPortType)helperListOutPort[index]).properties;
                                if ((sourceProperties != null) && (sourceProperties.Length > 0)) {
                                    //if (outPort.PropertyArrayList.Count > 0) {
                                    foreach (propertyType compProperty in outPort.properties) {
                                        int outPortIndex = 0;
                                        while (compProperty.name != sourceProperties[outPortIndex].name) {
                                            outPortIndex++;
                                        }
                                        // copy the properties of the outPort
                                        compProperty.DataType = sourceProperties[outPortIndex].type;
                                        compProperty.Description = sourceProperties[outPortIndex].description;
                                        if (sourceProperties[outPortIndex].combobox != null) {
                                            compProperty.ComboBoxStrings = sourceProperties[outPortIndex].combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                        }
                                        compProperty.PropertyChanged += OutPortPropertyChanged;
                                        compProperty.PropertyChangeError += ComponentPropertyChangeError;
                                    }
                                    // check the amount of properties. Cause an exception, if the bundle has more properties then the deployment
                                    if (outPort.properties.Length != sourceProperties.Length) {
                                        throw new Exception();
                                    }
                                }
                                outPort.properties = (propertyType[])outPort.PropertyArrayList.ToArray(typeof(propertyType));
                            }
                        }
                    }
                    catch (Exception ex) {
                        MessageBox.Show(Properties.Resources.CopyPropertiesErrorTextFormat(modelComp.id), Properties.Resources.CopyPropertiesErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                        traceSource.TraceEvent(TraceEventType.Error, 3, ex.Message);

                        //versionconflict
                        int posX;
                        int posY;
                        // set coordinates for the component in case there are not already set
                        if ((modelComp.layout.posX == null) || (modelComp.layout.posX == "") || (modelComp.layout.posY == null) || (modelComp.layout.posY == "")) {
                            posX = 40;
                            posY = 40;
                        }
                        else {
                            posX = Int32.Parse(modelComp.layout.posX);
                            posY = Int32.Parse(modelComp.layout.posY);
                        }

                        // backup component to load properties
                        componentType backupComp = modelComp;

                        modelComp = componentType.CopyFromBundleModel((Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id], modelComp.id);
                        modelComp.layout.posX = Convert.ToString(posX);
                        modelComp.layout.posY = Convert.ToString(posY);
                        // HasVersionConflict indicates a version conflict between the component in a stored model and
                        // the component in the bundle descriptor
                        modelComp.HasVersionConflict = true;
                        modelComp.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                        //break;

                        // new code, copy property values from invalid (version conflict) component
                        foreach (propertyType deploymentProperty in modelComp.properties) {
                            foreach (propertyType backupProperty in backupComp.properties) {
                                if (deploymentProperty.name == backupProperty.name) {
                                    if (CheckPropertyDatatype(backupProperty.value, deploymentProperty.DataType)) {
                                        deploymentProperty.value = backupProperty.value; // try-parse is missing
                                    }
                                    break;
                                }
                            }
                        }

                    } // end of exception

                    // set coordinates for the component in case there are not already set
                    if ((modelComp.layout.posX == null) || (modelComp.layout.posX == "") || (modelComp.layout.posY == null) || (modelComp.layout.posY == "")) {
                        int[] pos = ProperComponentCoordinates(40, 40);
                        modelComp.layout.posX = Convert.ToString(pos[0]);
                        modelComp.layout.posY = Convert.ToString(pos[1]);
                    }

                    // Searching for the event triggers and event listeners of a component
                    Asterics.ACS2.componentTypesComponentType bundleComponentEvents = (Asterics.ACS2.componentTypesComponentType)componentList[modelComp.type_id];
                    // If component has version conflict, the events are already set by 'CopyFromBundleModel'
                    if ((bundleComponentEvents.events != null) && (bundleComponentEvents.events != null) && !modelComp.HasVersionConflict) {
                        foreach (object eventO in bundleComponentEvents.events) {
                            if (eventO is ACS2.eventsTypeEventListenerPortType) {
                                ACS2.eventsTypeEventListenerPortType compEl = (ACS2.eventsTypeEventListenerPortType)eventO;
                                EventListenerPort el = new EventListenerPort();
                                el.EventListenerId = compEl.id;
                                el.ComponentId = modelComp.id;
                                el.EventDescription = compEl.description;
                                modelComp.EventListenerList.Add(el);
                            }
                            else if (eventO is ACS2.eventsTypeEventTriggererPortType) {
                                ACS2.eventsTypeEventTriggererPortType compEl = (ACS2.eventsTypeEventTriggererPortType)eventO;
                                EventTriggerPort el = new EventTriggerPort();
                                el.EventTriggerId = compEl.id;
                                el.ComponentId = modelComp.id;
                                el.EventDescription = compEl.description;
                                modelComp.EventTriggerList.Add(el);
                            }
                        }
                    }

                    // if the component has no version conflict, it will be pasted on the layout, otherwise, it is already on the
                    // canvas (done by 'CopyFromBundleModel')
                    if (!modelComp.HasVersionConflict) {
                        modelComp.InitGraphLayout(modelComp.id);
                    }
                    else {
                        //deploymentModel.components = deploymentComponentList.Values.ToArray();
                    }
                    canvas.Children.Add(modelComp.ComponentCanvas);
                    KeyboardNavigation.SetTabIndex(modelComp.ComponentCanvas, canvas.Children.Count + 1);

                    modelComp.Label.Text = modelComp.id;
                    double positionX = (Int32.Parse(modelComp.layout.posX) + copyXOffset * copyOffsetMulti);
                    if (positionX + modelComp.ComponentCanvas.Width > canvas.RenderSize.Width)
                        positionX = canvas.RenderSize.Width - modelComp.ComponentCanvas.Width;
                    double positionY = (Int32.Parse(modelComp.layout.posY) + copyYOffset * copyOffsetMulti);
                    if (positionY + modelComp.ComponentCanvas.Height > canvas.RenderSize.Height)
                        positionY = canvas.RenderSize.Height - modelComp.ComponentCanvas.Height;
                    modelComp.layout.posX = positionX.ToString();
                    modelComp.layout.posY = positionY.ToString();
                    deploymentComponentList.Add(modelComp.id, modelComp);
                    //componentList.Add(modelComp.id, modelComp);
                    // adding context menu
                    modelComp.MainRectangle.ContextMenu = componentContextMenu;
                    // adding keyboard focus listener
                    modelComp.ComponentCanvas.KeyDown += Component_KeyDown;
                    modelComp.ComponentCanvas.KeyUp += Component_KeyUp;
                    modelComp.ComponentCanvas.Focusable = true;
                    modelComp.ComponentCanvas.GotKeyboardFocus += ComponentCanvas_GotKeyboardFocus;
                    modelComp.ComponentCanvas.LostKeyboardFocus += ComponentCanvas_LostKeyboardFocus;

                    // adding property changed listener
                    modelComp.PropertyChanged += ComponentIntPropertyChanged;
                    modelComp.TopGrid.ContextMenu = componentContextMenu;
                    modelComp.TopRectangle.ContextMenu = componentContextMenu;
                    // set position of component on the canvas
                    Canvas.SetLeft(modelComp.ComponentCanvas, Int32.Parse(modelComp.layout.posX));
                    Canvas.SetTop(modelComp.ComponentCanvas, Int32.Parse(modelComp.layout.posY));

                    // Adapt the size of MainRectangle, if more then MAINRECTANGLENUMBEROFPORTS are in a component
                    int numInPorts = 0;
                    int numOutPorts = 0;
                    foreach (object objPort in modelComp.PortsList.Values) {
                        if (objPort is inputPortType) {
                            numInPorts++;
                        }
                        else {
                            numOutPorts++;
                        }
                    }
                    if (numOutPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) {
                        modelComp.MainRectangle.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE);
                        modelComp.ComponentCanvas.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE);
                    }
                    else if (numInPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) {
                        modelComp.MainRectangle.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE);
                        modelComp.ComponentCanvas.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE);
                    }
                    // Adapt the position of event trigger and event listener port, if the component has more input/output ports
                    if (modelComp.EventListenerList.Count > 0) {
                        Canvas.SetTop(modelComp.EventListenerPolygon.InputEventPortCanvas, modelComp.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10);
                    }
                    if (modelComp.EventTriggerList.Count > 0) {
                        Canvas.SetTop(modelComp.EventTriggerPolygon.OutputEventPortCanvas, modelComp.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10);
                    }

                }
                else {
                    MessageBox.Show(Properties.Resources.LoadComponentNotFoundFormat(modelComp.type_id), Properties.Resources.CopyPropertiesErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                }

                // check, if component has a gui component, and load the gui component
                if (modelComp.gui != null) {
                    AddGUIComponent(modelComp);
                }
            }
            deploymentModel.components = deploymentComponentList.Values.ToArray();

            // loading the channels
            if (modelToPaste.channels != null) {
                foreach (object o in modelToPaste.channels) {
                    channel modChannel = (channel)o;
                    // check versionconflict: add only channels to components without a conflict
                    if ((deploymentComponentList.ContainsKey(modChannel.source.component.id)) && (deploymentComponentList.ContainsKey(modChannel.target.component.id))) {

                        // one of the channels component has a conflict. Check, if port is available and datatype fits together
                        componentType tempCompOut = (componentType)deploymentComponentList[modChannel.source.component.id];
                        componentType tempCompIn = (componentType)deploymentComponentList[modChannel.target.component.id];
                        // try, if the ports are still available

                        if ((tempCompOut.PortsList.Contains(modChannel.source.port.id)) && (tempCompIn.PortsList.Contains(modChannel.target.port.id))) {
                            // check the datatypes of the ports, for the case, that they have been changed
                            //if (CheckInteroperabilityOfPorts(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortDataType, ((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortDataType)) {
                                modChannel.id = NewIdForChannel();
                                AddChannel(modChannel);
                                modChannel.Line.Y1 = Canvas.GetTop(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortRectangle) + Canvas.GetTop(tempCompOut.ComponentCanvas) + 5;
                                modChannel.Line.X1 = Canvas.GetLeft(((outputPortType)tempCompOut.PortsList[modChannel.source.port.id]).PortRectangle) + Canvas.GetLeft(tempCompOut.ComponentCanvas) + 20;

                                modChannel.Line.Y2 = Canvas.GetTop(((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortRectangle) + Canvas.GetTop(tempCompIn.ComponentCanvas) + 5;
                                modChannel.Line.X2 = Canvas.GetLeft(((inputPortType)tempCompIn.PortsList[modChannel.target.port.id]).PortRectangle) + Canvas.GetLeft(tempCompIn.ComponentCanvas);
                                Canvas.SetZIndex(modChannel.Line, Canvas.GetZIndex(modChannel.Line) + 1000);
                            //}
                            //else {
                            //    // if no event listener Port can be found, the component has a version conflict
                            //    MessageBox.Show(Properties.Resources.CopyChannelsErrorTextFormat(tempCompOut.id, tempCompIn.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                            //    tempCompIn.ComponentCanvas.Background = new SolidColorBrush(Colors.Red);
                            //    tempCompIn.HasVersionConflict = true;
                            //    tempCompOut.ComponentCanvas.Background = new SolidColorBrush(Colors.Red);
                            //    tempCompOut.HasVersionConflict = true;
                            //}
                        }
                        else {
                            if (!tempCompOut.PortsList.Contains(modChannel.source.port.id)) {
                                MessageBox.Show(Properties.Resources.CopyChannelErrorNotFoundFormat(tempCompOut.id, tempCompIn.id, modChannel.source.port.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                tempCompOut.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                tempCompOut.HasVersionConflict = true;
                            }
                            else {
                                MessageBox.Show(Properties.Resources.CopyChannelErrorNotFoundFormat(tempCompOut.id, tempCompIn.id, modChannel.source.port.id), Properties.Resources.CopyChannelsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                tempCompIn.ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                tempCompIn.HasVersionConflict = true;
                            }
                        }

                    }
                }
            }
            // Loading the events and drawing the lines between the event ports
            if (modelToPaste.eventChannels != null) {
                bool foundLine = false;
                foreach (object o in modelToPaste.eventChannels) {
                    eventChannel evChannel = (eventChannel)o;
                    bool foundTriggerPort = false;
                    bool foundListenerPort = false;
                    try {
                        foreach (EventTriggerPort checkEvent in ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).EventTriggerList) {
                            if (checkEvent.ComponentId == evChannel.sources.source.component.id && checkEvent.EventTriggerId == evChannel.sources.source.eventPort.id) {
                                foundTriggerPort = true;
                                break;
                            }
                        }
                        if (foundTriggerPort) {
                            foreach (EventListenerPort checkEvent in ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).EventListenerList) {
                                if (checkEvent.ComponentId == evChannel.targets.target.component.id && checkEvent.EventListenerId == evChannel.targets.target.eventPort.id) {
                                    foundListenerPort = true;
                                    break;
                                }
                            }
                            if (foundListenerPort) {
                                foreach (eventChannelLine channelLine in eventChannelLinesList) {
                                    if ((evChannel.sources.source.component.id == channelLine.TriggerComponentId) && (evChannel.targets.target.component.id == channelLine.ListenerComponentId)) {
                                        foundLine = true;
                                        break;
                                    }
                                }
                                if (!foundLine) {
                                    eventChannelLine eCL = new eventChannelLine();

                                    eCL.Line.X1 = Canvas.GetLeft(((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) + LayoutConstants.EVENTOUTPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5;
                                    //eCL.Line.Y1 = Canvas.GetTop(((modelComponent)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) + LayoutConstants.EVENTOUTPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3;
                                    eCL.Line.Y1 = Canvas.GetTop(((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas) +
                                        ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).MainRectangle.Height + LayoutConstants.EVENTPORTHEIGHT + LayoutConstants.MAINRECTANGLEOFFSETY - 7;
                                    eCL.Line.X2 = Canvas.GetLeft(((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETX + LayoutConstants.EVENTPORTWIDTH / 2 + 5;
                                    //eCL.Line.Y2 = Canvas.GetTop(((modelComponent)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) + LayoutConstants.EVENTINPORTCANVASOFFSETY + LayoutConstants.EVENTPORTHEIGHT + 3;
                                    eCL.Line.Y2 = Canvas.GetTop(((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas) +
                                        ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).MainRectangle.Height + LayoutConstants.EVENTPORTHEIGHT + LayoutConstants.MAINRECTANGLEOFFSETY - 7;

                                    eCL.Line.Focusable = true;
                                    eCL.ListenerComponentId = evChannel.targets.target.component.id;
                                    eCL.TriggerComponentId = evChannel.sources.source.component.id;
                                    eCL.Line.GotKeyboardFocus += EventChannel_GotKeyboardFocus;
                                    eCL.Line.LostKeyboardFocus += EventChannel_LostKeyboardFocus;
                                    eCL.Line.KeyDown += EventChannel_KeyDown;
                                    eCL.Line.ContextMenu = eventChannelContextMenu;
                                    eventChannelLinesList.Add(eCL);
                                    canvas.Children.Add(eCL.Line);
                                    KeyboardNavigation.SetTabIndex(eCL.Line, canvas.Children.Count + 1);
                                    Canvas.SetZIndex(eCL.Line, Canvas.GetZIndex(eCL.Line) + 2000);
                                }
                                eventChannelList.Add(o);
                                foundLine = false;
                            }
                            else {
                                // if no event listener Port can be found, the component has a version conflict
                                MessageBox.Show(Properties.Resources.CopyEventsErrorTextFormat(evChannel.targets.target.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                                ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                                ((componentType)deploymentComponentList[evChannel.targets.target.component.id]).HasVersionConflict = true;
                            }
                        }
                        else {
                            // if no event trigger Port can be found, the component has a version conflict
                            MessageBox.Show(Properties.Resources.CopyEventsErrorTextFormat(evChannel.sources.source.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                            ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).ComponentCanvas.Background = new SolidColorBrush(Colors.Orange);
                            ((componentType)deploymentComponentList[evChannel.sources.source.component.id]).HasVersionConflict = true;
                        }
                    }
                    catch (Exception) {
                        MessageBox.Show(Properties.Resources.CopyEventsExceptionTextFormat(evChannel.sources.source.component.id, evChannel.sources.source.eventPort.id,
                            evChannel.targets.target.component.id, evChannel.targets.target.component.id), Properties.Resources.CopyEventsErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                deploymentModel.eventChannels = (eventChannel[])eventChannelList.ToArray(typeof(eventChannel));
            }

            // focus the first element
            if (canvas.Children.Count > 0) {
                Keyboard.Focus(canvas.Children[0]);
            }
            else {
                Keyboard.Focus(canvas);
            }
            copyOffsetMulti++;
            ClearSelectedChannelList();
            if (modelToPaste.channels != null) {
                foreach (channel c in modelToPaste.channels) {
                    selectedChannelList.AddLast(c);
                    co.InvolvedObjects.Add(c);
                }
            }
            UpdateSelectedChannels();
            ClearSelectedEventChannelList();
            LinkedList<eventChannelLine> selEventChannels = new LinkedList<eventChannelLine>();
            foreach (eventChannelLine ecl in eventChannelLinesList) {
                if (modelToPaste.eventChannels != null) {
                    foreach (eventChannel ech in modelToPaste.eventChannels) {
                        if (ecl.ListenerComponentId == ech.targets.target.component.id ||
                            ecl.TriggerComponentId == ech.sources.source.component.id) {
                            selEventChannels.AddLast(ecl);
                            break;
                        }
                    }
                }
            }
            foreach (eventChannelLine ecl in selEventChannels) {
                selectedEventChannelList.AddLast(ecl);
                co.InvolvedObjects.Add(ecl);
            }
            UpdateSelectedEventChannels();
            // select all inserted components
            ClearSelectedComponentList();
            foreach (componentType mc in modelToPaste.components) {
                selectedComponentList.AddLast(mc);
                co.InvolvedObjects.Add(mc);
            }
            UpdateSelectedComponents();
            if (addToUndoStack) {
                undoStack.Push(co);
                redoStack.Clear();
            }
            SetKeyboardFocus();
            int groupIndex = 0;
            AddDummyToModel(copyDummyName);
            foreach (ArrayList group in groupComps) {
                ClearSelectedChannelList();
                ClearSelectedComponentList();
                ClearSelectedEventChannelList();
                foreach (componentType ct in group) {
                    AddSelectedComponent(ct);
                }
                componentType groupComponent = (componentType) groups[groupIndex];
                // add dummy channels to retain all ports of the copied group element
                foreach (object o in groupComponent.ports) {
                    if (o is inputPortType) {
                        inputPortType inPort = (inputPortType) o;

                        string targetComponent = inPort.refs.componentID;
                        componentType newTarget = null;
                        foreach (componentType ct in group) {
                            if (ct.id.StartsWith(targetComponent)) {
                                if (newTarget == null)
                                    newTarget = ct;
                                else {
                                    if (newTarget.id.Length < ct.id.Length)
                                        newTarget = ct;
                                }
                            }
                        }
                        if (newTarget == null)
                            continue;

                        // check if an channel already exists for this inputporttype
                        bool duplicate = false;
                        foreach (channel c in deploymentChannelList.Values) {
                            if (c.target.component.id.Equals(newTarget.id) &&
                                c.target.port.id.Equals(inPort.portTypeID.Substring(targetComponent.Length + 1))) {
                                    duplicate = true;
                            }
                        }
                        if (duplicate)
                            continue;

                        // add dummy channel
                        channel groupChannel = new channel();

                        groupChannel.id = NewIdForChannel();
                        groupChannel.target.component.id = newTarget.id;
                        groupChannel.target.port.id = inPort.refs.portID;
                        groupChannel.source.component.id = copyDummyName;
                        groupChannel.source.port.id = "out";
                        if (!ChannelExists(groupChannel))
                            AddChannel(groupChannel);
                    } else if (o is outputPortType) {
                        outputPortType outPort = (outputPortType) o;
                        string sourceComponent = outPort.refs.componentID;
                        componentType newSource = null;
                        foreach (componentType ct in group) {
                            if (ct.id.StartsWith(sourceComponent)) {
                                if (newSource == null)
                                    newSource = ct;
                                else {
                                    if (newSource.id.Length < ct.id.Length)
                                        newSource = ct;
                                }
                            }
                        }
                        if (newSource == null)
                            continue;

                        // add dummy channel
                        channel groupChannel = new channel();

                        groupChannel.id = NewIdForChannel();
                        groupChannel.source.component.id = newSource.id;
                        groupChannel.source.port.id = outPort.refs.portID;
                        groupChannel.target.component.id = copyDummyName;
                        groupChannel.target.port.id = "in";
                        if (!ChannelExists(groupChannel))
                            AddChannel(groupChannel);
                    }

                }
                // add dummy eventchannels to retain all eventchannel ports of the copied group

                foreach (ArrayList echList in copyGroupEventChannels) {
                    foreach (eventChannel ech in echList) {
                        componentType source = null;
                        componentType target = null;
                        foreach (componentType ct in group) {
                            if (ct.id.StartsWith(ech.sources.source.component.id)) {
                                if (source == null)
                                    source = ct;
                                else if (ct.id.Length > source.id.Length)
                                    source = ct;
                            }
                            if (ct.id.StartsWith(ech.targets.target.component.id)) {
                                if (target == null)
                                    target = ct;
                                else if (ct.id.Length > target.id.Length)
                                    target = ct;
                            }
                        }
                        if (source != null)
                            ech.sources.source.component.id = source.id;
                        if (target != null) {
                            ech.targets.target.component.id = target.id;
                            ech.id = target.id + "_" + ech.sources.source.eventPort.id + "_" + ech.targets.target.eventPort.id;
                        }
                        if (source != null || target != null)
                            eventChannelList.Add(ech);
                    }
                }

                LinkedList<portAlias> newPortAlias = new LinkedList<portAlias>();
                group originalGroup = null;
                foreach (object o in groups) {
                   // groups.Add(ct);
                    groupComponent gc = groupsList[((componentType)o).id];
                    // adapting the alias to the new group port names

                    foreach (group gr in deploymentModel.groups) {
                        if (gr.id == ((componentType)o).id) {
                            originalGroup = gr;
                            break;
                        }
                    }

                    if (originalGroup != null && originalGroup.portAlias != null) {
                        foreach (portAlias alias in originalGroup.portAlias) {
                            foreach (string oldCompName in changedComponents.Keys) {
                                if (alias.portId.Contains(oldCompName)) {
                                    portAlias pAlias = new portAlias();
                                    pAlias.portId = alias.portId.Replace(oldCompName, changedComponents[oldCompName]);
                                    pAlias.portAlias1 = alias.portAlias1;
                                    newPortAlias.AddLast(pAlias);
                                    break;
                                }
                            }
                        }
                    }
                }

                DoGrouping((string) groupNames[groupIndex], false, true);
                group groupToUpdate = null;
                foreach (group gr in deploymentModel.groups) {
                    if (gr.id == (string)groupNames[groupIndex]) {
                        gr.portAlias = newPortAlias.ToArray();
                        groupToUpdate = gr;
                        break;
                    }
                }
                if (groupToUpdate.portAlias != null) {
                    foreach (portAlias alias in groupToUpdate.portAlias) {
                        componentType groupComponentToUpdate = deploymentComponentList[groupToUpdate.id];
                        groupComponentToUpdate.description = originalGroup.description;
                        foreach (object port in groupComponentToUpdate.ports) {
                            if ((port is inputPortType) && (((inputPortType)port).portTypeID == alias.portId)) {
                                ((inputPortType)port).PortAliasForGroups = alias.portAlias1;
                                ((inputPortType)port).PortLabel.Text = alias.portAlias1;
                                break;
                            } else if ((port is outputPortType) && (((outputPortType)port).portTypeID == alias.portId)) {
                                ((outputPortType)port).PortAliasForGroups = alias.portAlias1;
                                ((outputPortType)port).PortLabel.Text = alias.portAlias1;
                                break;
                            }
                        }
                    }
                }
                groupToUpdate.description = originalGroup.description;
                groupIndex++;
            }
            RemoveDummyFromModel(copyDummyName);
            DeleteDanglingChannels();
            DeleteDanglingEventChannels();

            // select the copied elements after paste
            selectedComponentList.Clear();
            foreach (componentType mc in modelToPaste.components) {
                selectedComponentList.AddLast(mc);
            }
            UpdateSelectedComponents();
        }
        // copy all relevant properties of an eventport
        //private void CopyEventPort(Canvas source, Canvas target) {
        //    target.Width = source.Width;
        //    target.Height = source.Height;
        //    PointCollection eventPortPointCollection = new PointCollection();
        //    Polygon eventPortPolygon = new Polygon();
        //    foreach (Polygon pg in source.Children) {
        //        foreach (Point p in pg.Points) {
        //            eventPortPointCollection.Add(new Point(p.X, p.Y));
        //        }
        //        eventPortPolygon.Points = eventPortPointCollection;
        //        eventPortPolygon.Fill = pg.Fill;
        //        eventPortPolygon.Stroke = pg.Stroke;
        //    }
        //    target.Children.Add(eventPortPolygon);
        //}
        /// <summary>
        /// Generate a new deployment component form a bundle component, deep copy
        /// </summary>
        /// <param name="component">The bundle component, which should be copied</param>
        /// <param name="id">The id of the new component</param>
        /// <returns>A new model component based on the bundle component</returns>
        public static componentType CopyFromBundleModel(Asterics.ACS2.componentTypesComponentType component, String id)
        {
            componentType mComponent = new componentType();
            //int portIndex = 0;

            mComponent.id = id;
            mComponent.componentTypeDataType = component.type.Value;
            //mComponent.componentId = component.id;
            mComponent.type_id = component.id;
            mComponent.description = component.description;

            // copy the graphical elements
            mComponent.ComponentCanvas.Height = component.ComponentCanvas.Height;
            mComponent.ComponentCanvas.Width = component.ComponentCanvas.Width;
            mComponent.ComponentCanvas.FocusVisualStyle = null;
            mComponent.CopyRectangel(component.MainRectangle, mComponent.MainRectangle);
            mComponent.ComponentCanvas.Children.Add(mComponent.MainRectangle);
            Canvas.SetLeft(mComponent.MainRectangle, Canvas.GetLeft(component.MainRectangle));
            Canvas.SetTop(mComponent.MainRectangle, Canvas.GetTop(component.MainRectangle));
            mComponent.Label.Text = id;

            mComponent.InitLabeling();

            // copy the properties
            if (component.properties != null) {
                foreach (Asterics.ACS2.propertyType compProperty in component.properties) {
                    propertyType property = new propertyType();
                    property.name = compProperty.name;
                    property.DataType = compProperty.type;
                    property.Description = compProperty.description;
                    property.value = compProperty.value;
                    if (compProperty.combobox != null) {
                        property.ComboBoxStrings = compProperty.combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                    }
                    if (compProperty.getStringList) {
                        property.GetStringList = true;
                    } else {
                        property.GetStringList = false;
                    }
                    mComponent.PropertyArrayList.Add(property);
                }
            }
            mComponent.propertiesField = new propertyType[mComponent.PropertyArrayList.Count];
            mComponent.PropertyArrayList.CopyTo(mComponent.propertiesField);

            // copy the ports

            if (component.ports != null) {
                foreach (object o in component.ports) {
                    // copy the inports
                    if (o is Asterics.ACS2.inputPortType) {
                        Asterics.ACS2.inputPortType compInPort = (Asterics.ACS2.inputPortType)o;
                        inputPortType inPort = new inputPortType();
                        inPort.portTypeID = compInPort.id;
                        inPort.ComponentId = id;
                        inPort.Description = compInPort.description;
                        inPort.MustBeConnected = compInPort.mustBeConnected;
                        inPort.PortDataType = compInPort.dataType;
                        inPort.ComponentTypeId = component.id;

                        inPort.PortLabel.Text = compInPort.id;
                        mComponent.componentCanvas.Children.Add(inPort.PortLabel);
                        Canvas.SetLeft(inPort.PortLabel, Canvas.GetLeft(compInPort.PortRectangle) + ACS.LayoutConstants.INPORTRECTANGLEWIDTH + 2);
                        Canvas.SetTop(inPort.PortLabel, Canvas.GetTop(compInPort.PortRectangle) - 2 );

                        mComponent.CopyRectangel(compInPort.PortRectangle, inPort.PortRectangle);
                        mComponent.ComponentCanvas.Children.Add(inPort.PortRectangle);
                        Canvas.SetLeft(inPort.PortRectangle, Canvas.GetLeft(compInPort.PortRectangle));
                        Canvas.SetTop(inPort.PortRectangle, Canvas.GetTop(compInPort.PortRectangle));

                        // copy the properties of the inports
                        if (compInPort.properties != null) {
                            foreach (Asterics.ACS2.propertyType portProperty in compInPort.properties) {
                                propertyType property = new propertyType();
                                property.name = portProperty.name;
                                property.DataType = portProperty.type;
                                property.Description = portProperty.description;
                                property.value = portProperty.value;
                                if (portProperty.combobox != null) {
                                    property.ComboBoxStrings = portProperty.combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                }
                                inPort.PropertyArrayList.Add(property);
                            }
                            inPort.properties = new propertyType[inPort.PropertyArrayList.Count];
                            inPort.PropertyArrayList.CopyTo(inPort.properties);
                        }

                        // copy the reference to another port (only available, if it is a group element)
                        if (compInPort.RefPort != null) {
                            inPort.refs = compInPort.RefPort;
                        }

                        mComponent.PortsList.Add(inPort.portTypeID,inPort);

                    // copy the outports
                    } else if (o is Asterics.ACS2.outputPortType) {
                        Asterics.ACS2.outputPortType compOutPort = (Asterics.ACS2.outputPortType)o;
                        outputPortType outPort = new outputPortType();
                        outPort.portTypeID = compOutPort.id;
                        outPort.ComponentId = id;
                        outPort.Description = compOutPort.description;
                        outPort.PortDataType = compOutPort.dataType;
                        outPort.ComponentTypeId = component.id;

                        outPort.PortLabel.Text = compOutPort.id;
                        mComponent.componentCanvas.Children.Add(outPort.PortLabel);
                        Canvas.SetLeft(outPort.PortLabel, Canvas.GetLeft(compOutPort.PortRectangle) - ACS.LayoutConstants.OUTPORTLABELWIDTH - 2);
                        Canvas.SetTop(outPort.PortLabel, Canvas.GetTop(compOutPort.PortRectangle) - 2);

                        mComponent.CopyRectangel(compOutPort.PortRectangle, outPort.PortRectangle);
                        mComponent.ComponentCanvas.Children.Add(outPort.PortRectangle);
                        Canvas.SetLeft(outPort.PortRectangle, Canvas.GetLeft(compOutPort.PortRectangle));
                        Canvas.SetTop(outPort.PortRectangle, Canvas.GetTop(compOutPort.PortRectangle));

                        // copy the properties of the outports
                        if (compOutPort.properties != null) {
                            foreach (Asterics.ACS2.propertyType portProperty in compOutPort.properties) {
                                propertyType property = new propertyType();
                                property.name = portProperty.name;
                                property.DataType = portProperty.type;
                                property.Description = portProperty.description;
                                property.value = portProperty.value;
                                if (portProperty.combobox != null) {
                                    property.ComboBoxStrings = portProperty.combobox.Split(new String[] { "//" }, StringSplitOptions.None);
                                }
                                outPort.PropertyArrayList.Add(property);
                            }
                            outPort.properties = new propertyType[outPort.PropertyArrayList.Count];
                            outPort.PropertyArrayList.CopyTo(outPort.properties);
                        }

                        // copy the reference to another port (only available, if it is a group element)
                        if (compOutPort.RefPort != null) {
                            outPort.refs = compOutPort.RefPort;
                        }

                        mComponent.PortsList.Add(outPort.portTypeID,outPort);
                    }

                }
                mComponent.ports = new object[mComponent.PortsList.Count];
                mComponent.PortsList.Values.CopyTo(mComponent.ports, 0);
            }

            // Searching for event listeners and event triggers and saving them in arrays
            if ((component.events != null)&&(component.events != null)) {
                foreach (object eventO in component.events) {
                    if (eventO is ACS2.eventsTypeEventListenerPortType) {
                        ACS2.eventsTypeEventListenerPortType compEl = (ACS2.eventsTypeEventListenerPortType)eventO;
                        EventListenerPort el = new EventListenerPort();
                        el.EventListenerId = compEl.id;
                        el.EventDescription = compEl.description;
                        el.ComponentId = id;
                        mComponent.EventListenerList.Add(el);
                    } else if (eventO is ACS2.eventsTypeEventTriggererPortType) {
                        ACS2.eventsTypeEventTriggererPortType compEl = (ACS2.eventsTypeEventTriggererPortType)eventO;
                        EventTriggerPort et = new EventTriggerPort();
                        et.EventTriggerId = compEl.id;
                        et.EventDescription = compEl.description;
                        et.ComponentId = id;
                        mComponent.EventTriggerList.Add(et);
                    }
                }
            }

            // Adapt the size of MainRectangle, if more then MAINRECTANGLENUMBEROFPORTS are in a component
            int numInPorts = 0;
            int numOutPorts = 0;
            foreach (object o in mComponent.PortsList.Values) {
                if (o is inputPortType) {
                    numInPorts++;
                } else {
                    numOutPorts++;
                }
            }
            if (numOutPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) {
                mComponent.MainRectangle.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE );
                mComponent.ComponentCanvas.Height += (numOutPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.OUTPORTDISTANCE);
            } else if (numInPorts > ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) {
                mComponent.MainRectangle.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE);
                mComponent.ComponentCanvas.Height += (numInPorts - ACS.LayoutConstants.MAINRECTANGLENUMBEROFPORTS) * (ACS.LayoutConstants.INPORTDISTANCE);
            }

            // Drawing the event listener and event trigger port, if events are available
            if (mComponent.EventListenerList.Count > 0) {
                EventListenerPolygon inputEventPolygon = new EventListenerPolygon();
                mComponent.EventListenerPolygon = inputEventPolygon;
                mComponent.componentCanvas.Children.Add(inputEventPolygon.InputEventPortCanvas);
                Canvas.SetLeft(inputEventPolygon.InputEventPortCanvas, ACS.LayoutConstants.EVENTINPORTCANVASOFFSETX);
                //Canvas.SetTop(inputEventPolygon.InputEventPortCanvas, ACS.LayoutConstants.EVENTINPORTCANVASOFFSETY);
                Canvas.SetTop(inputEventPolygon.InputEventPortCanvas, mComponent.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10);
            }
            if (mComponent.EventTriggerList.Count > 0) {
                EventTriggerPolygon outputEventPolygon = new EventTriggerPolygon();
                mComponent.EventTriggerPolygon = outputEventPolygon;
                mComponent.componentCanvas.Children.Add(outputEventPolygon.OutputEventPortCanvas);
                Canvas.SetLeft(outputEventPolygon.OutputEventPortCanvas, ACS.LayoutConstants.EVENTOUTPORTCANVASOFFSETX);
                //Canvas.SetTop(outputEventPolygon.OutputEventPortCanvas, ACS.LayoutConstants.EVENTOUTPORTCANVASOFFSETY);
                Canvas.SetTop(outputEventPolygon.OutputEventPortCanvas, mComponent.MainRectangle.Height + ACS.LayoutConstants.MAINRECTANGLEOFFSETY - 10);
            }

            return mComponent;
        }