public static void ExportSettingsDefinition(ISettingsStore store, SettingDefinition request, string dataFile) { var version = new Version(request.Version); var allSettingsGroups = store.ListSettingsGroups(); var group = allSettingsGroups.SingleOrDefault(g => g.Name.Equals(request.Group) && g.Version.Equals(version)); if (group == null) { Platform.Log(LogLevel.Info, "Cannot find settings group: {0}/{1}", request.Group, request.Version); return; } var settings = store.GetSettingsValues(group, null, null); if (!settings.ContainsKey(request.Property)) { Platform.Log(LogLevel.Info, "Cannot find settings property: {0}/{1}/{2}", request.Group, request.Version, request.Property); return; } var value = settings[request.Property]; File.WriteAllText(dataFile, value); Platform.Log(LogLevel.Info, "Setting value written to {0}", value); }
public void RunApplication(string[] args) { var cmdLine = new GetSettingCommandLine(); try { cmdLine.Parse(args); using (new AuthenticationScope(cmdLine.UserName, "setup", Dns.GetHostName(), cmdLine.Password)) { ISettingsStore store; try { store = SettingsStore.Create(); //If there is a store, and it is not online, then settings can't be edited. if (!store.IsOnline) { Platform.Log(LogLevel.Error, "Settings Store is not online, cannot update configuration"); return; } } catch (NotSupportedException) { // There is no central settings store; all settings will be treated as though they were local. Platform.Log(LogLevel.Error, "No Enterprise settings store, cannot update configuration"); return; } var setting = new SettingDefinition { Group = cmdLine.SettingGroup, Property = cmdLine.SettingName, Version = cmdLine.Version, }; SetupHelper.ExportSettingsDefinition(store, setting, cmdLine.SettingData); } } catch (CommandLineException e) { Console.WriteLine(e.Message); Platform.Log(LogLevel.Error, e, "Command line error."); } }