コード例 #1
0
        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);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
                        }
                    }
                }
            });
        }
コード例 #4
0
        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);
                    }
                }
            }
        }