/// <summary> /// Gets configuration data and returns it in a server configuration object /// </summary> /// <returns></returns> public ServerConfiguration GetConfiguration() { // instantiate the object ServerConfiguration serverConfiguration = new ServerConfiguration(); // set app settings serverConfiguration.AppSettings = new List<AppSetting>(); foreach (string name in ConfigurationManager.AppSettings) serverConfiguration.AppSettings.Add(new AppSetting() { Key = name, Value = ConfigurationManager.AppSettings[name] }); // create list of section settings serverConfiguration.SectionSettings = new List<ConfigurableSettingsData>(); // add facebook section serverConfiguration.AddSettingsFromConfig<FacebookSettings, FacebookSection>(CONFIG_ENCRYPTION_KEY, "facebookConfig"); return serverConfiguration; }
/// <summary> /// Gets configuration from the server and invokes a callback when completed /// </summary> /// <param name="callback"></param> public void LoadConfiguration(Action callback) { // invoke service call base.Channel.BeginGetConfiguration( (asyncResult) => { // get server configuration by ending async call Shared.ServerConfiguration serverConfiguration = base.Channel.EndGetConfiguration(asyncResult); if (serverConfiguration != null) { // load app settings if (serverConfiguration.AppSettings != null) { serverConfiguration.AppSettings.ForEach(appSetting => AppSettings.Add(appSetting.Key, appSetting.Value)); } // load configuration sections if (serverConfiguration.SectionSettings != null) { serverConfiguration.SectionSettings.ForEach(sectionData => { // check that the type is recognized Type sectionType = DataContractUtility.GetType(sectionData.TypeAssemblyQualifiedName, sectionData.TypeFullName, false); if (sectionType != null) { // deserialize to object and store in configuration section object section = serverConfiguration.ReadSection(sectionType, EncryptionKey); if (section != null) { ConfigurationSections.Add(sectionData.Name, section); } } }); } } callback(); }, null); }