Exemple #1
0
        public Dictionary <string, List <string> > GetPasswordList()
        {
            string passwordFilePath = Path.Combine(enviConfig.ProductionWorkspace, "password", "password.txt");

            ClearDir(Path.GetDirectoryName(passwordFilePath));
            CreateDir(Path.GetDirectoryName(passwordFilePath));
            if (enviConfig.TransferMode == TransferMode.FTP)
            {
                if (!ftpDownload.FileExists(enviConfig.ServerProgDir + @"/password/password.txt"))
                {
                    throw new Exception("Password file is missing, please contact the developer!");
                }
                ftpDownload.Download(enviConfig.ServerProgDir + @"/password/password.txt", passwordFilePath);
            }
            else
            {
                if (!File.Exists(enviConfig.ServerProgDir + @"\password\password.txt"))
                {
                    throw new Exception("Password file is missing, please contact the developer!");
                }
                File.Copy(enviConfig.ServerProgDir + @"\password\password.txt", passwordFilePath, true);
            }

            Dictionary <string, List <string> > dictPassword = new Dictionary <string, List <string> >();

            using (StreamReader sr = new StreamReader(passwordFilePath))
            {
                string line = string.Empty;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.StartsWith("#"))
                    {
                        continue;
                    }

                    string[] s = line.Split('=');
                    if (s.Length != 2)
                    {
                        continue;
                    }

                    if (dictPassword.Keys.Contains(s[0].Trim()))
                    {
                        dictPassword[s[0].Trim()].Add(s[1].Trim());
                    }
                    else
                    {
                        dictPassword.Add(s[0].Trim(), new List <string>()
                        {
                            s[1].Trim()
                        });
                    }
                }
                sr.Close();
            }

            return(dictPassword);
        }