public IEnumerable <RegisteredUserAgentDiscovery> GetRegisteredUserAgentsDiscovery() { return(_lazyCache.GetOrAddRegisteredUserAgentsDiscovery(() => _internalRepository.GetRegisteredUserAgentsDiscovery())); }
public IEnumerable <RegisteredUserAgentAndProfilesDiscovery> GetRegisteredUserAgentsAndProfiles() { var sipDomain = _settingsManager.SipDomain; // Registered user agents IEnumerable <RegisteredUserAgentDiscovery> registeredUserAgentsList = _registeredSipRepository.GetRegisteredUserAgentsDiscovery(); if (registeredUserAgentsList == null) { return(null); } // User agent types and profiles for each User Agent IDictionary <Guid, UserAgentAndProfiles> userAgentsTypesList = _userAgentRepository.GetUserAgentsTypesAndProfiles(); // Locations and profile groups IDictionary <Guid, LocationAndProfiles> locationsAndProfileGroupList = _locationRepository.GetLocationsAndProfiles(); // Profile groups IReadOnlyList <ProfileGroup> profileGroupsList = _profileGroupRepository.GetAll(); // Ongoing calls IReadOnlyCollection <OnGoingCall> callsList = _callRepository.GetOngoingCalls(true); return(registeredUserAgentsList.Select(regSip => { // The sort order is most important as it decides the order // of recommended profiles in the Discovery service. // Sorting is based on the sort order of the location. // Match register user agent user agent profiles var profilesUserAgent = Enumerable.Empty <string>(); if (regSip.UserAgentId != null && userAgentsTypesList.TryGetValue(regSip.UserAgentId.Value, out var profilesUa)) { profilesUserAgent = profilesUa.Profiles.OrderBy(z => z.SortIndex).Select(y => y.Name); // TODO: No sort is done here...it's done earlier. trust? Is it the right sort? } // Match location profiles and add profile names to locations profile groups int?profilesLocationSortWeight = null; var profilesLocation = Enumerable.Empty <string>(); if (regSip.LocationId != null && locationsAndProfileGroupList.TryGetValue(regSip.LocationId.Value, out var profileLoc)) { //var locMatch = profileGroupsList.FirstOrDefault(x => x.Id == profileLoc.ProfileGroupId)?.Profiles.OrderBy(z => z.SortIndex).Select(y => y.Name); var locMatch = profileGroupsList.FirstOrDefault(x => x.Id == profileLoc.ProfileGroupId)?.Profiles.Select(y => y.Name); if (locMatch != null) { profilesLocation = locMatch; } // Get location profile group sort weight var locMatchGroup = profileGroupsList.FirstOrDefault(x => x.Id == profileLoc.ProfileGroupId); if (locMatchGroup != null) { profilesLocationSortWeight = locMatchGroup.GroupSortWeight; } } IList <string> filteredProfiles = profilesLocation.Intersect(profilesUserAgent).ToList(); // Call information var call = callsList.FirstOrDefault(c => c.FromSip == regSip.SipUri || c.ToSip == regSip.SipUri); bool inCall = call != null; string inCallWithId = string.Empty; string inCallWithSip = string.Empty; string inCallWithName = string.Empty; if (inCall) { var isFromCaller = call.FromSip == regSip.SipUri; inCallWithId = isFromCaller ? call.ToId : call.FromId; inCallWithSip = isFromCaller ? call.ToSip : call.FromSip; inCallWithName = isFromCaller ? call.ToDisplayName : call.FromDisplayName; } // Registered user agent var dispName = DisplayNameHelper.GetDisplayName(regSip.DisplayName, regSip.UserDisplayName, string.Empty, regSip.Username, regSip.SipUri, "", sipDomain); return new RegisteredUserAgentAndProfilesDiscovery( id: regSip.Id, sipUri: regSip.SipUri, displayName: dispName, username: regSip.Username, ipAddress: regSip.IpAddress, userAgentHeader: regSip.UserAgentHeader, userAgentName: regSip.UserAgentName, locationName: regSip.LocationName, locationShortName: regSip.LocationShortName, regionName: regSip.RegionName, cityName: regSip.CityName, userOwnerName: regSip.UserOwnerName, userDisplayName: regSip.UserDisplayName, codecTypeName: regSip.CodecTypeName, metaData: regSip.MetaData, orderedProfiles: filteredProfiles, locationProfileGroupSortWeight: profilesLocationSortWeight, inCall: inCall, inCallWithId: inCallWithId, inCallWithSip: inCallWithSip, inCallWithName: inCallWithName); }).ToList()); }