Exemple #1
0
 /// <summary>
 /// Adds a connection
 /// </summary>
 /// <param name="connection">Connection</param>
 public virtual void Add(Connection connection)
 {
     if (this._connections.Contains(connection))
     {
         return;
     }
     if (!ConnectionInstancePool.Contains(connection))
     {
         ConnectionInstancePool.Add(connection);
     }
     this._connections.Add(connection);
     connection.PropertyChanged += this._handler;
     this.RaiseAdded(connection);
     this.Save();
 }
Exemple #2
0
        /// <summary>
        /// Loads the connections from the underlying graph
        /// </summary>
        protected virtual void Load()
        {
            this._connections.Clear();
            if (this.Graph.Triples.Count == 0)
            {
                return;
            }

            SparqlParameterizedString query = new SparqlParameterizedString();

            query.Namespaces.AddNamespace("dnr", new Uri(ConfigurationLoader.ConfigurationNamespace));

            query.CommandText = "SELECT * WHERE { ?connection a @type . }";

            Graph g = new Graph();

            query.SetParameter("type", g.CreateUriNode(UriFactory.Create(ConfigurationLoader.ClassStorageProvider)));

            SparqlResultSet results = this.Graph.ExecuteQuery(query) as SparqlResultSet;

            if (results == null)
            {
                return;
            }
            foreach (SparqlResult r in results)
            {
                INode connectionNode = r["connection"];
                if (connectionNode.NodeType != NodeType.Uri)
                {
                    continue;
                }
                Uri connectionUri = ((IUriNode)connectionNode).Uri;

                Connection connection;
                if (!ConnectionInstancePool.TryGetInstance(connectionUri, out connection))
                {
                    connection = new Connection(this.Graph, connectionUri);
                    ConnectionInstancePool.Add(connection);
                }
                this._connections.Add(connection);
                connection.PropertyChanged += this._handler;
            }
        }