Example #1
0
        public void loadItems(string XMLItemsFile)
        {
            if (System.IO.File.Exists(XMLItemsFile))
            {
                try
                {

                    XmlReaderSettings readerSettings = new XmlReaderSettings();
                    readerSettings.IgnoreComments = true;
                    using (XmlReader reader = XmlReader.Create(XMLItemsFile, readerSettings))
                    {
                        // SECTION 1. Create a DOM Document and load the XML data into it.
                        XmlDocument dom = new XmlDocument();
                        dom.Load(reader);

                        // SECTION 2. Initialize Elements
                        XmlNode inXmlNode = dom.DocumentElement;

                        // SECTION 3. Populate Items with the DOM nodes.
                        foreach (XmlNode xnode in inXmlNode.ChildNodes)
                        {
                            if (xnode.Name.Equals("item"))
                            {
                            ToolboxItem t = new ToolboxItem((XmlElement)xnode);
                            if (t!= null)
                                items.Add(t);
                            }
                        }
                    }
                }
                catch (XmlException xmlEx)
                {
                    System.Windows.MessageBox.Show(xmlEx.Message);
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.Message);
                }
            }
            else
                MessageBox.Show("Could not load Items file : " + XMLItemsFile, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
        }
Example #2
0
        private void SaveAndGenerateCode_Click(object sender, RoutedEventArgs e)
        {
            string xslCode = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
            xslCode += "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n";

            xslCode += "<xsl:template match=\"/\">\n";

            //if (e.Data.GetDataPresent("ToolboxItem"))
            //{
            //    ToolboxItem t = e.Data.GetData("ToolboxItem") as ToolboxItem;
            //    xslCode += t.visualElement.templateVM.generateXSLTCall(t.visualElement.templateVM.TemplateName).OuterXml + "\n";
            //}
            //else
            //{
            //    VisualElement v = e.Data.GetData("VisualElement") as VisualElement;
            //    xslCode += v.templateVM.generateXSLTCall(v.templateVM.TemplateName).OuterXml + "\n";
            //}

            //XSLTTemplate tempStart = templateRepo.findTemplateByAddressID((tvvm.FirstChild.ElementAt(0).getFullAddress()));

            //if (tempStart == null)
            //{
            //    //what should go here?
            //}else
            //{
            //    xslCode += tempStart.generateXSLTCall(tempStart.TemplateName);
            //}
            //MessageBox.Show("final template : \n\n" + visEl.templateVM.generateXSLTTemplateCode());
            VisElementCanvas.Children.Remove(visEl);

            ToolboxItem myItem = new ToolboxItem(visEl);

            //save template to be embedded in the code
            templateRepo.templates.Add(visEl.templateVM);

            customToolbox.Items.Add(myItem);

            xslCode += visEl.templateVM.generateXSLTCall(visEl.templateVM.TemplateName).OuterXml + "\n";
            xslCode += "</xsl:template>\n";

            foreach (XSLTTemplate xt in templateRepo.templates)
                xslCode += xt.generateXSLTTemplateCode() + "\n";

            xslCode += "</xsl:stylesheet>\n";

            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Title = "Save XSLT Template";
            saveDialog.ShowDialog();

            if (!saveDialog.FileName.Equals(""))
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xslCode);
                xslFile = saveDialog.FileName;
                doc.Save(xslFile);

                //Run it
                saveDialog.Title = "Save Target file";
                saveDialog.FileName = "";
                saveDialog.ShowDialog();

                if (!saveDialog.FileName.Equals(""))
                {
                    modelVisualFile = saveDialog.FileName;
                    XslCompiledTransform myXslTransform;
                    myXslTransform = new XslCompiledTransform();
                    myXslTransform.Load(xslFile);
                    myXslTransform.Transform(modelFile, modelVisualFile);

                    //clear defined visual templates
                    //customToolbox.Items.Clear();
                    templateRepo.templates.Clear();

                    reportMessage("Transformation generated and executed successfully!", ReportIcon.OK);
                }
                else
                    reportMessage("Transformation could not be executed as the target file was empty!", ReportIcon.Error);
            }
        }
