public static void LoadMaterialControlsFile(ref MaterialControlsContainer controlsContainer, string filename) { try { controlsContainer = new MaterialControlsContainer(); var sr = new StreamReader(ResourceGroupManager.Instance.OpenResource(filename, "Popular")); string sLine = string.Empty; bool newSection = false; bool inSection = false; var _sections = new Dictionary <string, List <KeyValuePair <string, string> > >(); string currentSection = string.Empty; while ((sLine = sr.ReadLine()) != null) { if (string.IsNullOrEmpty(sLine)) { continue; } if (sLine.StartsWith("[")) { newSection = true; inSection = false; currentSection = sLine.Replace("[", "").Replace("]", ""); _sections[currentSection] = new List <KeyValuePair <string, string> >(); } if (inSection) { string[] sectionSplit = sLine.Split(' '); string sectionName = sectionSplit[0]; string sectionParams = string.Empty; for (int i = 1; i < sectionSplit.Length; i++) { if (sectionSplit[i] == "") { continue; } if (sectionSplit[i] == "=") { continue; } sectionParams += sectionSplit[i].Trim() + ' '; } _sections[currentSection].Add(new KeyValuePair <string, string>(sectionName, sectionParams)); } if (newSection) { newSection = false; inSection = true; } } foreach (string section in _sections.Keys) { //foreach ( List<KeyValuePair<string, string>> pai in _sections.Values ) List <KeyValuePair <string, string> > pai = _sections[section]; { int index = 0; for (int i = 0; i < pai.Count; i++) { if (pai[i].Key == "material") { var newMaterialControls = new MaterialControls(section, pai[i].Value.TrimStart().TrimEnd()); controlsContainer.Add(newMaterialControls); index = controlsContainer.Count - 1; } if (pai[i].Key == "control") { controlsContainer[index].AddControl(pai[i].Value); } } } } LogManager.Instance.Write("Material Controls setup"); } catch { // Guess the file didn't exist controlsContainer = new MaterialControlsContainer(); } }
public static void LoadMaterialControlsFile( ref MaterialControlsContainer controlsContainer, string filename ) { try { controlsContainer = new MaterialControlsContainer(); var sr = new StreamReader( ResourceGroupManager.Instance.OpenResource( filename, "Popular" ) ); string sLine = string.Empty; bool newSection = false; bool inSection = false; var _sections = new Dictionary<string, List<KeyValuePair<string, string>>>(); string currentSection = string.Empty; while ( ( sLine = sr.ReadLine() ) != null ) { if ( string.IsNullOrEmpty( sLine ) ) { continue; } if ( sLine.StartsWith( "[" ) ) { newSection = true; inSection = false; currentSection = sLine.Replace( "[", "" ).Replace( "]", "" ); _sections[ currentSection ] = new List<KeyValuePair<string, string>>(); } if ( inSection ) { string[] sectionSplit = sLine.Split( ' ' ); string sectionName = sectionSplit[ 0 ]; string sectionParams = string.Empty; for ( int i = 1; i < sectionSplit.Length; i++ ) { if ( sectionSplit[ i ] == "" ) { continue; } if ( sectionSplit[ i ] == "=" ) { continue; } sectionParams += sectionSplit[ i ].Trim() + ' '; } _sections[ currentSection ].Add( new KeyValuePair<string, string>( sectionName, sectionParams ) ); } if ( newSection ) { newSection = false; inSection = true; } } foreach ( string section in _sections.Keys ) { //foreach ( List<KeyValuePair<string, string>> pai in _sections.Values ) List<KeyValuePair<string, string>> pai = _sections[ section ]; { int index = 0; for ( int i = 0; i < pai.Count; i++ ) { if ( pai[ i ].Key == "material" ) { var newMaterialControls = new MaterialControls( section, pai[ i ].Value.TrimStart().TrimEnd() ); controlsContainer.Add( newMaterialControls ); index = controlsContainer.Count - 1; } if ( pai[ i ].Key == "control" ) { controlsContainer[ index ].AddControl( pai[ i ].Value ); } } } } LogManager.Instance.Write( "Material Controls setup" ); } catch { // Guess the file didn't exist controlsContainer = new MaterialControlsContainer(); } }