123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System;
- using System.Collections.Generic;
- namespace fis.Vid
- {
- public class DisplayChannel:IDisposable
- {
- private static readonly Dictionary<VidType, Func<string, IDisplayEngine>> EngineCreators = new Dictionary<VidType, Func<string, IDisplayEngine>>();
- private bool _disposed;
- public event EventHandler Disposing;
-
- public IDisplayEngine Engine { get; }
- public string ChannelId { get; }
- public byte[] BasicData { get; }
- public int ImageCount { get; }
- public byte[] ExtendedData { get; }
- static DisplayChannel()
- {
- EngineCreators.Add(VidType.VinnoVidSingle, s => new VidDisplayEngine(s));
- EngineCreators.Add(VidType.VinnoVidMovie, s => new VidDisplayEngine(s));
- EngineCreators.Add(VidType.ThirdVidSingle, s => new ThirdPartVidDisplayEngine(s));
- EngineCreators.Add(VidType.ThirdVidMovie, s => new ThirdPartVidDisplayEngine(s));
- }
- public DisplayChannel(VidType dataType, string filePath)
- {
- ChannelId = Guid.NewGuid().ToString("N").ToUpper();
- if (!EngineCreators.ContainsKey(dataType))
- {
- throw new KeyNotFoundException($"Can not find engine creator of {dataType}");
- }
- var engine = EngineCreators[dataType](filePath);
- Engine = engine;
- ImageCount = Engine.ImageCount;
- BasicData = Engine.BasicData;
- ExtendedData = Engine.ExtendedData;
- }
- ~DisplayChannel()
- {
- Dispose(false);
- }
- public byte[] GetImageData(int index)
- {
- return Engine.GetImageData(index);
- }
- protected void Dispose(bool disposing)
- {
- if (!_disposed)
- {
- Engine?.Close();
- }
- _disposed = true;
- }
- public void Dispose()
- {
- OnDisposing();
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- public override string ToString()
- {
- return ChannelId;
- }
- protected virtual void OnDisposing()
- {
- Disposing?.Invoke(this, EventArgs.Empty);
- }
- }
- }
|