예제 #1
0
        public void loadProfile(string profile)
        {
            config       = Configuration.LoadFromFile(profile);
            mprofilename = config["General"]["name"].StringValue;
            var sectionG = config["General"];

            SharpConfig.Section[] sections = new SharpConfig.Section[] {
                config["Korg1"],
                config["Korg2"],
                config["Korg3"],
                config["Korg4"],
                config["Korg5"],
                config["Korg6"],
                config["Korg7"],
                config["Korg8"]
            };

            //Set profile values for bars
            int inibpm = Int32.Parse(sectionG["bpm"].StringValue);

            setBpms(inibpm);
            setSounds(sections);
            setVolumes(sections);
            setRests(sections);
            setAccentedBeats(sections);
        }
예제 #2
0
    /// <summary>
    /// Tries the get named setting or returns null.
    /// </summary>
    /// <returns>The get.</returns>
    /// <param name="section">Section.</param>
    /// <param name="setting">Setting.</param>
    public static SharpConfig.Setting TryGet(this SharpConfig.Section section, string setting)
    {
        Debug.Assert(section != null);
        Debug.Assert(!string.IsNullOrEmpty(setting));

        if (section.Contains(setting))
        {
            return(section[setting]);
        }
        return(null);
    }
예제 #3
0
    /// <summary>
    /// Get setting from section while setting a default value if it has none.
    /// Can not deal with arrays
    /// </summary>
    /// <returns>The setting.</returns>
    /// <param name="section">Section.</param>
    /// <param name="setting">Setting name.</param>
    /// <param name="fallback">Fallback default value for the setting.</param>
    /// <typeparam name="T">Setting type.</typeparam>
    public static SharpConfig.Setting GetSetDefault <T>(this SharpConfig.Section section, string setting, T fallback, out bool defaulted)
    {
        Debug.Assert(section != null);
        Debug.Assert(!string.IsNullOrEmpty(setting));

        SharpConfig.Setting rv;
        rv = section[setting];
        if (!rv.IsArray && string.IsNullOrEmpty(rv.GetValue <string>()))
        {
            section[setting].SetValue(fallback);
            defaulted = true;
        }
        else
        {
            defaulted = false;
        }
        // todo: what do do about arrays?

        return(rv);
    }
예제 #4
0
 public static SharpConfig.Setting GetSetDefault <T>(this SharpConfig.Section section, string setting, T fallback)
 {
     return(section.GetSetDefault(setting, fallback, out bool unused));
 }
예제 #5
0
        // Parses a configuration from a source string.
        // This is the core parsing function.
        private static Configuration Parse( string source )
        {
            // Reset temporary fields.
            mLineNumber = 0;

            Configuration config = new Configuration();
            Section currentSection = null;
            var preComments = new List<Comment>();

            using (var reader = new StringReader( source ))
            {
                string line = null;

                // Read until EOF.
                while ((line = reader.ReadLine()) != null)
                {
                    mLineNumber++;

                    // Remove all leading / trailing white-spaces.
                    line = line.Trim();

                    // Empty line? If so, skip.
                    if (string.IsNullOrEmpty(line))
                        continue;

                    int commentIndex = 0;
                    var comment = ParseComment( line, out commentIndex );

                    if (commentIndex == 0)
                    {
                        // This is a comment line (pre-comment).
                        // Add it to the list of pre-comments.
                        preComments.Add( comment );
                        continue;
                    }
                    else if (commentIndex > 0)
                    {
                        // Strip away the comments of this line.
                        line = line.Remove( commentIndex ).Trim();
                    }

                    // Sections start with a '['.
                    if (line.StartsWith( "[" ))
                    {
                        currentSection = ParseSection( line );
                        currentSection.Comment = comment;
                        
                        if (config.Contains(currentSection.Name))
                        {
                            throw new ParserException( string.Format(
                                "The section '{0}' was already declared in the configuration.",
                                currentSection.Name ), mLineNumber );
                        }

                        if (preComments.Count > 0)
                        {
                            currentSection.mPreComments = new List<Comment>( preComments );
                            preComments.Clear();
                        }

                        config.mSections.Add( currentSection );
                    }
                    else
                    {
                        Setting setting = ParseSetting( line );
                        setting.Comment = comment;
                        
                        if (currentSection == null)
                        {
                            throw new ParserException( string.Format(
                                "The setting '{0}' has to be in a section.",
                                setting.Name ), mLineNumber );
                        }

                        if (currentSection.Contains( setting.Name ))
                        {
                            throw new ParserException( string.Format(
                                "The setting '{0}' was already declared in the section.",
                                setting.Name ), mLineNumber );
                        }

                        if (preComments.Count > 0)
                        {
                            setting.mPreComments = new List<Comment>( preComments );
                            preComments.Clear();
                        }

                        currentSection.Add( setting );
                    }

                }
            }

            return config;
        }