示例#1
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 " + ConfigurationLoader.ClassGenericManager + " . OPTIONAL { ?obj rdfs:label ?label } }";
            query.CommandText += " ORDER BY DESC(?obj)";

            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)
                {
                    try
                    {
                        IGenericIOManager manager     = connect.GetConnection();
                        StoreManagerForm storeManager = new StoreManagerForm(manager);
                        storeManager.MdiParent        = Program.MainForm;
                        storeManager.Show();

                        //Add to Recent Connections
                        Program.MainForm.AddRecentConnection(manager);

                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error Opening Connection " + connect.ToString() + ":\n" + ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            });
        }
示例#2
0
        private void QuickConnectClick(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
                    {
                        IStorageProvider manager    = qc.GetConnection();
                        StoreManagerForm genManager = new StoreManagerForm(manager);
                        genManager.MdiParent = this;
                        genManager.Show();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Unable to load the Connection due to an error: " + ex.Message, "Quick Connect Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
示例#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);
                        }
                    }
                }
            });
        }