using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; using FObjBase; using static FLY.Thick.BulkDataModule.BulkDataService; using System.Collections.Specialized; namespace FLY.Thick.BulkDataModule { /// /// 推送服务,(AsyncState,param) 作为一个对,不能存在 两个一样的(AsyncState,param)。 它只会推送一次 /// public interface IBulkDataService : INotifyPropertyChanged { /// /// 获取一幅数据, 默认带推送 /// 参数 Pack_CallGetFrameDataParam /// 回复 Pack_CallGetFrameDataReturn /// /// /// /// void GetFrameData( BULKDATA_OBJ_INTERFACE.Pack_CallGetFrameDataParam param, AsyncCBHandler AsyncDelegate, object AsyncState); /// /// 关闭 扫描图 推送 /// /// /// void ClosePushFrameData( BULKDATA_OBJ_INTERFACE.Pack_CallClosePushFrameData param, object AsyncState); /// /// 获取纵向趋势图,默认带推送 /// /// /// /// void GetTrendData( BULKDATA_OBJ_INTERFACE.Pack_CallGetTrendDataParam param, AsyncCBHandler AsyncDelegate, object AsyncState); /// /// 关闭 纵向趋势图 推送 /// /// /// void ClosePushTrendData( BULKDATA_OBJ_INTERFACE.Pack_CallClosePushTrendData param, object AsyncState); /// /// 注册新数据推送 /// /// /// /// void PushNewFrameData( BULKDATA_OBJ_INTERFACE.Pack_CallPushNewFrameDataParam param, AsyncCBHandler AsyncDelegate, object AsyncState); /// /// 关闭 新数据推送 /// /// /// void ClosePushNewFrameData( BULKDATA_OBJ_INTERFACE.Pack_CallClosePushNewFrameData param, object AsyncState); /// /// 获取一幅数据, 默认带推送 /// 参数 Pack_CallGetFrameDataMixRequest /// 回复 Pack_CallGetFrameDataMixReponse /// /// /// /// void GetFrameDataMix( Pack_CallGetFrameDataMixRequest param, AsyncCBHandler AsyncDelegate, object AsyncState); /// /// 关闭 扫描图 推送 /// /// /// void ClosePushFrameDataMix( Pack_CallClosePushFrameDataMixRequest param, object AsyncState); /// /// 清空缓存区 /// void Clear(); /// /// 只要 AsyncState 满足 match 的都要删除 /// /// AsyncState 规则 void ClosePush(Predicate match); /// /// 准备好,只有在 IsReady=true ,发送的命令才能执行,才能推送 /// bool IsReady { get; } /// /// 缓冲区数据 /// List Datas { get; } /// /// 数量 /// int Count { get; } /// /// 分区数 /// int NBolts { get; } /// /// 第1分区号 /// int BoltNo1st { get; } /// /// 最新的bookmark /// int CurrentBookmark { get; } // // 摘要: // 在添加、移除、更改或者在刷新整个列表时发生。 event NotifyDatasChangedEventHandler DatasChanged; } public class NotifyDatasChangedEventArgs : EventArgs { public NotifyDatasChangedAction Action; public int NewStartingIndex; public List Items; } public enum NotifyDatasChangedAction { Add, Replace, Reset } public delegate void NotifyDatasChangedEventHandler(object sender, NotifyDatasChangedEventArgs e); /// /// 作为服务器端 添加,改变 数据 /// public interface IBulkDataServiceAdd { /// /// 分区数 /// int NBolts { get; set; } /// /// 第1分区号 /// int BoltNo1st { get; set; } /// /// 初始化推送 /// void InitPush(); /// /// 添加空数据 /// /// int AddEmply(); /// /// 添加数据 /// /// /// /// /// int Add(int[] buf, FR_DATA_TYPE type, DateTime dt); /// /// 添加数据 /// /// /// /// int Add(int[] buf, FR_DATA_TYPE type); /// /// 改变数据 /// /// /// /// /// /// /// bool Change(int bm, int start_boltIndex, int[] buf, FR_DATA_TYPE type, DateTime time); /// /// 改变数据 /// /// /// /// /// /// bool Change(int bm, int start_boltIndex, int[] buf, FR_DATA_TYPE type); /// /// 改变数据为空 /// /// /// bool ChangeEmply(int bm); /// /// 改变最新幅数据为空 /// /// bool ChangeEmply(); /// /// 保存 /// void Save(); } /// /// /// public class Pack_CallGetFrameDataMixRequest : Pack_CallClosePushFrameDataMixRequest { /// /// 当数据变化时,是否需要推送 /// public bool NeedPush; #region IPack 成员 /// /// 转换为 17个字节 /// /// public override byte[] ToBytes() { List buf = new List(); buf.AddRange(base.ToBytes()); buf.AddRange(BitConverter.GetBytes(NeedPush)); return buf.ToArray(); } /// /// 17个字节 类型转换 /// /// /// public override bool TryParse(byte[] value) { if (!base.TryParse(value)) return false; int index = 16; int cnt = 1; int idx = index; if (value.Length < cnt+index) return false; NeedPush = BitConverter.ToBoolean(value, idx); idx += 1; return true; } #endregion } /// /// /// public class Pack_CallGetFrameDataMixReponse : Pack_CallGetFrameDataMixRequest { /// /// 结果对应的 bookmark /// public int bookmark = -1; /// /// 结果对应的 实际结束时间 /// public DateTime dt = DateTime.MinValue; /// /// 结果对应的 实际开始时间 /// public DateTime act_startDt = DateTime.MinValue; /// /// 开始分区index /// public int fromBoltIndex = 0; /// /// 结束分区index /// public int toBoltIndex = 0; /// /// 结果.数据是否有效 /// public FR_DATA_TYPE type = FR_DATA_TYPE.INVALID; /// /// 结果, 当needPush=true, 以后推送时,只发送变化了的数据 /// public FrameDataCell[] result = null; #region IPack 成员 /// /// /// /// public override byte[] ToBytes() { List buf = new List(); buf.AddRange(base.ToBytes());//17 buf.AddRange(BitConverter.GetBytes(bookmark));//4 buf.AddRange(BitConverter.GetBytes(dt.Ticks));//8 buf.AddRange(BitConverter.GetBytes(act_startDt.Ticks));//8 buf.AddRange(BitConverter.GetBytes(fromBoltIndex));//4 buf.AddRange(BitConverter.GetBytes(toBoltIndex));//4 buf.Add((byte)type);//1 if (result != null) { buf.AddRange(BitConverter.GetBytes((int)result.Length));//4 foreach (FrameDataCell dat in result) buf.AddRange(dat.ToBytes()); } else { buf.AddRange(BitConverter.GetBytes((int)0));//4 } return buf.ToArray(); } /// /// /// /// /// public override bool TryParse(byte[] value) { if (!base.TryParse(value)) return false; int index = 17; int cnt = 4 + 8 + 8 + 4 + 4 + 1 + 4; if (value.Length < cnt+index) return false; int idx = index; bookmark = BitConverter.ToInt32(value, idx); idx += 4; try { dt = new DateTime(BitConverter.ToInt64(value, idx)); } catch { return false; } idx += 8; try { act_startDt = new DateTime(BitConverter.ToInt64(value, idx)); } catch { return false; } idx += 8; fromBoltIndex = BitConverter.ToInt32(value, idx); idx += 4; toBoltIndex = BitConverter.ToInt32(value, idx); idx += 4; type = (FR_DATA_TYPE)value[idx]; idx += 1; int length = BitConverter.ToInt32(value, idx); idx += 4; if (length > 0) { cnt += length * 4; if (value.Length < cnt + index) return false; result = new FrameDataCell[length]; for (int i = 0; i < length; i++) { result[i] = new FrameDataCell(); result[i].TryParse(value, idx); idx += 8; } } else { result = null; } return true; } #endregion } /// /// /// public class Pack_CallClosePushFrameDataMixRequest : IPack { /// /// 标记, 当bm>0 为bookmark,当bm <=0 为往前面数 /// public int bm; /// /// 混合数 /// public int mix; /// /// 混合数据,只能从 start_dt 开始 /// public DateTime start_dt; #region IPack 成员 /// /// 转换为 16个字节 /// /// public virtual byte[] ToBytes() { List buf = new List(); buf.AddRange(BitConverter.GetBytes(bm)); buf.AddRange(BitConverter.GetBytes(mix)); buf.AddRange(BitConverter.GetBytes(start_dt.Ticks)); return buf.ToArray(); } /// /// 16个字节 类型转换 /// /// public virtual bool TryParse(byte[] value) { int count = 4+4+8; if (value.Length < count) return false; int idx = 0; bm = BitConverter.ToInt32(value, idx); idx += 4; mix = BitConverter.ToInt32(value, idx); idx += 4; try { start_dt = new DateTime(BitConverter.ToInt64(value, idx)); } catch { start_dt = DateTime.MinValue; } idx += 8; return true; } #endregion /// /// 参数是否一样 /// /// /// public bool IsSame(Pack_CallClosePushFrameDataMixRequest dest) { if ((bm == dest.bm) && (mix == dest.mix) && (start_dt == dest.start_dt)) { return true; } else { return false; } } } }