public Boolean loadFromFile(string strConfigFile) { if (File.Exists(strConfigFile)) { try { YamlStream YamlStream = CYamlParser.Load(strConfigFile); if (YamlStream != null) { foreach (YamlDocument YamlDoc in YamlStream.Documents) { DataItem Item = YamlDoc.Root; if (Item is Mapping) { Mapping Mapping = Item as Mapping; if (Mapping != null) { foreach (MappingEntry MapEntry in Mapping.Enties) { string strKey = (MapEntry.Key == null ? "" : MapEntry.Key.ToString()); string strValue = (MapEntry.Value == null ? "" : MapEntry.Value.ToString()); // access_key_id if (strKey.Equals("access_key_id")) { this.accessKey = strValue; } // secret_access_key else if (strKey.Equals("secret_access_key")) { this.accessSecret = strValue; } // host else if (strKey.Equals("host")) { this.host = strValue; } // port else if (strKey.Equals("port")) { this.port = strValue; } // protocol else if (strKey.Equals("protocol")) { this.protocol = strValue; } } // foreach (MappingEntry MapEntry in Mapping.Enties) return(true); } // if (Mapping != null) } // if (Item is Mapping) } // foreach (YamlDocument YamlDoc in YamlStream.Documents) } // if (YamlStream != null) return(false); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } } else { return(false); } }
private bool LoadConfigFile(string strConfigFile) { if (File.Exists(strConfigFile)) { try { YamlStream YamlStream = CYamlParser.Load(strConfigFile); if (YamlStream != null) { foreach (YamlDocument YamlDoc in YamlStream.Documents) { DataItem Item = YamlDoc.Root; if (Item is Mapping) { Mapping Mapping = Item as Mapping; if (Mapping != null) { foreach (MappingEntry MapEntry in Mapping.Enties) { string strKey = (MapEntry.Key == null ? "" : MapEntry.Key.ToString()); string strValue = (MapEntry.Value == null ? "" : MapEntry.Value.ToString()); // access_key_id if (strKey.Equals("access_key_id")) { this.AccessKeyID = strValue; } // secret_access_key else if (strKey.Equals("secret_access_key")) { this.SecretAccessKey = strValue; } // host else if (strKey.Equals("host")) { this.Host = strValue; } // port else if (strKey.Equals("port")) { this.Port = strValue; } // protocol else if (strKey.Equals("protocol")) { this.Protocol = strValue; } // connection_retries else if (strKey.Equals("connection_retries")) { this.ConnectionRetry = int.Parse(strValue); } // additional_user_agent else if (strKey.Equals("additional_user_agent")) { this.UserAgent = strValue; } // log_level else if (strKey.Equals("log_level")) { this.LogLevel = strValue; } } // foreach (MappingEntry MapEntry in Mapping.Enties) return(true); } // if (Mapping != null) } // if (Item is Mapping) } // foreach (YamlDocument YamlDoc in YamlStream.Documents) } // if (YamlStream != null) return(false); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } } else { return(false); } }