public DataSetHelper(Type datasettype, Type tableadaptermanagertype, Type queriestableadaptertype, string connectionstringname, System.Configuration.ApplicationSettingsBase settings) { if (datasettype == null || tableadaptermanagertype == null) { throw new ArgumentNullException(); } Settings = settings; ConnectionStringName = connectionstringname; _dataSetType = datasettype; _tableAdapterManagerType = tableadaptermanagertype; _queriesTableAdapterType = queriestableadaptertype; DataSet = Activator.CreateInstance(_dataSetType) as DataSet; TableAdapterManager = null; QueriesTableAdapter = null; if (_tableAdapterManagerType != null) { TableAdapterManager = Activator.CreateInstance(_tableAdapterManagerType) as Component; } if (_queriesTableAdapterType != null) { QueriesTableAdapter = Activator.CreateInstance(_queriesTableAdapterType) as Component; } }
public static void LoadUIText(this Form form, System.Configuration.ApplicationSettingsBase settings) { if (form != null) { LoadUIText(form.Controls, settings); } }
public static void Maintain(this Form @this, System.Configuration.ApplicationSettingsBase settings, string recPropertyId, bool checkWorkingArea = true) { @this.Load += (sender, args) => { Rectangle rec = (Rectangle)settings[recPropertyId]; if (checkWorkingArea) { if (partVisible(rec) < 0.01) { return; } } if (!rec.IsEmpty) { @this.Location = rec.Location; @this.Size = rec.Size; } }; @this.Closing += (sender, args) => { Point loc = @this.Location; var s = @this.WindowState == FormWindowState.Normal ? @this.Size : @this.RestoreBounds.Size; settings[recPropertyId] = new Rectangle(loc, s); settings.Save(); }; }
static public IRDB Create(System.Configuration.ApplicationSettingsBase settings, IREncoding encoding = IREncoding.HEX, String dbnameKey = null) { IRDB db = dbnameKey != null?DB.Create <IRDB>(settings, dbnameKey) : DB.Create <IRDB>(settings); db.Encoding = encoding; return(db); }
public static void FensterEinstellung(System.Windows.Window Fenster, System.Configuration.ApplicationSettingsBase Setting) { if (Setting["FensterEinstellung"] != null) { Fenster.Closing += (sen, erg) => { Setting["FensterEinstellung"] = $"{Fenster.Top};{Fenster.Left};{Fenster.Width};{Fenster.Height};{(byte)Fenster.WindowState}"; }; var props = Setting["FensterEinstellung"].ToString().Split(new char[] { ';' }); if (props.Length == 5) { try { var oben = Convert.ToDouble(props[0]); var links = Convert.ToDouble(props[1]); var breite = Convert.ToDouble(props[2]); var hoehe = Convert.ToDouble(props[3]); var status = (System.Windows.WindowState)Convert.ToByte(props[4]); Fenster.Top = oben; Fenster.Left = links; Fenster.Width = breite; Fenster.Height = hoehe; Fenster.WindowState = status; } catch { } } } }
public static void BackupUserConfigSettings(System.Configuration.ApplicationSettingsBase settings, string fileName, string settingsPath, string backupPath) { if (settings == null || string.IsNullOrWhiteSpace(fileName)) { return; } var settingsFileName = Path.GetFileNameWithoutExtension(fileName); var settingsFileExt = Path.GetExtension(fileName); var settingsFile = IOUtils.NormalizePath(Path.Combine(settingsPath, $"{fileName}")); try { // save the settings file to a json settings file var jsonSettings = new JsonSerializerSettings { ContractResolver = new UserScopedSettingContractResolver() }; JsonUtils.Serialize(settings, settingsFile, jsonSettings); } catch (Exception) { // do nothing, just exit } if (!string.IsNullOrWhiteSpace(backupPath)) { // create a backup of the settings file var backupFile = IOUtils.NormalizePath(Path.Combine(backupPath, $"{settingsFileName}_{DateTime.UtcNow.ToString("yyyyMMdd_HHmmss")}{settingsFileExt}")); try { if (!Directory.Exists(backupPath)) { Directory.CreateDirectory(backupPath); } File.Copy(settingsFile, backupFile); } catch (Exception) { // do nothing, just exit } var filesToDelete = new DirectoryInfo(backupPath).GetFiles($"{settingsFileName}_*{settingsFileExt}").Where(f => f.LastWriteTimeUtc.AddDays(7) < DateTime.UtcNow).ToArray(); foreach (var fileToDelete in filesToDelete) { try { fileToDelete.Delete(); } catch (Exception) { // do nothing, just exit } } } }
public void ApplyAppSettingMetadataDictionary(System.Configuration.ApplicationSettingsBase _SettingsCollection) { PropertyOverridingTypeDescriptor ctd = new PropertyOverridingTypeDescriptor(TypeDescriptor.GetProvider(_SettingsCollection).GetTypeDescriptor(_SettingsCollection)); // iterate through properies in the supplied object/type foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(_SettingsCollection)) { // for every property that complies to our criteria AppSettingMetadata asmd; bool found = this.TryGetValue(pd.Name, out asmd); if (found) { // we first construct the custom PropertyDescriptor with the TypeDescriptor's // built-in capabilities Attribute[] attribute_list = new Attribute[2]; attribute_list[0] = new CategoryAttribute(asmd.SettingCategory); attribute_list[1] = new DescriptionAttribute(asmd.SettingDescription); PropertyDescriptor pd2 = TypeDescriptor.CreateProperty( _SettingsCollection.GetType(), // or just _settings, if it's already a type pd, // base property descriptor to which we want to add attributes // The PropertyDescriptor which we'll get will just wrap that // base one returning attributes we need. attribute_list //new CategoryAttribute(asmd.SettingCategory) // this method really can take as many attributes as you like, // not just one ); //PropertyDescriptor pd3 = // TypeDescriptor.CreateProperty( // _SettingsCollection.GetType(), // or just _settings, if it's already a type // pd, // base property descriptor to which we want to add attributes // // The PropertyDescriptor which we'll get will just wrap that // // base one returning attributes we need. // new DescriptionAttribute(asmd.SettingDescription) // // this method really can take as many attributes as you like, // // not just one // ); // and then we tell our new PropertyOverridingTypeDescriptor to override that property ctd.OverrideProperty(pd2); //ctd.OverrideProperty(pd3); } } // then we add new descriptor provider that will return our descriptor instead of default TypeDescriptor.AddProvider(new TypeDescriptorOverridingProvider(ctd), _SettingsCollection); }
public static bool TryGetValue <T>(this System.Configuration.ApplicationSettingsBase settings, string key, out T value) { if (settings.Properties[key] != null) { value = (T)settings[key]; return(true); } value = default(T); return(false); }
// PortableSettingsProvider code obtained from http://stackoverflow.com/a/2579399 (Accessed 02-01-2014 @ 17:04). private static void MakeSettingsPortable(System.Configuration.ApplicationSettingsBase settings) { var portableSettingsProvider = new PortableSettingsProvider(settings.GetType().Name + ".settings"); settings.Providers.Add(portableSettingsProvider); foreach (System.Configuration.SettingsProperty prop in settings.Properties) { prop.Provider = portableSettingsProvider; } settings.Reload(); }
public void Localize( System.Configuration.ApplicationSettingsBase applicationSettings) { try { teklaObject.Localize(applicationSettings); } catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException ex) { throw DynamicAPINotFoundException.CouldNotFindMethod(nameof(Localize), ex); } }
public void Configure(System.Configuration.ApplicationSettingsBase settings, String[] keys) { if (keys == null || keys.Length != 4) { throw new Exception("Incorrect number of keys ... must be 4"); } var pwd = Chetch.Utilities.BasicEncryption.Decrypt((String)settings[keys[3]], "dbpasswd"); Configure((String)settings[keys[0]], (String)settings[keys[1]], (String)settings[keys[2]], pwd); }
static public D Create <D>(System.Configuration.ApplicationSettingsBase settings, String[] keys) where D : DB, new() { var db = new D(); db.Configure(settings, keys); db.Initialize(); try { db.OpenConnection(); } finally { db.CloseConnection(); } return(db); }
public static void CommonSettings(System.Configuration.ApplicationSettingsBase settings) { try { Abnaki.Windows.Software.Wpf.Diplomat.Troubleshooter.Email = (string)settings["TroubleShooterEmail"]; string suri = (string)settings["UpgradeUri"]; if (false == string.IsNullOrEmpty(suri)) { Abnaki.Windows.Software.Wpf.Ultimate.MainMenuBus.UpgradeUri = new Uri(suri); } } catch (Exception ex) { Abnaki.Windows.AbnakiLog.Exception(ex); } }
public DataSetHelper(DataSet dataset, Component tableadaptermanager, Component queriestableadapter, string connectionstringname, System.Configuration.ApplicationSettingsBase settings) { if (dataset == null || tableadaptermanager == null) { throw new ArgumentNullException(); } Settings = settings; ConnectionStringName = connectionstringname; DataSet = dataset; TableAdapterManager = tableadaptermanager; QueriesTableAdapter = queriestableadapter; _dataSetType = DataSet.GetType(); _tableAdapterManagerType = TableAdapterManager.GetType(); }
public static void MigrateSettings(System.Configuration.ApplicationSettingsBase settings, string settingsFile) { if (settings == null || string.IsNullOrWhiteSpace(settingsFile) || !File.Exists(settingsFile)) { return; } try { // read the json settings file to a settings file var jsonSettings = new JsonSerializerSettings { //ContractResolver = new UserScopedSettingContractResolver(), }; JsonUtils.PopulateFromFile(settingsFile, settings, jsonSettings); } catch (Exception) { // do nothing, just exit } }
/// <summary> /// 화면 요소 Text 설정 /// </summary> /// <param name="rootControl">컨트롤 객체 집합</param> /// <param name="settings">설정 객체</param> public static void LoadUIText(this Control.ControlCollection rootControl, System.Configuration.ApplicationSettingsBase settings) { if ((rootControl != null) && (settings != null)) { //TODO: 사용자 설정 PropertyValues 생성 if (settings.PropertyValues.Count == 0) { using (System.Windows.Forms.PropertyGrid pg = new PropertyGrid()) { pg.SelectedObject = settings; } } foreach (System.Configuration.SettingsProperty p in settings.Properties) { string name = string.Copy(p.Name); string value = string.Empty; if (settings.PropertyValues.Count > 0) { value = settings.PropertyValues[name].PropertyValue.ToString(); } else { value = p.DefaultValue.ToString(); } foreach (Control control in rootControl) { if (LoadUIText(control, name, value)) { break; } } } } }
static public GPSDB Create(System.Configuration.ApplicationSettingsBase settings) { GPSDB db = DB.Create <GPSDB>(settings); return(db); }
static public EngineRoomServiceDB Create(System.Configuration.ApplicationSettingsBase settings, String dbnameKey = null) { EngineRoomServiceDB db = dbnameKey != null?DB.Create <EngineRoomServiceDB>(settings, dbnameKey) : DB.Create <EngineRoomServiceDB>(settings); return(db); }
static public new BBMediaServiceDB Create(System.Configuration.ApplicationSettingsBase settings, String dbnameKey = null) { BBMediaServiceDB db = dbnameKey != null?DB.Create <BBMediaServiceDB>(settings, dbnameKey) : DB.Create <BBMediaServiceDB>(settings); return(db); }
public static void LoadToolTips(ToolTip toolTip, Control.ControlCollection rootControl, System.Configuration.ApplicationSettingsBase target) { if (target != null) { //TODO: 사용자 설정 PropertyValues 생성 if (target.PropertyValues.Count == 0) { using (System.Windows.Forms.PropertyGrid pg = new PropertyGrid()) { pg.SelectedObject = target; } } foreach (System.Configuration.SettingsProperty p in target.Properties) { string name = string.Copy(p.Name); string value = string.Empty; if (target.PropertyValues.Count > 0) { value = target.PropertyValues[name].PropertyValue.ToString(); } else { value = p.DefaultValue.ToString(); } if (rootControl != null) { foreach (Control control in rootControl) { if (LoadToolTips(toolTip, control, name, value)) { break; } } } } } }
/// <summary> /// Your Window should call this before showing the virtual keyboard, if you want it to remember which language it was set to. /// </summary> /// <param name="appSettings">Your application's Settings object</param> public static void SaveStateToMySettings(System.Configuration.ApplicationSettingsBase appSettings) { _appSettings = appSettings; }
public static bool ContainsKey(this System.Configuration.ApplicationSettingsBase settings, string key) { return(settings.Properties[key] != null); }
static public D Create <D>(System.Configuration.ApplicationSettingsBase settings, String dbnameKey) where D : DB, new() { var keys = new String[] { "DBServer", dbnameKey, "DBUsername", "DBPassword" }; return(Create <D>(settings, keys)); }
public static void SetValue <T>(this System.Configuration.ApplicationSettingsBase settings, string key, T value) { settings[key] = value; settings.Save(); }
public void Dispose() { ConnectionNames = null; ConnectionStrings = null; SettingsBase = null; }
public ConfigEditor(System.Configuration.ApplicationSettingsBase settings) : this() { this.settings = settings; }