Beispiel #1
0
    static bool TryParseAuthFile(string path, out string username, out string repository, out string encryptedPassword)
    {
        username          = "";
        repository        = "";
        encryptedPassword = "";

        // Read file and parse key/value pairs
        Dictionary <string, string> results = null;

        try {
            results = AuthFileParser.ReadFile(path);
            if (!results.TryGetValue("username", out username))
            {
                return(false);
            }
            if (!results.TryGetValue("svn:realmstring", out repository))
            {
                return(false);
            }
            if (!results.TryGetValue("password", out encryptedPassword))
            {
                return(false);
            }
            return(true);
        } catch (AuthParseException e) {
            Console.WriteLine(e.Message);
            return(false);
        }
    }
Beispiel #2
0
    public static Dictionary <string, string> ReadFile(string path)
    {
        AuthFileParser parser = new AuthFileParser();

        using (StreamReader rd = File.OpenText(path)) {
            int    lineNum = 1;
            string line    = rd.ReadLine();
            while (line != null)
            {
                if (lineNum > MAX_LINES)
                {
                    break;
                }

                // Skip comment lines
                if (!line.Trim().StartsWith("#"))
                {
                    // Check for end of file marker
                    if (parser.state == States.ExpectingKeyDef && line.Trim().ToUpper() == "END")
                    {
                        return(parser.props); // Return results
                    }

                    // Attempt to parse the line
                    if (!parser.tryParseNextLine(line))
                    {
                        throw new AuthParseException(path, lineNum);
                    }
                }

                // Read next line
                lineNum++;
                line = rd.ReadLine();
            }

            // If reached this point, we either encountered too many lines or the file
            // ended prematurely.
            throw new AuthParseException(path, -1);
        }
    }