示例#1
0
        /// <summary>
        /// Discovers the Knowledge Bases on a Server asynchronously
        /// </summary>
        /// <param name="callback">Callback to invoke when the operation completes</param>
        /// <param name="state"></param>
        private void Discover(PelletServerReadyCallback callback, Object state)
        {
            //Make the request to the Server Root URL to get the JSON description of the server
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this._serverUri);

            request.Method = "GET";
            request.Accept = ServerDescriptionFormat;

            Tools.HttpDebugRequest(request);

            //Get the response and parse the JSON
            String  jsonText;
            JObject json;

            request.BeginGetResponse(result =>
            {
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);

                Tools.HttpDebugResponse(response);

                //Get and parse the JSON
                jsonText = new StreamReader(response.GetResponseStream()).ReadToEnd();
                json     = JObject.Parse(jsonText);

                response.Close();

                JToken kbs = json.SelectToken("knowledge-bases");
                foreach (JToken kb in kbs.Children())
                {
                    this._kbs.Add(new KnowledgeBase(kb));
                }

                callback(this, state);
            }, null);
        }
示例#2
0
        /// <summary>
        /// Creates a new connection to a Pellet Server
        /// </summary>
        /// <param name="serverUri">Server URI</param>
        /// <param name="callback">Callback to invoke when the connection is ready</param>
        /// <param name="state">State to pass to the callback</param>
        private PelletServer(Uri serverUri, PelletServerReadyCallback callback, Object state)
        {
            if (serverUri == null)
            {
                throw new ArgumentNullException("serverUri", "A Server URI must be specified in order to connect to a Pellet Server");
            }
            this._serverUri = serverUri.AbsoluteUri;
            if (!this._serverUri.EndsWith("/"))
            {
                this._serverUri += "/";
            }

            this.Discover(callback, state);
        }
示例#3
0
        /// <summary>
        /// Creates a new connection to a Pellet Server
        /// </summary>
        /// <param name="serverUri">Server URI</param>
        /// <param name="callback">Callback to invoke when the connection is ready</param>
        /// <param name="state">State to pass to the callback</param>
        private PelletServer(String serverUri, PelletServerReadyCallback callback, Object state)
        {
            if (serverUri == null)
            {
                throw new ArgumentNullException("serverUri", "A Server URI must be specified in order to connect to a Pellet Server");
            }
            if (serverUri.Equals(String.Empty))
            {
                throw new ArgumentException("Server URI cannot be the empty string", "serverUri");
            }
            this._serverUri = serverUri;
            if (!this._serverUri.EndsWith("/"))
            {
                this._serverUri += "/";
            }

            this.Discover(callback, state);
        }
示例#4
0
 /// <summary>
 /// Connects to a Pellet Server instance asynchronously invoking the callback when the connection is ready
 /// </summary>
 /// <param name="serverUri">Server URI</param>
 /// <param name="callback">Callback to invoke when the connection is ready</param>
 /// <param name="state">State to pass to the callback</param>
 public static void Connect(Uri serverUri, PelletServerReadyCallback callback, Object state)
 {
     new PelletServer(serverUri, callback, state);
 }
示例#5
0
 /// <summary>
 /// Connects to a Pellet Server instance asynchronously invoking the callback when the connection is ready
 /// </summary>
 /// <param name="serverUri">Server URI</param>
 /// <param name="callback">Callback to invoke when the connection is ready</param>
 /// <param name="state">State to pass to the callback</param>
 public static void Connect(Uri serverUri, PelletServerReadyCallback callback, Object state)
 {
     new PelletServer(serverUri, callback, state);
 }
示例#6
0
        /// <summary>
        /// Discovers the Knowledge Bases on a Server asynchronously
        /// </summary>
        /// <param name="callback">Callback to invoke when the operation completes</param>
        /// <param name="state"></param>
        private void Discover(PelletServerReadyCallback callback, Object state)
        {
            //Make the request to the Server Root URL to get the JSON description of the server
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this._serverUri);
            request.Method = "GET";
            request.Accept = ServerDescriptionFormat;


#if DEBUG
            if (Options.HttpDebugging)
            {
                Tools.HttpDebugRequest(request);
            }
#endif

            //Get the response and parse the JSON
            String jsonText;
            JObject json;
            request.BeginGetResponse(result =>
                {
                    HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
#if DEBUG
                    if (Options.HttpDebugging)
                    {
                        Tools.HttpDebugResponse(response);
                    }
#endif
                    //Get and parse the JSON
                    jsonText = new StreamReader(response.GetResponseStream()).ReadToEnd();
                    json = JObject.Parse(jsonText);

                    response.Close();

                    JToken kbs = json.SelectToken("knowledge-bases");
                    foreach (JToken kb in kbs.Children())
                    {
                        this._kbs.Add(new KnowledgeBase(kb));
                    }

                    callback(this, state);
                }, null);
        }
示例#7
0
        /// <summary>
        /// Creates a new connection to a Pellet Server
        /// </summary>
        /// <param name="serverUri">Server URI</param>
        /// <param name="callback">Callback to invoke when the connection is ready</param>
        /// <param name="state">State to pass to the callback</param>
        private PelletServer(String serverUri, PelletServerReadyCallback callback, Object state)
        {
            if (serverUri == null) throw new ArgumentNullException("serverUri", "A Server URI must be specified in order to connect to a Pellet Server");
            if (serverUri.Equals(String.Empty)) throw new ArgumentException("Server URI cannot be the empty string", "serverUri");
            this._serverUri = serverUri;
            if (!this._serverUri.EndsWith("/")) this._serverUri += "/";

            this.Discover(callback, state);
        }
示例#8
0
        /// <summary>
        /// Creates a new connection to a Pellet Server
        /// </summary>
        /// <param name="serverUri">Server URI</param>
        /// <param name="callback">Callback to invoke when the connection is ready</param>
        /// <param name="state">State to pass to the callback</param>
        private PelletServer(Uri serverUri, PelletServerReadyCallback callback, Object state)
        {
            if (serverUri == null) throw new ArgumentNullException("serverUri", "A Server URI must be specified in order to connect to a Pellet Server");
            this._serverUri = serverUri.ToString();
            if (!this._serverUri.EndsWith("/")) this._serverUri += "/";

            this.Discover(callback, state);
        }