示例#1
0
        /// <summary>
        /// 寻找现在已有的文件记录
        /// </summary>
        private void ProcAddData()
        {
            while (true)
            {
                DataUnit[] datas = null;
                lock (((ICollection)queueData).SyncRoot)
                {
                    datas = queueData.ToArray();
                    queueData.Clear();
                }

                if (datas != null && datas.Length > 0)
                {
                    lock (dicFile)
                    {
                        for (int i = 0; i < datas.Length; i++)
                        {
                            int analogIndex = datas[i].Type * 10000 + datas[i].Index;
                            if (dicFile.ContainsKey(analogIndex) == false)
                            {
                                AnalogFile fileAnalog = new AnalogFile(this, datas[i].Type, datas[i].Index);
                                dicFile.Add(analogIndex, fileAnalog);
                                dicFile[analogIndex].AddAnalog(datas[i].Time, float.NaN, (byte)0x0f); //开始的第一个点加入无效数据
                            }
                            dicFile[analogIndex].AddAnalog(datas[i].Time, datas[i].Analog, datas[i].Digit);
                        }
                    }
                }
                else
                {
                    dataReceivedEvent.WaitOne();
                }
            }
        }
示例#2
0
        public List <List <AnalogPoint> > GetAnalogPoint(int type, int index, DateTime timeBegin, DateTime timeEnd)
        {
            int analogIndex = type * 10000 + index;

            if (dicFile.ContainsKey(analogIndex) == false)
            {
                AnalogFile fileAnalog = new AnalogFile(this, type, index);
                dicFile.Add(analogIndex, fileAnalog);
            }
            return(dicFile[analogIndex].GetAnalogPoint(timeBegin, timeEnd));
        }
示例#3
0
        public List <DateTime> QueryAnalogTimes(int type, int index)
        {
            int analogIndex = type * 10000 + index;

            if (dicFile.ContainsKey(analogIndex) == false)
            {
                AnalogFile fileAnalog = new AnalogFile(this, type, index);
                dicFile.Add(analogIndex, fileAnalog);
            }

            return(dicFile[analogIndex].QueryAnalogTimes());
        }
