Ejemplo n.º 1
0
        internal static LogRowData CreateData(Stream stream, LogRowIndex index)
        {
            byte[] buffer = new byte[index.RowLength + 2];
            char[] chars  = new char[index.RowLength];

            if (stream.Position != index.RowStart)
            {
                stream.Seek(index.RowStart, SeekOrigin.Begin);
            }

            stream.Read(buffer, 0, 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 itemId          = new string(chars, nameIndex, index.NameLength);
            var timeStamp       = LogRowDataFactory.ParseDate(chars, 0, LogRowIndex.TimeStampLength);
            var user            = new string(chars, userIndex, index.UserLength);
            var cycleIndexValue = long.Parse(new string(chars, cycleIndex, index.CycleLength), NumberStyles.None);
            var value           = new string(chars, valueIndex, length - valueIndex);

            return(new LogRowData(timeStamp, itemId, user, cycleIndexValue, value));
        }
Ejemplo n.º 2
0
        public IEnumerable <LogRowDataPoint> GetDataPoints(IEnumerable <LogRowIndex> indexes)
        {
            foreach (LogRowIndex logRowIndex in indexes)
            {
                if (!m_DataPointCache.TryGetValue(logRowIndex.RowStart, out var reference))
                {
                    LogRowDataPoint point = LogRowDataFactory.CreateDataPoint(m_PagedReader, logRowIndex);
                    reference = new WeakReference(point);
                    m_DataPointCache.Add(logRowIndex.RowStart, reference);
                }

                LogRowDataPoint dataPoint = reference.Target as LogRowDataPoint;

                //Reload data point
                if (dataPoint == null)
                {
                    dataPoint        = LogRowDataFactory.CreateDataPoint(m_PagedReader, logRowIndex);
                    reference.Target = dataPoint;
                }

                yield return(dataPoint);
            }
        }
Ejemplo n.º 3
0
        public IEnumerable <LogRowData> GetData(IEnumerable <LogRowIndex> indexes)
        {
            foreach (LogRowIndex logRowIndex in indexes)
            {
                WeakReference reference;

                if (!m_DataCache.TryGetValue(logRowIndex.RowStart, out reference))
                {
                    reference = new WeakReference(null);
                    m_DataCache.Add(logRowIndex.RowStart, reference);
                }

                LogRowData data = reference.Target as LogRowData;

                //Reload data point
                if (data == null)
                {
                    data             = LogRowDataFactory.CreateData(m_Stream, logRowIndex);
                    reference.Target = data;
                }

                yield return(data);
            }
        }
Ejemplo n.º 4
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;
            }
        }