Exemple #1
0
        /// <summary>
        /// remove a server entry by passing an entry instance
        /// </summary>
        public void RemoveServerDetails(ServerDetails sd)
        {
            if (sd == null)
            {
                return;
            }
            int l = details.Count - 1;

            for (; l >= 0; l--)
            {
                ServerDetails sdr = details[l];
                if (sd.GetHashCode() == sdr.GetHashCode())
                {
                    details.RemoveAt(l);
                    return;
                }
            }
        }
Exemple #2
0
        public void LoadFile(string path)
        {
            if (!File.Exists(path))
            {
                FileUtil.WriteToFileUTF8(path, null);
                return;
            }

            string[]      lines  = File.ReadAllLines(path);
            ServerDetails detail = null;

            foreach (string line in lines)
            {
                if (line.Substring(0, 1).Equals("#"))
                {
                    AddServerDetails(detail, true);
                    detail = new ServerDetails();
                    detail.SetName(line.Substring(1));
                }
                if (detail == null)
                {
                    continue;
                }
                string sub = line.Substring(0, 2);
                if (sub.Equals("s:"))
                {
                    detail.SetAddress(line.Substring(2));
                }
                if (sub.Equals("u:"))
                {
                    detail.SetUser(line.Substring(2));
                }
                if (sub.Equals("p:"))
                {
                    detail.SetPass(line.Substring(2));
                }
                if (sub.Equals("l:"))
                {
                    detail.SetLocation(line.Substring(2));
                }
            }
            AddServerDetails(detail, true);
        }
Exemple #3
0
        /// <summary>
        /// add a server detail object to the list.
        /// overwrite existing entry if exists
        /// </summary>
        public void AddServerDetails(ServerDetails sd, bool overwrite)
        {
            if (sd == null)
            {
                return;
            }
            var detail = GetServerDetailsByName(sd.GetName());

            if (detail != null)
            {
                if (!overwrite)
                {
                    return;
                }
                detail.SetAddress(sd.GetAddress());
                detail.SetLocation(sd.GetLocation());
                detail.SetUser(sd.GetUser());
                detail.SetPass(sd.GetPass());
                return;
            }
            details.Add(sd);
        }
Exemple #4
0
 /// <summary>
 ///
 /// </summary>
 public void SetSelected(ServerDetails sd)
 {
     selected = sd;
 }
Exemple #5
0
 /// <summary>
 /// private singleton constructor
 /// </summary>
 private ServersConfig()
 {
     details        = new List <ServerDetails>();
     selected       = null;
     utf8WithoutBom = new UTF8Encoding(false);
 }