123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Edge.Core.Processor.Communicator
- {
- public interface IMessageCutter<T>
- {
-
-
-
- event EventHandler OnMessageCut;
-
-
-
- event EventHandler<MessageCutterInvalidMessageReadEventArg> OnInvalidMessageRead;
- void Feed(T data);
- T Message { get; }
- }
- public class MessageCutterInvalidMessageReadEventArg : System.EventArgs
- {
- public string Message { get; set; }
- }
-
-
-
-
- public class SizableWindow<T> : IList<T>
- {
- public Action<List<T>> OnWindowFull;
- private List<T> list = new List<T>();
- private int initialSize;
- private int? size;
- public int RealSize => this.list.Count;
-
-
-
- public SizableWindow() : this(1)
- {
- }
- public SizableWindow(int initialSize)
- {
- this.initialSize = initialSize;
- this.size = initialSize;
- }
- public void Add(T data)
- {
- this.list.Add(data);
- if (this.size == null || this.size.Value == 0)
- {
- if (OnWindowFull != null)
- this.OnWindowFull(this.list);
- }
- else if (this.list.Count == this.NewSize)
- {
- if (OnWindowFull != null)
- this.OnWindowFull(this.list);
- }
- }
- #region MyRegion
- public void Clear()
- {
- this.list.Clear();
- this.size = this.initialSize;
- }
- public IEnumerator<T> GetEnumerator()
- {
- return this.list.GetEnumerator();
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this.list.GetEnumerator();
- }
- public int IndexOf(T item)
- {
- return this.list.IndexOf(item);
- }
- public void Insert(int index, T item)
- {
- this.list.Insert(index, item);
- }
- public void RemoveAt(int index)
- {
- this.list.RemoveAt(index);
- }
- public bool Contains(T item)
- {
- return this.list.Contains(item);
- }
- public void CopyTo(T[] array, int arrayIndex)
- {
- this.list.CopyTo(array, arrayIndex);
- }
- public bool Remove(T item)
- {
- return this.list.Remove(item);
- }
- #endregion
-
-
-
-
- public int? NewSize
- {
- get { return this.size; }
- set
- {
- if (this.list.Count > 0 && this.list.Count >= value)
- {
- throw new ArgumentOutOfRangeException($"The input NewSize: {value} should > the size of current internal window(current size: {this.list.Count})");
- }
- this.size = value;
- }
- }
- public int Count => this.list.Count;
- public bool IsReadOnly => false;
- public T this[int index] { get => this.list[index]; set => this.list[index] = value; }
- }
- }
|