示例#4
0
 public AnalogRecordFile(AnalogFile analog)
 {
     this.fileAnalog = analog;
     try
     {
         dataName   = Path.Combine(analog.DataManager.StoreDir, analog.Type.ToString("X2") + "H-" + analog.Index.ToString("000") + ".dat");
         fileStream = new FileStream(dataName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
     }
     catch
     {
         fileStream = null;
     }
 }
 public AnalogRecordFile(AnalogFile analog)
 {
     this.fileAnalog = analog;
     try
     {
          dataName = Path.Combine(analog.DataManager.StoreDir, analog.Type.ToString("X2") + "H-" + analog.Index.ToString("000") + ".dat");
         fileStream = new FileStream(dataName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
     }
     catch
     {
         fileStream = null;
     }
 }
 public AnalogRequestBlock(AnalogFile fileAnalog, DateTime timeBegin, DateTime timeEnd)
 {
     this.fileAnalog = fileAnalog;
     if (timeBegin < timeEnd)
     {
         this.timeBegin = timeBegin;
         this.timeEnd   = timeEnd;
     }
     else
     {
         this.timeBegin = timeEnd;
         this.timeEnd   = timeBegin;
     }
 }
示例#7
0
        public AnalogIndexFile(AnalogFile analog)
        {
            this.fileAnalog = analog;
            byte[] buffer = new byte[IndexCount * 32];
            Array.Clear(buffer, 0, buffer.Length);
            try
            {
                string indexName = Path.Combine(analog.DataManager.StoreDir, analog.Type.ToString("X2") + "H-" + analog.Index.ToString("000") + ".idx");
                fileStream = new FileStream(indexName, FileMode.OpenOrCreate, FileAccess.ReadWrite);


                if (fileStream.Length < buffer.Length)
                {
                    fileStream.SetLength(buffer.Length); //默认建立16KB的文件
                }

                fileStream.Read(buffer, 0, buffer.Length);
            }
            catch
            {
                fileStream = null;
            }
            for (int i = 0; i < IndexCount; i++)
            {
                AnalogIndex indexRecord = new AnalogIndex(i, buffer, i * 32);
                listIndex.Add(indexRecord);
            }
            listIndex.Sort();

            //TODO:必须加入对重叠的Index处理
            for (int i = 0; i < listIndex.Count; i++)
            {
                if (listIndex[i].IsValid == false)
                {
                    break;
                }

                for (int j = i + 1; j < listIndex.Count; j++)
                {
                    if (listIndex[j].IsValid && listIndex[j].ConflictWith(listIndex[i], this.fileAnalog.MaxFileSize))
                    {
                        for (int k = j; k < listIndex.Count; k++)
                        {
                            listIndex[k].FileIndex = 0; //设置为无效
                        }
                        break;
                    }
                }
            }
        }
 public AnalogRequestBlock(AnalogFile fileAnalog,DateTime timeBegin,DateTime timeEnd)
 {
     this.fileAnalog = fileAnalog;
      if (timeBegin < timeEnd)
      {
          this.timeBegin = timeBegin;
          this.timeEnd = timeEnd;
      }
      else
      {
          this.timeBegin = timeEnd;
          this.timeEnd = timeBegin;
      }
 }
        List<AnalogIndex> listIndex = new List<AnalogIndex>(); //按文件记录索引排序

        #endregion Fields

        #region Constructors

        public AnalogIndexFile(AnalogFile analog)
        {
            this.fileAnalog = analog;
            byte[] buffer = new byte[IndexCount * 32];
            Array.Clear(buffer, 0, buffer.Length);
            try
            {
                string indexName = Path.Combine(analog.DataManager.StoreDir, analog.Type.ToString("X2") + "H-" + analog.Index.ToString("000") + ".idx");
                fileStream = new FileStream(indexName, FileMode.OpenOrCreate, FileAccess.ReadWrite);

                if (fileStream.Length < buffer.Length)
                {
                    fileStream.SetLength(buffer.Length); //默认建立16KB的文件
                }

                fileStream.Read(buffer, 0, buffer.Length);
            }
            catch
            {
                fileStream = null;
            }
            for (int i = 0; i < IndexCount; i++)
            {
                AnalogIndex indexRecord = new AnalogIndex(i, buffer, i * 32);
                listIndex.Add(indexRecord);
            }
            listIndex.Sort();

            //TODO:必须加入对重叠的Index处理
            for (int i = 0; i < listIndex.Count; i++)
            {
                if (listIndex[i].IsValid == false) break;

                for (int j = i + 1; j < listIndex.Count; j++)
                {
                    if (listIndex[j].IsValid && listIndex[j].ConflictWith(listIndex[i], this.fileAnalog.MaxFileSize))
                    {
                        for (int k = j; k < listIndex.Count; k++)
                        {
                            listIndex[k].FileIndex = 0; //设置为无效
                        }
                        break;

                    }
                }

            }
        }
示例#10
0
 public AnalogStoreBlock(int index, AnalogFile analogFile)
 {
     this.Index       = index;
     this.fileAanlog  = analogFile;
     this.IsNullBlock = false;
 }
示例#11
0
 public AnalogStoreBlock(int index,AnalogFile analogFile)
 {
     this.Index = index;
     this.fileAanlog = analogFile;
     this.IsNullBlock = false;
 }
示例#12
0
 public List<List<AnalogPoint>> GetAnalogPoint(int type, int index, DateTime timeBegin, DateTime timeEnd)
 {
     int analogIndex = type * 10000 + index;
     if (dicFile.ContainsKey(analogIndex) == false)
     {
         AnalogFile fileAnalog = new AnalogFile(this, type, index);
         dicFile.Add(analogIndex, fileAnalog);
     }
       return  dicFile[analogIndex].GetAnalogPoint(timeBegin, timeEnd);
 }
示例#13
0
        /// <summary>
        /// 寻找现在已有的文件记录
        /// </summary>
        private void ProcAddData()
        {
            while (true)
            {

                DataUnit[] datas = null;
                lock (((ICollection)queueData).SyncRoot)
                {
                 datas=   queueData.ToArray();
                 queueData.Clear();
                }

                if (datas != null && datas.Length > 0)
                {
                    lock (dicFile)
                    {
                        for (int i = 0; i < datas.Length; i++)
                        {
                            int analogIndex = datas[i].Type * 10000 + datas[i].Index;
                            if (dicFile.ContainsKey(analogIndex) == false)
                            {

                                AnalogFile fileAnalog = new AnalogFile(this, datas[i].Type, datas[i].Index);
                                dicFile.Add(analogIndex, fileAnalog);
                                dicFile[analogIndex].AddAnalog(datas[i].Time, float.NaN, (byte)0x0f); //开始的第一个点加入无效数据
                            }
                            dicFile[analogIndex].AddAnalog(datas[i].Time, datas[i].Analog, datas[i].Digit);

                        }
                    }
                }
                else
                {
                    dataReceivedEvent.WaitOne();
                }

            }
        }
示例#14
0
        public List<DateTime> QueryAnalogTimes(int type, int index)
        {
            int analogIndex = type * 10000 + index;

            if (dicFile.ContainsKey(analogIndex) == false)
            {
                AnalogFile fileAnalog = new AnalogFile(this, type, index);
                dicFile.Add(analogIndex, fileAnalog);
            }

            return dicFile[analogIndex].QueryAnalogTimes();
        }