Beispiel #1
0
        /// <summary>
        /// Save the graph onto xml file
        /// </summary>
        private void SaveToFile()
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter = "XML file (*.xml) | *.xml";

            if (dialog.ShowDialog() == true)
            {
                CanvasGraphXML output = new CanvasGraphXML();
                output.Save(dialog.FileName, graph);
            }
        }
Beispiel #2
0
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            // TODO
            //string xmlFileContents = "Some testing string";
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter = "XML file (*.xml) | *.xml";

            if (dialog.ShowDialog() == true)
            {
                CanvasGraphXML output   = new CanvasGraphXML();
                string         savePath = System.IO.Path.GetDirectoryName(dialog.FileName);
                // Save to file
                output.Save(savePath, CGraph);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Open and load graph from xml
        /// </summary>
        private void OpenFromFile()
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Multiselect = false;
            fileDialog.Filter      = "XML Files(*.xml)|*.xml|Textfiles(*.txt)|*.txt|All Files(*.*)|*.*";
            fileDialog.DefaultExt  = ".xml";
            Nullable <bool> getFile = fileDialog.ShowDialog();

            if (getFile == true)
            {
                CanvasGraphXML reader = new CanvasGraphXML();
                //CanvasGraph cGraph = new CanvasGraph();
                try
                {
                    MainCanvas.Children.Clear();
                    graph = reader.Load((fileDialog.FileName).ToString());
                    foreach (var node in graph.Impl.AllNodes.Values)
                    {
                        DrawNode(graph[node]);
                    }
                    foreach (var edge in graph.Impl.AllEdges.Values)
                    {
                        CanvasNode fromNode = graph[edge.From];
                        CanvasNode toNode   = graph[edge.To];

                        DrawEdge(fromNode, toNode, graph[edge]);
                    }
                }
                catch (ArgumentNullException)
                {
                    MessageBox.Show("Failed to load the invalid XML file.\nPlease use a valid one");
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.Message);
                }
            }
        }