Example #1
0
        /*Button Click method to add node to the dictionary list of previously created custom software nodes*/
        void button_Click(object sender, EventArgs e)
        {
            var vm = v.DataContext as MainViewModel;

            var strings = Controls.OfType <TextBox>()
                          .Select(c => c.Text)
                          .ToList();

            //Gets the string [] of values of the strings on the form
            string[] nodeString = new string[strings.Count];
            for (int i = 0; i < strings.Count; i++)
            {
                nodeString[i] = strings[i];
            }


            bool addToDictionary = true;

            //Checks to see if the name already exists
            foreach (var item in vm.NodeSkeletons)
            {
                if (item.Key == nodeString[0])
                {
                    addToDictionary = false;
                    MessageBox.Show("Cannot create a node with the same name as a previously created node");
                    break;
                }
            }
            //if it passes all the test the node is then added to the dictionary of available nodes
            if (addToDictionary)
            {
                //create node
                Node node = vm.CreateNewNode(numFields, numFields, nodeString);
                //add to dictionary
                vm.NodeSkeletons.Add(node.Name, v.writeNode(node).Split(','));
            }
            v.updateNodes();
            Close();
        }
Example #2
0
        /*Button Click method to open a saved file
         * It first uses an Open File Dialog to get the file. It then reads all the lines and creates string[] for connectors, software nodes, and data nodes.
         * Next it uses a switch case based on the number of file lines to  determine which elements exist in the save file
         * Lastly, based on the case, it reads in the relevant information for each data structure and adds them to the screen.
         */
        private void button2_Click(object sender, EventArgs e)
        {
            //clear screen before loading
            x.clearScreen();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //create variables based on the file read in.
                string   filename  = openFileDialog1.FileName;
                string[] filelines = File.ReadAllLines(filename);
                string[] connectors;
                string[] nodes;
                string[] nodes2;
                //Switch case that is used to determine which elements need to be created and added
                switch (filelines.Count())
                {
                //Just Software Nodes
                case 1:
                    nodes = filelines[0].Split('+');
                    for (int i = 0; i < nodes.Length; i++)
                    {
                        string[] nodeString = nodes[i].Split(',');
                        string[] strings    = new string[(nodeString.Length - 3)];
                        for (int j = 0; j < strings.Length; j++)
                        {
                            strings[j] = nodeString[(j + 3)];
                        }

                        var  vm = x.DataContext as MainViewModel;
                        Node n  = vm.CreateNewNode(Convert.ToInt32(nodeString[2]), 10, strings);
                        n.Location.Value = new System.Windows.Point(Convert.ToInt32(nodeString[0]), Convert.ToInt32(nodeString[1]));
                        vm.viewNodes(n);
                        x.updateNodes();
                    }

                    break;

                //Software and Data Nodes
                case 2:
                    nodes = filelines[0].Split('+');
                    for (int i = 0; i < nodes.Length; i++)
                    {
                        string[] nodeString = nodes[i].Split(',');
                        string[] strings    = new string[(nodeString.Length - 3)];
                        for (int j = 0; j < strings.Length; j++)
                        {
                            strings[j] = nodeString[(j + 3)];
                        }

                        var  vm = x.DataContext as MainViewModel;
                        Node n  = vm.CreateNewNode(Convert.ToInt32(nodeString[2]), 10, strings);
                        n.Location.Value = new System.Windows.Point(Convert.ToInt32(nodeString[0]), Convert.ToInt32(nodeString[1]));
                        vm.viewNodes(n);
                        x.updateNodes();
                    }
                    nodes2 = filelines[1].Split('+');
                    for (int i = 0; i < nodes2.Length; i++)
                    {
                        string[] node2String = nodes2[i].Split(',');
                        string[] strings2    = new string[(node2String.Length - 3)];
                        for (int j = 0; j < strings2.Length; j++)
                        {
                            strings2[j] = node2String[(j + 3)];
                        }

                        var   vm = x.DataContext as MainViewModel;
                        Node2 n2 = vm.CreateNewNode2(Convert.ToInt32(node2String[2]), strings2);
                        n2.Location.Value = new System.Windows.Point(Convert.ToInt32(node2String[0]), Convert.ToInt32(node2String[1]));
                        x.updateNodes();
                    }
                    break;

                //Software Nodes, Data Nodes, and Connectors
                case 3:
                    connectors = filelines[2].Split('+');
                    nodes      = filelines[0].Split('+');
                    nodes2     = filelines[1].Split('+');


                    for (int i = 0; i < nodes.Length; i++)
                    {
                        string[] nodeString = nodes[i].Split(',');
                        string[] strings    = new string[(nodeString.Length - 3)];
                        for (int j = 0; j < strings.Length; j++)
                        {
                            strings[j] = nodeString[(j + 3)];
                        }

                        var  vm = x.DataContext as MainViewModel;
                        Node n  = vm.CreateNewNode(Convert.ToInt32(nodeString[2]), 10, strings);
                        n.Location.Value = new System.Windows.Point(Convert.ToInt32(nodeString[0]), Convert.ToInt32(nodeString[1]));
                        vm.viewNodes(n);
                        x.updateNodes();
                    }
                    for (int i = 0; i < nodes2.Length; i++)
                    {
                        string[] node2String = nodes2[i].Split(',');
                        string[] strings2    = new string[(node2String.Length - 3)];
                        for (int j = 0; j < strings2.Length; j++)
                        {
                            strings2[j] = node2String[(j + 3)];
                        }

                        var   vm = x.DataContext as MainViewModel;
                        Node2 n2 = vm.CreateNewNode2(Convert.ToInt32(node2String[2]), strings2);
                        n2.Location.Value = new System.Windows.Point(Convert.ToInt32(node2String[0]), Convert.ToInt32(node2String[1]));
                        x.updateNodes();
                    }


                    for (int i = 0; i < connectors.Length; i++)
                    {
                        var      vm       = x.DataContext as MainViewModel;
                        string[] conSplit = connectors[i].Split(',');
                        if (conSplit[0] == "N2")
                        {
                            Node2 n2 = vm.Nodes2[0];
                            for (int n = 0; n < vm.Nodes2.Count; n++)
                            {
                                if (vm.Nodes2[n].Name == conSplit[1])
                                {
                                    n2 = vm.Nodes2[n];
                                    break;
                                }
                            }
                            SnapSpot snapA = n2.Snaps[1];
                            Node     n1    = vm.Nodes[0];
                            for (int n = 0; n < vm.Nodes.Count; n++)
                            {
                                if (vm.Nodes[n].Name == conSplit[3])
                                {
                                    n1 = vm.Nodes[n];
                                    break;
                                }
                            }
                            SnapSpot snapB = n1.InSnaps[conSplit[4]];
                            vm.customConnectorFromData(snapA, snapB);
                        }
                        else
                        {
                            Node n1 = vm.Nodes[0];
                            for (int n = 0; n < vm.Nodes.Count; n++)
                            {
                                if (vm.Nodes[n].Name == conSplit[1])
                                {
                                    n1 = vm.Nodes[n];
                                    break;
                                }
                            }
                            SnapSpot snapA = n1.OutSnaps[conSplit[2]];
                            Node2    n2    = vm.Nodes2[0];
                            for (int n = 0; n < vm.Nodes2.Count; n++)
                            {
                                if (vm.Nodes2[n].Name == conSplit[3])
                                {
                                    n2 = vm.Nodes2[n];
                                    break;
                                }
                            }
                            SnapSpot snapB = n2.Snaps[0];

                            vm.customConnectorToData(snapA, snapB);
                        }
                        x.updateNodes();
                    }
                    break;
                }
            }
            Close();
        }