public ConnectionProperties() { AssemblyLocations = new HashSet <string>(); CollectionTypeMappings = new Dictionary <string, HashSet <CollectionTypeMapping> >(); CustomSerializers = new Dictionary <string, string>(); AdditionalOptions = new ConnectionAdditionalOptions(); }
public bool Equals(ConnectionAdditionalOptions other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (!Equals(BlanketIgnoreExtraElements, other.BlanketIgnoreExtraElements)) { return(false); } if (!Equals(AllowSaveForAllTypes, other.AllowSaveForAllTypes)) { return(false); } if (!ExplicitSaveEqualityComparer.Equals(this.ExplicitSaveAllowedTypes, other.ExplicitSaveAllowedTypes)) { return(false); } return(true); }
/// <summary> /// Checks to see if the data changed from save, and if so, prompts the user. /// </summary> /// <returns>True if the form should close, False if the form should stay open.</returns> private bool DoCancel() { var working = new ConnectionAdditionalOptions(); this.Populate(working); if (!working.Equals(this.mProps.AdditionalOptions)) { var result = MessageBox.Show("Changes have been made. Do you want to save first?", "Cancel", MessageBoxButtons.YesNoCancel); if (result == System.Windows.Forms.DialogResult.No) { this.DialogResult = System.Windows.Forms.DialogResult.Cancel; return(true); } else if (result == System.Windows.Forms.DialogResult.Cancel) { return(false); } else if (result == System.Windows.Forms.DialogResult.Yes) { return(this.DoSave()); } return(false); } this.DialogResult = System.Windows.Forms.DialogResult.Cancel; return(true); }
/// <summary> /// Populates the Connection Options with the current values in the form controls /// </summary> /// <param name="options"></param> private void Populate(ConnectionAdditionalOptions options) { options.AllowSaveForAllTypes = this.cbAllowSave.Checked; options.BlanketIgnoreExtraElements = this.cbBlanketIgnoreExtraElements.Checked; options.ExplicitSaveAllowedTypes.AddRange(this.lbSaveAllowedTypes.Items.Cast <string>()); }
public ConnectionAdditionalOptions Clone() { var ret = new ConnectionAdditionalOptions(); ret.AllowSaveForAllTypes = this.AllowSaveForAllTypes; ret.BlanketIgnoreExtraElements = this.BlanketIgnoreExtraElements; ret.ExplicitSaveAllowedTypes.AddRange(this.ExplicitSaveAllowedTypes); return(ret); }
/// <summary> /// validates and saves the data to the connection /// </summary> /// <returns>true if the data successfully saved, false if the form should stay open</returns> private bool DoSave() { var options = new ConnectionAdditionalOptions(); this.Populate(options); this.SelectedOptions = options; this.DialogResult = System.Windows.Forms.DialogResult.OK; return(true); }
private void additionalOptionsToolStripMenuItem1_Click(object sender, EventArgs e) { ConnectionProperties props = new ConnectionProperties(); this.Populate(props); using (var frm = new AdditionalOptions(props, this.LoadedTypes)) { frm.Name = "Additional Options"; DialogResult result = frm.ShowDialog(); if (result == DialogResult.OK) { this.mAdditionalOptions = frm.SelectedOptions; } } }
public ConnectionDialog(ConnectionProperties props, bool isNewConnection, Func <string, Assembly> loadSafely) { this.mConnection = props; this.mAdditionalOptions = props.AdditionalOptions.Clone(); this.mIsNewConnection = isNewConnection; this.loadSafely = loadSafely; InitializeComponent(); this.SetLoadedQueryName(null); if (!this.mIsNewConnection) { this.LoadFrom(props); } else { this.UpdateLoadedAssemblies(); } }
/// <summary> /// loads the saved connection properties into the form /// </summary> private void LoadFrom(ConnectionProperties props) { this.txtConnectionString.Text = props.ConnectionString; this.LoadedAssemblies = props.AssemblyLocations.ToDictionary(loc => loc, loc => { if (!File.Exists(loc)) { return(null); } else { return(this.loadSafely(loc)); } }); this.LoadedTypes.Clear(); this.LoadedTypes.AddRange(MongoDynamicDataContextDriver.CommonTypes.Values); var badAssemblies = new HashSet <Assembly>(); this.LoadedTypes.AddRange(this.LoadedAssemblies.Values.Where(x => x != null) .SelectMany(ass => { try { return(ass.GetExportedTypes()); } catch (Exception) { badAssemblies.Add(ass); return(Enumerable.Empty <Type>()); } })); foreach (var badAssembly in badAssemblies) { var key = this.LoadedAssemblies.First(x => x.Value == badAssembly).Key; this.LoadedAssemblies[key] = null; } this.mDatabases = new Dictionary <string, HashSet <CollectionTypeMapping> >(); foreach (var pair in props.CollectionTypeMappings) { this.mDatabases[pair.Key] = new HashSet <CollectionTypeMapping>(pair.Value); } this.cbDatabases.Items.Clear(); this.cbDatabases.Items.AddRange(this.mDatabases.Keys.Cast <object>().ToArray()); string db = this.mDatabases.Keys.FirstOrDefault(); this.cbDatabases.SelectedItem = db; if (db != null) { this.dgCollectionTypes.DataSource = this.mDatabases[db].Select(m => new TypeMappingWrapper(m)).ToList(); } else { this.dgCollectionTypes.DataSource = null; } if (props.SelectedDatabase != null) { this.cbDatabases.SelectedIndex = this.cbDatabases.Items.IndexOf(props.SelectedDatabase); } this.lbCustomSerializers.Items.Clear(); this.SerializerMappings.Clear(); if (props.CustomSerializers != null) { foreach (var pair in props.CustomSerializers) { var keyType = this.LoadedTypes.FirstOrDefault(x => string.Equals(pair.Key, x.FullName)); var valType = this.LoadedTypes.FirstOrDefault(x => string.Equals(pair.Value, x.FullName)); if (keyType != null && valType != null) { this.SerializerMappings[keyType] = valType; } } } this.lbCustomSerializers.Items.AddRange(this.SerializerMappings.Select(pair => new SerializerMappingWrapper { Type = pair.Key, Serializer = pair.Value }).Cast <object>().ToArray()); this.mAdditionalOptions = props.AdditionalOptions; this.mInitializationQuery = props.InitializationQuery; if (this.mInitializationQuery != null) { this.SetLoadedQueryName(Path.GetFileName(this.mInitializationQuery.Location)); } UpdateLoadedAssemblies(); }