/// <summary> /// Creates a new <see cref="RebroadcastFormatName"/>. /// </summary> /// <param name="provider"></param> /// <returns></returns> public static RebroadcastFormatName Create(IRebroadcastFormatProvider provider) { return(new RebroadcastFormatName() { UniqueId = provider.UniqueId, ShortName = provider.ShortName, }); }
/// <summary> /// See interface docs. /// </summary> /// <param name="providerId"></param> /// <returns></returns> public IRebroadcastFormatProvider GetProvider(string providerId) { Initialise(); IRebroadcastFormatProvider result = null; if (!String.IsNullOrEmpty(providerId)) { var map = _Providers; map.TryGetValue(providerId, out result); } return(result); }
/// <summary> /// See interface docs. /// </summary> public void Initialise() { if (UniqueId == 0) { throw new InvalidOperationException("UniqueId must be set before calling Initialise"); } if (Feed == null) { throw new InvalidOperationException("Feed must be set before calling Initialise"); } if (Connector == null) { throw new InvalidOperationException("Connector must be set before calling Initialise"); } if (String.IsNullOrEmpty(Format)) { throw new InvalidOperationException("Format must be specified before calling Initialise"); } if (_Provider != null) { throw new InvalidOperationException("Initialise has already been called"); } Connector.Name = Name; Connector.EstablishConnection(); var providerManager = Factory.Singleton.Resolve <IRebroadcastFormatManager>().Singleton; _Provider = providerManager.CreateProvider(Format); if (_Provider == null) { throw new InvalidOperationException($"There is no rebroadcast format registered with a unique ID of {Format}"); } _Provider.RebroadcastServer = this; _Provider.HookFeed(); if (_Provider.UsesSendIntervalMilliseconds) { _Timer = Factory.Singleton.Resolve <ITimer>(); _Timer.Elapsed += Timer_Elapsed; _Timer.AutoReset = false; _Timer.Enabled = true; _Timer.Interval = SendIntervalMilliseconds; _Timer.Start(); } }
/// <summary> /// Disposes of or finalises the object. /// </summary> /// <param name="disposing"></param> private void Dispose(bool disposing) { if (disposing) { if (_Timer != null) { var timer = _Timer; _Timer = null; timer.Elapsed -= Timer_Elapsed; timer.Dispose(); } if (_Provider != null) { _Provider.UnhookFeed(); _Provider = null; } } }
/// <summary> /// See interface docs. /// </summary> /// <param name="provider"></param> public void RegisterProvider(IRebroadcastFormatProvider provider) { Initialise(); if (provider == null || String.IsNullOrEmpty(provider.UniqueId)) { throw new InvalidOperationException("You must supply a provider and the UniqueId property must return a non-null non-empty string"); } lock (_SyncLock) { var newMap = CollectionHelper.ShallowCopy(_Providers); if (newMap.ContainsKey(provider.UniqueId)) { newMap[provider.UniqueId] = provider; } else { newMap.Add(provider.UniqueId, provider); } _Providers = newMap; } }