static void Main(string[] args) { ConsoleColor old = Console.ForegroundColor; try{ var props = new ConnectionProperties(); using (var frm = new ConnectionDialog(props, true, Assembly.LoadFrom)) { var result = frm.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) return; } var cxi = new FakeConnection(); new ConnectionPropertiesSerializer().Serialize(cxi.DriverData, props); var driver = new MongoDynamicDataContextDriver(); List<Assembly> assemblies = props.AssemblyLocations.Select(Assembly.LoadFrom).ToList(); var code = driver.GetStaticCodeFiles() .Concat(new string[] {driver.GenerateDynamicCode(props, assemblies, "", "driver")}); if(props.InitializationQuery != null) code = code.Concat(new string[]{driver.GenerateCustomInitQuery(props.InitializationQuery, "driver")}); Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine("------------------------------------------------"); foreach (string s in code) { Console.WriteLine(s); Console.WriteLine("------------------------------------------------"); } Console.ForegroundColor = old; using (var frm = new SaveFileDialog()) { var result = frm.ShowDialog(); if (result == DialogResult.OK) { using (StreamWriter writer = new StreamWriter(frm.OpenFile())) { foreach (string s in code) { writer.WriteLine(s); writer.WriteLine("---------------------------------------------------"); } writer.Flush(); } } } }catch(Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex); } finally{ Console.ForegroundColor = old; } }
private void ShowAddAllowTypeDialog() { IEnumerable <Type> typesInTree; if (string.IsNullOrEmpty(mProps.SelectedDatabase)) { typesInTree = this.mLoadedTypes; } else { HashSet <String> visibleTypes = new HashSet <string>(mProps.CollectionTypeMappings[mProps.SelectedDatabase].Select(x => x.CollectionType).Where(x => x != null)); typesInTree = mLoadedTypes.Where(x => visibleTypes.Contains(x.ToString()) || //backwards compatibility (x.AssemblyQualifiedName != null && visibleTypes.Contains(x.AssemblyQualifiedName))); } TreeNode[] nodes = ConnectionDialog.MakeTree(typesInTree); using (var selector = new SingleTypeSelector(nodes)) { selector.Name = "Select Type to allow Save"; DialogResult result = selector.ShowDialog(); if (result == DialogResult.OK) { this.lbSaveAllowedTypes.Items.Add(selector.SelectedType.ToString()); } } }
/// <summary> /// LinqPad calls this to display the Connection Options dialog & generate the connection /// properties. /// </summary> /// <param name="cxInfo">the serialized connection properties.</param> /// <param name="isNewConnection">True if this is a brand new connection</param> /// <returns>true if the connection dialog completed successfully</returns> public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) { ConnectionProperties props; if (isNewConnection) { props = new ConnectionProperties(); } else { props = propsSerializer.Deserialize(cxInfo.DriverData); } using (var form = new ConnectionDialog(props, isNewConnection, LoadAssemblySafely)) { var result = form.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { propsSerializer.Serialize(cxInfo.DriverData, props); cxInfo.DisplayName = string.Format("{0} ({1})", props.SelectedDatabase, props.ConnectionString); return(true); } } return(false); }
/// <summary> /// LinqPad calls this to display the Connection Options dialog & generate the connection /// properties. /// </summary> /// <param name="cxInfo">the serialized connection properties.</param> /// <param name="isNewConnection">True if this is a brand new connection</param> /// <returns>true if the connection dialog completed successfully</returns> public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) { ConnectionProperties props; if(isNewConnection) { props = new ConnectionProperties(); } else { props = propsSerializer.Deserialize(cxInfo.DriverData); } using(var form = new ConnectionDialog(props, isNewConnection, LoadAssemblySafely)) { var result = form.ShowDialog(); if(result == System.Windows.Forms.DialogResult.OK) { propsSerializer.Serialize(cxInfo.DriverData, props); cxInfo.DisplayName = string.Format("{0} ({1})", props.SelectedDatabase, props.ConnectionString); return true; } } return false; }