@@ -1588,6 +1588,104 @@ private void OnUpdateDocumentResponse(RESTConnector.Request req, RESTConnector.R
15881588 #endregion
15891589
15901590 #region Queries
1591+ public delegate void OnQuery ( QueryResponse resp , string customData ) ;
1592+
1593+ public bool Query ( OnQuery callback , string environmentID , string collectionID , string filter , string query , string aggregation , int count , string _return , int offset , string customData = default ( string ) )
1594+ {
1595+ if ( callback == null )
1596+ throw new ArgumentNullException ( "callback" ) ;
1597+ if ( string . IsNullOrEmpty ( environmentID ) )
1598+ throw new ArgumentNullException ( "environmentID" ) ;
1599+ if ( string . IsNullOrEmpty ( collectionID ) )
1600+ throw new ArgumentNullException ( "collectionID" ) ;
1601+ if ( string . IsNullOrEmpty ( filter ) )
1602+ throw new ArgumentNullException ( "filter" ) ;
1603+ if ( string . IsNullOrEmpty ( query ) )
1604+ throw new ArgumentNullException ( "query" ) ;
1605+ if ( string . IsNullOrEmpty ( aggregation ) )
1606+ throw new ArgumentNullException ( "aggregation" ) ;
1607+ if ( string . IsNullOrEmpty ( _return ) )
1608+ throw new ArgumentNullException ( "_return" ) ;
1609+
1610+ QueryRequest req = new QueryRequest ( ) ;
1611+ req . Callback = callback ;
1612+ req . Data = customData ;
1613+ req . EnvironmentID = environmentID ;
1614+ req . CollectionID = collectionID ;
1615+ req . Filter = filter ;
1616+ req . Query = query ;
1617+ req . Aggregation = aggregation ;
1618+ req . Count = count ;
1619+ req . Return = _return ;
1620+ req . Offset = offset ;
1621+
1622+ if ( ! string . IsNullOrEmpty ( filter ) )
1623+ req . Parameters [ "filter" ] = filter ;
1624+
1625+ if ( ! string . IsNullOrEmpty ( query ) )
1626+ req . Parameters [ "query" ] = query ;
1627+
1628+ if ( ! string . IsNullOrEmpty ( aggregation ) )
1629+ req . Parameters [ "aggregation" ] = aggregation ;
1630+
1631+ if ( ! string . IsNullOrEmpty ( _return ) )
1632+ req . Parameters [ "_return" ] = _return ;
1633+
1634+ req . Parameters [ "offset" ] = offset ;
1635+ req . Parameters [ "count" ] = count ;
1636+ req . Parameters [ "version" ] = DiscoveryVersion . Version ;
1637+ req . OnResponse = OnQueryResponse ;
1638+
1639+ RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , string . Format ( SERVICE_ENVIRONMENT_COLLECTION_QUERY , environmentID , collectionID ) ) ;
1640+ if ( connector == null )
1641+ return false ;
1642+
1643+ return connector . Send ( req ) ;
1644+ }
1645+
1646+ private class QueryRequest : RESTConnector . Request
1647+ {
1648+ public string Data { get ; set ; }
1649+ public string EnvironmentID { get ; set ; }
1650+ public string CollectionID { get ; set ; }
1651+ public string Filter { get ; set ; }
1652+ public string Query { get ; set ; }
1653+ public string Aggregation { get ; set ; }
1654+ public int Count { get ; set ; }
1655+ public string Return { get ; set ; }
1656+ public int Offset { get ; set ; }
1657+ public OnQuery Callback { get ; set ; }
1658+ }
1659+
1660+ private void OnQueryResponse ( RESTConnector . Request req , RESTConnector . Response resp )
1661+ {
1662+ QueryResponse queryResponse = new QueryResponse ( ) ;
1663+
1664+ if ( resp . Success )
1665+ {
1666+ try
1667+ {
1668+ fsData data = null ;
1669+ fsResult r = fsJsonParser . Parse ( Encoding . UTF8 . GetString ( resp . Data ) , out data ) ;
1670+
1671+ if ( ! r . Succeeded )
1672+ throw new WatsonException ( r . FormattedMessages ) ;
1673+
1674+ object obj = queryResponse ;
1675+ r = sm_Serializer . TryDeserialize ( data , obj . GetType ( ) , ref obj ) ;
1676+ if ( ! r . Succeeded )
1677+ throw new WatsonException ( r . FormattedMessages ) ;
1678+ }
1679+ catch ( Exception e )
1680+ {
1681+ Log . Error ( "Discovery" , "OnQueryResponse Exception: {0}" , e . ToString ( ) ) ;
1682+ resp . Success = false ;
1683+ }
1684+ }
1685+
1686+ if ( ( ( QueryRequest ) req ) . Callback != null )
1687+ ( ( QueryRequest ) req ) . Callback ( resp . Success ? queryResponse : null , ( ( QueryRequest ) req ) . Data ) ;
1688+ }
15911689 #endregion
15921690
15931691 #region IWatsonService Interface
0 commit comments