예제 #1
0
        /// <summary>
        /// Gets the Namespaces used in the Knowledge Base
        /// </summary>
        /// <param name="callback">Callback to invoke when the operation completes</param>
        /// <param name="state">State to be passed to the callback</param>
        public void GetNamespaces(NamespaceCallback callback, Object state)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.Endpoint.Uri);

            request.Method = this.Endpoint.HttpMethods.First();
            request.Accept = "text/json";

            Tools.HttpDebugRequest(request);

            String  jsonText;
            JObject json;

            request.BeginGetResponse(result =>
            {
                using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result))
                {
                    Tools.HttpDebugResponse(response);
                    jsonText = new StreamReader(response.GetResponseStream()).ReadToEnd();
                    json     = JObject.Parse(jsonText);

                    response.Close();
                }

                //Parse the Response into a NamespaceMapper
                NamespaceMapper nsmap = new NamespaceMapper(true);
                foreach (JProperty nsDef in json.Properties())
                {
                    nsmap.AddNamespace(nsDef.Name, UriFactory.Create((String)nsDef.Value));
                }

                callback(nsmap, state);
            }, null);
        }
예제 #2
0
파일: Namespace.cs 프로젝트: jdruin/F5Eagle
        ///////////////////////////////////////////////////////////////////////

        public ReturnCode Traverse(
            NamespaceCallback callback,
            IClientData clientData,
            ref Result error
            )
        {
            CheckDisposed();

            if (callback == null)
            {
                error = "invalid callback";
                return(ReturnCode.Error);
            }

            ReturnCode code;

            code = callback(this, clientData, ref error);

            if (code != ReturnCode.Ok)
            {
                return(code);
            }

            if (children == null)
            {
                return(code);
            }

            if (children.Count == 0)
            {
                return(code);
            }

            foreach (KeyValuePair <string, INamespace> pair in children)
            {
                INamespace child = pair.Value;

                if (child == null)
                {
                    continue;
                }

                code = child.Traverse(callback, clientData, ref error);

                if (code != ReturnCode.Ok)
                {
                    return(code);
                }
            }

            return(code);
        }
예제 #3
0
        /// <summary>
        /// Gets the Namespaces used in the Knowledge Base
        /// </summary>
        /// <param name="callback">Callback to invoke when the operation completes</param>
        /// <param name="state">State to be passed to the callback</param>
        /// <remarks>
        /// If the operation succeeds the callback will be invoked normally, if there is an error the callback will be invoked with a instance of <see cref="AsyncError"/> passed as the state which provides access to the error message and the original state passed in.
        /// </remarks>
        public void GetNamespaces(NamespaceCallback callback, Object state)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.Endpoint.Uri);

            request.Method = this.Endpoint.HttpMethods.First();
            request.Accept = "text/json";

            Tools.HttpDebugRequest(request);

            try
            {
                String  jsonText;
                JObject json;
                request.BeginGetResponse(result =>
                {
                    try
                    {
                        using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result))
                        {
                            Tools.HttpDebugResponse(response);
                            jsonText = new StreamReader(response.GetResponseStream()).ReadToEnd();
                            json     = JObject.Parse(jsonText);

                            response.Close();
                        }

                        //Parse the Response into a NamespaceMapper
                        NamespaceMapper nsmap = new NamespaceMapper(true);
                        foreach (JProperty nsDef in json.Properties())
                        {
                            nsmap.AddNamespace(nsDef.Name, UriFactory.Create((String)nsDef.Value));
                        }

                        callback(nsmap, state);
                    }
                    catch (WebException webEx)
                    {
                        if (webEx.Response != null)
                        {
                            Tools.HttpDebugResponse((HttpWebResponse)webEx.Response);
                        }
                        callback(null, new AsyncError(new RdfReasoningException("A HTTP error occurred while communicating with the Pellet Server, see inner exception for details", webEx), state));
                    }
                    catch (Exception ex)
                    {
                        callback(null, new AsyncError(new RdfReasoningException("An unexpected error occurred while communicating with the Pellet Server, see inner exception for details", ex), state));
                    }
                }, null);
            }
            catch (WebException webEx)
            {
                if (webEx.Response != null)
                {
                    Tools.HttpDebugResponse((HttpWebResponse)webEx.Response);
                }
                callback(null, new AsyncError(new RdfReasoningException("A HTTP error occurred while communicating with the Pellet Server, see inner exception for details", webEx), state));
            }
            catch (Exception ex)
            {
                callback(null, new AsyncError(new RdfReasoningException("An unexpected error occurred while communicating with the Pellet Server, see inner exception for details", ex), state));
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the Namespaces used in the Knowledge Base
        /// </summary>
        /// <param name="callback">Callback to invoke when the operation completes</param>
        /// <param name="state">State to be passed to the callback</param>
        public void GetNamespaces(NamespaceCallback callback, Object state)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.Endpoint.Uri);
            request.Method = this.Endpoint.HttpMethods.First();
            request.Accept = "text/json";

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

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

                        response.Close();
                    }

                    //Parse the Response into a NamespaceMapper
                    NamespaceMapper nsmap = new NamespaceMapper(true);
                    foreach (JProperty nsDef in json.Properties())
                    {
                        nsmap.AddNamespace(nsDef.Name, UriFactory.Create((String)nsDef.Value));
                    }

                    callback(nsmap, state);
                }, null);
        }