Пример #1
0
        internal static LogRowDataPoint CreateDataPoint(PagedStreamReader reader, LogRowIndex index)
        {
            byte[] buffer = new byte[index.RowLength];
            char[] chars  = new char[index.RowLength];

            reader.Read(buffer, index.RowStart, index.RowLength);

            int length = buffer.IndexOf((byte)'\r', 0);

            if (length == -1)
            {
                length = buffer.IndexOf((byte)'\n', 0);
            }

            for (int i = 0; i < length; i++)
            {
                chars[i] = (char)buffer[i];
            }

            index.GetValues(out int timeStampIndex, out int nameIndex, out int userIndex, out int cycleIndex, out int valueIndex);

            var timeStamp = ParseDate(chars, 0, LogRowIndex.TimeStampLength); //, "yyyy-MM-dd hh:mm:ss.fff", culture);

            string valueString = new string(chars, valueIndex, length - valueIndex);

            double value;

            if (!double.TryParse(valueString, NumberStyles.Any, m_Culture, out double val))
            {
                value = valueString == "True" ? 1d : 0d;
            }
            else
            {
                value = val;
            }

            return(new LogRowDataPoint(timeStamp, value));
        }
Пример #2
0
        private void OnQueuedReadThreadExecute()
        {
            try
            {
                Trace.TraceInformation("QueuedReadThread started: {0}", m_DatabaseInstanceID);

                using (var stream = new BufferedStream(new FileStream(m_Filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, FileOptions.RandomAccess), 1024 * 1024))
                {
                    //int handle;
                    WaitHandle[] handles = new WaitHandle[] { m_Quit, m_Event };

                    var pagedReader = new PagedStreamReader(stream, 4096);

                    while (WaitHandle.WaitAny(handles) == 1) // (handle = WaitHandle.WaitAny(handles)) == 0)
                    {
                        Thread.Sleep(200);                   //Wait to consolidate if more requests are coming in.

                        QueuedReadRequest[] requests = null;
                        lock (m_SyncObject)
                        {
                            if (m_Queue.Count > 0)
                            {
                                requests = m_Queue.ToArray();
                                m_Queue.Clear();
                            }
                            else
                            {
                                m_Event.Reset();
                            }
                        }

                        if (requests == null)
                        {
                            continue;
                        }

                        LinkedList <LogRowIndex> indicesList = new LinkedList <LogRowIndex>();
                        Dictionary <LogRowIndex, List <RequestPoints> > indexToRequestPoints = new Dictionary <LogRowIndex, List <RequestPoints> >();

                        foreach (var readRequest in requests)
                        {
                            var indices = m_Indexes.GetItemRows(readRequest.ItemID, readRequest.StartIndex, readRequest.Count);

                            var requestPoints = new RequestPoints(readRequest);

                            foreach (var logRowIndex in indices)
                            {
                                if (!indexToRequestPoints.TryGetValue(logRowIndex, out var list))
                                {
                                    list = new List <RequestPoints>();
                                    indexToRequestPoints.Add(logRowIndex, list);
                                }
                                list.Add(requestPoints);
                            }

                            indicesList.AddSorted(indices);
                        }



                        foreach (var logRowIndex in indicesList)
                        {
                            var point = LogRowDataFactory.CreateDataPoint(pagedReader, logRowIndex);

                            var list = indexToRequestPoints[logRowIndex];
                            foreach (var rp in list)
                            {
                                if (rp.Add(point))
                                {
                                    rp.Send(m_DatabaseInstanceID);
                                }
                            }
                        }

                        foreach (var index in indexToRequestPoints)
                        {
                            index.Value.ForEach(points => points.Send(m_DatabaseInstanceID));
                        }
                    }
                }
                Trace.TraceInformation("QueuedReadThread ended: {0}", m_DatabaseInstanceID);
            }
            catch (Exception ex)
            {
                m_Log.Fatal(ex.Message, ex);
                throw;
            }
        }
Пример #3
0
 public LogDataCache(Stream stream)
 {
     m_Stream      = stream;
     m_PagedReader = new PagedStreamReader(m_Stream, 4096);
 }