Exemple #1
0
        /// <summary>
        /// The Initialize method initializes the streaming database component, preparing it for data queries.
        /// </summary>
        /// <param name="qt">Specifies the query type to use (see remarks).</param>
        /// <param name="strSchema">Specifies the query schema to use.</param>
        /// <remarks>
        /// Additional settings for each query type are specified in the 'strSettings' parameter as a set
        /// of key=value pairs for each of the settings.  The following are the query specific settings
        /// that are expected for each QUERY_TYPE.
        ///
        /// qt = TIME:
        ///    'QueryCount' - Specifies the number of items to include in each query.
        ///    'Start' - Specifies the start date of the stream.
        ///    'TimeSpanInMs' - Specifies the time increment between data items in the stream in milliseconds.
        ///    'SegmentSize' - Specifies the segment size of data queried from the database.
        ///    'MaxCount' - Specifies the maximum number of items to load into memory for each custom query.
        ///
        /// qt = GENERAL:
        ///    none at this time.
        ///
        /// 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:
        ///
        /// "ConnectionCount=2;
        ///  Connection0_CustomQueryName=Test1;
        ///  Connection0_CustomQueryParam=param_string1
        ///  Connection1_CustomQueryName=Test2;
        ///  Connection1_CustomQueryParam=param_string2"
        ///
        /// 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 void Initialize(QUERY_TYPE qt, string strSchema)
        {
            if (qt == QUERY_TYPE.SYNCHRONIZED)
            {
                PropertySet ps            = new PropertySet(strSchema);
                int         nQueryCount   = ps.GetPropertyAsInt("QueryCount", 0);
                DateTime    dtStart       = ps.GetPropertyAsDateTime("Start");
                int         nTimeSpanInMs = ps.GetPropertyAsInt("TimeSpanInMs");
                int         nSegmentSize  = ps.GetPropertyAsInt("SegmentSize");
                int         nMaxCount     = ps.GetPropertyAsInt("MaxCount");

                m_iquery = new MgrQueryTime(nQueryCount, dtStart, nTimeSpanInMs, nSegmentSize, nMaxCount, strSchema, m_rgCustomQueryToAdd);
            }
            else
            {
                m_iquery = new MgrQueryGeneral(strSchema, m_rgCustomQueryToAdd);
            }
        }
Exemple #2
0
        public string GetSetupParameterQuery(string key, object val, QUERY_TYPE type)
        {
            int    err     = -1;
            string strRes  = string.Empty;
            UNITS  id_unit = UNITS.UNKNOWN;

            id_unit = val.GetType().Equals(typeof(bool)) == true ? UNITS.BOOL
                : val.GetType().Equals(typeof(string)) == true ? UNITS.STRING
                    : val.GetType().Equals(typeof(int)) == true ? UNITS.INTEGER
                        : new List <Type> ()
            {
                typeof(double), typeof(float), typeof(decimal)
            }.Contains(val.GetType()) == true ? UNITS.FLOAT
                            : UNITS.UNKNOWN;

            if (type == QUERY_TYPE.UPDATE)
            {
                //query = @"UPDATE [dbo].[setup] SET [VALUE] = '" + val + @"' WHERE [KEY]='" + key + @"'";
                strRes = string.Format(@"UPDATE setup SET [VALUE]='{0}', [LAST_UPDATE]=GETDATE() WHERE [KEY]='{1}'", val, key);
            }
            else if (type == QUERY_TYPE.INSERT)
            {
                if (!(id_unit == UNITS.UNKNOWN))
                {
                    strRes = string.Format(@"INSERT INTO [setup] ([ID], [VALUE],[KEY],[LAST_UPDATE],[ID_UNIT]) VALUES (({0}),'{1}','{2}',GETDATE(),{3})"
                                           , "SELECT MAX([ID]) + 1 FROM [setup]"
                                           , val
                                           , key
                                           , (int)id_unit
                                           );
                }
                else
                {
                    ASUTP.Logging.Logg().Error($"FormParametersDB.getWriteStringRequest(KEY={key}, VALUE={val.ToString ()}) - не удалось определить тип значения ..."
                                               , ASUTP.Logging.INDEX_MESSAGE.NOT_SET);
                }
            }
            else
            {
                ;
            }

            return(strRes);
        }