Esempio n. 1
0
 private void _VR33BTerminal_OnVR33BSampleStarted(object sender, VR33BSampleProcess e)
 {
     OxyPlotModel.Title  = e.Name.ToString();
     _LoadedSampleValues = new VR33BSampleValue[0];
     TimeSpanPlotAxis.Pan((((_LatestPlotAxisActualMinMax.ActualMaximum - _LatestPlotAxisActualMinMax.ActualMinimum) * 0.5 + _LatestPlotAxisActualMinMax.ActualMinimum) - 0) * TimeSpanPlotAxis.Scale);
     OxyPlotView.InvalidatePlot();
 }
Esempio n. 2
0
 private void VR33BTerminal_OnVR33BSampleValueReceived(object sender, VR33BSampleValue e)
 {
     /*
      * Dispatcher.Invoke(() =>
      * {
      *  //TestTable.Insert(0, e);
      * });
      */
 }
Esempio n. 3
0
 public static VR33BSampleValueEntity FromStruct(VR33BSampleValue vr33bSampleValue)
 {
     return(new VR33BSampleValueEntity
     {
         SampleProcessGuid = vr33bSampleValue.SampleProcessGuid,
         SampleIndex = vr33bSampleValue.SampleIndex,
         SampleDateTime = vr33bSampleValue.SampleDateTime,
         RawAccelerometerValueX = vr33bSampleValue.RawAccelerometerValue.X,
         RawAccelerometerValueY = vr33bSampleValue.RawAccelerometerValue.Y,
         RawAccelerometerValueZ = vr33bSampleValue.RawAccelerometerValue.Z,
         RawTemperature = vr33bSampleValue.RawTemperature,
         RawHumidity = vr33bSampleValue.RawHumidity,
         SampleTimeSpanInMs = vr33bSampleValue.SampleTimeSpanInMs
     });
 }
Esempio n. 4
0
        private async void _VR33BTerminal_OnVR33BSampleValueReceived(object sender, VR33BSampleValue e)
        {
            lock (_BeforeStoreBufferLock)
            {
                _BeforeStoreBuffer.Add(VR33BSampleValueEntity.FromStruct(e));
            }
            if (_InMemoryBufferLock.WaitingWriteCount > 2)
            {
                return;
            }
            await Task.Run(() =>
            {
                int inMemorySize;
                _InMemoryBufferLock.EnterWriteLock();
                {
                    lock (_BeforeStoreBufferLock)
                    {
                        _InMemoryBuffer.AddRange(_BeforeStoreBuffer);
                        _BeforeStoreBuffer.Clear();
                    }
                    inMemorySize = _InMemoryBuffer.Count;
                }
                _InMemoryBufferLock.ExitWriteLock();
                if (inMemorySize > Setting.InMemoryBufferSize && !_TransferingDataToDatabase) //添加!_DataContextLock.IsWriteLockHeld这个条件可能会使后面数据库增长到很大时,InMemory中的条目数越来越多
                {
                    Task.Run(() =>
                    {
                        lock (_MemoryToDataBaseTransferLock)
                        {
                            _TransferingDataToDatabase = true;
                            List <VR33BSampleValueEntity> memToDBMiddleBuffer;

                            _InMemoryBufferLock.EnterReadLock();
                            inMemorySize = _InMemoryBuffer.Count;
                            if (inMemorySize <= Setting.InMemoryBufferSize)
                            {
                                _InMemoryBufferLock.ExitReadLock();
                            }
                            else
                            {
                                memToDBMiddleBuffer = _InMemoryBuffer.GetRange(0, Setting.MemoryToDBBatchSize);
                                _InMemoryBufferLock.ExitReadLock();
                                _DataContextLock.EnterWriteLock();
                                {
                                    _TransferingDataToDatabase   = true;
                                    DateTime beginTimingDateTime = DateTime.Now;
                                    System.Diagnostics.Debug.WriteLine("BEGIN MOVING MEMORY TO DB");
                                    _DataContext.SampleValueEntities.AddRange(memToDBMiddleBuffer);
                                    _DataContext.SaveChanges();
                                    System.Diagnostics.Debug.WriteLine("MOVE MEMORY TO DB TAKES " + (DateTime.Now - beginTimingDateTime).TotalMilliseconds + "Ms");
                                    _TransferingDataToDatabase = false;
                                }
                                _DataContextLock.ExitWriteLock();

                                _InMemoryBufferLock.EnterWriteLock();
                                {
                                    _InMemoryBuffer.RemoveRange(0, Setting.MemoryToDBBatchSize);
                                }
                                _InMemoryBufferLock.ExitWriteLock();
                            }
                            _TransferingDataToDatabase = false;
                        }
                    });
                }

                Updated?.Invoke(this, e);
            });
        }