/// <summary> /// Create an ARE GUI element, needed for older models, to update them to the current version /// </summary> /// <param name="mw">The MainWindow</param> /// <param name="deployModel">Deployment Motel, containing all components of the model</param> /// <param name="componentList">List with all available components (plug-ins)</param> public static void UpdateMissingGUI(MainWindow mw, model deployModel, Hashtable componentList) { foreach (componentType comp in deployModel.components) { Asterics.ACS2.componentTypesComponentType compType = (Asterics.ACS2.componentTypesComponentType)componentList[comp.type_id]; if (comp.gui == null && compType != null && compType.gui != null) { comp.gui = new guiType(); comp.gui.height = compType.gui.height; comp.gui.width = compType.gui.width; comp.gui.posX = "0"; comp.gui.posY = "0"; mw.AddGUIComponent(comp); mw.ModelHasBeenEdited = true; } } }
/// <summary> /// Create an ARE GUI element, needed for older models, to update them to the current version /// </summary> /// <param name="mw">The MainWindow</param> /// <param name="deployModel">Deployment Motel, containing all components of the model</param> public static void UpdateToCurrentVersion(MainWindow mw, model deployModel) { if (deployModel.version != model.VERSION) { if (deployModel.version == "20120301" || deployModel.version == "20120509" || deployModel.version == "20111104") { // From version 20120301 to 20120509, only minor changes without any change in the older deployment files are made // 20111104 should also work, needs further tests!!! //Update GUI components resolution from, 1/100 to 1/10000 foreach (componentType comp in deployModel.components) { if (comp.gui != null) { comp.gui.height = String.Concat(comp.gui.height, "00"); comp.gui.width = String.Concat(comp.gui.width, "00"); comp.gui.posX = String.Concat(comp.gui.posX, "00"); comp.gui.posY = String.Concat(comp.gui.posY, "00"); } } // Add the AREGUIWindow deployModel.modelGUI = new modelGUIType(); deployModel.modelGUI.AREGUIWindow = new guiType(); deployModel.modelGUI.AREGUIWindow.height = "5000"; deployModel.modelGUI.AREGUIWindow.width = "9000"; deployModel.modelGUI.AREGUIWindow.posX = "0"; deployModel.modelGUI.AREGUIWindow.posY = "0"; deployModel.modelGUI.AlwaysOnTop = false; deployModel.modelGUI.Decoration = true; deployModel.modelGUI.Fullscreen = false; deployModel.modelGUI.ShopControlPanel = true; deployModel.modelGUI.ToSystemTray = false; MessageBox.Show(Properties.Resources.UpdateModelVersionGUIInfoFormat(deployModel.version, model.VERSION), Properties.Resources.UpdateModelVersionGUIHeader, MessageBoxButton.OK, MessageBoxImage.Information); deployModel.version = model.VERSION; mw.ModelHasBeenEdited = true; } } }
/// <summary> /// Pastes all elements of a temporary copy list to the model /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Paste_Click(object sender, RoutedEventArgs e) { model tmpModel = CopyModel(copyModel); PasteCopiedModel(copyModel, false,true); copyModel = tmpModel; }
/// <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(); }
/// <summary> /// Activating (setting to the run modus) a stored model of the ARE storage and downloading it to the ACS /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ActivateStoredModel_Click(object sender, RoutedEventArgs e) { List<string> storedModels = null; try { storedModels = asapiClient.listAllStoredModels(); } catch (Exception ex) { MessageBox.Show(Properties.Resources.LoadStoredModelsListError, Properties.Resources.LoadStoredModelsListErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); traceSource.TraceEvent(TraceEventType.Error, 3, ex.Message); } if (storedModels != null) { storageDialog = new StorageDialog(); foreach (string s in storedModels) { if (s.EndsWith(".acs")) { storageDialog.filenameListbox.Items.Add(s); } } storageDialog.filenameListbox.SelectionChanged += filenameListbox_SelectionChanged; storageDialog.Title = Properties.Resources.ActivateStoredModelButton; storageDialog.Owner = this; storageDialog.filenameTextbox.IsEnabled = false; storageDialog.ShowDialog(); if (storageDialog.filenameTextbox.Text != null && storageDialog.filenameTextbox.Text != "") { try { string storedModel = asapiClient.getModelFromFile(storageDialog.filenameTextbox.Text); if (storedModel != null && storedModel != "") { XmlSerializer ser2 = new XmlSerializer(typeof(model)); StringReader sr2 = new StringReader(storedModel); deploymentModel = (model)ser2.Deserialize(sr2); sr2.Close(); // Validate, if downlaoded schema is valid // Should be valid, is double-check XmlSerializer x = new XmlSerializer(deploymentModel.GetType()); // firstly, write the data to a tempfile and use this temp file, checking valitity against schema FileStream str = new FileStream(System.IO.Path.GetTempPath() + ini.IniReadValue("model", "tempfile"), FileMode.Create); x.Serialize(str, deploymentModel); str.Close(); // check, if model is valid against the deployment_model schema String xmlError; XmlValidation xv = new XmlValidation(); xmlError = xv.validateXml(System.IO.Path.GetTempPath() + ini.IniReadValue("model", "tempfile"), ini.IniReadValue("model", "deployment_schema")); // if valid, xml-file will be written if (xmlError.Equals("")) { LoadComponentsCommand(); SetSaveFile(storageDialog.filenameTextbox.Text); asapiClient.DeployFile(storageDialog.filenameTextbox.Text); areStatus.Status = AREStatus.ConnectionStatus.Synchronised; asapiClient.RunModel(); areStatus.Status = AREStatus.ConnectionStatus.Running; } else { deploymentModel = null; MessageBox.Show(Properties.Resources.ReadXmlErrorText, Properties.Resources.ReadXmlErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); traceSource.TraceEvent(TraceEventType.Error, 3, xmlError); } } } catch (Exception ex) { MessageBox.Show(Properties.Resources.ActivateStoredModelError, Properties.Resources.ActivateStoredModelErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); traceSource.TraceEvent(TraceEventType.Error, 3, ex.Message); } } } }
/// <summary> /// Load a deployment model to the drawing board /// </summary> private void OpenLocalCommand(String inputFile) { if (inputFile == null) { System.Windows.Forms.OpenFileDialog openLocalXML = new System.Windows.Forms.OpenFileDialog(); //openLocalXML.InitialDirectory = "c:\\temp\\" ; openLocalXML.Filter = "AsTeRICS-Files (*.acs)|*.acs|All files (*.*)|*.*"; openLocalXML.FilterIndex = 1; openLocalXML.RestoreDirectory = true; if (openLocalXML.ShowDialog() == System.Windows.Forms.DialogResult.OK) { inputFile = openLocalXML.FileName; } } if (inputFile != null) { // check if the file is valid against the deployment_schema String xmlError; XmlValidation xv = new XmlValidation(); // old, working code: xmlError = xv.validateXml(inputFile, ini.IniReadValue("model", "deployment_schema")); if (!File.Exists(ini.IniReadValue("model", "deployment_schema"))) { xmlError = xv.validateXml(inputFile, AppDomain.CurrentDomain.BaseDirectory + ini.IniReadValue("model", "deployment_schema")); } else { xmlError = xv.validateXml(inputFile, ini.IniReadValue("model", "deployment_schema")); } if (xmlError.Equals("")) { XmlSerializer ser2 = new XmlSerializer(typeof(model)); StreamReader sr2 = new StreamReader(inputFile); deploymentModel = (model)ser2.Deserialize(sr2); sr2.Close(); ResetPropertyDock(); ModelVersionUpdater.UpdateMissingGUI(this, deploymentModel, componentList); ModelVersionUpdater.UpdateToCurrentVersion(this, deploymentModel); LoadComponentsCommand(); // set the saveFile in order to still know the filename when trying to save the schema again SetSaveFile(inputFile); if (areStatus.Status == AREStatus.ConnectionStatus.Synchronised) { areStatus.Status = AREStatus.ConnectionStatus.Connected; } else if ((areStatus.Status == AREStatus.ConnectionStatus.Running) || (areStatus.Status == AREStatus.ConnectionStatus.Pause)) { areStatus.Status = AREStatus.ConnectionStatus.Synchronised; areStatus.Status = AREStatus.ConnectionStatus.Connected; } } else { MessageBox.Show(Properties.Resources.ReadXmlErrorText, Properties.Resources.ReadXmlErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); traceSource.TraceEvent(TraceEventType.Error, 3, xmlError); SetSaveFile(null); MessageBoxResult result = MessageBox.Show(Properties.Resources.UpdateModelVersionQuestion, Properties.Resources.UpdateModelVersionHeader, MessageBoxButton.YesNo, MessageBoxImage.Question); if (result.Equals(MessageBoxResult.Yes)) { ModelVersionUpdater.ParseErrorUpdate(xmlError, inputFile); } } AddToRecentList(inputFile); } }
// Read the Application arguments - used after a .acs file has been double clicked to start ACS /// <summary> /// Function called, when the MainWindow will be loaded. Used to read the application arguments (filename) and load the file by using LoadComponentsCommand() /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void MainWindow_Loaded(object sender, RoutedEventArgs e) { if (Application.Current.Properties["ArbitraryArgName"] != null) { string fname = Application.Current.Properties["ArbitraryArgName"].ToString(); // check if the file is valid against the deployment_schema String xmlError; XmlValidation xv = new XmlValidation(); string dsFile = ini.IniReadValue("model", "deployment_schema"); if (!File.Exists(dsFile)) { dsFile = AppDomain.CurrentDomain.BaseDirectory + ini.IniReadValue("model", "deployment_schema"); } xmlError = xv.validateXml(fname, dsFile); if (xmlError.Equals("")) { XmlSerializer ser2 = new XmlSerializer(typeof(model)); StreamReader sr2 = new StreamReader(fname); deploymentModel = (model)ser2.Deserialize(sr2); sr2.Close(); ResetPropertyDock(); ModelVersionUpdater.UpdateMissingGUI(this, deploymentModel, componentList); ModelVersionUpdater.UpdateToCurrentVersion(this, deploymentModel); LoadComponentsCommand(); // set the saveFile in order to still know the filename when trying to save the schema again SetSaveFile(fname); AddToRecentList(fname); } else { MessageBox.Show(Properties.Resources.ReadXmlErrorText, Properties.Resources.ReadXmlErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); traceSource.TraceEvent(TraceEventType.Error, 3, "xmlError Msg:" + xmlError); } } TimerCallback tcbFocus = this.DoFocusTimer; statusTimer = new Timer(tcbFocus, dockableComponentProperties, 300, Timeout.Infinite); }
/// <summary> /// Downlaod a deployment schema from the ARE to the ACS /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DownloadSchema_Click(object sender, RoutedEventArgs e) { bool doOverride = true; if ((undoStack.Count > 0 || redoStack.Count > 0) && (showOverrideLocalModelQuestion)) { CustomMessageBox messageBox = new CustomMessageBox(Properties.Resources.OverrideACSDialog, Properties.Resources.OverrideDialogHeader, CustomMessageBox.messageType.Warning, CustomMessageBox.resultType.YesNo); messageBox.Owner = this; messageBox.showCheckbox.IsChecked = showOverrideLocalModelQuestion; messageBox.ShowDialog(); showOverrideLocalModelQuestion = (bool)messageBox.showCheckbox.IsChecked; if (showOverrideLocalModelQuestion) { ini.IniWriteValue("Options", "showOverrideLocalModelQuestion", "true"); } else { ini.IniWriteValue("Options", "showOverrideLocalModelQuestion", "false"); } doOverride = (bool)messageBox.DialogResult; } if (doOverride) { try { String xmlModel = asapiClient.GetModel(); if (xmlModel != null && xmlModel != "") { XmlSerializer ser2 = new XmlSerializer(typeof(model)); StringReader sr2 = new StringReader(xmlModel); deploymentModel = (model)ser2.Deserialize(sr2); sr2.Close(); // Validate, if downlaoded schema is valid // Should be valid, is double-check XmlSerializer x = new XmlSerializer(deploymentModel.GetType()); // firstly, write the data to a tempfile and use this temp file, checking valitity against schema FileStream str = new FileStream(System.IO.Path.GetTempPath() + ini.IniReadValue("model", "tempfile"), FileMode.Create); x.Serialize(str, deploymentModel); str.Close(); // check, if model is valid against the deployment_model schema String xmlError; XmlValidation xv = new XmlValidation(); xmlError = xv.validateXml(System.IO.Path.GetTempPath() + ini.IniReadValue("model", "tempfile"), ini.IniReadValue("model", "deployment_schema")); // if valid, xml-file will be written if (xmlError.Equals("")) { ResetPropertyDock(); ModelVersionUpdater.UpdateMissingGUI(this, deploymentModel, componentList); ModelVersionUpdater.UpdateToCurrentVersion(this, deploymentModel); LoadComponentsCommand(); areStatus.Status = AREStatus.ConnectionStatus.Synchronised; } else { MessageBox.Show(Properties.Resources.ReadXmlErrorText, Properties.Resources.ReadXmlErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); traceSource.TraceEvent(TraceEventType.Error, 3, xmlError); } } else { CleanACS(); } } catch (Exception ex) { MessageBox.Show(Properties.Resources.SynchronisationDownloadError, Properties.Resources.SynchronisationDownloadErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); traceSource.TraceEvent(TraceEventType.Error, 3, ex.Message); CleanACS(); CheckASAPIConnection(); } SetSaveFile(null); } }
/// <summary> /// Download a model from ARE to the canvas and check, if the model is valid /// </summary> private void DownloadAndCheckModel() { try { String xmlModel = asapiClient.GetModel(); if (xmlModel != null && xmlModel != "") { XmlSerializer ser2 = new XmlSerializer(typeof(model)); StringReader sr2 = new StringReader(xmlModel); deploymentModel = (model)ser2.Deserialize(sr2); sr2.Close(); // Validate, if downlaoded schema is valid // Should be valid, is double-check XmlSerializer x = new XmlSerializer(deploymentModel.GetType()); // firstly, write the data to a tempfile and use this temp file, checking valitity against schema FileStream str = new FileStream(System.IO.Path.GetTempPath() + ini.IniReadValue("model", "tempfile"), FileMode.Create); x.Serialize(str, deploymentModel); str.Close(); // check, if model is valid against the deployment_model schema String xmlError; XmlValidation xv = new XmlValidation(); xmlError = xv.validateXml(System.IO.Path.GetTempPath() + ini.IniReadValue("model", "tempfile"), ini.IniReadValue("model", "deployment_schema")); // if valid, xml-file will be written if (xmlError.Equals("")) { ResetPropertyDock(); LoadComponentsCommand(); areStatus.Status = AREStatus.ConnectionStatus.Synchronised; } else { MessageBox.Show(Properties.Resources.ReadXmlErrorText, Properties.Resources.ReadXmlErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); traceSource.TraceEvent(TraceEventType.Error, 3, xmlError); } } else { CleanACS(); } } catch (Exception ex) { MessageBox.Show(Properties.Resources.SynchronisationDownloadError, Properties.Resources.SynchronisationDownloadErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); traceSource.TraceEvent(TraceEventType.Error, 3, ex.Message); CleanACS(); } SetSaveFile(null); }
/// <summary> /// Copy selected Items into the copyModel /// </summary> private void CopySelectedCommand() { copyOffsetMulti = 1; copyModel = new model(); copyModel.modelName = "copy"; // insert all selected components to the model LinkedList<componentType> t = new LinkedList<componentType>(); for (int i = 0; i < selectedComponentList.Count; i++) { componentType ct = selectedComponentList.ElementAt(i); if (!((Asterics.ACS2.componentTypesComponentType)componentList[ct.type_id]).singleton) { t.AddLast(ct); } else { //if (ct.ComponentCanvas.Visibility == System.Windows.Visibility.Visible) MessageBox.Show(Properties.Resources.SingletonErrorHeaderFormat(ct.type_id), Properties.Resources.SingletonErrorDialogHeader, MessageBoxButton.OK, MessageBoxImage.Warning); } } copyModel.components = t.ToArray(); //get all selected channels where the source and target components //are selected LinkedList<channel> copyChannels = new LinkedList<channel>(); foreach (channel c in selectedChannelList) { bool sourceFound, targetFound; sourceFound = targetFound = false; foreach (componentType mc in copyModel.components) { if (mc.ComponentType == ACS2.componentTypeDataTypes.group) continue; if (mc.id == c.source.component.id) sourceFound = true; if (mc.id == c.target.component.id) targetFound = true; if (sourceFound && targetFound) { break; } } if (sourceFound && targetFound) copyChannels.AddLast(c); } copyModel.channels = new channel[copyChannels.Count]; for (int i = 0; i < copyChannels.Count; i++) copyModel.channels[i] = copyChannels.ElementAt(i); // get all selected Eventchannels LinkedList<eventChannel> selEventChannels = new LinkedList<eventChannel>(); foreach (eventChannelLine ecl in selectedEventChannelList) { //bool eventfound = false; foreach (eventChannel ech in eventChannelList) { if (ecl.ListenerComponentId == ech.targets.target.component.id && ecl.TriggerComponentId == ech.sources.source.component.id) { selEventChannels.AddLast(ech); } } } LinkedList<eventChannel> copyEventChannels = new LinkedList<eventChannel>(); // get all selected eventchannels with a selected source and target foreach (eventChannel ech in selEventChannels) { bool sourceFound, targetFound; sourceFound = targetFound = false; foreach (componentType mc in copyModel.components) { if (mc.id == ech.sources.source.component.id) { if (mc.ComponentType != ACS2.componentTypeDataTypes.group) sourceFound = true; } else if (mc.id == ech.targets.target.component.id) { if (mc.ComponentType != ACS2.componentTypeDataTypes.group) targetFound = true; } if (sourceFound && targetFound) break; } if (sourceFound && targetFound) copyEventChannels.AddLast(ech); } /* * Check all groups if they have docked EventListeners and EventTriggers * and add dummy lines to the model to retain these eventports in the pasted * model * */ copyGroupEventChannels = new ArrayList(); foreach (componentType ct in copyModel.components) { if (ct.ComponentType != ACS2.componentTypeDataTypes.group) continue; ArrayList echannels = new ArrayList(); foreach (EventListenerPort elp in ct.EventListenerList) { componentType target = null; foreach (componentType tmpct in copyModel.components) { if (elp.EventListenerId.StartsWith(tmpct.id)) { if (target == null) { target = tmpct; } else if (tmpct.id.Length > target.id.Length) target = tmpct; } } if (target == null) continue; eventChannel tmpEC = new eventChannel(); tmpEC.sources.source.component.id = copyDummyName; tmpEC.sources.source.eventPort.id = "eventtrigger"; tmpEC.targets.target.component.id = target.id; tmpEC.targets.target.eventPort.id = elp.EventListenerId.Substring(target.id.Length+1); tmpEC.id = target.id + "_" + tmpEC.sources.source.eventPort.id + "_" + tmpEC.targets.target.eventPort.id; tmpEC.GroupOriginalSource = null; tmpEC.GroupOriginalTarget = null; bool found = false; foreach (eventChannel ech in copyEventChannels) { if (ech.sources.source.component.id.Equals(copyDummyName) && ech.targets.target.component.id.Equals(target.id)) { found = true; break; } } if (!found) echannels.Add(tmpEC); } foreach (EventTriggerPort etp in ct.EventTriggerList) { componentType source = null; foreach (componentType tmpct in copyModel.components) { if (etp.EventTriggerId.StartsWith(tmpct.id)) { if (source == null) { source = tmpct; } else if (tmpct.id.Length > source.id.Length) source = tmpct; } } if (source == null) continue; eventChannel tmpEC = new eventChannel(); tmpEC.sources.source.component.id = source.id; tmpEC.sources.source.eventPort.id = etp.EventTriggerId.Substring(source.id.Length + 1); tmpEC.targets.target.component.id = copyDummyName; tmpEC.targets.target.eventPort.id = "eventlistener"; tmpEC.id = source.id + "_" + tmpEC.sources.source.eventPort.id + "_" + tmpEC.targets.target.eventPort.id; tmpEC.GroupOriginalSource = null; tmpEC.GroupOriginalTarget = null; bool found = false; foreach (eventChannel ech in copyEventChannels) { if (ech.sources.source.component.id.Equals(copyDummyName) && ech.targets.target.component.id.Equals(source.id)) { found = true; break; } } if (!found) echannels.Add(tmpEC); } copyGroupEventChannels.Add(echannels); } copyModel.eventChannels = copyEventChannels.ToArray(); copyModel = CopyModel(copyModel); }
/// <summary> /// Copy Model /// </summary> private model CopyModel(model m) { if (m == null) return null; XmlSerializer x = new XmlSerializer(m.GetType()); MemoryStream ms = new MemoryStream(); x.Serialize(ms, m); ms.Seek(0, SeekOrigin.Begin); StreamReader sr = new StreamReader(ms); model copyModel = (model)x.Deserialize(ms); sr.Close(); ms.Close(); // copy attributes, not being copies because of [XMLIgnoreAttirubte] foreach (componentType component in copyModel.components) { if (componentList.ContainsKey(component.type_id)) component.ComponentType = ((Asterics.ACS2.componentTypesComponentType)componentList[component.type_id]).type.Value; } return copyModel; }
/// <summary> /// Reset the ACS. All lists, arrays, canvas, propertydock, etc. will be cleared /// </summary> private void CleanACS() { // reset component list, channel list and canvas deploymentComponentList.Clear(); deploymentChannelList.Clear(); eventChannelList.Clear(); eventChannelLinesList.Clear(); canvas.Children.Clear(); groupsList.Clear(); // initialize the model for drawing a new schema deploymentModel = new model(); deploymentModel.channels = new channel[1]; deploymentModel.eventChannels = new eventChannel[1]; deploymentModel.components = new componentType[1]; // clear the undo/redo stack undoStack.Clear(); redoStack.Clear(); ResetPropertyDock(); statusList.Clear(); // clean the GUI editor NewAREGUIWindow(); CleanGUICanvas(); if (areStatus.Status == AREStatus.ConnectionStatus.Synchronised) { areStatus.Status = AREStatus.ConnectionStatus.Connected; } }
/// <summary> /// Constructor /// </summary> public MainWindow() { // make an ACS folder in the AppData folder // uncomment for the final version // Also, change useAppDateFolder in asterics.ini !!! //if ((!Directory.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\")) || // (!Directory.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\")) || // (!Directory.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\groups\\"))) { // Directory.CreateDirectory(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\groups\\"); //} //if (!Directory.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\componentcollections\\")) { // Directory.CreateDirectory(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\componentcollections\\"); //} // uncomment for local use if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\groups\\")) { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\groups\\"); } if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\componentcollections\\")) { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\componentcollections\\"); } // loading the asterics.ini file, containing some basic settings // uncomment for the final version /*if (File.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)+"\\AsTeRICS\\ACS\\asterics.ini")) { ini = new IniFile(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\asterics.ini"); } else */ if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "asterics.ini")) { ini = new IniFile(AppDomain.CurrentDomain.BaseDirectory + "asterics.ini"); } else { MessageBox.Show(Properties.Resources.IniFileNotFoundText, Properties.Resources.IniFileNotFoundHeader, MessageBoxButton.OK, MessageBoxImage.Error); Application.Current.Shutdown(); } // Setting the localisation info, if no value is set, the system value will be used. // More info about the used localisation technique can be found at: // http://www.codeproject.com/KB/WPF/WPFUsingLocbaml.aspx // Localisation should be done before initializing the components ACS.Properties.Resources.Culture = new System.Globalization.CultureInfo(ini.IniReadValue("Options", "language")); //ACS.Properties.Resources.Culture = new System.Globalization.CultureInfo("de-AT"); // Read local language settings: //ACS.Properties.Resources.Culture = System.Threading.Thread.CurrentThread.CurrentCulture; InitializeComponent(); // Remove the original default trace listener and add a new one (for logging exceptions) traceListener = new FileLogTraceListener(); if (ini.IniReadValue("Options", "useAppDataFolder").Equals("true")) { traceListener.BaseFileName = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\ACS"; } else { traceListener.BaseFileName = "ACS"; } traceListener.TraceOutputOptions = TraceOptions.DateTime | TraceOptions.ProcessId | TraceOptions.Callstack; traceListener.LogFileCreationSchedule = LogFileCreationScheduleOption.None; traceListener.CustomLocation = "."; traceListener.AutoFlush = true; traceListener.Append = false; traceListener.Delimiter = "\r\n"; traceListener.Filter = new EventTypeFilter(SourceLevels.Error); traceSource = new TraceSource("mySource"); sourceSwitch = new SourceSwitch("SourceSwitch", "Verbose"); traceSource.Switch = sourceSwitch; traceSource.Listeners.Add(traceListener); this.Closing += MainWindow_Closing; // Adding mouse listeners to the drawing canvas canvas.MouseLeftButtonDown += OnLeftDown; canvas.MouseLeftButtonUp += OnLeftUp; canvas.MouseMove += OnMouseMove; // Context menu for the components componentContextMenu = new ContextMenu(); // Channel related context menu entries componentContextMenuItemAddChannel = new MenuItem(); componentContextMenuItemAddChannel.Header = Properties.Resources.ComponentContextMenuAddChannel; componentContextMenu.Items.Add(componentContextMenuItemAddChannel); componentContextMenuItemConnectChannel = new MenuItem(); componentContextMenuItemConnectChannel.Header = Properties.Resources.ComponentContextMenuConnectChannel; // set inactive componentContextMenuItemAddChannel.IsEnabled = false; // making channels with ontext menu only when context menu is called by keyboard componentContextMenuItemConnectChannel.IsEnabled = false; componentContextMenu.Items.Add(componentContextMenuItemConnectChannel); componentContextMenuItemDropChannel = new MenuItem(); componentContextMenuItemDropChannel.Header = Properties.Resources.ComponentContextMenuDropChannel; componentContextMenuItemDropChannel.IsEnabled = false; componentContextMenu.Items.Add(componentContextMenuItemDropChannel); componentContextMenuItemDropChannel.Click += ComponentContextMenuItemDrop_Click; componentContextMenu.Items.Add(new Separator()); // Event Channel related context menu entries componentContextMenuItemAddEventChannel = new MenuItem(); componentContextMenuItemAddEventChannel.Header = Properties.Resources.ComponentContextMenuAddEventChannel; componentContextMenuItemAddEventChannel.Click += ComponentContextMenuItemAddEvent_Click; componentContextMenu.Items.Add(componentContextMenuItemAddEventChannel); componentContextMenuItemConnectEventChannel = new MenuItem(); componentContextMenuItemConnectEventChannel.Header = Properties.Resources.ComponentContextMenuConnectEventChannel; componentContextMenuItemConnectEventChannel.Click += ComponentContextMenuItemConnectEvent_Click; // set inactive componentContextMenuItemConnectEventChannel.IsEnabled = false; componentContextMenuItemAddEventChannel.IsEnabled = false; // making event channels with ontext menu only when context menu is called by keyboard componentContextMenu.Items.Add(componentContextMenuItemConnectEventChannel); componentContextMenuItemDropEventChannel = new MenuItem(); componentContextMenuItemDropEventChannel.Header = Properties.Resources.ComponentContextMenuDropEventChannel; componentContextMenuItemDropEventChannel.IsEnabled = false; componentContextMenu.Items.Add(componentContextMenuItemDropEventChannel); componentContextMenuItemDropEventChannel.Click += ComponentContextMenuItemDropEvent_Click; componentContextMenu.Items.Add(new Separator()); MenuItem componentContextMenuItemMove = new MenuItem(); componentContextMenuItemMove.Header = Properties.Resources.ComponentContextMenuMoveComponent; componentContextMenuItemMove.Click += ComponentContextMenuItemMove_Click; componentContextMenu.Items.Add(componentContextMenuItemMove); componentContextMenuItemDelete = new MenuItem(); componentContextMenuItemDelete.Header = Properties.Resources.ComponentContextMenuDeleteComponent; componentContextMenuItemDelete.Click += ComponentContextItemDelete_Click; componentContextMenu.Items.Add(componentContextMenuItemDelete); MenuItem componentContextItemProperties = new MenuItem(); componentContextItemProperties.Header = Properties.Resources.ComponentContextMenuComponentProperties; componentContextItemProperties.Click += ComponentContextItemProperties_Click; componentContextMenu.Items.Add(componentContextItemProperties); MenuItem componentContextItemStatus = new MenuItem(); componentContextItemStatus.Header = Properties.Resources.ComponentContextMenuComponentStatus; componentContextItemStatus.Click += ComponentContextItemStatus_Click; componentContextMenu.Items.Add(componentContextItemStatus); componentContextMenuItemSolveConflict = new MenuItem(); componentContextMenuItemSolveConflict.Header = Properties.Resources.ComponentContextMenuRemoveConflict; componentContextMenuItemSolveConflict.Click += ComponentContextItemSolveConflict_Click; componentContextMenuItemSolveConflict.IsEnabled = false; componentContextMenu.Items.Add(componentContextMenuItemSolveConflict); componentContextMenu.Opened += ComponentContextMenu_Opened; // Context menu for the channels channelContextMenu = new ContextMenu(); MenuItem channelContextMenuItemDelete = new MenuItem(); channelContextMenuItemDelete.Header = Properties.Resources.ChannelContextMenuDeleteChannel; channelContextMenuItemDelete.Click += ChannelContextItemDelete_Click; channelContextMenu.Items.Add(channelContextMenuItemDelete); channelContextMenu.Opened += ChannelContextMenu_Opened; // Context menu for the event channels eventChannelContextMenu = new ContextMenu(); MenuItem eventChannelContextMenuItemDelete = new MenuItem(); eventChannelContextMenuItemDelete.Header = Properties.Resources.EventChannelContextMenuDeleteChannel; eventChannelContextMenuItemDelete.Click += EventChannelContextItemDelete_Click; eventChannelContextMenu.Items.Add(eventChannelContextMenuItemDelete); MenuItem eventChannelContextMenuItemEvents = new MenuItem(); eventChannelContextMenuItemEvents.Header = Properties.Resources.EventChannelContextMenuSetEvents; eventChannelContextMenuItemEvents.Click += EventChannelContextItemSetEvents_Click; eventChannelContextMenu.Items.Add(eventChannelContextMenuItemEvents); eventChannelContextMenu.Opened += EventChannelContextMenu_Opened; // load all components to the ribbon menu LoadBundle(null); // initialize the model for drawing a new schema deploymentModel = new ACS.model(); deploymentModel.channels = new channel[1]; deploymentModel.eventChannels = new eventChannel[0]; deploymentModel.components = new componentType[1]; eventChannelLinesList = new ArrayList(); eventChannelList = new ArrayList(); NewAREGUIWindow(); DateTime dt = DateTime.UtcNow; deploymentModel.modelName = dt.ToShortDateString() + "_" + dt.Hour + dt.Minute; // Set the keyboard navigation KeyboardNavigation.SetTabIndex(canvas, 1); KeyboardNavigation.SetTabNavigation(canvas, KeyboardNavigationMode.Cycle); asapiNet = new AsapiNetMain(); redoStack = new AstericsStack<CommandObject>(); undoStack = new AstericsStack<CommandObject>(); undoStack.PropertyChanged += undoStack_PropertyChanged; redoStack.PropertyChanged += redoStack_PropertyChanged; // Creating the AvalonDock (split window and properties on the right hand side) BuildDockingLayout(); // init dummy element pasteDummyName += (char) 86; pasteDummyName += (char)101; pasteDummyName += (char)105; pasteDummyName += (char)103; pasteDummyName += (char)108; pasteDummyName += (char)49; pasteDummyName += (char)50; pasteDummyName += (char)51; pasteDummyName += (char)53; pasteDummyName += (char)56; // read options from ini-file String tmp = ini.IniReadValue("Options", "showNamingDialogOnComponentInsert"); if (tmp.Equals("true")) { showNamingDialogOnComponentInsert = true; } else { showNamingDialogOnComponentInsert = false; } tmp = ini.IniReadValue("Options", "showHostPortDialogOnConnect"); if (tmp.Equals("true")) { showHostPortDialogOnConnect = true; } else { showHostPortDialogOnConnect = false; } tmp = ini.IniReadValue("Options", "showEventChannelConnectMessage"); if (tmp.Equals("true")) { showEventChannelConnectMessage = true; } else { showEventChannelConnectMessage = false; } tmp = ini.IniReadValue("Options", "showAREConnectedMessage"); if (tmp.Equals("true")) { showAREConnectedMessage = true; } else { showAREConnectedMessage = false; } tmp = ini.IniReadValue("Options", "showOverrideModelQuestion"); if (tmp.Equals("true")) { showOverrideModelQuestion = true; } else { showOverrideModelQuestion = false; } tmp = ini.IniReadValue("Options", "showOverrideLocalModelQuestion"); if (tmp.Equals("true")) { showOverrideLocalModelQuestion = true; } else { showOverrideLocalModelQuestion = false; } tmp = ini.IniReadValue("Options", "showOverrideLocalWhenConnected"); if (tmp.Equals("true")) { showOverrideAtConnectionQuestion = true; } else { showOverrideAtConnectionQuestion = false; } tmp = ini.IniReadValue("Options", "showOverrideAndRunLocalWhenConnected"); if (tmp.Equals("true")) { showOverrideAndRunAtConnectionQuestion = true; } else { showOverrideAndRunAtConnectionQuestion = false; } tmp = ini.IniReadValue("Options", "showOverrideComponentCollectionQuestion"); if (tmp.Equals("true")) { showOverrideComponentCollectionQuestion = true; } else { showOverrideComponentCollectionQuestion = false; } // Eventhandler needed to read start parameter (start file after double-click) this.Loaded += new RoutedEventHandler(MainWindow_Loaded); areStatus = new AREStatus(); //AREStatus.Disconnected; areStatus.PropertyChanged += AreStatusChanged; statusBar.Text = Properties.Resources.AREStatusDisconnected; statusList = new List<StatusObject>(); //showPortsRibbonButton.IsChecked = true; //showEventsRibbonButton.IsChecked = true; this.KeyDown += Global_KeyDown; canvas.MouseWheel += Zoom_MouseWheele; canvas.Focusable = true; canvas.Focus(); //Adding event handlers to the selected Elemts lists. selectedComponentList.PropertyChanged += LinkedList_SizeChanged; selectedChannelList.PropertyChanged += LinkedList_SizeChanged; selectedEventChannelList.PropertyChanged += LinkedList_SizeChanged; // make sure a file for recently opened documents exists if (ini.IniReadValue("Options", "useAppDataFolder").Equals("true")) { if (!File.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\recent.txt")) { File.Create(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\recent.txt"); } } else { if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "recent.txt")) { File.Create(AppDomain.CurrentDomain.BaseDirectory + "recent.txt"); } } }
private model RemoveGroupingElementsInDeployment(model modelToClean) { model retModel = CopyModel(modelToClean); LinkedList<componentType> retModelComponentList = new LinkedList<componentType>(); LinkedList<channel> retModelChannelList = new LinkedList<channel>(); LinkedList<eventChannel> retModelEventChannelList = new LinkedList<eventChannel>(); foreach (componentType component in retModel.components) { retModelComponentList.AddLast(component); } if (retModel.channels != null) { foreach (channel ch in retModel.channels) { retModelChannelList.AddLast(ch); } } if (retModel.eventChannels != null) { foreach (eventChannel ec in retModel.eventChannels) { retModelEventChannelList.AddLast(ec); } } foreach (componentType component in retModel.components) { if (component.ComponentType == ACS2.componentTypeDataTypes.group) { if (retModel.channels != null) { foreach (channel ch in retModel.channels) { if ((ch.source.component.id == component.id) || (ch.target.component.id == component.id)) { retModelChannelList.Remove(ch); } } } if (retModel.eventChannels != null) { foreach (eventChannel ec in retModel.eventChannels) { if ((ec.sources.source.component.id == component.id) || (ec.targets.target.component.id == component.id)) { retModelEventChannelList.Remove(ec); } } } retModelComponentList.Remove(component); } } if (retModelChannelList.Count == 0) { retModel.channels = null; } else { retModel.channels = retModelChannelList.ToArray(); } if (retModelEventChannelList.Count == 0) { retModel.eventChannels = null; } else { retModel.eventChannels = retModelEventChannelList.ToArray(); } retModel.components = retModelComponentList.ToArray(); return retModel; }
/// <summary> /// Save the selected group to a file, so that it can be reused /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveGroupButton_Click(object sender, RoutedEventArgs e) { groupComponent groupToSave = null; foreach (componentType mc in selectedComponentList) { if (mc.ComponentType == ACS2.componentTypeDataTypes.group) { groupToSave = groupsList[mc.id]; break; } } if (groupToSave != null) { storageDialog = new StorageDialog(); string[] filesInGroupsFolder; if (ini.IniReadValue("Options", "useAppDataFolder").Equals("true")) { filesInGroupsFolder = Directory.GetFiles(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\groups\\", "*.agr"); } else { filesInGroupsFolder = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\groups\\", "*.agr"); } foreach (string s in filesInGroupsFolder) { storageDialog.filenameListbox.Items.Add(s.Substring(s.LastIndexOf('\\') + 1)); } storageDialog.filenameListbox.SelectionChanged += filenameListbox_SelectionChanged; storageDialog.Title = Properties.Resources.GroupStoreDialogTitle; storageDialog.listLabel.Content = Properties.Resources.GroupStoreDialogListLabel; storageDialog.filenameTextbox.Text = "NewGroup.agr"; storageDialog.modelNameLabel.Content = Properties.Resources.GroupStoreDialogGroupName; storageDialog.Owner = this; storageDialog.ShowDialog(); if (storageDialog.filenameTextbox.Text != null && storageDialog.filenameTextbox.Text != "") { try { model groupModelToSave; if (groupToSave != null) { ClearSelectedChannelList(); ClearSelectedEventChannelList(); ClearSelectedComponentList(); foreach (componentType componentInGroup in groupToSave.AddedComponentList) { AddSelectedComponent(deploymentComponentList[componentInGroup.id]); } // make a submodel, containing all grouging relevant data groupModelToSave = new model(); groupModelToSave.modelName = groupToSave.GroupID; // insert all selected components to the model LinkedList<componentType> t = new LinkedList<componentType>(); for (int i = 0; i < selectedComponentList.Count; i++) { componentType ct = selectedComponentList.ElementAt(i); t.AddLast(ct); } groupModelToSave.components = t.ToArray(); // adding a group element to save the aliases groupModelToSave.groups = new group[1]; foreach (group groupToAdd in deploymentModel.groups) { if (groupToAdd.id == groupToSave.ID) { groupModelToSave.groups[0] = groupToAdd; break; } } //get all selected channels where the source and target components //are also selected LinkedList<channel> copyChannels = new LinkedList<channel>(); foreach (channel c in groupToSave.AddedChannelsList) { bool sourceFound, targetFound; sourceFound = targetFound = false; foreach (componentType mc in groupModelToSave.components) { if (mc.id == c.source.component.id) sourceFound = true; if (mc.id == c.target.component.id) targetFound = true; if (sourceFound && targetFound) break; } if (sourceFound && targetFound) copyChannels.AddLast(c); } // Adding dummy channels to make the input and output ports of the group visible componentType groupComponent = deploymentComponentList[groupToSave.ID]; int index = 0; foreach (object o in groupComponent.ports) { channel c = new channel(); c.id = "bindingveigl." + index; if (o is inputPortType) { c.source.component.id = pasteDummyName; c.source.port.id = "out"; c.target.component.id = ((inputPortType)o).refs.componentID; c.target.port.id = ((inputPortType)o).refs.portID; } else { c.source.component.id = ((outputPortType)o).refs.componentID; c.source.port.id = ((outputPortType)o).refs.portID; c.target.component.id = pasteDummyName; c.target.port.id = "in"; } copyChannels.AddLast(c); index++; } groupModelToSave.channels = new channel[copyChannels.Count]; for (int i = 0; i < copyChannels.Count; i++) groupModelToSave.channels[i] = copyChannels.ElementAt(i); // get all selected Eventchannels index = 0; LinkedList<eventChannel> copyEventChannels = new LinkedList<eventChannel>(); LinkedList<EventListenerPort> foundEdgeListenerEvents = new LinkedList<EventListenerPort>(); LinkedList<EventTriggerPort> foundEdgeTriggerEvents = new LinkedList<EventTriggerPort>(); foreach (eventChannel ec in eventChannelList) { // search for each event channel on the edge of the group element if (!selectedComponentList.Contains(deploymentComponentList[ec.targets.target.component.id]) && selectedComponentList.Contains(deploymentComponentList[ec.sources.source.component.id])) { eventChannel newEc = new eventChannel(); newEc.id = "eventbindingveigl." + index; newEc.sources.source.component.id = ec.sources.source.component.id; newEc.sources.source.eventPort.id = ec.sources.source.eventPort.id; newEc.targets.target.component.id = pasteDummyName; newEc.targets.target.eventPort.id = "eventlistener"; index++; copyEventChannels.AddLast(newEc); // search for each event channel on the edge of the group element } else if (selectedComponentList.Contains(deploymentComponentList[ec.targets.target.component.id]) && !selectedComponentList.Contains(deploymentComponentList[ec.sources.source.component.id])) { eventChannel newEc = new eventChannel(); newEc.id = "eventbindingveigl." + index; newEc.sources.source.component.id = pasteDummyName; newEc.sources.source.eventPort.id = "eventtrigger"; newEc.targets.target.component.id = ec.targets.target.component.id; newEc.targets.target.eventPort.id = ec.targets.target.eventPort.id; index++; copyEventChannels.AddLast(newEc); } else if ((selectedComponentList.Contains(deploymentComponentList[ec.targets.target.component.id]) && selectedComponentList.Contains(deploymentComponentList[ec.sources.source.component.id]))) { copyEventChannels.AddFirst(ec); } } // Adding dummy eventchannels to make the input and output ports of the group visible foreach (EventListenerPort elp in groupComponent. EventListenerList) { eventChannel newEc = new eventChannel(); foreach (componentType mc in groupModelToSave.components) { if (elp.EventListenerId.StartsWith(mc.id)) { newEc.targets.target.component.id = mc.id; newEc.targets.target.eventPort.id = ((EventListenerPort)mc.EventListenerList[0]).EventListenerId; newEc.id = "eventbindingveigl." + index; newEc.sources.source.component.id = pasteDummyName; newEc.sources.source.eventPort.id = "eventtrigger"; index++; copyEventChannels.AddLast(newEc); break; } } } foreach (EventTriggerPort etp in groupComponent.EventTriggerList) { eventChannel newEc = new eventChannel(); foreach (componentType mc in groupModelToSave.components) { if (etp.EventTriggerId.StartsWith(mc.id)) { newEc.id = "eventbindingveigl." + index; newEc.sources.source.component.id = mc.id; newEc.sources.source.eventPort.id = ((EventTriggerPort)mc.EventTriggerList[0]).EventTriggerId; newEc.targets.target.component.id = pasteDummyName; newEc.targets.target.eventPort.id = "eventlistener"; index++; copyEventChannels.AddLast(newEc); break; } } } if (copyEventChannels.Count == 0) { groupModelToSave.eventChannels = null; } else { groupModelToSave.eventChannels = copyEventChannels.ToArray(); } groupModelToSave = CopyModel(groupModelToSave); // write group stream XmlSerializer x = new XmlSerializer(groupModelToSave.GetType()); string filename; if (ini.IniReadValue("Options", "useAppDataFolder").Equals("true")) { filename = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\groups\\" + storageDialog.filenameTextbox.Text; } else { filename = AppDomain.CurrentDomain.BaseDirectory + "\\groups\\" + storageDialog.filenameTextbox.Text; } if (!filename.EndsWith(".agr")) { filename += ".agr"; } FileStream str = new FileStream(filename, FileMode.Create); x.Serialize(str, groupModelToSave); str.Close(); // add new group to list of groups bool alreadyInMenu = false; foreach (RibbonApplicationSplitMenuItem i in groupDropDown.Items) { if (((string)i.CommandParameter) == filename) { alreadyInMenu = true; break; } } if (!alreadyInMenu) { RibbonApplicationSplitMenuItem i = new RibbonApplicationSplitMenuItem(); string header = filename.Substring(filename.LastIndexOf('\\') + 1); i.Header = header.Substring(0, header.LastIndexOf('.')); i.Click += AddGroupFromRibbonMenu; i.CommandParameter = filename; groupDropDown.Items.Add(i); } } } catch (Exception ex) { MessageBox.Show(Properties.Resources.StoreModelOnAREError, Properties.Resources.GroupStoreErrorHeader, MessageBoxButton.OK, MessageBoxImage.Error); traceSource.TraceEvent(TraceEventType.Error, 3, ex.Message); } } } else { MessageBox.Show(Properties.Resources.GroupStoreNoGroupSelected, Properties.Resources.GroupStoreErrorHeader, MessageBoxButton.OK, MessageBoxImage.Information); } }
/// <summary> /// Global keyboard listener within the application. Used to handle 'Esc'-key, F-keys, Zoom and Shortcuts for avalon-windows /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Global_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) { if (channelToConnect != null) { canvas.Children.Remove(channelToConnect.Line); channelToConnect = null; } if (eventChannelToConnect != null) { canvas.Children.Remove(eventChannelToConnect.Line); eventChannelToConnect = null; } } if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.P)) { Keyboard.Focus(dockableComponentProperties); } else if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.E)) { Keyboard.Focus(dockableEventsTab); } else if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.D)) { Keyboard.Focus(scrollCanvars); // Timer is setting the focus to the first element. Otherwise, the system is still changing the tabs // and the focus will not be set, as the elements are not visible TimerCallback tcbFocus = this.DoFocusTimer; statusTimer = new Timer(tcbFocus, canvas, 300, Timeout.Infinite); } else if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.G)) { Keyboard.Focus(GUIEditorCanvas); // Timer is setting the focus to the first element. Otherwise, the system is still changing the tabs // and the focus will not be set, as the elements are not visible TimerCallback tcbFocus = this.DoFocusTimer; statusTimer = new Timer(tcbFocus, guiCanvas, 300, Timeout.Infinite); } else if ((Keyboard.Modifiers == ModifierKeys.Control) && ((e.Key == Key.Add) || (e.Key == Key.OemPlus))) { if (zoomSlider.Value < zoomSlider.Maximum) { zoomSlider.Value += zoomSlider.SmallChange; } } else if ((Keyboard.Modifiers == ModifierKeys.Control) && ((e.Key == Key.Subtract) || (e.Key == Key.OemMinus))) { if (zoomSlider.Value > zoomSlider.Minimum) { zoomSlider.Value -= zoomSlider.SmallChange; } } else if (e.Key == Key.F1) { Help_Click(sender, null); } else if (e.Key == Key.F5) { if (runModelButton.IsEnabled) { StartModel_Click(null, null); } } else if (e.Key == Key.F6) { if (pauseModelButton.IsEnabled) { PauseModel_Click(null, null); } } else if (e.Key == Key.F7) { if (stopModelButton.IsEnabled) { StopModel_Click(null, null); } } else if (e.Key == Key.A && ModifierKeys.Control == e.KeyboardDevice.Modifiers) { SelectAll(); } else if (e.Key == Key.C && ModifierKeys.Control == e.KeyboardDevice.Modifiers) { if (!((areStatus.Status == AREStatus.ConnectionStatus.Running) || (areStatus.Status == AREStatus.ConnectionStatus.Pause))) { CopySelectedCommand(); e.Handled = true; pasteRibbonButton.IsEnabled = true; } } else if (e.Key == Key.V && ModifierKeys.Control == e.KeyboardDevice.Modifiers) { if (!((areStatus.Status == AREStatus.ConnectionStatus.Running) || (areStatus.Status == AREStatus.ConnectionStatus.Pause))) { model tmpModel = CopyModel(copyModel); PasteCopiedModel(copyModel, false,true); copyModel = tmpModel; } } else if (e.Key == Key.X && ModifierKeys.Control == e.KeyboardDevice.Modifiers) { if (!((areStatus.Status == AREStatus.ConnectionStatus.Running) || (areStatus.Status == AREStatus.ConnectionStatus.Pause))) { CopySelectedCommand(); DeleteSelectedComponents(); pasteRibbonButton.IsEnabled = true; } } else if (e.Key == Key.Delete) { if (!((areStatus.Status == AREStatus.ConnectionStatus.Running) || (areStatus.Status == AREStatus.ConnectionStatus.Pause))) { DeleteSelectedComponents(); } } else if (e.Key == Key.Z && ModifierKeys.Control == e.KeyboardDevice.Modifiers) { if (undoButton.IsEnabled) { Undo_Click(sender, e); } } else if (e.Key == Key.Y && ModifierKeys.Control == e.KeyboardDevice.Modifiers) { if (redoButton.IsEnabled) { Redo_Click(sender, e); } } else if (e.Key == Key.S && ModifierKeys.Control == e.KeyboardDevice.Modifiers) { // If a property has been edited and the focus has not been set to another element, the property will not be set. // Clicking ribbon elments did not remove focus from property editor, so the property will // not be set. Causes problems, saving, uplaoding, ... the model if (canvas.Children.Count > 0) { Keyboard.Focus(canvas.Children[0]); } else { Keyboard.Focus(canvas); } String mustBeConnectedError = MustBeConnectedChecker(); if (mustBeConnectedError != "") { MessageBox.Show(mustBeConnectedError, Properties.Resources.MustBeConnectedCheckerHeader, MessageBoxButton.OK, MessageBoxImage.Error); } else { // if no file for saving is defined yet, show the saveas-dialog if (saveFile != null) { SaveLocalCommand(false); } else { SaveLocalCommand(true); } } } }
/// <summary> /// Create an ARE GUI element, needed for older models, to update them to the current version /// </summary> /// <param name="mw">The MainWindow</param> /// <param name="deployModel">Deployment Motel, containing all components of the model</param> public static void UpdateToCurrentVersion(MainWindow mw, model deployModel) { if (deployModel.version != model.VERSION) { if (deployModel.version == "20120301" || deployModel.version == "20120509" || deployModel.version == "20111104") { // From version 20120301 to 20120509, only minor changes without any change in the older deployment files are made // 20111104 should also work, needs further tests!!! //Update GUI components resolution from, 1/100 to 1/10000 foreach (componentType comp in deployModel.components) { if (comp.gui != null) { comp.gui.height = String.Concat(comp.gui.height, "00"); comp.gui.width = String.Concat(comp.gui.width, "00"); comp.gui.posX = String.Concat(comp.gui.posX, "00"); comp.gui.posY = String.Concat(comp.gui.posY, "00"); } } // Add the AREGUIWindow deployModel.modelGUI = new modelGUIType(); deployModel.modelGUI.AREGUIWindow = new guiType(); deployModel.modelGUI.AREGUIWindow.height = "5000"; deployModel.modelGUI.AREGUIWindow.width = "9000"; deployModel.modelGUI.AREGUIWindow.posX = "0"; deployModel.modelGUI.AREGUIWindow.posY = "0"; deployModel.modelGUI.AlwaysOnTop = false; deployModel.modelGUI.Decoration = true; deployModel.modelGUI.Fullscreen = false; deployModel.modelGUI.ShopControlPanel = true; deployModel.modelGUI.ToSystemTray = false; MessageBox.Show(Properties.Resources.UpdateModelVersionGUIInfoFormat(deployModel.version,model.VERSION), Properties.Resources.UpdateModelVersionGUIHeader, MessageBoxButton.OK, MessageBoxImage.Information); deployModel.version = model.VERSION; mw.ModelHasBeenEdited = true; } } }
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); } }