SuperPutty.Data.SessionData.CombineSessionIds C# (CSharp) Method

CombineSessionIds() public static method

public static CombineSessionIds ( string parent, string child ) : string
parent string
child string
return string
        public static string CombineSessionIds(string parent, string child) 
        {
            if (parent == null && child == null)
            {
                return null;
            } 
            else if (child == null) 
            {
                return parent;
            }
            else if (parent == null)
            {
                return child;
            }
            else
            {
                return parent + "/" + child;
            }
        }

Usage Example

コード例 #1
0
        public static List <SessionData> GetAllSessionsFromPuTTYCM(string fileExport)
        {
            List <SessionData> sessions = new List <SessionData>();

            if (fileExport == null || !File.Exists(fileExport))
            {
                return(sessions);
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(fileExport);


            XmlNodeList connections = doc.DocumentElement.SelectNodes("//connection[@type='PuTTY']");

            foreach (XmlElement connection in connections)
            {
                List <string> folders = new List <string>();
                XmlElement    node    = connection.ParentNode as XmlElement;
                while (node != null && node.Name != "root")
                {
                    if (node.Name == "container" && node.GetAttribute("type") == "folder")
                    {
                        folders.Add(node.GetAttribute("name"));
                    }
                    node = node.ParentNode as XmlElement;
                }
                folders.Reverse();
                string parentPath = string.Join("/", folders.ToArray());

                XmlElement info  = (XmlElement)connection.SelectSingleNode("connection_info");
                XmlElement login = (XmlElement)connection.SelectSingleNode("login");

                SessionData session = new SessionData
                {
                    SessionName = info.SelectSingleNode("name").InnerText,
                    Host        = info.SelectSingleNode("host").InnerText,
                    Port        = Convert.ToInt32(info.SelectSingleNode("port").InnerText),
                    Proto       =
                        (ConnectionProtocol)
                        Enum.Parse(typeof(ConnectionProtocol), info.SelectSingleNode("protocol").InnerText),
                    PuttySession = info.SelectSingleNode("session").InnerText
                };
                session.SessionId = string.IsNullOrEmpty(parentPath)
                    ? session.SessionName
                    : SessionData.CombineSessionIds(parentPath, session.SessionName);
                session.Username = login.SelectSingleNode("login").InnerText;

                sessions.Add(session);
            }

            return(sessions);
        }