public CCTV1Adapter(string host, string infoServiceBaseUri) { _baseUri = infoServiceBaseUri; _globalSync = new StaticInfoSynchronizer <CCTVGlobalInfo>(_baseUri, "CCTVGlobal", TimeSpan.FromSeconds(5)); _staticSync = new StaticInfoSynchronizer <CCTVStaticInfo>(_baseUri, "CCTVStatic", TimeSpan.FromSeconds(5)); _dynamicSync = new StaticInfoSynchronizer <CCTVDynamicInfo>(_baseUri, "CCTVDynamic", TimeSpan.FromSeconds(5)); _hierarchySync = new StaticInfoSynchronizer <HierarchyInfo>(_baseUri, "CCTVHierarchy.Default", TimeSpan.FromSeconds(5)); _onlineSync = new StaticInfoSynchronizer <OnlineStatus>(_baseUri, "CCTVOnlineStatus", TimeSpan.FromSeconds(5)); _videoPosSync = new StaticInfoSynchronizer <VideoPosition>(_baseUri, "VideoPosition", TimeSpan.FromSeconds(5)); _videoBufSync = new StaticInfoSynchronizer <VideoBuffering>(_baseUri, "VideoBuffering", TimeSpan.FromHours(1)); _globalInfo = new CCTVGlobalInfo() { CCTV1Host = host, }; _globalSync.ReplaceAll((new CCTVGlobalInfo[] { _globalInfo }).ToDictionary(x => "Default")); _info = new CCTVInfo(host); _thumbnailProducer = new ThumbnailProducer(_info); _thumbnailProducer.ThumbnailEvent += _thumbnailProducer_ThumbnailEvent; _info.ConnectedEvent += _info_ConnectedEvent; _info.DisconnectedEvent += _info_DisconnectedEvent; _info.AuthenticationEvent += _info_AuthenticationEvent; _info.NodeTreeEvent += _info_NodeTreeEvent; _info.RealtimeInfoEvent += _info_RealtimeInfoEvent; _info.Start(); var bufferInfo = VideoBufferingInfoProvider.Instance.GetVideoBufferingInfo(); _videoBufSync.ReplaceAll(bufferInfo.ToDictionary(x => getKey(x))); }
internal void OnUpdate(StaticInfoSynchronizer <T> synchronizer, IEnumerable <string> keysUpdated) { _hasUpdated = true; if (UpdateHandler != null) { UpdateHandler(keysUpdated); } }
private void deleteAndUpdate <T>(StaticInfoSynchronizer <T> sync, IEnumerable <string> allKeys, Dictionary <string, T> newValues, Func <T, string> keyInEle) { var delKeyDict = allKeys.Where(x => !newValues.ContainsKey(x)).ToDictionary(x => x); var delValues = sync.Values.Where(x => delKeyDict.ContainsKey(keyInEle(x))); var delDict = delValues.ToDictionary(x => keyInEle(x)); sync.PutUpdate(toObjectItems(delDict, true)); sync.PutUpdate(toObjectItems(newValues, false)); }
void stop() { if (_synchronizer != null) { var synchronizer = _synchronizer; _synchronizer = null; synchronizer.Dispose(); } }
private void onUpdate(StaticInfoSynchronizer <ThumbnailInfo> synchronizer, IEnumerable <string> keysUpdated) { string key = keysUpdated.FirstOrDefault(); ThumbnailInfo info; if (key != null && synchronizer.TryGetValue(key, out info)) { _info = info; fireUpdateEvent(info); } }
void start() { if (!_disposed) { if (_synchronizer == null) { string section = $"Thumbnail/{getSection(VideoId)}"; _synchronizer = new StaticInfoSynchronizer <ThumbnailInfo>(_baseUrl, section, TimeSpan.Zero, _savePath, onUpdate); } } }
private void Dispose(bool disposing) { if (!_disposed) { if (disposing) { if (_synchronizer != null) { _synchronizer.Dispose(); } } _synchronizer = null; _disposed = true; } }
public void RegisterHierarchy(string logicalTreeName, TimeSpan interval, SyncUpdateHandler updateHandler, string savePath) { if (_syncParams.ContainsKey(CCTVInfoType.HierarchyInfo)) { IDisposable dis = _syncParams[CCTVInfoType.HierarchyInfo] as IDisposable; dis.Dispose(); } SyncParams <CCTVHierarchyInfo> sp = new SyncParams <CCTVHierarchyInfo>(HierarchyInfoUtil.CreateSection(logicalTreeName), interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVHierarchyInfo> sync = new StaticInfoSynchronizer <CCTVHierarchyInfo>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[CCTVInfoType.HierarchyInfo] = new ParamHolder <CCTVHierarchyInfo>() { Sync = sync, Param = sp }; }
public void RegisterSynchronizer <T>(SyncParams <T> param) { Type t = typeof(T); if (_dictSyncs.ContainsKey(t)) { ParamHolder <T> holder = _dictSyncs[t] as ParamHolder <T>; holder.Sync.Dispose(); } StaticInfoSynchronizer <T> newSync = new StaticInfoSynchronizer <T>(_baseAddress, param.Section, param.Interval, param.SavePath, param.OnUpdate); _dictSyncs[t] = new ParamHolder <T>() { Sync = newSync, Param = param }; }
private void _thumbnailProducer_ThumbnailEvent(ulong videoId, Image thumbnail) { ThumbnailInfo ti = new ThumbnailInfo() { VideoId = getNodeId(videoId), Time = DateTime.Now, ImageBytes = getImageBytes(thumbnail) }; InfoItem item = new InfoItem() { Key = ti.VideoId, IsDeleted = false, Info = StaticInfoSynchronizer <ThumbnailInfo> .SerializeItem(ti) }; string section = $"Thumbnail/{getSection(ti.VideoId)}"; using (var client = new StaticInfoClient.StaticInfoClient(_baseUri, section)) client.PutUpdate(new InfoItem[] { item }); }
public void RegisterDefault(CCTVInfoType type, TimeSpan interval, SyncUpdateHandler updateHandler, string savePath) { if (_syncParams.ContainsKey(type)) { IDisposable dis = _syncParams[type] as IDisposable; dis.Dispose(); } switch (type) { case CCTVInfoType.TargetTrackInfo: { SyncParams <CCTVTargetTrack> sp = new SyncParams <CCTVTargetTrack>(DefaultSections.TargetTrackInfo, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVTargetTrack> sync = new StaticInfoSynchronizer <CCTVTargetTrack>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVTargetTrack>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.VideoAnalyzeInfo: { SyncParams <CCTVVideoAnalyze> sp = new SyncParams <CCTVVideoAnalyze>(DefaultSections.VideoAnalyzeInfo, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVVideoAnalyze> sync = new StaticInfoSynchronizer <CCTVVideoAnalyze>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVVideoAnalyze>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.VideoTrackInfo: { SyncParams <CCTVVideoTrack> sp = new SyncParams <CCTVVideoTrack>(DefaultSections.VideoTrackInfo, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVVideoTrack> sync = new StaticInfoSynchronizer <CCTVVideoTrack>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVVideoTrack>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.CameraLimitsInfo: { SyncParams <CCTVCameraLimits> sp = new SyncParams <CCTVCameraLimits>(DefaultSections.CameraLimitsInfo, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVCameraLimits> sync = new StaticInfoSynchronizer <CCTVCameraLimits>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVCameraLimits>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.DynamicInfo: { SyncParams <CCTVDynamicInfo> sp = new SyncParams <CCTVDynamicInfo>(DefaultSections.DynamicInfo, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVDynamicInfo> sync = new StaticInfoSynchronizer <CCTVDynamicInfo>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVDynamicInfo>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.GlobalInfo: { SyncParams <CCTVGlobalInfo> sp = new SyncParams <CCTVGlobalInfo>(DefaultSections.GlobalInfo, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVGlobalInfo> sync = new StaticInfoSynchronizer <CCTVGlobalInfo>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVGlobalInfo>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.HierarchyInfo: { SyncParams <CCTVHierarchyInfo> sp = new SyncParams <CCTVHierarchyInfo>(HierarchyInfoUtil.CreateSection("Default"), interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVHierarchyInfo> sync = new StaticInfoSynchronizer <CCTVHierarchyInfo>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVHierarchyInfo>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.LogicalTree: { SyncParams <CCTVLogicalTree> sp = new SyncParams <CCTVLogicalTree>(DefaultSections.LogicalTree, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVLogicalTree> sync = new StaticInfoSynchronizer <CCTVLogicalTree>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVLogicalTree>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.OnlineStatus: { SyncParams <CCTVOnlineStatus> sp = new SyncParams <CCTVOnlineStatus>(DefaultSections.OnlineStatus, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVOnlineStatus> sync = new StaticInfoSynchronizer <CCTVOnlineStatus>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVOnlineStatus>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.ServerInfo: { SyncParams <CCTVServerInfo> sp = new SyncParams <CCTVServerInfo>(DefaultSections.ServerInfo, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVServerInfo> sync = new StaticInfoSynchronizer <CCTVServerInfo>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVServerInfo>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.StaticInfo: { SyncParams <CCTVStaticInfo> sp = new SyncParams <CCTVStaticInfo>(DefaultSections.StaticInfo, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVStaticInfo> sync = new StaticInfoSynchronizer <CCTVStaticInfo>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVStaticInfo>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.ControlConfig: { SyncParams <CCTVControlConfig> sp = new SyncParams <CCTVControlConfig>(DefaultSections.ControlConfig, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVControlConfig> sync = new StaticInfoSynchronizer <CCTVControlConfig>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVControlConfig>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.DeviceInfo: { SyncParams <CCTVDeviceInfo> sp = new SyncParams <CCTVDeviceInfo>(DefaultSections.DeviceInfo, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVDeviceInfo> sync = new StaticInfoSynchronizer <CCTVDeviceInfo>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVDeviceInfo>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.UserInfo: { SyncParams <CCTVUserInfo> sp = new SyncParams <CCTVUserInfo>(DefaultSections.UserInfo, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVUserInfo> sync = new StaticInfoSynchronizer <CCTVUserInfo>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVUserInfo>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.Privilege: { SyncParams <CCTVPrivilege> sp = new SyncParams <CCTVPrivilege>(DefaultSections.Privilege, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVPrivilege> sync = new StaticInfoSynchronizer <CCTVPrivilege>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVPrivilege>() { Sync = sync, Param = sp }; } break; case CCTVInfoType.UserPrivilege: { { SyncParams <CCTVUserPrivilege> sp = new SyncParams <CCTVUserPrivilege>(DefaultSections.UserPrivilege, interval, updateHandler, savePath); StaticInfoSynchronizer <CCTVUserPrivilege> sync = new StaticInfoSynchronizer <CCTVUserPrivilege>(_baseAddress, sp.Section, sp.Interval, sp.SavePath, sp.OnUpdate); _syncParams[type] = new ParamHolder <CCTVUserPrivilege>() { Sync = sync, Param = sp }; } } break; default: break; } }
public StaticInfoClassifier(CCTVGlobalInfo global, StaticInfoSynchronizer <VideoPosition> vpSync) { _global = global; _vpSync = vpSync; }