Exemplo n.º 1
0
        public void DiscoInfoQuery(jabber.JID to, string node, bool refresh, QueryCallback callback, object state)
        {
            if (!refresh) {
                IQ cache_version = XmppGlobal.InternalQueryCache.DiscoInfo[to.ToString () + "!!!!!" + node];

                if (cache_version != null) {
                    callback.Invoke (this, cache_version, state);
                    return;
                }
            }

            DiscoInfoIQ iq = XmppGlobal.Queries.CreateDiscoInfoQuery ();
            iq.To = to;

            if (!string.IsNullOrEmpty (node))
                iq.Node = node;

            XmppGlobal.Queries.SendQuery (iq, callback, state);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Query a method with the provided arguments for a character.
        /// </summary>
        /// <typeparam name="T">The type of the deserialization object.</typeparam>
        /// <param name="method"></param>
        /// <param name="userID"></param>
        /// <param name="apiKey"></param>
        /// <param name="charID"></param>
        /// <param name="callback">The callback to invoke once the query has been completed. It will be done on the data actor (see <see cref="DataObject.CommonActor"/>).</param>
        public void QueryMethodAsync <T>(APIMethods method, long userID, string apiKey, long charID, QueryCallback <T> callback)
        {
            HttpPostData postData = new HttpPostData("userID=" + userID + "&apiKey=" + apiKey + "&characterID=" + charID.ToString());

            QueryMethodAsync <T>(method, postData, RowsetsTransform, callback);
        }
Exemplo n.º 3
0
 public QueryBuilder WhereInSub(string column, QueryCallback callback, Conditional condition, bool not)
 {
     return(WhereInSub(new Column(column), callback, condition, not));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Processes a SPARQL Query asynchronously passing the results to the relevant handler and invoking the callback when the query completes
 /// </summary>
 /// <param name="rdfHandler">RDF Handler</param>
 /// <param name="resultsHandler">Results Handler</param>
 /// <param name="query">SPARQL Query</param>
 /// <param name="callback">Callback</param>
 /// <param name="state">State to pass to the callback</param>
 public void ProcessQuery(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, SparqlQuery query, QueryCallback callback, Object state)
 {
     ProcessQueryAsync d = new ProcessQueryAsync(this.ProcessQuery);
     d.BeginInvoke(rdfHandler, resultsHandler, query, r =>
     {
         d.EndInvoke(r);
         callback(rdfHandler, resultsHandler, state);
     }, state);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Processes a SPARQL Query against the Knowledge Base passing the results to the RDF or Results handler as appropriate
        /// </summary>
        /// <param name="rdfHandler">RDF Handler</param>
        /// <param name="resultsHandler">Results Handler</param>
        /// <param name="sparqlQuery">SPARQL Query</param>
        /// <param name="callback">Callback to invoke once handling of results has completed</param>
        /// <param name="state">State to pass to the callback</param>
        public void Query(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, String sparqlQuery, QueryCallback callback, Object state)
        {
            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery q = parser.ParseFromString(sparqlQuery);

            SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(UriFactory.Create(this._sparqlUri));
            switch (q.QueryType)
            {
                case SparqlQueryType.Ask:
                case SparqlQueryType.Select:
                case SparqlQueryType.SelectAll:
                case SparqlQueryType.SelectAllDistinct:
                case SparqlQueryType.SelectAllReduced:
                case SparqlQueryType.SelectDistinct:
                case SparqlQueryType.SelectReduced:
                    endpoint.QueryWithResultSet(sparqlQuery, (rs, _) =>
                        {
                            resultsHandler.Apply(rs);
                            callback(rdfHandler, resultsHandler, state);
                        }, state);
                    break;
                case SparqlQueryType.Construct:
                case SparqlQueryType.Describe:
                case SparqlQueryType.DescribeAll:
                    endpoint.QueryWithResultGraph(sparqlQuery, (g, _) =>
                        {
                            rdfHandler.Apply(g);
                            callback(rdfHandler, resultsHandler, state);
                        }, state);
                    break;

                default:
                    throw new RdfQueryException("Cannot execute unknown query types against Pellet Server");
            }
        }
 public void GetItemMetaDataAsync(int itemId, QueryCallback queryCallback)
 {
     string body = SQLGetItemMetaData(itemId);
     queryCallback(body);
 }
Exemplo n.º 7
0
 public CallbackState(QueryCallback cb, object state)
 {
     this.callback = cb;
     this.state = state;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Evaluates an FQL (Facebook Query Language) query.
 /// </summary>
 /// <typeparam name="T">The generic type should be an object that wraps the returned type.  Some like users_getInfo_response</typeparam>
 /// <param name="query">The query to perform, as described in the FQL documentation.</param>
 /// <param name="callback">The AsyncCallback delegate</param>
 /// <param name="state">An object containing state information for this asynchronous request</param>
 /// <returns>This method returns data that very closely resembles the returns of other API calls like users.getInfo. This is not a coincidence - in fact, many of the other API functions are simply wrappers for FQL queries. Note that it preserves the order of the fields in your SELECT clause and that it can contain multiple elements with the same name depending on how you structure the query.</returns>
 public void QueryAsync <T>(string query, QueryCallback <T> callback, Object state)
 {
     Query <T>(query, true, callback, state);
 }
Exemplo n.º 9
0
 public ThreadQueue.TaskControl Query(string query, QueryCallback callback, object state)
 {
     return(ThreadQueue.QueueUserWorkItem(new ThreadQueue.WorkCallback(CreateQuery), new WaitCallback(CreateQueryComplete), new QueryState(query, callback, state)));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Performs the query to the provider, passing the required arguments.
 /// </summary>
 /// <param name="provider">The API provider to use.</param>
 /// <param name="callback">The callback invoked on the UI thread after a result has been queried.</param>
 protected override void QueryAsyncCore(APIProvider provider, QueryCallback <T> callback)
 {
     provider.QueryMethodAsync <T>(m_method, m_account.UserID, m_account.APIKey, callback);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Evaluates an FQL (Facebook Query Language) query.
 /// </summary>
 /// <example>
 /// <code>
 /// private static void RunDemoAsync()
 /// {
 ///     Api api = new Api(new DesktopSession(Constants.ApplicationKey, Constants.ApplicationSecret, Constants.SessionSecret, Constants.SessionKey));
 ///     var query = string.Format("SELECT uid, name FROM user WHERE uid IN ({0})", Constants.UserId);
 ///     api.Fql.QueryAsync(query, AsyncDemoCompleted, null);
 /// }
 ///
 /// private static void AsyncDemoCompleted(string result, Object state, FacebookException e)
 /// {
 ///     var actual = result;
 /// }
 /// </code>
 /// </example>
 /// <param name="query">The query to perform, as described in the FQL documentation.</param>
 /// <param name="callback">The AsyncCallback delegate</param>
 /// <param name="state">An object containing state information for this asynchronous request</param>
 /// <returns>This method returns data that very closely resembles the returns of other API calls like users.getInfo. This is not a coincidence - in fact, many of the other API functions are simply wrappers for FQL queries. Note that it preserves the order of the fields in your SELECT clause and that it can contain multiple elements with the same name depending on how you structure the query.</returns>
 public void QueryAsync(string query, QueryCallback callback, Object state)
 {
     Query(query, true, callback, state);
 }
Exemplo n.º 12
0
 public PolyShapesCallback(IDrawer drawer)
 {
     _drawer  = drawer;
     Count    = 0;
     Callback = ReportFixture;
 }
Exemplo n.º 13
0
 /// <summary>Stop listening for specific types of Queries through typeof(Element).</summary>
 public void Unregister(Type et, QueryCallback method)
 {
   lock(_demux) {
     _demux[et] -= method;
   }
 }
Exemplo n.º 14
0
 /// <summary>Listen to a specific type of Query through typeof(Element).</summary>
 public void Register(Type et, QueryCallback method)
 {
   lock(_demux) {
     if(!_demux.ContainsKey(et)) {
       _demux[et] = method;
     } else {
       _demux[et] += method;
     }
   }
 }
Exemplo n.º 15
0
        /// <summary>
        /// Processes a SPARQL Query against the Knowledge Base passing the results to the RDF or Results handler as appropriate.
        /// </summary>
        /// <param name="rdfHandler">RDF Handler.</param>
        /// <param name="resultsHandler">Results Handler.</param>
        /// <param name="sparqlQuery">SPARQL Query.</param>
        /// <param name="callback">Callback to invoke once handling of results has completed.</param>
        /// <param name="state">State to pass 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 Query(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, String sparqlQuery, QueryCallback callback, Object state)
        {
            SparqlQueryParser parser = new SparqlQueryParser();
            SparqlQuery       q      = parser.ParseFromString(sparqlQuery);

            SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(UriFactory.Create(_sparqlUri));

            switch (q.QueryType)
            {
            case SparqlQueryType.Ask:
            case SparqlQueryType.Select:
            case SparqlQueryType.SelectAll:
            case SparqlQueryType.SelectAllDistinct:
            case SparqlQueryType.SelectAllReduced:
            case SparqlQueryType.SelectDistinct:
            case SparqlQueryType.SelectReduced:
                endpoint.QueryWithResultSet(sparqlQuery, (rs, s) =>
                {
                    resultsHandler.Apply(rs);
                    callback(rdfHandler, resultsHandler, s);
                }, state);
                break;

            case SparqlQueryType.Construct:
            case SparqlQueryType.Describe:
            case SparqlQueryType.DescribeAll:
                endpoint.QueryWithResultGraph(sparqlQuery, (g, s) =>
                {
                    rdfHandler.Apply(g);
                    callback(rdfHandler, resultsHandler, s);
                }, state);
                break;

            default:
                throw new RdfQueryException("Cannot execute unknown query types against Pellet Server");
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Processes a SPARQL Query asynchronously passing the results to the relevant handler and invoking the callback when the query completes
        /// </summary>
        /// <param name="rdfHandler">RDF Handler</param>
        /// <param name="resultsHandler">Results Handler</param>
        /// <param name="query">SPARQL Query</param>
        /// <param name="callback">Callback</param>
        /// <param name="state">State to pass to the callback</param>
        public void ProcessQuery(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, SparqlQuery query, QueryCallback callback, Object state)
        {
            ProcessQueryAsync d = new ProcessQueryAsync(this.ProcessQuery);

            d.BeginInvoke(rdfHandler, resultsHandler, query, r =>
            {
                d.EndInvoke(r);
                callback(rdfHandler, resultsHandler, state);
            }, state);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Processes a SPARQL Query asynchronously passing the results to the relevant handler and invoking the callback when the query completes
        /// </summary>
        /// <param name="rdfHandler">RDF Handler</param>
        /// <param name="resultsHandler">Results Handler</param>
        /// <param name="query">SPARQL Query</param>
        /// <param name="callback">Callback</param>
        /// <param name="state">State to pass to the callback</param>
        /// <remarks>
        /// In the event of a success the callback will be invoked, if there is an error the callback will be invoked and passed an instance of <see cref="AsyncError"/> which contains details of the error and the original state information passed in.
        /// </remarks>
        public void ProcessQuery(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, SparqlQuery query, QueryCallback callback, Object state)
        {
            ProcessQueryAsync d = new ProcessQueryAsync(ProcessQuery);

            d.BeginInvoke(rdfHandler, resultsHandler, query, r =>
            {
                try
                {
                    d.EndInvoke(r);
                    callback(rdfHandler, resultsHandler, state);
                }
                catch (RdfQueryException queryEx)
                {
                    callback(rdfHandler, resultsHandler, new AsyncError(queryEx, state));
                }
                catch (Exception ex)
                {
                    callback(rdfHandler, resultsHandler, new AsyncError(new RdfQueryException("Unexpected error making an asynchronous query", ex), state));
                }
            }, state);
        }
Exemplo n.º 18
0
 public void Query(string query, QueryCallback callback, object state)
 {
     ThreadQueue.QueueUserWorkItem(new ThreadQueue.WorkCallback(CreateQuery), new WaitCallback(CreateQueryComplete), new QueryState(query, callback, state));
 }
Exemplo n.º 19
0
 /// <summary>
 /// Query a method without arguments.
 /// </summary>
 /// <typeparam name="T">The type of the deserialization object.</typeparam>
 /// <param name="method"></param>
 /// <param name="callback">The callback to invoke once the query has been completed. It will be done on the data actor (see <see cref="DataObject.CommonActor"/>).</param>
 public void QueryMethodAsync <T>(APIMethods method, QueryCallback <T> callback)
 {
     QueryMethodAsync <T>(method, null, RowsetsTransform, callback);
 }
Exemplo n.º 20
0
 public QueryState(string sql, QueryCallback callback, object state)
 {
     this.sql      = sql;
     this.callback = callback;
     this.state    = state;
 }
Exemplo n.º 21
0
        /// <summary>
        /// Makes a Query asynchronously where the expected Result is a <see cref="SparqlResultSet">SparqlResultSet</see> i.e. SELECT and ASK Queries
        /// </summary>
        /// <param name="query">SPARQL Query String</param>
        /// <param name="handler">Results Handler</param>
        /// <param name="callback">Callback to invoke when the query completes</param>
        /// <param name="state">State to pass to the callback</param>
        public void QueryWithResultSet(ISparqlResultsHandler handler, String query, QueryCallback callback, Object state)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.Uri);
            request.Method = "POST";
            request.ContentType = MimeTypesHelper.WWWFormURLEncoded;
            request.Accept = MimeTypesHelper.HttpSparqlAcceptHeader;

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

            request.BeginGetRequestStream(result =>
            {
                Stream stream = request.EndGetRequestStream(result);
                using (StreamWriter writer = new StreamWriter(stream))
                {
                    writer.Write("query=");
                    writer.Write(HttpUtility.UrlEncode(query));

                    foreach (String u in this.DefaultGraphs)
                    {
                        writer.Write("&default-graph-uri=");
                        writer.Write(Uri.EscapeDataString(u));
                    }
                    foreach (String u in this.NamedGraphs)
                    {
                        writer.Write("&named-graph-uri=");
                        writer.Write(Uri.EscapeDataString(u));
                    }

                    writer.Close();
                }

                request.BeginGetResponse(innerResult =>
                {
                    using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(innerResult))
                    {
            #if DEBUG
                        if (Options.HttpDebugging)
                        {
                            Tools.HttpDebugResponse(response);
                        }
            #endif
                        ISparqlResultsReader parser = MimeTypesHelper.GetSparqlParser(response.ContentType, false);
                        parser.Load(handler, new StreamReader(response.GetResponseStream()));

                        response.Close();
                        callback(null, handler, state);
                    }
                }, null);
            }, null);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Processes a SPARQL Query asynchronously passing the results to the relevant handler and invoking the callback when the query completes
        /// </summary>
        /// <param name="rdfHandler">RDF Handler</param>
        /// <param name="resultsHandler">Results Handler</param>
        /// <param name="query">SPARQL Query</param>
        /// <param name="callback">Callback</param>
        /// <param name="state">State to pass to the callback</param>
        public void ProcessQuery(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, SparqlQuery query, QueryCallback callback, Object state)
        {
            query.QueryExecutionTime = null;
            DateTime start = DateTime.Now;

            try
            {
                this._svc.Query(rdfHandler, resultsHandler, query.ToString(), callback, state);
            }
            finally
            {
                TimeSpan elapsed = (DateTime.Now - start);
                query.QueryExecutionTime = (DateTime.Now - start);
            }
        }
Exemplo n.º 23
0
		public QueryState(string sql, QueryCallback callback, object state){
			this.sql = sql; 
			this.callback = callback;
			this.state = state;
		}
Exemplo n.º 24
0
 /**
    * Query the world for all fixtures that potentially overlap the provided AABB.
    *
    * @param callback a user implemented callback class.
    * @param aabb the query box.
    */
 public void queryAABB(QueryCallback callback, AABB aabb)
 {
     wqwrapper.broadPhase = m_contactManager.m_broadPhase;
     wqwrapper.callback = callback;
     m_contactManager.m_broadPhase.query(wqwrapper, aabb);
 }
Exemplo n.º 25
0
        public virtual bool MouseDown(b2Vec2 p)
        {
            m_mouseWorld = p;

            if (m_mouseJoint != null)
            {
                return false;
            }

            // Make a small box.
            b2AABB aabb = new b2AABB();
            b2Vec2 d = new b2Vec2();
            d.Set(0.001f, 0.001f);
            aabb.LowerBound = p - d;
            aabb.UpperBound = p + d;

            // Query the world for overlapping shapes.
            QueryCallback callback = new QueryCallback(p);
            m_world.QueryAABB(callback, aabb);

            if (callback.m_fixture != null)
            {
                b2Body body = callback.m_fixture.Body;
                b2MouseJointDef md = new b2MouseJointDef();
                md.BodyA = m_groundBody;
                md.BodyB = body;
                md.target = p;
                md.maxForce = 1000.0f * body.Mass;
                m_mouseJoint = (b2MouseJoint) m_world.CreateJoint(md);
                body.SetAwake(true);
                return true;
            }
            return false;
        }
Exemplo n.º 26
0
 /**
    * Query the world for all fixtures and particles that potentially overlap the provided AABB.
    *
    * @param callback a user implemented callback class.
    * @param particleCallback callback for particles.
    * @param aabb the query box.
    */
 public void queryAABB(QueryCallback callback, ParticleQueryCallback particleCallback, AABB aabb)
 {
     wqwrapper.broadPhase = m_contactManager.m_broadPhase;
     wqwrapper.callback = callback;
     m_contactManager.m_broadPhase.query(wqwrapper, aabb);
     m_particleSystem.queryAABB(particleCallback, aabb);
 }
Exemplo n.º 27
0
	public void Query(string query, QueryCallback callback, object state)
	{
		ThreadQueue.QueueUserWorkItem(new ThreadQueue.WorkCallback(CreateQuery), new WaitCallback(CreateQueryComplete), new QueryState(query,callback,state));
	}
Exemplo n.º 28
0
        /// <summary>
        /// Asynchronously download an XML and deserializes it into the specified type.
        /// </summary>
        /// <typeparam name="T">The inner type to deserialize</typeparam>
        /// <param name="url">The url to query</param>
        /// <param name="postData">The HTTP POST data to send, may be null.</param>
        /// <param name="transform">The XSL transform to apply, may be null.</param>
        /// <param name="callback">The callback to call once the query has been completed. It will be done on the data actor (see <see cref="DataObject.CommonActor"/>).</param>
        internal static void DownloadAPIResultAsync <T>(string url, HttpPostData postData, XslCompiledTransform transform, QueryCallback <T> callback)
        {
            EveClient.HttpWebService.DownloadXmlAsync(url, postData, (asyncResult, userState) =>
            {
                APIResult <T> result;

                // Was there an HTTP error ?
                if (asyncResult.Error != null)
                {
                    result = new APIResult <T>(asyncResult.Error);
                }
                // No http error, let's try to deserialize
                else
                {
                    result = DeserializeAPIResultCore <T>(transform, asyncResult.Result);
                }

                // We got the result, let's invoke the callback on this actor
                Dispatcher.Invoke(() => callback.Invoke(result));
            },
                                                      null);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Makes a Query asynchronously where the expected Result is an RDF Graph ie. CONSTRUCT and DESCRIBE Queries
        /// </summary>
        /// <param name="query">SPARQL Query String</param>
        /// <param name="handler">RDF Handler</param>
        /// <param name="callback">Callback to invoke when the query completes</param>
        /// <param name="state">State to pass to the callback</param>
        public void QueryWithResultGraph(IRdfHandler handler, String query, QueryCallback callback, Object state)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Uri);

            request.Method      = "POST";
            request.ContentType = MimeTypesHelper.Utf8WWWFormURLEncoded;
            request.Accept      = ResultsAcceptHeader;
            ApplyRequestOptions(request);
            Tools.HttpDebugRequest(request);

            request.BeginGetRequestStream(result =>
            {
                try
                {
                    Stream stream = request.EndGetRequestStream(result);
                    using (StreamWriter writer = new StreamWriter(stream, new UTF8Encoding(Options.UseBomForUtf8)))
                    {
                        writer.Write("query=");
                        writer.Write(HttpUtility.UrlEncode(query));

                        foreach (String u in DefaultGraphs)
                        {
                            writer.Write("&default-graph-uri=");
                            writer.Write(HttpUtility.UrlEncode(u));
                        }
                        foreach (String u in NamedGraphs)
                        {
                            writer.Write("&named-graph-uri=");
                            writer.Write(HttpUtility.UrlEncode(u));
                        }

                        writer.Close();
                    }

                    request.BeginGetResponse(innerResult =>
                    {
                        try
                        {
                            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(innerResult);
                            Tools.HttpDebugResponse(response);
                            IRdfReader parser = MimeTypesHelper.GetParser(response.ContentType);
                            parser.Load(handler, new StreamReader(response.GetResponseStream()));

                            callback(handler, null, state);
                        }
                        catch (SecurityException secEx)
                        {
                            callback(handler, null, new AsyncError(new RdfQueryException("Calling code does not have permission to access the specified remote endpoint, see inner exception for details", secEx), state));
                        }
                        catch (WebException webEx)
                        {
                            if (webEx.Response != null)
                            {
                                Tools.HttpDebugResponse((HttpWebResponse)webEx.Response);
                            }
                            callback(handler, null, new AsyncError(new RdfQueryException("A HTTP error occurred while making an asynchronous query, see inner exception for details", webEx), state));
                        }
                        catch (Exception ex)
                        {
                            callback(handler, null, new AsyncError(new RdfQueryException("Unexpected error while making an asynchronous query, see inner exception for details", ex), state));
                        }
                    }, null);
                }
                catch (SecurityException secEx)
                {
                    callback(handler, null, new AsyncError(new RdfQueryException("Calling code does not have permission to access the specified remote endpoint, see inner exception for details", secEx), state));
                }
                catch (WebException webEx)
                {
                    if (webEx.Response != null)
                    {
                        Tools.HttpDebugResponse((HttpWebResponse)webEx.Response);
                    }
                    callback(handler, null, new AsyncError(new RdfQueryException("A HTTP error occurred while making an asynchronous query, see inner exception for details", webEx), state));
                }
                catch (Exception ex)
                {
                    callback(handler, null, new AsyncError(new RdfQueryException("Unexpected error while making an asynchronous query, see inner exception for details", ex), state));
                }
            }, null);
        }
Exemplo n.º 30
0
 public void SendQuery(IQ iq, QueryCallback callback, object state)
 {
     XmppGlobal.InternalTracker.BeginIQ (iq, new jabber.connection.IqCB (GotQueryResponse), new CallbackState (callback, state));
 }
Exemplo n.º 31
0
        /// <summary>
        /// Asynchrnoneously queries this method with the provided HTTP POST data
        /// </summary>
        /// <typeparam name="T">The subtype to deserialize (the deserialized type being <see cref="APIResult{T}"/>).</typeparam>
        /// <param name="method">The method to query</param>
        /// <param name="postData">The http POST data</param>
        /// <param name="callback">The callback to invoke once the query has been completed. It will be done on the data actor (see <see cref="DataObject.CommonActor"/>).</param>
        /// <param name="transform">The XSL transform to apply, may be null.</param>
        private void QueryMethodAsync <T>(APIMethods method, HttpPostData postData, XslCompiledTransform transform, QueryCallback <T> callback)
        {
            // Check callback not null
            if (callback == null)
            {
                throw new ArgumentNullException("The callback cannot be null.", "callback");
            }

            // Lazy download
            string url = GetMethodUrl(method);

            Util.DownloadAPIResultAsync <T>(url, postData, transform, (result) =>
            {
                // On failure with a custom method, fallback to CCP
                if (ShouldRetryWithCCP(result))
                {
                    result = s_ccpProvider.QueryMethod <T>(method, postData, transform);
                }

                // If the result is a character sheet, we store the result
                if (method == APIMethods.CharacterSheet && !result.HasError)
                {
                    SerializableAPICharacter sheet = (SerializableAPICharacter)(Object)result.Result;
                    LocalXmlCache.Save(sheet.Name, result.XmlDocument);
                }

                // Invokes the callback
                callback(result);
            });
        }
		/// <summary>
		/// Execute select on sql database
		/// Close returned datareader when done or use using(reader) { ... }
		/// </summary>
		/// <param name="sqlcommand"></param>
		/// <param name="callback"></param>
		public void ExecuteSelect(string sqlcommand, QueryCallback callback, Transaction.IsolationLevel isolation)
		{
			if (connType == ConnectionType.DATABASE_MYSQL)
			{
				if (log.IsDebugEnabled)
				{
					log.Debug("SQL: " + sqlcommand);
				}

				bool repeat = false;
				do
				{
					repeat = false;

					using (var conn = new MySqlConnection(connString))
					{
						using (var cmd = conn.CreateCommand())
						{
							try
							{
							    cmd.CommandText = sqlcommand;
								conn.Open();
							    long start = (DateTime.UtcNow.Ticks / 10000);
							    using (var reader = cmd.ExecuteReader())
							    {
							    	try
							    	{
							        	callback(reader);
							    	}
							    	catch (Exception es)
							    	{
							    		if(log.IsWarnEnabled)
							    			log.Warn("Exception in Select Callback : ", es);
							    	}
							    }
						    
							    if (log.IsDebugEnabled)
									log.Debug("SQL Select (" + isolation + ") exec time " + ((DateTime.UtcNow.Ticks / 10000) - start) + "ms");
								else if ((DateTime.UtcNow.Ticks / 10000) - start > 500 && log.IsWarnEnabled)
									log.Warn("SQL Select (" + isolation + ") took " + ((DateTime.UtcNow.Ticks / 10000) - start) + "ms!\n" + sqlcommand);
							
							}
							catch (Exception e)
							{
								if (!HandleException(e))
								{
									if (log.IsErrorEnabled)
										log.Error("ExecuteSelect: \"" + sqlcommand + "\"\n", e);
									throw;
								}
		
								repeat = true;
							}
						}
					}
					
				}
				while (repeat);

				return;
			}
			else if (connType == ConnectionType.DATABASE_SQLITE)
			{
				if (log.IsDebugEnabled)
				{
					log.Debug("SQL: " + sqlcommand);
				}

				bool repeat = false;
				do
				{
					repeat = false;

					using (var conn = new SQLiteConnection(connString))
					{
					    using (var cmd = new SQLiteCommand(sqlcommand, conn))
						{
							try
							{
						    	conn.Open();
							    
							    long start = (DateTime.UtcNow.Ticks / 10000);
							    using (var reader = cmd.ExecuteReader())
							    {
							    	try
							    	{
							        	callback(reader);
							    	}
							    	catch (Exception es)
							    	{
							    		if(log.IsWarnEnabled)
							    			log.Warn("Exception in Select Callback : ", es);
							    	}
							    	finally
							    	{
							    		reader.Close();
							    	}
							    }
						    
							    if (log.IsDebugEnabled)
									log.Debug("SQL Select (" + isolation + ") exec time " + ((DateTime.UtcNow.Ticks / 10000) - start) + "ms");
								else if ((DateTime.UtcNow.Ticks / 10000) - start > 500 && log.IsWarnEnabled)
									log.Warn("SQL Select (" + isolation + ") took " + ((DateTime.UtcNow.Ticks / 10000) - start) + "ms!\n" + sqlcommand);
							
							}
							catch (Exception e)
							{
								if (!HandleException(e))
								{
									if (log.IsErrorEnabled)
										log.Error("ExecuteSelect: \"" + sqlcommand + "\"\n", e);
									throw;
								}
		
								repeat = true;
							}
							finally
							{
								conn.Close();
							}
					    }
					}
					
				}
				while (repeat);

				return;
			}

			if (log.IsWarnEnabled)
				log.Warn("SQL Selects not supported for this connection type");
		}
Exemplo n.º 33
0
 /// <summary>
 /// Processes a SPARQL Query asynchronously passing the results to the relevant handler and invoking the callback when the query completes.
 /// </summary>
 /// <param name="rdfHandler">RDF Handler.</param>
 /// <param name="resultsHandler">Results Handler.</param>
 /// <param name="query">SPARQL Query.</param>
 /// <param name="callback">Callback.</param>
 /// <param name="state">State to pass to the callback.</param>
 /// <remarks>
 /// In the event of a success the callback will be invoked, if there is an error the callback will be invoked and passed an instance of <see cref="AsyncError"/> which contains details of the error and the original state information passed in.
 /// </remarks>
 public void ProcessQuery(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, SparqlQuery query, QueryCallback callback, object state)
 {
     Task.Factory.StartNew(() => ProcessQuery(rdfHandler, resultsHandler, query))
     .ContinueWith(antecedent =>
     {
         if (antecedent.Exception != null)
         {
             var innerException = antecedent.Exception.InnerExceptions[0];
             var queryException = innerException as RdfQueryException ??
                                  new RdfQueryException(
                 "Unexpected error while making an asynchronous query, see inner exception for details",
                 innerException);
             callback?.Invoke(rdfHandler, resultsHandler, new AsyncError(queryException, state));
         }
         else
         {
             callback?.Invoke(rdfHandler, resultsHandler, state);
         }
     });
 }
Exemplo n.º 34
0
		/// <summary>
		/// Execute select on sql database
		/// Close returned datareader when done or use using(reader) { ... }
		/// </summary>
		/// <param name="sqlcommand"></param>
		/// <param name="callback"></param>
		public void ExecuteSelect(string sqlcommand, QueryCallback callback, Transaction.IsolationLevel isolation)
		{
			if (connType == ConnectionType.DATABASE_MYSQL)
			{
				if (log.IsDebugEnabled)
				{
					log.Debug("SQL: " + sqlcommand);
				}

				bool repeat = false;
				MySqlConnection conn = null;
				do
				{
					bool isNewConnection = true;
					try
					{
						conn = GetMySqlConnection(out isNewConnection);

						long start = Environment.TickCount;

						var cmd = new MySqlCommand(sqlcommand, conn);
						MySqlDataReader reader = cmd.ExecuteReader();
						callback(reader);
						reader.Close();

						if (log.IsDebugEnabled)
							log.Debug("SQL Select (" + isolation + ") exec time " + (Environment.TickCount - start) + "ms");
						else if (Environment.TickCount - start > 500 && log.IsWarnEnabled)
							log.Warn("SQL Select (" + isolation + ") took " + (Environment.TickCount - start) + "ms!\n" + sqlcommand);

						ReleaseConnection(conn);

						repeat = false;
					}
					catch (Exception e)
					{
						if (conn != null)
						{
							conn.Close();
						}

						if (!HandleException(e) || isNewConnection)
						{
							if (log.IsErrorEnabled)
								log.Error("ExecuteSelect: \"" + sqlcommand + "\"\n", e);
							throw;
						}

						repeat = true;
					}
				} while (repeat);

				return;
			}

			if (log.IsWarnEnabled)
				log.Warn("SQL Selects not supported for this connection type");
		}
Exemplo n.º 35
0
 public void GetItemBodyAsync(int itemId, QueryCallback queryCallback)
 {
     string body = SQLGetItemBody(itemId);
     queryCallback(body);
 }
Exemplo n.º 36
0
        /// <summary>
        /// Processes a SPARQL Query asynchronously passing the results to the relevant handler and invoking the callback when the query completes
        /// </summary>
        /// <param name="rdfHandler">RDF Handler</param>
        /// <param name="resultsHandler">Results Handler</param>
        /// <param name="query">SPARQL Query</param>
        /// <param name="callback">Callback</param>
        /// <param name="state">State to pass to the callback</param>
        /// <remarks>
        /// In the event of a success the callback will be invoked, if there is an error the callback will be invoked and passed an instance of <see cref="AsyncError"/> which contains details of the error and the original state information passed in.
        /// </remarks>
        public void ProcessQuery(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, SparqlQuery query, QueryCallback callback, Object state)
        {
            query.QueryExecutionTime = null;
            DateTime start = DateTime.Now;

            try
            {
                switch (query.QueryType)
                {
                case SparqlQueryType.Ask:
                case SparqlQueryType.Select:
                case SparqlQueryType.SelectAll:
                case SparqlQueryType.SelectAllDistinct:
                case SparqlQueryType.SelectAllReduced:
                case SparqlQueryType.SelectDistinct:
                case SparqlQueryType.SelectReduced:
                    this._endpoint.QueryWithResultSet(resultsHandler, this._formatter.Format(query), callback, state);
                    break;

                case SparqlQueryType.Construct:
                case SparqlQueryType.Describe:
                case SparqlQueryType.DescribeAll:
                    this._endpoint.QueryWithResultGraph(rdfHandler, this._formatter.Format(query), callback, state);
                    break;

                default:
                    throw new RdfQueryException("Unable to execute an unknown query type against a Remote Endpoint");
                }
            }
            finally
            {
                TimeSpan elapsed = (DateTime.Now - start);
                query.QueryExecutionTime = elapsed;
            }
        }
Exemplo n.º 37
0
 /// <summary>
 /// Performs the query to the provider, passing the required arguments.
 /// </summary>
 /// <param name="provider">The API provider to use.</param>
 /// <param name="callback">The callback invoked on the UI thread after a result has been queried.</param>
 protected virtual void QueryAsyncCore(APIProvider provider, QueryCallback <T> callback)
 {
     provider.QueryMethodAsync <T>(m_method, callback);
 }
Exemplo n.º 38
0
 internal static extern int Foreach(IntPtr query, QueryCallback cb, IntPtr userData);
Exemplo n.º 39
0
        public void RequestVCard(QueryCallback callback, object state, bool forceRefresh)
        {
            jabber.protocol.client.IQ cached = XmppGlobal.InternalQueryCache.VCard[jid];

            if (!forceRefresh && cached != null) {
                if (callback != null)
                    callback.Invoke (this, cached, state);
            } else {
                jabber.protocol.iq.VCardIQ iq = new jabber.protocol.iq.VCardIQ (XmppGlobal.InternalClient.Document);
                iq.To = jid;

                XmppGlobal.InternalTracker.BeginIQ (iq, new jabber.connection.IqCB (GotVCardResponse), new CallbackState (callback, state));
            }
        }
Exemplo n.º 40
0
    // TODO: create proxy, destory proxy, move proxy

    public void Query(BoundingVolume bounds, QueryCallback callback)
    {
        // TODO: Query method
    }
        void HandleServerQueryResponse( IPacketMsg packetMsg )
        {
            var queryResponse = new ClientMsgProtobuf<CMsgGMSClientServerQueryResponse>( packetMsg );

#if STATIC_CALLBACKS
            var innerCallback = new QueryCallback( Client, queryResponse.Body );
            var callback = new SteamClient.JobCallback<QueryCallback>( Client, queryResponse.TargetJobID, innerCallback );
            SteamClient.PostCallback( callback );
#else
            var innerCallback = new QueryCallback( queryResponse.Body );
            var callback = new SteamClient.JobCallback<QueryCallback>( queryResponse.TargetJobID, innerCallback );
            Client.PostCallback( callback );
#endif
        }
Exemplo n.º 42
0
 public QueryBuilder Where(QueryCallback callback, Conditional condition = Conditional.And)
 {
     return(WhereNested(callback, condition));
 }
Exemplo n.º 43
0
 /// <summary>
 /// Processes a SPARQL Query asynchronously passing the results to the relevant handler and invoking the callback when the query completes
 /// </summary>
 /// <param name="rdfHandler">RDF Handler</param>
 /// <param name="resultsHandler">Results Handler</param>
 /// <param name="query">SPARQL Query</param>
 /// <param name="callback">Callback</param>
 /// <param name="state">State to pass to the callback</param>
 public void ProcessQuery(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, SparqlQuery query, QueryCallback callback, Object state)
 {
     query.QueryExecutionTime = null;
     DateTime start = DateTime.Now;
     try
     {
         switch (query.QueryType)
         {
             case SparqlQueryType.Ask:
             case SparqlQueryType.Select:
             case SparqlQueryType.SelectAll:
             case SparqlQueryType.SelectAllDistinct:
             case SparqlQueryType.SelectAllReduced:
             case SparqlQueryType.SelectDistinct:
             case SparqlQueryType.SelectReduced:
                 this._endpoint.QueryWithResultSet(resultsHandler, this._formatter.Format(query), callback, state);
                 break;
             case SparqlQueryType.Construct:
             case SparqlQueryType.Describe:
             case SparqlQueryType.DescribeAll:
                 this._endpoint.QueryWithResultGraph(rdfHandler, this._formatter.Format(query), callback, state);
                 break;
             default:
                 throw new RdfQueryException("Unable to execute an unknown query type against a Remote Endpoint");
         }
     }
     finally
     {
         TimeSpan elapsed = (DateTime.Now - start);
         query.QueryExecutionTime = elapsed;
     }
 }
Exemplo n.º 44
0
 public QueryBuilder OrWhere(QueryCallback callback)
 {
     return(WhereNested(callback, Conditional.Or));
 }
Exemplo n.º 45
0
 public void Query(QueryCallback callback)
 {
     NativeImports.tio_container_query(
         _nativeContainerHandle,
         0,
         0,
         null,
         delegate(int result,
         IntPtr handle,
         IntPtr cookie,
         uint queryid,
         string containerName,
         ref NativeImports.TIO_DATA key,
         ref NativeImports.TIO_DATA value,
         ref NativeImports.TIO_DATA metadata)
         {
             callback(
                 NativeImports.TioDataConverter.ToObject(key),
                 NativeImports.TioDataConverter.ToObject(value),
                 NativeImports.TioDataConverter.ToObject(metadata));
         },
         IntPtr.Zero);
 }
Exemplo n.º 46
0
 public QueryBuilder WhereSubQuery(string column, Is op, QueryCallback callback, Conditional condition)
 {
     return(WhereSubQuery(new Column(column), op, callback, condition));
 }
Exemplo n.º 47
0
	public ThreadQueue.TaskControl Query(string query, QueryCallback callback, object state)
	{
		return ThreadQueue.QueueUserWorkItem(new ThreadQueue.WorkCallback(CreateQuery), new WaitCallback(CreateQueryComplete), new QueryState(query,callback,state));
	}
Exemplo n.º 48
0
 public QueryBuilder OrWhereExists(QueryCallback callback, bool not = false)
 {
     return(WhereExists(callback, Conditional.Or, not));
 }
Exemplo n.º 49
0
        void HandleServerQueryResponse( IPacketMsg packetMsg )
        {
            var queryResponse = new ClientMsgProtobuf<CMsgGMSClientServerQueryResponse>( packetMsg );

            var callback = new QueryCallback(queryResponse.TargetJobID, queryResponse.Body);
            Client.PostCallback( callback );
        }
Exemplo n.º 50
0
 public QueryBuilder WhereNotExists(QueryCallback callback, Conditional condition = Conditional.And)
 {
     return(WhereExists(callback, condition, true));
 }
Exemplo n.º 51
0
        // Exécute un Select (bloquand) et retourn le DataSet correspondant
        public void ExecuteSelect(string sqlcommand, QueryCallback callback, IsolationLevel isolation)
        {
            if (connType == ConnectionType.DATABASE_MYSQL)
            {
               Log.Debug("DataConnecion","SQL: " + sqlcommand);

                bool repeat = false;
                MySqlConnection conn = null;
                do
                {
                    bool isNewConnection = true;
                    try
                    {
                        conn = GetMySqlConnection(out isNewConnection);

                        long start = Environment.TickCount;

                        var cmd = new MySqlCommand(sqlcommand, conn);
                        MySqlDataReader reader = cmd.ExecuteReader();
                        callback(reader);
                        reader.Close();

                        Log.Debug("DataConnecion","SQL Select (" + isolation + ") exec time " + (Environment.TickCount - start) + "ms");

                        if (Environment.TickCount - start > 500)
                            Log.Notice("DataConnecion", "SQL Select (" + isolation + ") took " + (Environment.TickCount - start) + "ms!\n" + sqlcommand);

                        ReleaseConnection(conn);

                        repeat = false;
                    }
                    catch (Exception e)
                    {
                        if (conn != null)
                        {
                            conn.Close();
                        }

                        if (!HandleException(e) || isNewConnection)
                        {
                            Log.Error("DataConnecion", "ExecuteSelect: \"" + sqlcommand + "\"\n" + e.ToString() );
                            return;
                        }

                        repeat = true;
                    }
                } while (repeat);

                return;
            }

            Log.Notice("DataConnecion", "SQL Selects not supported");
        }
Exemplo n.º 52
0
 public QueryBuilder OrWhereNotExists(QueryCallback callback)
 {
     return(OrWhereExists(callback, true));
 }
Exemplo n.º 53
0
 /// <summary>
 /// Processes a SPARQL Query asynchronously passing the results to the relevant handler and invoking the callback when the query completes
 /// </summary>
 /// <param name="rdfHandler">RDF Handler</param>
 /// <param name="resultsHandler">Results Handler</param>
 /// <param name="query">SPARQL Query</param>
 /// <param name="callback">Callback</param>
 /// <param name="state">State to pass to the callback</param>
 public void ProcessQuery(IRdfHandler rdfHandler, ISparqlResultsHandler resultsHandler, SparqlQuery query, QueryCallback callback, Object state)
 {
     query.QueryExecutionTime = null;
     DateTime start = DateTime.Now;
     try
     {
         this._svc.Query(rdfHandler, resultsHandler, query.ToString(), callback, state);
     }
     finally
     {
         TimeSpan elapsed = (DateTime.Now - start);
         query.QueryExecutionTime = (DateTime.Now - start);
     }
 }
Exemplo n.º 54
0
        /// <summary>
        /// Execute select on sql database
        /// Close returned datareader when done or use using(reader) { ... }
        /// </summary>
        /// <param name="sqlcommand"></param>
        /// <param name="callback"></param>
        public void ExecuteSelect(string sqlcommand, QueryCallback callback, Transaction.IsolationLevel isolation)
        {
            if (connType == ConnectionType.DATABASE_MYSQL)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("SQL: " + sqlcommand);
                }

                bool repeat = false;
                do
                {
                    repeat = false;

                    using (var conn = new MySqlConnection(connString))
                    {
                        using (var cmd = conn.CreateCommand())
                        {
                            try
                            {
                                cmd.CommandText = sqlcommand;
                                conn.Open();
                                long start = (DateTime.UtcNow.Ticks / 10000);
                                using (var reader = cmd.ExecuteReader())
                                {
                                    try
                                    {
                                        callback(reader);
                                    }
                                    catch (Exception es)
                                    {
                                        if (log.IsWarnEnabled)
                                        {
                                            log.Warn("Exception in Select Callback : ", es);
                                        }
                                    }
                                }

                                if (log.IsDebugEnabled)
                                {
                                    log.Debug("SQL Select (" + isolation + ") exec time " + ((DateTime.UtcNow.Ticks / 10000) - start) + "ms");
                                }
                                else if ((DateTime.UtcNow.Ticks / 10000) - start > 500 && log.IsWarnEnabled)
                                {
                                    log.Warn("SQL Select (" + isolation + ") took " + ((DateTime.UtcNow.Ticks / 10000) - start) + "ms!\n" + sqlcommand);
                                }
                            }
                            catch (Exception e)
                            {
                                if (!HandleException(e))
                                {
                                    if (log.IsErrorEnabled)
                                    {
                                        log.Error("ExecuteSelect: \"" + sqlcommand + "\"\n", e);
                                    }
                                    throw;
                                }

                                repeat = true;
                            }
                        }
                    }
                }while (repeat);

                return;
            }
            else if (connType == ConnectionType.DATABASE_SQLITE)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("SQL: " + sqlcommand);
                }

                bool repeat = false;
                do
                {
                    repeat = false;

                    using (var conn = new SQLiteConnection(connString))
                    {
                        using (var cmd = new SQLiteCommand(sqlcommand, conn))
                        {
                            try
                            {
                                conn.Open();

                                long start = (DateTime.UtcNow.Ticks / 10000);
                                using (var reader = cmd.ExecuteReader())
                                {
                                    try
                                    {
                                        callback(reader);
                                    }
                                    catch (Exception es)
                                    {
                                        if (log.IsWarnEnabled)
                                        {
                                            log.Warn("Exception in Select Callback : ", es);
                                        }
                                    }
                                    finally
                                    {
                                        reader.Close();
                                    }
                                }

                                if (log.IsDebugEnabled)
                                {
                                    log.Debug("SQL Select (" + isolation + ") exec time " + ((DateTime.UtcNow.Ticks / 10000) - start) + "ms");
                                }
                                else if ((DateTime.UtcNow.Ticks / 10000) - start > 500 && log.IsWarnEnabled)
                                {
                                    log.Warn("SQL Select (" + isolation + ") took " + ((DateTime.UtcNow.Ticks / 10000) - start) + "ms!\n" + sqlcommand);
                                }
                            }
                            catch (Exception e)
                            {
                                if (!HandleException(e))
                                {
                                    if (log.IsErrorEnabled)
                                    {
                                        log.Error("ExecuteSelect: \"" + sqlcommand + "\"\n", e);
                                    }
                                    throw;
                                }

                                repeat = true;
                            }
                            finally
                            {
                                conn.Close();
                            }
                        }
                    }
                }while (repeat);

                return;
            }

            if (log.IsWarnEnabled)
            {
                log.Warn("SQL Selects not supported for this connection type");
            }
        }