예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        /// <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);
                    }
                }
            }
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <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);
            }
        }
예제 #5
0
        /// <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;
        }