private void ScriptProjectFileBrowse(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); if (string.IsNullOrWhiteSpace(ScriptProjectFile)) { dlg.FileName = "*.csproj"; dlg.InitialDirectory = Path.GetDirectoryName(GeneratorConfig.GetConfigurationFilePath()); } else { var scriptProjectFile = Path.GetFullPath(ScriptProjectFile); dlg.FileName = Path.GetFileName(scriptProjectFile); dlg.InitialDirectory = Path.GetDirectoryName(scriptProjectFile); } Nullable <bool> result = dlg.ShowDialog(); if (result == true) { ScriptProjectFile = GeneratorConfig.GetRelativePath(dlg.FileName, AppDomain.CurrentDomain.BaseDirectory); config.Save(); } }
public MainWindow() { InitializeComponent(); var loadProviderDLLs = (ConfigurationManager.AppSettings["LoadProviderDLLs"] ?? "") .Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (var dll in loadProviderDLLs) { try { Assembly.LoadFrom(dll); } catch (Exception ex) { MessageBox.Show("Can't load: " + dll + "\n" + ex.ToString()); } } _connections = new BindingList <GeneratorConfig.Connection>(); _tables = new BindingList <TableItem>(); this.ConnectionsCombo.DataContext = _connections; this.DataContext = this; this.config = GeneratorConfig.Load(); foreach (var connection in config.Connections) { _connections.Add(connection); } if (!config.WebProjectFile.IsEmptyOrNull()) { config.UpdateConnectionsFrom(GetWebConfigLocation(), x => _connections.Add(x)); } if (!string.IsNullOrEmpty(config.CustomTemplates)) { Templates.TemplatePath = config.CustomTemplates; } if (config.CustomSettings != null) { foreach (var pair in config.CustomSettings.OrderBy(x => x.Key)) { if (pair.Value is Boolean) { var binding = new Binding("CustomSettings[" + pair.Key + "]"); binding.Source = this; var checkbox = new CheckBox(); checkbox.SetBinding(CheckBox.IsCheckedProperty, binding); checkbox.Content = Inflector.Inflector.Titleize(pair.Key); checkbox.HorizontalAlignment = HorizontalAlignment.Left; checkbox.Margin = new Thickness(10, 0, 10, 0); checkbox.Click += (s, e) => { CustomSettings[pair.Key] = checkbox.IsChecked; config.Save(); }; GenerationOptions.Children.Add(checkbox); } else { var dockPanel = new DockPanel(); dockPanel.LastChildFill = true; dockPanel.Margin = new Thickness(5); var textBlock = new TextBlock(); textBlock.Margin = new Thickness(0, 0, 4, 0); textBlock.Width = 200; textBlock.Text = Inflector.Inflector.Titleize(pair.Key); dockPanel.Children.Add(textBlock); var binding = new Binding("CustomSettings[" + pair.Key + "]"); binding.Source = this; var textbox = new TextBox(); textbox.SetBinding(TextBox.TextProperty, binding); textbox.TextChanged += (s, e) => { CustomSettings[pair.Key] = textbox.Text; config.Save(); }; dockPanel.Children.Add(textbox); GenerationOptions.Children.Add(dockPanel); DockPanel.SetDock(dockPanel, Dock.Top); DockPanel.SetDock(textBlock, Dock.Left); dockPanel.HorizontalAlignment = HorizontalAlignment.Stretch; } } } }