Example #1
0
        static void dm_OnInterleavedInput(InterleavedInput interleavedInput)
        {
            _completionApproach.InterleavedInput(interleavedInput.InputDateTime, interleavedInput.InputLine);

            _interleavedInputCount++;

            if (_interleavedInputCount % 100000 == 0 && _debugOutput)
                Console.WriteLine("Interleaved input " + _interleavedInputCount + " (" + interleavedInput.InputLine + ")");
        }
Example #2
0
        /// <summary>
        /// Begin reading the files
        /// </summary>
        public void BeginReading()
        {
            StreamReader queryLogFile = new StreamReader(_queryLog.FullName, UTF8Encoding.UTF8);
            StreamReader interleavedInputFile = null;
            if (_interleavedInputFile != null)
                interleavedInputFile = new StreamReader(_interleavedInputFile.FullName);

            // Read lines to start date
            string queryLine = queryLogFile.ReadLine();
            while (queryLine != null)
            {
                if (_endDataModelStream)
                    return; // End the stream prematurely

                // In the format query{TAB}timestamp
                string[] rows = queryLine.Split('\t');
                DateTime queryDateTime = DateTime.ParseExact(rows[1], "yyyy-MM-dd HH:mm:ss", null);

                if (queryDateTime >= _startFrom)
                    break;

                queryLine = queryLogFile.ReadLine();
            }

            // Only read interleaved input if not null
            InterleavedInput interleavedInput = null;
            string interleavedInputLine = null;
            if (_interleavedInputFile != null)
            {
                interleavedInputLine = interleavedInputFile.ReadLine();
                while (interleavedInputLine != null)
                {
                    if (_endDataModelStream)
                        return; // End the stream prematurely

                    // In the format: timestamp{tab}value...
                    string[] rows = interleavedInputLine.Split('\t');
                    DateTime inputDateTime = DateTime.ParseExact(rows[0], "yyyy-MM-dd HH:mm:ss", null);

                    if (inputDateTime >= _startFrom)
                    {
                        interleavedInput = new InterleavedInput(inputDateTime, interleavedInputLine);
                        break;
                    }

                    interleavedInputLine = interleavedInputFile.ReadLine();
                }
            }

            // The current lines
            QuerySubmitted currentQuerySubmitted = new QuerySubmitted(queryLine);
            string currentInterleavedInputLine = interleavedInputLine;

            // Now, begin reading the files and firing events
            while (true)
            {
                if (_endDataModelStream)
                    return; // End the stream prematurely

                // Output query submitted
                if ((currentQuerySubmitted != null && interleavedInput != null
                    && (currentQuerySubmitted.QueryDateTime <= interleavedInput.InputDateTime) || interleavedInput == null)) // Output query if the query is before the changes, or there are no more wiki changes
                {
                    OnQuerySubmitted(currentQuerySubmitted);

                    _queryCount++;
                    if (_queryCount > _maxQueryCount)
                        break; // Only allow up to the max query count

                    // Read next line
                    queryLine = queryLogFile.ReadLine();
                    if (queryLine != null && queryLine.Length > 1 && queryLine != "Query\tQueryTime")
                        currentQuerySubmitted = new QuerySubmitted(queryLine);
                }

                // Output interleaved input
                if ((currentQuerySubmitted != null && interleavedInput != null
                    && (interleavedInput.InputDateTime <= currentQuerySubmitted.QueryDateTime) || currentQuerySubmitted == null)) // Output wiki change if the change is before the query, or there are no more queries submitted
                {
                    OnInterleavedInput(interleavedInput);

                    // Read next line
                    interleavedInputLine = interleavedInputFile.ReadLine();
                    if (interleavedInputLine != null && queryLine.Length > 1)
                    {
                        string[] rows = interleavedInputLine.Split('\t');
                        DateTime inputDateTime = DateTime.ParseExact(rows[0], "yyyy-MM-dd HH:mm:ss", null);

                        interleavedInput = new InterleavedInput(inputDateTime, interleavedInputLine);
                    }
                }

                if (queryLine == null && interleavedInputLine == null)
                    break; // End the loop
            }

            // Fire the final event
            if (OnEndOfData != null)
                OnEndOfData();
        }