Exemplo n.º 1
0
 /// <summary>
 /// Clear the graph if not empty
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MenuReset_Click(object sender, RoutedEventArgs e)
 {
     if (!MainCanvas.IsEmpty())
     {
         MessageBoxResult result = MessageBox.Show("Would you like to save the current graph before openning a new one?", "Current graph is not saved!", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
         if (result == MessageBoxResult.Yes)
         {
             SaveToFile();
         }
         else if (result == MessageBoxResult.No)
         {
             MainCanvas.Children.Clear();
             graph = new CanvasGraph();
         }
         else if (result == MessageBoxResult.Cancel)
         {
             // do nothing
         }
     }
     else
     {
         MainCanvas.Children.Clear();
         graph = new CanvasGraph();
     }
 }
        public CanvasGraph Load(String path)
        {
            File                    = XDocument.Load(path);
            cgraph                  = new CanvasGraph();
            cgraph.Impl             = Dump(File.Root);
            cgraph.CommonAttributes = LoadCommonAttributes(File.Root.Element("CommonAttributes"));

            return(cgraph);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add edge to the graph, avoid duplicates
        /// </summary>
        /// <param name="cgraph"></param>
        /// <param name="cnode"></param>
        private void AddIfNotContain(CanvasGraph cgraph, CanvasNode cnode)
        {
            INode resultNode = cnode.Impl;

            //if (resultNode.GetType() != typeof(ResultNode))
            //	throw new Exception("AddIfNotContain Error!");

            if (cgraph.Call(graph => !graph.Contains(resultNode)))
            {
                cgraph.Call(graph => graph.Add(resultNode));
            }
        }
        public void Save(String path, CanvasGraph graph)
        {
            cgraph = graph;
            XElement root = new XElement("NetworkObservability");

            DumpTo(graph.Call(graphImpl => graphImpl), ref root);
            root.Add(CreateCommonAttributes(cgraph.CommonAttributes));
            File.Add(root);

            // New way to save
            File.Save(path);
        }
Exemplo n.º 5
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);
                }
            }
        }
Exemplo n.º 6
0
 public ResultGraph()//I might pass the content to the constructor
 {
     InitializeComponent();
     CGraph = new CanvasGraph();
 }