Esempio n. 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);
            }
        }
        // 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;
        }