/// <summary> /// The constructor. /// </summary> /// <param name="strSchema">Specifies the database schema.</param> /// <param name="rgCustomQueries">Optionally, specifies any custom queries to diretly add.</param> /// <remarks> /// The database schema defines the number of custom queries to use along with their names. A simple key=value; list /// defines the streaming database schema using the following format: /// \code{.cpp} /// "ConnectionCount=1; /// Connection0_CustomQueryName=Test1; /// Connection0_CustomQueryParam=param_string1 /// \endcode /// Each param_string specifies the parameters of the custom query and may include the database connection string, database /// table, and database fields to query. /// </remarks> public MgrQueryGeneral(string strSchema, List <IXCustomQuery> rgCustomQueries) { m_colCustomQuery.Load(); m_schema = new PropertySet(strSchema); m_colCustomQuery.Add(new StandardQueryTextFile()); m_colCustomQuery.Add(new StandardQueryWAVFile()); foreach (IXCustomQuery icustomquery in rgCustomQueries) { m_colCustomQuery.Add(icustomquery); } int nConnections = m_schema.GetPropertyAsInt("ConnectionCount"); if (nConnections != 1) { throw new Exception("Currently, the general query type only supports 1 connection."); } string strConTag = "Connection0"; string strCustomQuery = m_schema.GetProperty(strConTag + "_CustomQueryName"); string strCustomQueryParam = m_schema.GetProperty(strConTag + "_CustomQueryParam"); IXCustomQuery iqry = m_colCustomQuery.Find(strCustomQuery); if (iqry == null) { throw new Exception("Could not find the custom query '" + strCustomQuery + "'!"); } if (iqry.QueryType != CUSTOM_QUERY_TYPE.BYTE && iqry.QueryType != CUSTOM_QUERY_TYPE.REAL_FLOAT && iqry.QueryType != CUSTOM_QUERY_TYPE.REAL_DOUBLE) { throw new Exception("The custom query '" + iqry.Name + "' must support the 'CUSTOM_QUERY_TYPE.BYTE' or 'CUSTOM_QUERY_TYPE.REAL_FLOAT' or 'CUSTOM_QUERY_TYPE.REAL_DOUBLE' query type!"); } string strParam = ParamPacker.UnPack(strCustomQueryParam); m_iquery = iqry.Clone(strParam); m_iquery.Open(); }
/// <summary> /// The query thread is where all data is collected from the underlying custom query managed. /// </summary> private void queryThread() { try { int nWait = 0; m_iquery.Open(); while (!m_evtCancel.WaitOne(nWait)) { if (!m_evtQueryEnabled.WaitOne(0)) { m_evtPaused.Set(); nWait = 250; continue; } m_evtPaused.Reset(); if (m_rgDataQueue.Count >= m_nMaxCount) { nWait = 10; continue; } double[] rgData = m_iquery.QueryByTime(m_dt, m_tsInc, m_nSegmentSize); if (rgData == null) { m_bQueryEnd = true; nWait = 10; continue; } nWait = 0; m_bQueryEnd = false; int nItemCount = rgData.Length / m_nSegmentSize; int nSrcIdx = 0; lock (m_objSync) { for (int i = 0; i < m_nSegmentSize; i++) { double[] rgItem = new double[nItemCount]; Array.Copy(rgData, nSrcIdx, rgItem, 0, nItemCount); nSrcIdx += nItemCount; m_rgDataQueue.Enqueue(rgItem); } } m_dt += TimeSpan.FromMilliseconds(m_nSegmentSize * m_tsInc.TotalMilliseconds); } } catch (Exception excpt) { throw excpt; } finally { m_iquery.Close(); } }