public IEnumerable <CodecStatusViewModel> GetAll()
        {
            var registeredUserAgents = _registeredSipRepository.GetRegisteredUserAgents();
            var sipDomain            = _settingsManager.SipDomain;
            var ongoingCalls         = _callRepository.GetOngoingCalls(true);

            var userAgentsOnline = registeredUserAgents.Select(regSip =>
            {
                string displayName = DisplayNameHelper.GetDisplayName(regSip.DisplayName, regSip.UserDisplayName,
                                                                      string.Empty, regSip.Username, regSip.SipUri, "", sipDomain);

                var result = new CodecStatusViewModel
                {
                    SipAddress       = regSip.SipUri,
                    Id               = regSip.Id,
                    PresentationName = displayName,
                    DisplayName      = displayName
                };

                var call      = ongoingCalls.FirstOrDefault(c => c.FromSip == regSip.SipUri || c.ToSip == regSip.SipUri);
                bool inCall   = call != null;
                result.InCall = inCall;

                if (inCall)
                {
                    var isFromCaller                   = call.FromSip == regSip.SipUri;
                    result.IsCallingPart               = isFromCaller;
                    result.ConnectedToSipAddress       = isFromCaller ? call.ToSip : call.FromSip;
                    result.ConnectedToPresentationName = isFromCaller
                        ? DisplayNameHelper.GetDisplayName(call.ToDisplayName, null, null, "", call.ToSip, "", sipDomain)
                        : DisplayNameHelper.GetDisplayName(call.FromDisplayName, null, null, "", call.FromSip, "", sipDomain);
                    result.ConnectedToLocation = isFromCaller ? call.ToLocationName : call.FromLocationName;
                    result.CallStartedAt       = call.Started;
                }
                // TODO: In Call with DisplayName is lacking the actual Display name (on user) entered in CCM. Not sure the importance.

                result.State = regSip.Id == Guid.Empty
                    ? CodecState.NotRegistered
                    : (inCall ? CodecState.InCall : CodecState.Available);

                return(result);
            }).ToList();

            return(userAgentsOnline);
        }
        public IEnumerable <RegisteredUserAgentViewModel> GetAll()
        {
            var registeredUserAgents = _registeredSipRepository.GetRegisteredUserAgents();
            var sipDomain            = _settingsManager.SipDomain;

            var calls = _callRepository.GetOngoingCalls(true);

            var userAgentsOnline = registeredUserAgents.Select(regSip =>
            {
                var result = new RegisteredUserAgentViewModel
                {
                    Sip = regSip.SipUri,
                    Id  = regSip.Id,

                    DisplayName = DisplayNameHelper.GetDisplayName(regSip.DisplayName, regSip.UserDisplayName,
                                                                   string.Empty, regSip.Username, regSip.SipUri, "", sipDomain),

                    Location          = regSip.Location,
                    LocationShortName = regSip.LocationShortName,
                    Image             = regSip.Image,
                    CodecTypeName     = regSip.CodecTypeName,
                    CodecTypeColor    = regSip.CodecTypeColor,
                    UserName          = regSip.Username,
                    UserComment       = regSip.UserComment,
                    RegionName        = regSip.RegionName
                };

                var call      = calls.FirstOrDefault(c => c.FromSip == regSip.SipUri || c.ToSip == regSip.SipUri);
                bool inCall   = call != null;
                result.InCall = inCall;

                if (inCall)
                {
                    var isFromCaller      = call.FromSip == regSip.SipUri;
                    result.InCallWithId   = isFromCaller ? call.ToId : call.FromId;
                    result.InCallWithSip  = isFromCaller ? call.ToSip : call.FromSip;
                    result.InCallWithName = isFromCaller ? call.ToDisplayName : call.FromDisplayName;
                }

                return(result);
            }).ToList();

            return(userAgentsOnline);
        }
Beispiel #3
0
 public IList <OnGoingCall> GetOngoingCalls(bool anonomize)
 {
     return(_internalRepository.GetOngoingCalls(anonomize));
 }
Beispiel #4
0
 public IReadOnlyCollection <OnGoingCall> GetOngoingCalls(bool anonymize)
 {
     return(_lazyCache.GetOrAddOngoingCalls(() => _internalRepository.GetOngoingCalls(anonymize)));
 }
Beispiel #5
0
 public IList <OnGoingCall> Post()
 {
     return(_callRepository.GetOngoingCalls(true));
 }
Beispiel #6
0
        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());
        }
Beispiel #7
0
 public IReadOnlyCollection <OnGoingCall> Post()
 {
     // TODO: Maybe this needs to be a sorted readonly list?
     return(_callRepository.GetOngoingCalls(true));
 }