示例#1
0
        /// <summary>
        /// Stops listening for requests, stops sending periodic broadcasts, disposes all internal resources.
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                DisposeRebroadcastTimer();

                var commsServer = _CommsServer;
                if (commsServer != null)
                {
                    commsServer.RequestReceived -= this.CommsServer_RequestReceived;
                }

                var tasks = Devices.ToList().Select(RemoveDevice).ToArray();
                Task.WaitAll(tasks);

                _CommsServer = null;
                if (commsServer != null)
                {
                    if (!commsServer.IsShared)
                    {
                        commsServer.Dispose();
                    }
                }

                _RecentSearchRequests = null;
            }
        }
        /// <summary>
        /// Disposes this object and all internal resources. Stops listening for all network messages.
        /// </summary>
        /// <param name="disposing">True if managed resources should be disposed, or false is only unmanaged resources should be cleaned up.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                Timer timer = _ExpireCachedDevicesTimer;

                if (timer != null)
                {
                    timer.Dispose();
                }

                var commsServer = _CommunicationsServer;
                _CommunicationsServer = null;

                if (commsServer != null)
                {
                    commsServer.ResponseReceived -= this.CommsServer_ResponseReceived;
                    commsServer.RequestReceived  -= this.CommsServer_RequestReceived;

                    if (!commsServer.IsShared)
                    {
                        commsServer.Dispose();
                    }
                }
            }
        }
示例#3
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            DisposeDevicePublisher();
            DisposePlayToManager();
            DisposeDeviceDiscovery();

            if (_communicationsServer != null)
            {
                _logger.LogInformation("Disposing SsdpCommunicationsServer");
                _communicationsServer.Dispose();
                _communicationsServer = null;
            }

            ContentDirectory       = null;
            ConnectionManager      = null;
            MediaReceiverRegistrar = null;
            Current = null;

            _disposed = true;
        }
        /// <summary>
        /// Stops listening for requests, stops sending periodic broadcasts, disposes all internal resources.
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                var commsServer = _CommsServer;
                _CommsServer = null;

                if (commsServer != null)
                {
                    commsServer.RequestReceived -= this.CommsServer_RequestReceived;
                    if (!commsServer.IsShared)
                    {
                        commsServer.Dispose();
                    }
                }

                DisposeRebroadcastTimer();

                foreach (var device in this.Devices)
                {
                    DisconnectFromDeviceEvents(device);
                }

                _RecentSearchRequests = null;
            }
        }
示例#5
0
		/// <summary>
		/// Default constructor.
		/// </summary>
		/// <param name="communicationsServer">The <see cref="ISsdpCommunicationsServer"/> implementation to use for network communications.</param>
		protected SsdpDeviceLocatorBase(ISsdpCommunicationsServer communicationsServer)
		{
			if (communicationsServer == null) throw new ArgumentNullException("communicationsServer");

			_CommunicationsServer = communicationsServer;
			_CommunicationsServer.ResponseReceived += CommsServer_ResponseReceived;

			_SearchResultsSynchroniser = new object();
			_Devices = new List<DiscoveredSsdpDevice>();
		}
示例#6
0
 private void StartDeviceDiscovery(ISsdpCommunicationsServer communicationsServer)
 {
     try
     {
         ((DeviceDiscovery)_deviceDiscovery).Start(communicationsServer);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "Error starting device discovery");
     }
 }
示例#7
0
 public SsdpDeviceLocator(ISsdpCommunicationsServer communicationsServer, ITimerFactory timerFacatory) : base(communicationsServer, timerFacatory)
 {
     // This is not the problem you are looking for;
     // Yes, this is poor man's dependency injection which some call an anti-pattern.
     // However, it makes the library really simple to get started with or to use if the calling code isn't using IoC/DI.
     // The fact we have injected dependencies is really an internal architectural implementation detail to allow for the
     // cross platform and testing concerns of this library. It shouldn't be something calling code worries about and is
     // not a deliberate extension point, except where adding new platform support in which case...
     // There is a constructor that takes a manually injected dependency anyway, so proper DI using
     // a container or whatever can be done anyway.
 }
示例#8
0
        public void Dispose()
        {
            DisposeDlnaServer();
            DisposePlayToManager();
            DisposeSsdpHandler();

            if (_communicationsServer != null)
            {
                _communicationsServer.Dispose();
                _communicationsServer = null;
            }
        }
示例#9
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public SsdpDeviceLocator(ISsdpCommunicationsServer communicationsServer)
        {
            if (communicationsServer == null)
            {
                throw new ArgumentNullException(nameof(communicationsServer));
            }

            _CommunicationsServer = communicationsServer;
            _CommunicationsServer.ResponseReceived += CommsServer_ResponseReceived;

            _Devices = new List <DiscoveredSsdpDevice>();
        }
示例#10
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public SsdpDeviceLocator(ISsdpCommunicationsServer communicationsServer, ITimerFactory timerFactory)
        {
            if (communicationsServer == null)
            {
                throw new ArgumentNullException("communicationsServer");
            }

            _CommunicationsServer = communicationsServer;
            _timerFactory         = timerFactory;
            _CommunicationsServer.ResponseReceived += CommsServer_ResponseReceived;

            _Devices = new List <DiscoveredSsdpDevice>();
        }
示例#11
0
        public void Dispose()
        {
            DisposeDevicePublisher();
            DisposePlayToManager();
            DisposeDeviceDiscovery();

            if (_communicationsServer != null)
            {
                _logger.Info("Disposing SsdpCommunicationsServer");
                _communicationsServer.Dispose();
                _communicationsServer = null;
            }
        }
示例#12
0
        public void Dispose()
        {
            DisposeDlnaServer();
            DisposePlayToManager();
            DisposeSsdpHandler();

            if (_communicationsServer != null)
            {
                _communicationsServer.Dispose();
                _communicationsServer = null;
            }
            GC.SuppressFinalize(this);
        }
示例#13
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="communicationsServer">The <see cref="ISsdpCommunicationsServer"/> implementation to use for network communications.</param>
        protected SsdpDeviceLocatorBase(ISsdpCommunicationsServer communicationsServer)
        {
            if (communicationsServer == null)
            {
                throw new ArgumentNullException("communicationsServer");
            }

            _CommunicationsServer = communicationsServer;
            _CommunicationsServer.ResponseReceived += CommsServer_ResponseReceived;

            _SearchResultsSynchroniser = new object();
            _Devices = new List <DiscoveredSsdpDevice>();
        }
示例#14
0
        /// <summary>
        /// Disposes this object and all internal resources. Stops listening for all network messages.
        /// </summary>
        /// <param name="disposing">True if managed resources should be disposed, or false is only unmanaged resources should be cleaned up.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                DisposeBroadcastTimer();

                var commsServer = _CommunicationsServer;
                _CommunicationsServer = null;
                if (commsServer != null)
                {
                    commsServer.ResponseReceived -= this.CommsServer_ResponseReceived;
                    commsServer.RequestReceived  -= this.CommsServer_RequestReceived;
                }
            }
        }
示例#15
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer, INetworkManager networkManager,
                                   string osName, string osVersion, bool sendOnlyMatchedHost)
        {
            if (communicationsServer == null)
            {
                throw new ArgumentNullException(nameof(communicationsServer));
            }

            if (networkManager == null)
            {
                throw new ArgumentNullException(nameof(networkManager));
            }

            if (osName == null)
            {
                throw new ArgumentNullException(nameof(osName));
            }

            if (osName.Length == 0)
            {
                throw new ArgumentException("osName cannot be an empty string.", nameof(osName));
            }

            if (osVersion == null)
            {
                throw new ArgumentNullException(nameof(osVersion));
            }

            if (osVersion.Length == 0)
            {
                throw new ArgumentException("osVersion cannot be an empty string.", nameof(osName));
            }

            _SupportPnpRootDevice = true;
            _Devices              = new List <SsdpRootDevice>();
            _ReadOnlyDevices      = new ReadOnlyCollection <SsdpRootDevice>(_Devices);
            _RecentSearchRequests = new Dictionary <string, SearchRequest>(StringComparer.OrdinalIgnoreCase);
            _Random = new Random();

            _networkManager = networkManager;
            _CommsServer    = communicationsServer;
            _CommsServer.RequestReceived += CommsServer_RequestReceived;
            _OSName              = osName;
            _OSVersion           = osVersion;
            _sendOnlyMatchedHost = sendOnlyMatchedHost;

            _CommsServer.BeginListeningForBroadcasts();
        }
示例#16
0
        // Call this method from somewhere in your code to start the search.
        public void Start(ISsdpCommunicationsServer communicationsServer)
        {
            _deviceLocator = new SsdpDeviceLocator(communicationsServer, _timerFactory);

            // (Optional) Set the filter so we only see notifications for devices we care about
            // (can be any search target value i.e device type, uuid value etc - any value that appears in the
            // DiscoverdSsdpDevice.NotificationType property or that is used with the searchTarget parameter of the Search method).
            //_DeviceLocator.NotificationFilter = "upnp:rootdevice";

            // Connect our event handler so we process devices as they are found
            _deviceLocator.DeviceAvailable   += deviceLocator_DeviceAvailable;
            _deviceLocator.DeviceUnavailable += _DeviceLocator_DeviceUnavailable;

            // Perform a search so we don't have to wait for devices to broadcast notifications
            // again to get any results right away (notifications are broadcast periodically).
            StartAsyncSearch();
        }
示例#17
0
        // Call this method from somewhere in your code to start the search.
        public void Start(ISsdpCommunicationsServer communicationsServer)
        {
            _deviceLocator = new SsdpDeviceLocator(communicationsServer, _timerFactory);

            // (Optional) Set the filter so we only see notifications for devices we care about
            // (can be any search target value i.e device type, uuid value etc - any value that appears in the
            // DiscoverdSsdpDevice.NotificationType property or that is used with the searchTarget parameter of the Search method).
            //_DeviceLocator.NotificationFilter = "upnp:rootdevice";

            // Connect our event handler so we process devices as they are found
            _deviceLocator.DeviceAvailable   += deviceLocator_DeviceAvailable;
            _deviceLocator.DeviceUnavailable += _DeviceLocator_DeviceUnavailable;

            var dueTime  = TimeSpan.FromSeconds(5);
            var interval = TimeSpan.FromSeconds(_config.GetDlnaConfiguration().ClientDiscoveryIntervalSeconds);

            _deviceLocator.RestartBroadcastTimer(dueTime, interval);
        }
示例#18
0
        private void StartSsdpHandler()
        {
            try
            {
                if (_communicationsServer == null)
                {
                    var enableMultiSocketBinding = _environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows;

                    _communicationsServer = new SsdpCommunicationsServer(_socketFactory, _networkManager, _logger, enableMultiSocketBinding)
                    {
                        IsShared = true
                    };

                    StartDeviceDiscovery(_communicationsServer);
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error starting ssdp handlers", ex);
            }
        }
示例#19
0
        /// <summary>
        /// Full constructor.
        /// </summary>
        /// <param name="communicationsServer">The <see cref="ISsdpCommunicationsServer"/> implementation, used to send and receive SSDP network messages.</param>
        /// <param name="osName">Then name of the operating system running the server.</param>
        /// <param name="osVersion">The version of the operating system running the server.</param>
        /// <param name="log">An implementation of <see cref="ISsdpLogger"/> to be used for logging activity. May be null, in which case no logging is performed.</param>
        protected SsdpDevicePublisherBase(ISsdpCommunicationsServer communicationsServer, string osName, string osVersion, ISsdpLogger log)
        {
            if (communicationsServer == null)
            {
                throw new ArgumentNullException("communicationsServer");
            }
            if (osName == null)
            {
                throw new ArgumentNullException("osName");
            }
            if (osName.Length == 0)
            {
                throw new ArgumentException("osName cannot be an empty string.", "osName");
            }
            if (osVersion == null)
            {
                throw new ArgumentNullException("osVersion");
            }
            if (osVersion.Length == 0)
            {
                throw new ArgumentException("osVersion cannot be an empty string.", "osName");
            }

            _Log = log ?? NullLogger.Instance;
            _SupportPnpRootDevice = true;
            _Devices              = new List <SsdpRootDevice>();
            _ReadOnlyDevices      = new ReadOnlyEnumerable <SsdpRootDevice>(_Devices);
            _RecentSearchRequests = new Dictionary <string, SearchRequest>(StringComparer.OrdinalIgnoreCase);
            _Random          = new Random();
            _DeviceValidator = new Upnp10DeviceValidator();             //Should probably inject this later, but for now we only support 1.0.

            _CommsServer = communicationsServer;
            _CommsServer.RequestReceived += CommsServer_RequestReceived;
            _OSName    = osName;
            _OSVersion = osVersion;

            _Log.LogInfo("Publisher started.");
            _CommsServer.BeginListeningForBroadcasts();
            _Log.LogInfo("Publisher started listening for broadcasts.");
        }
示例#20
0
        private void StartSsdpHandler()
        {
            try
            {
                if (_communicationsServer == null)
                {
                    var enableMultiSocketBinding = OperatingSystem.Id == OperatingSystemId.Windows ||
                                                   OperatingSystem.Id == OperatingSystemId.Linux;

                    _communicationsServer = new SsdpCommunicationsServer(_config, _socketFactory, _networkManager, _logger, enableMultiSocketBinding)
                    {
                        IsShared = true
                    };

                    StartDeviceDiscovery(_communicationsServer);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error starting ssdp handlers");
            }
        }
示例#21
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="communicationsServer">The <see cref="ISsdpCommunicationsServer"/> implementation, used to send and receive SSDP network messages.</param>
        /// <param name="osName">Then name of the operating system running the server.</param>
        /// <param name="osVersion">The version of the operating system running the server.</param>
        protected SsdpDevicePublisherBase(ISsdpCommunicationsServer communicationsServer, string osName, string osVersion)
        {
            if (communicationsServer == null) throw new ArgumentNullException("communicationsServer");
            if (osName == null) throw new ArgumentNullException("osName");
            if (osName.Length == 0) throw new ArgumentException("osName cannot be an empty string.", "osName");
            if (osVersion == null) throw new ArgumentNullException("osVersion");
            if (osVersion.Length == 0) throw new ArgumentException("osVersion cannot be an empty string.", "osName");

            _SupportPnpRootDevice = true;
            _Devices = new List<SsdpRootDevice>();
            _ReadOnlyDevices = new ReadOnlyEnumerable<SsdpRootDevice>(_Devices);
            _RecentSearchRequests = new Dictionary<string, SearchRequest>(StringComparer.OrdinalIgnoreCase);
            _Random = new Random();
            _DeviceValidator = new Upnp10DeviceValidator(); //Should probably inject this later, but for now we only support 1.0.

            _CommsServer = communicationsServer;
            _CommsServer.RequestReceived += CommsServer_RequestReceived;
            _OSName = osName;
            _OSVersion = osVersion;

            _CommsServer.BeginListeningForBroadcasts();
        }
示例#22
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer, ITimerFactory timerFactory, string osName, string osVersion, Func <int> deviceCacheSeconds)
        {
            if (communicationsServer == null)
            {
                throw new ArgumentNullException("communicationsServer");
            }
            if (osName == null)
            {
                throw new ArgumentNullException("osName");
            }
            if (osName.Length == 0)
            {
                throw new ArgumentException("osName cannot be an empty string.", "osName");
            }
            if (osVersion == null)
            {
                throw new ArgumentNullException("osVersion");
            }
            if (osVersion.Length == 0)
            {
                throw new ArgumentException("osVersion cannot be an empty string.", "osName");
            }

            _SupportPnpRootDevice = true;
            _timerFactory         = timerFactory;
            _Devices              = new List <SsdpRootDevice>();
            _ReadOnlyDevices      = new ReadOnlyCollection <SsdpRootDevice>(_Devices);
            _RecentSearchRequests = new Dictionary <string, SearchRequest>(StringComparer.OrdinalIgnoreCase);
            _Random = new Random();

            _CommsServer = communicationsServer;
            _CommsServer.RequestReceived += CommsServer_RequestReceived;
            _OSName               = osName;
            _OSVersion            = osVersion;
            _deviceCacheSecondsFn = deviceCacheSeconds;

            _CommsServer.BeginListeningForBroadcasts();
        }
示例#23
0
 /// <summary>
 /// Full constructor. Constructs a new instance using the provided <see cref="ISsdpCommunicationsServer"/> implementation.
 /// </summary>
 public SsdpDeviceLocator(ISsdpCommunicationsServer communicationsServer)
     : base(communicationsServer)
 {
 }
示例#24
0
 public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer, ITimerFactory timerFactory, string osName, string osVersion)
     : base(communicationsServer, timerFactory, osName, osVersion)
 {
 }
示例#25
0
 /// <summary>
 /// Full constructor. Constructs a new instance using the provided <see cref="ISsdpCommunicationsServer"/> implementation.
 /// </summary>
 public SsdpDeviceLocator(ISsdpCommunicationsServer communicationsServer)
     : base(communicationsServer)
 {
 }
示例#26
0
 public Discovery(ISsdpCommunicationsServer communicationsServer, ILogger logger)
     : base(communicationsServer, OsName, OsVersion, new SsdpTraceLogger(logger))
 {
 }
示例#27
0
 /// <summary>
 /// Full constructor.
 /// </summary>
 /// <remarks>
 /// <para>Allows the caller to specify their own <see cref="ISsdpCommunicationsServer"/> implementation for full control over the networking, or for mocking/testing purposes..</para>
 /// </remarks>
 public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer)
     : base(communicationsServer, GetOSName(), GetOSVersion())
 {
 }
示例#28
0
        // Call this method from somewhere in your code to start the search.
        public void Start(ISsdpCommunicationsServer communicationsServer)
        {
            _commsServer = communicationsServer;

            StartInternal();
        }
示例#29
0
 public Discovery(ISsdpCommunicationsServer communicationsServer, string osName, string osVersion, ISsdpLogger log) : base(communicationsServer, osName, osVersion, log)
 {
 }
示例#30
0
 private void StartPublishing(ISsdpCommunicationsServer communicationsServer)
 {
     SsdpDevicePublisherBase.LogFunction = LogMessage;
     _Publisher = new SsdpDevicePublisher(communicationsServer, _timerFactory, _environmentInfo.OperatingSystemName, _environmentInfo.OperatingSystemVersion);
 }
示例#31
0
 /// <summary>
 /// Full constructor.
 /// </summary>
 /// <remarks>
 /// <para>Allows the caller to specify their own <see cref="ISsdpCommunicationsServer"/> implementation for full control over the networking, or for mocking/testing purposes..</para>
 /// </remarks>
 public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer, ISsdpLogger log)
     : base(communicationsServer, GetOSName(), GetOSVersion(), log ?? new SsdpTraceLogger())
 {
 }
示例#32
0
 /// <summary>
 /// Full constructor. 
 /// </summary>
 /// <remarks>
 /// <para>Allows the caller to specify their own <see cref="ISsdpCommunicationsServer"/> implementation for full control over the networking, or for mocking/testing purposes..</para>
 /// </remarks>
 public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer)
     : base(communicationsServer, GetOSName(), GetOSVersion())
 {
 }
示例#33
0
        /// <summary>
        /// Stops listening for requests, stops sending periodic broadcasts, disposes all internal resources.
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                var commsServer = _CommsServer;
                _CommsServer = null;

                if (commsServer != null)
                {
                    commsServer.RequestReceived -= this.CommsServer_RequestReceived;
                    if (!commsServer.IsShared)
                        commsServer.Dispose();
                }

                DisposeRebroadcastTimer();

                foreach (var device in this.Devices)
                {
                    DisconnectFromDeviceEvents(device);
                }

                _RecentSearchRequests = null;
            }
        }
示例#34
0
 public Discovery(ISsdpCommunicationsServer communicationsServer, string osName, string osVersion) : base(communicationsServer, osName, osVersion)
 {
 }
示例#35
0
 public TestDevicePublisher(ISsdpCommunicationsServer commsServer, string osName, string osVersion)
     : base(commsServer, osName, osVersion)
 {
 }
示例#36
0
 public TestDevicePublisher(ISsdpCommunicationsServer commsServer)
     : base(commsServer, "TestOS", "1.1")
 {
 }
示例#37
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="communicationsServer">The <see cref="ISsdpCommunicationsServer"/> implementation, used to send and receive SSDP network messages.</param>
 /// <param name="osName">Then name of the operating system running the server.</param>
 /// <param name="osVersion">The version of the operating system running the server.</param>
 protected SsdpDevicePublisherBase(ISsdpCommunicationsServer communicationsServer, string osName, string osVersion) : this(communicationsServer, osName, osVersion, NullLogger.Instance)
 {
 }
示例#38
0
		/// <summary>
		/// Disposes this object and all internal resources. Stops listening for all network messages.
		/// </summary>
		/// <param name="disposing">True if managed resources should be disposed, or false is only unmanaged resources should be cleaned up.</param>
		protected override void Dispose(bool disposing)
		{

			if (disposing)
			{
				var timer = _ExpireCachedDevicesTimer;
				if (timer != null)
					timer.Dispose();

				var commsServer = _CommunicationsServer;
				_CommunicationsServer = null;
				if (commsServer != null)
				{
					commsServer.ResponseReceived -= this.CommsServer_ResponseReceived;
					commsServer.RequestReceived -= this.CommsServer_RequestReceived;
					if (!commsServer.IsShared)
						commsServer.Dispose();
				}
			}
		}