private void btnImport_Click(object sender, EventArgs e) { try { using (var chooser = new OpenFileDialog()) { chooser.DefaultExt = ".xml"; chooser.Filter = "Xml Files|*.xml|All Files|*.*"; var result = chooser.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { ConnectionProperties props; using (var reader = System.Xml.XmlReader.Create(chooser.OpenFile(), new System.Xml.XmlReaderSettings { CloseInput = true })) { var doc = XDocument.Load(reader); props = connectionPropertiesSerializer.Deserialize(doc.Element("Properties")); } this.LoadFrom(props); } } }catch (Exception ex) { MessageBox.Show("Import failed: " + ex.ToString()); } }
/// <summary> /// Gets the arguments that are passed to the dynamically instantiated driver /// </summary> /// <param name="cxInfo">the serialized connection properties.</param> public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo) { var props = propsSerializer.Deserialize(cxInfo.DriverData); // dynamically create a Mongo database object object mongo = MongoServer.Create(props.ConnectionString); return(new[] { mongo }); }
public ConnectionProperties Deserialize(XElement root) { ConnectionProperties obj = new ConnectionProperties(); var xElement = root.Element("ConnectionString"); if (xElement != null) { obj.ConnectionString = xElement.Value; } //assembly locations xElement = root.Element("AssemblyLocations"); if (xElement != null) { obj.AssemblyLocations = new HashSet <string>(); foreach (var el in xElement.Descendants("Location")) { obj.AssemblyLocations.Add(el.Value); } } //collection type mappings xElement = root.Element("CollectionTypeMappings"); if (xElement != null) { obj.CollectionTypeMappings = new Dictionary <string, HashSet <CollectionTypeMapping> >(); foreach (var db in xElement.Descendants("Database").Where(x => x.Attribute("name") != null)) { var set = new HashSet <CollectionTypeMapping>(); foreach (var coll in db.Descendants("CollectionTypeMapping")) { CollectionTypeMapping newMap = ctmSerializer.Deserialize(coll); set.Add(newMap); } obj.CollectionTypeMappings.Add(db.Attribute("name").Value, set); } } //selected DB xElement = root.Element("SelectedDb"); if (xElement != null) { obj.SelectedDatabase = xElement.Value; } //custom serializers xElement = root.Element("CustomSerializers"); if (xElement != null) { obj.CustomSerializers = new Dictionary <string, string>(); foreach (var serializer in xElement.Descendants("Serializer")) { var key = serializer.Attribute("type").Value; var value = serializer.Attribute("serializer").Value; obj.CustomSerializers[key] = value; } } //additional options xElement = root.Element("AdditionalOptions"); if (xElement != null) { obj.AdditionalOptions = this.additionalOptionsSerializer.Deserialize(xElement); } //Initialization query xElement = root.Element("InitializationQuery"); if (xElement != null) { obj.InitializationQuery = this.linqPadQuerySerializer.Deserialize(xElement); } return(obj); }