public IEnumerable <CodecStatusViewModel> GetAllCodecsIncludeOffline()
        {
            // TODO: Try to remove this one as an endpoint
            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();

            // Add the offline accounts to the list
            var userAgentsIdsOnline = userAgentsOnline.Select(rs => rs.SipAddress);
            var sipAccounts         = _sipAccountRepository.GetAll();
            var accountsNotOnline   = sipAccounts.Where(a => !userAgentsIdsOnline.Contains(a.UserName));

            IEnumerable <CodecStatusViewModel> notRegisteredSips = accountsNotOnline.Select(a => new CodecStatusViewModel
            {
                Id          = Guid.Empty,
                SipAddress  = a.UserName,
                DisplayName = DisplayNameHelper.GetDisplayName("", a.DisplayName, string.Empty, "", a.UserName, "", sipDomain),
                State       = CodecState.NotRegistered
            });

            return(userAgentsOnline.Concat(notRegisteredSips).ToList());
        }
예제 #2
0
        public ActionResult GetSipAccounts()
        {
            var accounts = _sipAccountRepository.GetAll();

            return(View(accounts));
        }
예제 #3
0
 public List <SipAccount> GetSipUsers()
 {
     return(_sipAccountRepository.GetAll());
 }
예제 #4
0
 public SipAccount GetSipAccountByUserName(string username)
 {
     // TODO: Keep this one. But maybe if nothing can be found, trigger cache reload of sipAccounts and search again.
     return(_sipAccountRepository.GetAll().ToList().FirstOrDefault(u => u.UserName.ToLower() == username));
 }
예제 #5
0
 public List <SipAccount> GetAll()
 {
     return(_lazyCache.GetOrAddSipAccounts(() => _internalRepository.GetAll()));
 }