Exemplo n.º 1
0
        private static void ExtractProfile(string filename)
        {
            string _s = Path.Combine(FileManager.GetProfilesFolder(), filename);

            if (!File.Exists(_s))
            {
                FileManager.ExtractPresetFile(filename, _s);
            }
        }
Exemplo n.º 2
0
        private void LoadSSHScripts()
        {
            // extract the scripts.xml if it NOT exists
            string _s = Path.Combine(FileManager.GetScriptsFolder(), "scripts.xml");

            if (!File.Exists(_s))
            {
                FileManager.ExtractPresetFile("scripts.xml", _s);
            }
            // dynamically create the Tools buttons
            try
            {
                XDocument _doc = XDocument.Load(_s);
                foreach (XElement _xe in _doc.XPathSelectElements("//script"))
                {
                    string _name = _xe.Attribute("name") != null?_xe.Attribute("name").Value : "??";

                    string _desc = _xe.Attribute("description") != null?_xe.Attribute("description").Value : "No description";

                    string _expect = "#";
                    try
                    {
                        _expect = _xe.Element("command").Attribute("prompt").Value;
                    }
                    catch (Exception ex)
                    {
                        Loggy.Logger.DebugException("element missing", ex);
                    }
                    string _method = "ssh";
                    try
                    {
                        _method = _xe.Element("command").Attribute("method").Value;
                    }
                    catch (Exception ex)
                    {
                        Loggy.Logger.DebugException("element missing", ex);
                    }
                    // create the button
                    Fluent.Button _btn = new Fluent.Button();
                    _btn.Text    = _name;
                    _btn.ToolTip = new Fluent.ScreenTip()
                    {
                        Title = _name, Text = _desc
                    };
                    // put the Dictionary<string> with the commands in the Tag
                    Dictionary <string, string> _commands = new Dictionary <string, string>();
                    foreach (XElement _line in _xe.XPathSelectElements("command/line"))
                    {
                        if (!string.IsNullOrEmpty(_line.Value))
                        {
                            _commands.Add(_line.Value, _expect);
                        }
                    }
                    _btn.Tag       = _commands;
                    _btn.LargeIcon = new BitmapImage(new Uri("/images/batch32.png", UriKind.RelativeOrAbsolute));
                    if (_method == "ssh")
                    {
                        _btn.Click += new RoutedEventHandler(CustomScriptButtonSSH_Click);
                    }
                    else
                    {
                        _btn.Click += new RoutedEventHandler(CustomScriptButtonTelnet_Click);
                    }
                    // add the button to the ribbon
                    grpSSHTools.Items.Add(_btn);
                }
            }
            catch (Exception ex)
            {
                Loggy.Logger.DebugException("Cannot load ssh scripts", ex);
            }
        }