/// <summary> /// Creates a connection which is in the open state /// </summary> /// <param name="definition">Definition</param> /// <param name="provider">Storage Provider</param> /// <param name="rootUri">Root URI</param> public Connection(IConnectionDefinition definition, IStorageProvider provider, Uri rootUri) { if (ReferenceEquals(definition, null)) { throw new ArgumentNullException("definition"); } if (ReferenceEquals(rootUri, null)) { throw new ArgumentNullException("rootUri"); } if (ReferenceEquals(provider, null)) { throw new ArgumentNullException("provider"); } this.Definition = definition; this.RootUri = rootUri; this.StorageProvider = provider; this.Created = DateTimeOffset.UtcNow; this.LastModified = this.Created; this.LastOpened = this.Created; this.IsReadOnly = false; // Because when created this way the definition may pertain not to this specific connection // we need to serialize and re-populate the definition to ensure we have the correct information IGraph g = new Graph(); this.SaveConfiguration(g); INode rootNode = g.CreateUriNode(this.RootUri); this.Definition.PopulateFrom(g, rootNode); }
private static void DiscoverTypes(Assembly assm) { Type conDefType = typeof(IConnectionDefinition); foreach (Type t in assm.GetTypes()) { if (conDefType.IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract) { if (_connectionDefTypes.Contains(t)) { //Skip if we've already seen, may happen on a rescan continue; } else { _connectionDefTypes.Add(t); //Try to get the definition type IConnectionDefinition def = null; try { def = Activator.CreateInstance(t) as IConnectionDefinition; } catch { //Ignore Errors } if (def != null) { _defs.Add(def); } } } } }
private void btnConnect_Click(object sender, EventArgs e) { IConnectionDefinition def = this.lstStoreTypes.SelectedItem as IConnectionDefinition; if (def == null) { return; } try { this._connection = def.OpenConnection(); if (this.chkForceReadOnly.Checked) { if (this._connection is IQueryableGenericIOManager) { this._connection = new QueryableReadOnlyConnector((IQueryableGenericIOManager)this._connection); } else { this._connection = new ReadOnlyConnector(this._connection); } } this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Connection to " + def.StoreName + " Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void mnuNewFromExisting_Click(object sender, EventArgs e) { if (this.ActiveMdiChild != null) { if (this.ActiveMdiChild is StoreManagerForm) { IStorageProvider manager = ((StoreManagerForm)this.ActiveMdiChild).Manager; IConnectionDefinition def = ConnectionDefinitionManager.GetDefinition(manager.GetType()); if (def != null) { if (manager is IConfigurationSerializable) { Graph g = new Graph(); ConfigurationSerializationContext ctx = new ConfigurationSerializationContext(g); INode n = g.CreateBlankNode(); ctx.NextSubject = n; ((IConfigurationSerializable)manager).SerializeConfiguration(ctx); def.PopulateFrom(g, n); EditConnectionForm editConn = new EditConnectionForm(def); if (editConn.ShowDialog() == DialogResult.OK) { StoreManagerForm managerForm = new StoreManagerForm(editConn.Connection); this.AddRecentConnection(editConn.Connection); managerForm.MdiParent = this; managerForm.Show(); } return; } } } } MessageBox.Show("The current connection is not editable", "New Connection from Current Error", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void lstStoreTypes_SelectedIndexChanged(object sender, EventArgs e) { IConnectionDefinition def = this.lstStoreTypes.SelectedItem as IConnectionDefinition; if (def != null) { connSettings.Definition = def; } }
/// <summary> /// Loads the connection definition for the connection from the given graph /// </summary> /// <param name="g">Graph</param> public void LoadConfiguration(IGraph g) { g.NamespaceMap.AddNamespace("store", UriFactory.Create(StoreManagerNamespace)); g.NamespaceMap.AddNamespace("dnr", UriFactory.Create(ConfigurationLoader.ConfigurationNamespace)); INode rootNode = g.CreateUriNode(this.RootUri); // First off need to find the definition type (if any) Triple t = g.GetTriplesWithSubjectPredicate(rootNode, g.CreateUriNode("store:definitionType")).FirstOrDefault(); if (t != null && t.Object.NodeType == NodeType.Literal) { String typeString = ((ILiteralNode)t.Object).Value; Type defType = TryGetType(typeString, new string[] { "StoreManager.Core", "dotNetRDF", "dotNetRDF.Data.Virtuoso" }); if (defType != null) { this.Definition = (IConnectionDefinition)Activator.CreateInstance(defType); } } if (ReferenceEquals(this.Definition, null)) { // Have to figure out the definition type another way t = g.GetTriplesWithSubjectPredicate(rootNode, g.CreateUriNode("dnr:type")).FirstOrDefault(); if (t != null && t.Object.NodeType == NodeType.Literal) { String typeString = ((ILiteralNode)t.Object).Value; Type providerType = TryGetType(typeString, new string[] { "StoreManager.Core", "dotNetRDF", "dotNetRDF.Data.Virtuoso" }); if (providerType != null) { IConnectionDefinition temp = ConnectionDefinitionManager.GetDefinitionByTargetType(providerType); if (temp != null) { this.Definition = (IConnectionDefinition)Activator.CreateInstance(temp.GetType()); } } } } if (ReferenceEquals(this.Definition, null)) { throw new ArgumentException("Unable to locate the necessary configuration information to load this connection from the given Graph"); } // Populate information this.Definition.PopulateFrom(g, rootNode); this.LoadInformation(g); }
/// <summary> /// Creates a new connection which will initially be in the closed state /// </summary> /// <param name="definition">Definition</param> /// <param name="rootUri">Root URI</param> public Connection(IConnectionDefinition definition, Uri rootUri) { if (ReferenceEquals(definition, null)) { throw new ArgumentNullException("definition"); } if (ReferenceEquals(rootUri, null)) { throw new ArgumentNullException("rootUri"); } this.Definition = definition; this.RootUri = rootUri; this.Created = DateTimeOffset.UtcNow; this.LastModified = this.Created; this.LastOpened = null; this.IsReadOnly = false; }
private void EditConnection(ListBox lbox) { QuickConnect connect = lbox.SelectedItem as QuickConnect; if (connect == null) { return; } Type t = connect.Type; if (t != null) { IConnectionDefinition def = ConnectionDefinitionManager.GetDefinition(t); if (def != null) { def.PopulateFrom(connect.Graph, connect.ObjectNode); EditConnectionForm edit = new EditConnectionForm(def); if (edit.ShowDialog() == DialogResult.OK) { IStorageProvider manager = edit.Connection; StoreManagerForm storeManager = new StoreManagerForm(manager); storeManager.MdiParent = Program.MainForm; storeManager.Show(); //Add to Recent Connections Program.MainForm.AddRecentConnection(manager); this.Close(); } } else { MessageBox.Show("The selected connection is not editable", "Edit Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("The selected connection is not editable", "Edit Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static IEnumerable <IConnectionDefinition> GetDefinitions() { if (!_init) { Init(); } foreach (Type t in _connectionDefTypes) { IConnectionDefinition def = null; try { def = Activator.CreateInstance(t) as IConnectionDefinition; } catch { //Ignore Errors } if (def != null) { yield return(def); } } }
/// <summary> /// Creates a new Edit Connection Form /// </summary> /// <param name="def">Definition</param> public EditConnectionForm(IConnectionDefinition def) { InitializeComponent(); this.connSettings.Definition = def; this.connSettings.Connected += this.HandleConnected; }
/// <summary> /// Renders the Connection Definition settings as user editable controls /// </summary> /// <param name="def">Definition</param> private void Render(IConnectionDefinition def) { this.lblDescrip.Text = def.StoreDescription; int i = 0; tblSettings.Controls.Clear(); foreach (KeyValuePair <PropertyInfo, ConnectionAttribute> setting in def.OrderBy(s => s.Value.DisplayOrder)) { if (setting.Value.Type != ConnectionSettingType.Boolean) { Label label = new Label(); label.Text = setting.Value.DisplayName + Resources.Colon; label.TextAlign = ContentAlignment.MiddleLeft; tblSettings.Controls.Add(label, 0, i); } switch (setting.Value.Type) { case ConnectionSettingType.String: case ConnectionSettingType.Password: //String/Password so show a Textbox TextBox box = new TextBox(); String s = (String)setting.Key.GetValue(def, null); box.Text = s ?? String.Empty; box.Width = 225; box.Tag = setting.Key; if (setting.Value.Type == ConnectionSettingType.Password) { box.PasswordChar = '*'; } //Add the Event Handler which updates the Definition as the user types box.TextChanged += (_, args) => { var propertyInfo = box.Tag as PropertyInfo; if (propertyInfo != null) { propertyInfo.SetValue(def, box.Text, null); } }; //Show DisplaySuffix if relevant if (!String.IsNullOrEmpty(setting.Value.DisplaySuffix)) { FlowLayoutPanel flow = new FlowLayoutPanel(); flow.Margin = new Padding(0); flow.Controls.Add(box); Label suffix = new Label(); suffix.Text = setting.Value.DisplaySuffix; suffix.AutoSize = true; suffix.TextAlign = ContentAlignment.MiddleLeft; flow.Controls.Add(suffix); flow.WrapContents = false; flow.AutoSize = true; flow.AutoScroll = false; tblSettings.Controls.Add(flow, 1, i); } else { tblSettings.Controls.Add(box, 1, i); } break; case ConnectionSettingType.Boolean: //Boolean so show a Checkbox CheckBox check = new CheckBox(); check.AutoSize = true; check.TextAlign = ContentAlignment.MiddleLeft; check.CheckAlign = ContentAlignment.MiddleLeft; check.Checked = (bool)setting.Key.GetValue(def, null); check.Text = setting.Value.DisplayName; check.Tag = setting.Key; //Add the Event Handler which updates the Definition when the Checkbox changes check.CheckedChanged += (_, args) => { var propertyInfo = check.Tag as PropertyInfo; if (propertyInfo != null) { propertyInfo.SetValue(def, check.Checked, null); } }; this.tblSettings.SetColumnSpan(check, 2); this.tblSettings.Controls.Add(check, 0, i); break; case ConnectionSettingType.Integer: //Integer so show a Numeric Up/Down control NumericUpDown num = new NumericUpDown(); num.ThousandsSeparator = true; num.DecimalPlaces = 0; int val = (int)setting.Key.GetValue(def, null); if (setting.Value.IsValueRestricted) { num.Minimum = setting.Value.MinValue; num.Maximum = setting.Value.MaxValue; } else { num.Minimum = Int32.MinValue; num.Maximum = Int32.MaxValue; } num.Value = val; num.Tag = setting.Key; //Add the Event Handler which updates the Definition as the number changes num.ValueChanged += (_, args) => { var propertyInfo = num.Tag as PropertyInfo; if (propertyInfo != null) { propertyInfo.SetValue(def, (int)num.Value, null); } }; tblSettings.Controls.Add(num, 1, i); break; case ConnectionSettingType.Enum: //Enum so show a ComboBox in DropDownList Mode ComboBox ebox = new ComboBox(); ebox.DropDownStyle = ComboBoxStyle.DropDownList; ebox.DataSource = Enum.GetValues(setting.Key.PropertyType); ebox.SelectedItem = setting.Key.GetValue(def, null); ebox.Tag = setting.Key; //Add the Event Handler which updates the Definition as the selection changes ebox.SelectedIndexChanged += (_, args) => { var propertyInfo = ebox.Tag as PropertyInfo; if (propertyInfo != null) { propertyInfo.SetValue(def, ebox.SelectedItem, null); } }; tblSettings.Controls.Add(ebox, 1, i); break; case ConnectionSettingType.File: //File so show a TextBox and a Browse Button String file = (String)setting.Key.GetValue(def, null); FlowLayoutPanel fileFlow = new FlowLayoutPanel(); fileFlow.Margin = new Padding(0); fileFlow.WrapContents = false; fileFlow.AutoSize = true; fileFlow.AutoScroll = false; TextBox fileBox = new TextBox(); fileBox.Width = 225; fileBox.Text = file ?? String.Empty; fileBox.Width = 225; fileBox.Tag = setting.Key; fileFlow.Controls.Add(fileBox); Button browse = new Button(); browse.Text = Resources.Browse; browse.Tag = setting.Value; fileFlow.Controls.Add(browse); //Add the Event Handler which updates the Definition as the user types fileBox.TextChanged += (_, args) => { var propertyInfo = fileBox.Tag as PropertyInfo; if (propertyInfo != null) { propertyInfo.SetValue(def, fileBox.Text, null); } }; //Add the Event Handler for the Browse Button browse.Click += (_, args) => { ConnectionAttribute attr = browse.Tag as ConnectionAttribute; if (attr == null) { return; } this.ofdBrowse.Title = string.Format(Resources.BrowseFor, attr.DisplayName); this.ofdBrowse.Filter = (String.IsNullOrEmpty(attr.FileFilter) ? "All Files|*.*" : attr.FileFilter); if (this.ofdBrowse.ShowDialog() == DialogResult.OK) { fileBox.Text = this.ofdBrowse.FileName; } }; tblSettings.Controls.Add(fileFlow, 1, i); break; } i++; } }
/// <summary> /// Creates a new Connection Settings Grid that displays the given definition /// </summary> /// <param name="def">Definition</param> public ConnectionSettingsGrid(IConnectionDefinition def) : this() { this.Render(def); this._def = def; }
private void FillConnectionList(IGraph config, ListBox lbox) { SparqlParameterizedString query = new SparqlParameterizedString(); query.Namespaces.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS)); query.Namespaces.AddNamespace("dnr", new Uri(ConfigurationLoader.ConfigurationNamespace)); query.CommandText = "SELECT * WHERE { ?obj a @type . OPTIONAL { ?obj rdfs:label ?label } }"; query.CommandText += " ORDER BY DESC(?obj)"; query.SetParameter("type", config.CreateUriNode(UriFactory.Create(ConfigurationLoader.ClassStorageProvider))); SparqlResultSet results = config.ExecuteQuery(query) as SparqlResultSet; if (results != null) { foreach (SparqlResult r in results) { QuickConnect connect; if (r.HasValue("label") && r["label"] != null) { connect = new QuickConnect(config, r["obj"], r["label"].ToString()); } else { connect = new QuickConnect(config, r["obj"]); } lbox.Items.Add(connect); } } lbox.DoubleClick += new EventHandler((sender, args) => { QuickConnect connect = lbox.SelectedItem as QuickConnect; if (connect != null) { if (Properties.Settings.Default.AlwaysEdit) { IConnectionDefinition def = ConnectionDefinitionManager.GetDefinition(connect.Type); if (def != null) { def.PopulateFrom(connect.Graph, connect.ObjectNode); EditConnectionForm edit = new EditConnectionForm(def); if (edit.ShowDialog() == DialogResult.OK) { IStorageProvider manager = edit.Connection; StoreManagerForm storeManager = new StoreManagerForm(manager); storeManager.MdiParent = Program.MainForm; storeManager.Show(); //Add to Recent Connections Program.MainForm.AddRecentConnection(manager); this.Close(); } } else { MessageBox.Show("Selected Connection is not editable", "Connection Edit Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { try { IStorageProvider manager = connect.GetConnection(); StoreManagerForm storeManager = new StoreManagerForm(manager); storeManager.MdiParent = Program.MainForm; storeManager.Show(); try { //Add to Recent Connections Program.MainForm.AddRecentConnection(manager); } catch { // silently ignore this error? seems like if MaxRecentConnections is hit, there is a bug in removing old connections... } this.Close(); } catch (Exception ex) { MessageBox.Show("Error Opening Connection " + connect.ToString() + ":\n" + ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }); }
/// <summary> /// Creates a new connection which will initially be in the closed state /// </summary> /// <param name="definition">Definition</param> public Connection(IConnectionDefinition definition) : this(definition, CreateRootUri()) { }
public NewConnectionForm(IConnectionDefinition def) : this() { this.lstStoreTypes.SelectedItem = def; }
/// <summary> /// Creates a connection which is in the open state /// </summary> /// <param name="definition">Definition</param> /// <param name="provider">Storage Provider</param> public Connection(IConnectionDefinition definition, IStorageProvider provider) : this(definition, provider, CreateRootUri()) { }
private void QuickEditClick(object sender, EventArgs e) { if (sender == null) { return; } Object tag = null; if (sender is Control) { tag = ((Control)sender).Tag; } else if (sender is ToolStripItem) { tag = ((ToolStripItem)sender).Tag; } else if (sender is Menu) { tag = ((Menu)sender).Tag; } if (tag != null) { if (tag is QuickConnect) { QuickConnect qc = (QuickConnect)tag; try { if (qc.Type != null) { IConnectionDefinition def = ConnectionDefinitionManager.GetDefinition(qc.Type); if (def != null) { def.PopulateFrom(qc.Graph, qc.ObjectNode); EditConnectionForm editConn = new EditConnectionForm(def); if (editConn.ShowDialog() == DialogResult.OK) { IStorageProvider manager = editConn.Connection; StoreManagerForm storeManager = new StoreManagerForm(manager); storeManager.MdiParent = Program.MainForm; storeManager.Show(); //Add to Recent Connections this.AddRecentConnection(manager); this.Close(); } } else { MessageBox.Show("This Connection is not ediatable", "Quick Edit Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("This Connection is not ediatable", "Quick Edit Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show("Unable to edit the Connection due to an error: " + ex.Message, "Quick Edit Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } }