private string GetIpOfGroup(Group group, DeviceEureka eurekaIn)
        {
            if (group.Elected_leader == null || group.Elected_leader == "self" || group.Elected_leader.IndexOf(":") < 0)
            {
                return(eurekaIn.Net.Ip_address);
            }

            return(group.Elected_leader.Substring(0, group.Elected_leader.IndexOf(":")));
        }
        private int GetPortOfGroup(Group group, DeviceEureka eurekaIn)
        {
            if (group.Elected_leader == null || group.Elected_leader == "self" || group.Elected_leader.IndexOf(":") < 0)
            {
                return(group.Cast_port);
            }

            if (int.TryParse(group.Elected_leader.Substring(group.Elected_leader.IndexOf(":") + 1), out int result))
            {
                return(result);
            }

            return(0);
        }
        /// <summary>
        /// Callback for when the device information is collected.
        /// </summary>
        /// <param name="eurekaIn"></param>
        private void SetDeviceInformation(DeviceEureka eurekaIn)
        {
            var discoveredDevice = new DiscoveredDevice
            {
                IPAddress         = eurekaIn.GetIpAddress(),
                Name              = eurekaIn.GetName(),
                Port              = 8009,
                Protocol          = "",
                Usn               = null,
                IsGroup           = false,
                AddedByDeviceInfo = true,
                Eureka            = eurekaIn
            };

            OnDeviceAvailable(discoveredDevice);

            if (eurekaIn?.Multizone?.Groups == null)
            {
                return;
            }

            foreach (var group in eurekaIn.Multizone.Groups)
            {
                discoveredDevice = new DiscoveredDevice
                {
                    IPAddress         = GetIpOfGroup(group, eurekaIn),
                    Name              = group.Name,
                    Port              = GetPortOfGroup(group, eurekaIn),
                    Protocol          = "",
                    Usn               = null,
                    IsGroup           = true,
                    AddedByDeviceInfo = true,
                    Eureka            = eurekaIn,
                    Group             = group
                };

                // Add the group.
                if (group.Elected_leader == "self")
                {
                    OnDeviceAvailable(discoveredDevice);
                }

                // Get device information from unknown devices.
                if (!deviceList.Any(x => x.GetHost() == GetIpOfGroup(group, eurekaIn)))
                {
                    applicationLogic.StartTask(DeviceInformation.GetDeviceInformation(discoveredDevice, SetDeviceInformation, logger));
                }
            }
        }
        /// <summary>
        /// Callback for when the device information is collected.
        /// </summary>
        /// <param name="eurekaIn"></param>
        private void SetDeviceInformation(DeviceEureka eurekaIn)
        {
            var discoveredDevice = new DiscoveredDevice
            {
                IPAddress         = eurekaIn.GetIpAddress(),
                MACAddress        = eurekaIn.GetMacAddress(),
                Name              = eurekaIn.GetName(),
                Port              = 8009,
                Protocol          = "",
                Usn               = null,
                IsGroup           = false,
                AddedByDeviceInfo = true,
                Eureka            = eurekaIn
            };

            OnDeviceAvailable(discoveredDevice);
        }
예제 #5
0
 /// <summary>
 /// Set the device information.
 /// </summary>
 /// <param name="eureka"></param>
 private void SetDeviceInformation(DeviceEureka eurekaIn)
 {
     SetDeviceName(eurekaIn.GetName());
     eureka = eurekaIn;
     setDeviceInformationCallback?.Invoke(eureka);
 }
 /// <summary>
 /// Set the device information.
 /// </summary>
 /// <param name="eureka"></param>
 private void SetDeviceInformation(DeviceEureka eurekaIn)
 {
     SetDeviceName(GetDiscoveredDevice()?.Name);
     eureka = eurekaIn;
     setDeviceInformationCallback?.Invoke(eureka);
 }