Example #3
0
        private void loadFunctionsToolbox(string functionsFile, Toolbox fToolbox)
        {
            //something should be done for templte repository
            if (System.IO.File.Exists(functionsFile))
            {
                try
                {
                    XmlReaderSettings readerSettings = new XmlReaderSettings();
                    readerSettings.IgnoreComments = true;
                    using (XmlReader reader = XmlReader.Create(functionsFile, readerSettings))
                    {
                        // SECTION 1. Create a DOM Document and load the XML data into it.
                        fdom = new XmlDocument();
                        fdom.Load(reader);

                        // SECTION 2. Initialize Elements
                        XmlNodeList arfunctions = fdom.SelectNodes("Functions/Arithmetic/Function");
                        XmlNodeList reffunctions = fdom.SelectNodes("Functions/Reference/Condition");
                        //MessageBox.Show(customNodes.Count.ToString());
                        // SECTION 3. Populate Items with the DOM nodes.
                        foreach (XmlNode func in arfunctions)
                        {
                            VisualFunction f = new VisualFunction(func);
                            ToolboxItem item = new ToolboxItem(f);
                            //item.Content = f;
                            //item.loadFunctionToolBoxItem(func);
                            fToolbox.Items.Add(item);
                        }

                        foreach (XmlNode func in reffunctions)
                        {
                            VisualCondition f = new VisualCondition(func);
                            ToolboxItem item = new ToolboxItem(f);
                            //item.Content = f;
                            //item.loadFunctionToolBoxItem(func);
                            fToolbox.Items.Add(item);
                        }

                        reader.Close();
                    }

                }
                catch (XmlException xmlEx)
                {
                    reportMessage(xmlEx.Message, ReportIcon.Error);
                }
                catch (Exception ex)
                {
                    reportMessage(ex.Message, ReportIcon.Error);
                }
            }
            else
                reportMessage("Could not load Function ToolboxItems file : " + functionsFile, ReportIcon.Error);
        }
Example #4
0
        private void loadCutomToolbox(string customElementsFile, Toolbox customToolbox)
        {
            //something should be done for templte repository
            if (System.IO.File.Exists(customElementsFile))
            {
                try
                {
                    XmlReaderSettings readerSettings = new XmlReaderSettings();
                    readerSettings.IgnoreComments = true;
                    using (XmlReader reader = XmlReader.Create(customElementsFile, readerSettings))
                    {
                        // SECTION 1. Create a DOM Document and load the XML data into it.
                        dom = new XmlDocument();
                        dom.Load(reader);

                        // SECTION 2. Initialize Elements
                        XmlNodeList customNodes = dom.SelectNodes("CustomItems/CustomItem");
                        //MessageBox.Show(customNodes.Count.ToString());
                        // SECTION 3. Populate Items with the DOM nodes.
                        foreach (XmlNode xnode in customNodes)
                        {
                            ToolboxItem item = new ToolboxItem();
                            item.loadCustomisedToolBoxItem(xnode);
                            customToolbox.Items.Add(item);
                        }

                        reader.Close();
                    }

                }
                catch (XmlException xmlEx)
                {
                    System.Windows.MessageBox.Show(xmlEx.Message);
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.Message);
                }
            }
            else
                reportMessage("Could not load Custom ToolboxItems file : " + customElementsFile, ReportIcon.Error);
        }
Example #5
0
        private void SaveVisualElementTemplate_Click(object sender, RoutedEventArgs e)
        {
            if (VisElementCanvas.Children.Count > 0)
            {
                if (visEl.templateVM != null)
                {

                    foreach (UIElement u in VisElementCanvas.Children)//look for functions
                        if (u.GetType().ToString().Equals("CONVErT.VisualFunction"))//add functions to templates
                        {
                            visEl.templateVM.functions.Add((u as VisualFunction).getFunctionCode());
                            visEl.templateVMR.functions.Add((u as VisualFunction).getReverseFunctionCode());
                        }

                    visEl.templateVM.insertFunctions();//put functions to the actual code
                    visEl.templateVMR.insertFunctions();

                    //remove elements from canvas
                    VisElementCanvas.Children.Clear();

                    ToolboxItem myItem = new ToolboxItem(visEl);

                    //save to file
                    saveCustomTooboxItem(myItem);

                    //show in custom toolbox
                    customToolbox.Items.Add(myItem);

                    //check, abstraction and signature
                    XmlNode x = visEl.sourceLatticeNodeToMatch.createSignatureNode(visEl.templateVM.HeaderNode);

                    //log event
                    logger.log("Visual Element \"" + visEl.VEName + "\" created.", ReportIcon.OK);

                    reportMessage("Visual Element Rule saved!", ReportIcon.OK);

                }
            }
            else
            {
                reportMessage("No visual element exists!", ReportIcon.Error);
                logger.log("Tried saving visual element that is not existing!", ReportIcon.Error);
            }
        }
Example #6
0
        /// <summary>
        /// Save custom Toolbox item to file for future use
        /// </summary>
        /// <param name="item">custom item to be saved</param>
        private void saveCustomTooboxItem(ToolboxItem item)
        {
            XmlNode customItems = dom.SelectSingleNode("CustomItems");

            if (customItems == null)
            {
                customItems = dom.CreateElement("CustomItems") as XmlNode;
                dom.AppendChild(customItems);
            }

            XmlNode itemToBeAdded = item.saveToolBoxItemToXml();

            if (itemToBeAdded != null)
            {
                customItems.AppendChild(customItems.OwnerDocument.ImportNode(itemToBeAdded, true));

                string customElementsFile = getDirectory("Resources\\CustomToolBoxItems.xml");
                customElementsFile = (customElementsFile.Replace("file:\\", ""));
                dom.Save(customElementsFile);
            }
            else
                MessageBox.Show("Custom Item to be added came back Null!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
        }