private float[] GetCurvePoint(CurveIndex record) { int recordSize = record.RecordLength; if (dicFileData.ContainsKey(recordSize) == false) { CurveRecordFile fileData = new CurveRecordFile(this, recordSize); dicFileData.Add(recordSize, fileData); } return(dicFileData[recordSize].GetCurvePoint(record)); }
public void Stroe(CurveIndex indexRecord, float[] points) { int size = indexRecord.RecordLength; if (dicFileData.ContainsKey(size) == false) { dicFileData.Add(size, new CurveRecordFile(this, size)); } dicFileData[size].Store(indexRecord, points); //保存数据 fileIndex.Store(indexRecord); //保存索引 }
public int CompareTo(object obj) { CurveIndex record = obj as CurveIndex; if (record.FileIndex == this.FileIndex) { return(record.Index - this.Index); } else { return(record.FileIndex - this.FileIndex); } }
public bool ConflictWith(CurveIndex other) { if (other.RecordLength != this.RecordLength) { return(false); } if (other.CurveFileIndex != this.CurveFileIndex) { return(false); } return(true); }
public CurveIndex NewRecord(int curvePoint) { int length = CurveIndex.IndexSize + curvePoint * 4; int needSize = 1; for (int i = 1; i <= 20; i++) { needSize = 1 << i; if (needSize >= length) { break; } } int dataRecordIndex = 0; if (dicDataIndex.ContainsKey(needSize)) { dataRecordIndex = dicDataIndex[needSize]; dataRecordIndex += 1; if (dataRecordIndex * needSize >= MaxFileSize) //返回 { dataRecordIndex = 0; } dicDataIndex[needSize] = dataRecordIndex; } else { dicDataIndex.Add(needSize, 0); } if (needSize < length) { curvePoint = (needSize - CurveIndex.IndexSize) / 4; } CurveIndex recordLast = listIndex[listIndex.Count - 1]; CurveIndex recordFirst = listIndex[0]; recordLast.FileIndex = recordFirst.FileIndex + 1; //文件记录索引 recordLast.CurvePoint = curvePoint; recordLast.CurveFileIndex = dataRecordIndex; recordLast.RecordLength = needSize; //记录长度 listIndex.Remove(recordLast); listIndex.Insert(0, recordLast); return(recordLast); }
public void Store(CurveIndex record) { if (record == null) { return; } if (fileStream != null) { byte[] data = record.GetBytes(); try { fileStream.Position = record.Index * CurveIndex.IndexSize; fileStream.Write(data, 0, data.Length); fileStream.Flush(); } catch (Exception) { } } }
public void AddCurves(CurveGroup grp) { List <StationCurve> listCurve = grp.Curves; if ((listCurve == null) || (listCurve.Count <= 0)) { return; } DateTime tmCurve = DateTime.Now; for (int i = 0; i < listCurve.Count; i++) { if (listCurve[i] != null) { tmCurve = listCurve[i].OccurTime; break; } } for (int i = 0; i < listCurve.Count; i++) { int ptNum = (listCurve[i] == null) ? 0 : listCurve[i].Points.Length; CurveIndex indexRecord = fileIndex.NewRecord(ptNum); indexRecord.CurveTime = tmCurve; indexRecord.CurveType = (Int16)grp.Type; indexRecord.CrvIndex = (Int16)grp.Index; indexRecord.CurvePhase = (byte)((listCurve.Count == 1) ? 0 : (i + 1)); indexRecord.Direction = (listCurve[i] == null) ? (byte)0 : listCurve[i].Dir; indexRecord.CurveMark = 0; indexRecord.SampleRate = (listCurve[i] == null) ? (Int16)0 : (Int16)listCurve[i].SampleRate; CurveStoreBlock blk = new CurveStoreBlock(this, indexRecord, (listCurve[i] == null) ? null:listCurve[i].Points); manager.AddBlock(blk); } }
public List <StationCurve> GetCurveHistory(int curveType, int curveindex, DateTime time) { List <StationCurve> list = new List <StationCurve>(); //排列顺序为动作曲线(A,B,C)+参考曲线定位到反位(A,B,C)+参考曲线反位到定位(A,B,C)+摩擦曲线定位到X位(A,B,C)+摩擦曲线反位到X位(A,B,C) for (int i = 0; i < 3; i++) { list.Add(null); } IList <CurveIndex> listRecord = fileIndex.AllIndex; for (int i = listRecord.Count - 1; i >= 0; i--) { CurveIndex rcd = listRecord[i]; byte mark = rcd.CurveMark; byte phase = rcd.CurvePhase; if (phase > 3) { phase = 3; } //不允许超过3个相位 if ((rcd.CurveType == curveType) && (rcd.CrvIndex == curveindex)) //曲线类型匹配 { if (Math.Abs((rcd.CurveTime - time).TotalSeconds) < 2) { float[] pt = this.GetCurvePoint(rcd); int index = (phase == 0) ? 0 : phase - 1; //CurveRecord cr = new CurveRecord(time, "", McType.None, curveType, curveindex, phase, rcd.Direction, rcd.SampleRate, pt); StationCurve cr = new StationCurve(rcd.CurveTime, rcd.SampleRate, pt); list[index] = cr; } } } return(list); }
public void Store(CurveIndex indexRecord, float[] points) { if (fileStream != null) { int ptNum = indexRecord.CurvePoint; List <byte> list = new List <byte>(); list.AddRange(indexRecord.GetBytes()); for (int i = 0; i < ptNum; i++) { list.AddRange(BitConverter.GetBytes(points[i])); } int leftNum = this.RecordSize - list.Count; for (int i = 0; i < leftNum; i++) { list.Add(0); } byte[] buffer = list.ToArray(); try { int offset = indexRecord.CurveFileIndex * this.RecordSize; if (fileStream.Length <= offset) { fileStream.SetLength(fileStream.Length + IncreaseSize); } fileStream.Position = indexRecord.CurveFileIndex * this.RecordSize; fileStream.Write(buffer, 0, this.RecordSize); fileStream.Flush(); } catch (Exception) { } } }
public float[] GetCurvePoint(CurveIndex record) { int offset = record.CurveFileIndex * record.RecordLength; byte[] buffer = null; if (fileStream != null) { try { if (fileStream.Length >= offset + record.RecordLength) { fileStream.Position = offset; byte[] data = new byte[record.RecordLength]; fileStream.Read(data, 0, data.Length); buffer = data; } } catch (Exception) { } } if (buffer != null) { List <float> listPt = new List <float>(); for (int i = 0; i < record.CurvePoint; i++) { listPt.Add(BitConverter.ToSingle(buffer, CurveIndex.IndexSize + i * 4)); } return(listPt.ToArray()); } return(null); }
public float[] GetCurvePoint(CurveIndex record) { int offset = record.CurveFileIndex * record.RecordLength; byte[] buffer = null; if (fileStream != null) { try { if (fileStream.Length >= offset + record.RecordLength) { fileStream.Position = offset; byte[] data = new byte[record.RecordLength]; fileStream.Read(data, 0, data.Length); buffer = data; } } catch (Exception) { } } if (buffer != null) { List<float> listPt = new List<float>(); for (int i = 0; i < record.CurvePoint; i++) { listPt.Add(BitConverter.ToSingle(buffer, CurveIndex.IndexSize + i * 4)); } return listPt.ToArray(); } return null; }
public CurveIndexFile(CurveFile curveFile) { this.curveFile = curveFile; byte[] buffer = new byte[MaxIndexNum * CurveIndex.IndexSize]; Array.Clear(buffer, 0, buffer.Length); try { string indexName = Path.Combine(curveFile.DataManager.StoreDir, "Curve.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 < MaxIndexNum; i++) { CurveIndex indexRecord = new CurveIndex(i, buffer, i * CurveIndex.IndexSize); 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])) { for (int k = j; k < listIndex.Count; k++) { listIndex[k].FileIndex = 0; //设置为无效 } break; } } } for (int i = listIndex.Count - 1; i >= 0; i--) { if (listIndex[i].IsValid == false) { continue; } int recordSize = listIndex[i].RecordLength; if (dicDataIndex.ContainsKey(recordSize) == false) { dicDataIndex.Add(recordSize, listIndex[i].CurveFileIndex); } else { dicDataIndex[recordSize] = listIndex[i].CurveFileIndex; } } }
public void Stroe(CurveIndex indexRecord, float[] points) { int size = indexRecord.RecordLength; if (dicFileData.ContainsKey(size)==false) { dicFileData.Add(size, new CurveRecordFile(this, size)); } dicFileData[size].Store(indexRecord, points); //保存数据 fileIndex.Store(indexRecord); //保存索引 }
private float[] GetCurvePoint(CurveIndex record) { int recordSize = record.RecordLength; if (dicFileData.ContainsKey(recordSize) == false) { CurveRecordFile fileData = new CurveRecordFile(this, recordSize); dicFileData.Add(recordSize, fileData); } return dicFileData[recordSize].GetCurvePoint(record); }
public CurveIndexFile(CurveFile curveFile) { this.curveFile = curveFile; byte[] buffer = new byte[MaxIndexNum * CurveIndex.IndexSize]; Array.Clear(buffer, 0, buffer.Length); try { string indexName = Path.Combine(curveFile.DataManager.StoreDir, "Curve.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 < MaxIndexNum; i++) { CurveIndex indexRecord = new CurveIndex(i, buffer, i * CurveIndex.IndexSize); 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])) { for (int k = j; k < listIndex.Count; k++) { listIndex[k].FileIndex = 0; //设置为无效 } break; } } } for (int i = listIndex.Count - 1; i >= 0; i--) { if (listIndex[i].IsValid == false) continue; int recordSize = listIndex[i].RecordLength; if (dicDataIndex.ContainsKey(recordSize) == false) { dicDataIndex.Add(recordSize, listIndex[i].CurveFileIndex); } else { dicDataIndex[recordSize]= listIndex[i].CurveFileIndex; } } }
public bool ConflictWith(CurveIndex other) { if (other.RecordLength != this.RecordLength) return false; if (other.CurveFileIndex != this.CurveFileIndex) return false; return true; }
public CurveStoreBlock(CurveFile file, CurveIndex indexRecord, float[] points) { this.file = file; this.indexRecord = indexRecord; this.points = points; }
public void Store(CurveIndex indexRecord, float[] points) { if (fileStream != null) { int ptNum = indexRecord.CurvePoint; List<byte> list = new List<byte>(); list.AddRange(indexRecord.GetBytes()); for (int i = 0; i < ptNum; i++) { list.AddRange(BitConverter.GetBytes(points[i])); } int leftNum = this.RecordSize - list.Count; for (int i = 0; i < leftNum; i++) { list.Add(0); } byte[] buffer = list.ToArray(); try { int offset=indexRecord.CurveFileIndex * this.RecordSize; if (fileStream.Length <= offset) { fileStream.SetLength(fileStream.Length + IncreaseSize); } fileStream.Position = indexRecord.CurveFileIndex * this.RecordSize; fileStream.Write(buffer, 0, this.RecordSize); fileStream.Flush(); } catch (Exception) { } } }
public void Store(CurveIndex record) { if (record == null) return; if (fileStream != null) { byte[] data = record.GetBytes(); try { fileStream.Position = record.Index * CurveIndex.IndexSize; fileStream.Write(data, 0, data.Length); fileStream.Flush(); } catch (Exception) { } } }