Ejemplo n.º 1
0
        void OnSaveModel(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "cfg files (*.cfg)|*.cfg";
            if (saveFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string filename = saveFileDialog.FileName;

            try
            {
                StreamWriter  file  = new StreamWriter(filename, false);
                List <string> lines = new List <string>();
                NodeIed       n     = (NodeIed)(sender as ToolStripItem).Tag;
                // Ensure we always save the IEC data structure, not the MMS one
                n = n.GetIecs().DataModel.iec;
                // Find model name = common LD names prefix
                List <string> ldnames = n.GetChildNodeNames();
                string        prefix  = findShortestString(ldnames);
                if (prefix == "" || ldnames.Count < 2)
                {
                    // User has to choose the name part, because it is unclear how to divide the MMS name(s) into MODEL and LD part
                    // Populate dialog
                    prefix = n.GetChildNodeNames()[0];
                    if (prefix.Length == 2)
                    {
                        prefix = prefix.Substring(0, 1);
                    }
                    if (prefix.Length > 2)
                    {
                        Dialogs.SplitStringDialog ssd = new Dialogs.SplitStringDialog(prefix, "Make Model name from LD name / choose a substring", "Model Name:", "LD Name:");
                        DialogResult res = ssd.ShowDialog();
                        //DialogResult res = ShowInputDialog(ref prefix, "Set Model Name / should be the first part of given LD name");
                        if (res != DialogResult.OK)
                        {
                            return;
                        }
                        prefix = ssd.Part1;
                    }
                }
                n.IedModelName = prefix;
                n.SaveModel(lines, false);

                foreach (string line in lines)
                {
                    file.WriteLine(line);
                }
                file.Close();
                MessageBox.Show("Model successfully exported! To " + filename, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            catch (Exception ex)
            {
                MessageBox.Show("Cannot export model to file " + filename + " ! Detail: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Ejemplo n.º 2
0
        void OnStopServer(object sender, EventArgs e)
        {
            NodeIed n = (NodeIed)(sender as ToolStripItem).Tag;

            if (runningServers.ContainsKey(n))
            {
                int port = runningServers[n].TcpPort;
                runningServers[n].Stop();
                n.SCLServerRunning = null;
                runningServers.Remove(n);
                removeStartedServer(port);
            }
        }
Ejemplo n.º 3
0
        void OnRunServer(object sender, EventArgs e)
        {
            NodeIed n = (NodeIed)(sender as ToolStripItem).Tag;

            foreach (Iec61850Model m in dataModels)
            {
                if (m.ied.Name == n.Name)
                {
                    SCLServer s = new SCLServer();
                    runningServers.Add(n, s);
                    int port = getFreePort();
                    s.Start(m, port);
                    m.iec.SCLServerRunning = s;
                    addStartedServer(port);
                }
            }
        }