Beispiel #1
0
 public static string GetDisplayName(Entities.RegisteredSipEntity regSip, string callDisplayName, string callUserName, string sipDomain)
 {
     return(DisplayNameHelper.GetDisplayName(
                regSip != null ? regSip.DisplayName : string.Empty,
                regSip != null && regSip.User != null ? regSip.User.DisplayName : string.Empty,
                callDisplayName,
                regSip != null ? regSip.Username : string.Empty,
                regSip != null ? regSip.SIP : string.Empty,
                callUserName,
                sipDomain));
 }
Beispiel #2
0
        public RegisteredSipDetails GetRegisteredSipById(Guid id)
        {
            using (var db = GetDbContext())
            {
                Entities.RegisteredSipEntity dbSip = db.RegisteredSips
                                                     .Include(rs => rs.Location)
                                                     .Include(rs => rs.Location.City)
                                                     .Include(rs => rs.Location.Region)
                                                     .Include(rs => rs.UserAgent)
                                                     .Include(rs => rs.User)
                                                     .SingleOrDefault(r => r.Id == id);

                return(MapToRegisteredSipDetails(dbSip));
            }
        }
Beispiel #3
0
        private RegisteredSipDto MapToRegisteredSipDto(Entities.RegisteredSipEntity dbSip, List <MetaType> metaList)
        {
            if (dbSip == null)
            {
                return(null);
            }

            var regSip = new RegisteredSipDto
            {
                Updated           = dbSip.Updated,
                Id                = dbSip.Id,
                Sip               = dbSip.SIP,
                DisplayName       = dbSip.DisplayName,
                UserDisplayName   = dbSip.User != null ? dbSip.User.DisplayName : string.Empty,
                IpAddress         = dbSip.IP,
                UserAgentHeader   = dbSip.UserAgentHead,
                UserName          = dbSip.Username,
                RegionName        = dbSip.Location != null && dbSip.Location.Region != null ? dbSip.Location.Region.Name : string.Empty,
                CodecTypeName     = dbSip.User != null && dbSip.User.CodecType != null ? dbSip.User.CodecType.Name : string.Empty,
                CodecTypeColor    = dbSip.User != null && dbSip.User.CodecType != null ? dbSip.User.CodecType.Color : string.Empty,
                Comment           = dbSip.User != null ? dbSip.User.Comment : string.Empty,
                Image             = dbSip.UserAgent != null ? dbSip.UserAgent.Image : string.Empty,
                Api               = dbSip.UserAgent != null ? dbSip.UserAgent.Api : string.Empty,
                LocationName      = dbSip.Location != null ? dbSip.Location.Name : string.Empty,
                LocationShortName = dbSip.Location != null ? dbSip.Location.ShortName : string.Empty,

                // Filtering properties. Not currently used.
                //OwnerName = dbSip.User != null && dbSip.User.Owner != null ? dbSip.User.Owner.Name : string.Empty,
                //CityName = dbSip.Location != null && dbSip.Location.City != null ? dbSip.Location.City.Name : string.Empty,
                //UserAgentName = dbSip.UserAgent != null ? dbSip.UserAgent.Name : string.Empty,

                HasGpo = dbSip.UserAgent != null && !string.IsNullOrEmpty(dbSip.UserAgent.GpoNames),
            };

            var locationProfiles = dbSip.Location != null?dbSip.Location.ProfileGroup.OrderedProfiles.OrderBy(op => op.SortIndex).Select(p => p.Profile.Name) : Enumerable.Empty <string>();

            var userAgentProfiles = dbSip.UserAgent != null?dbSip.UserAgent.OrderedProfiles.OrderBy(op => op.SortIndex).Select(p => p.Profile.Name) : Enumerable.Empty <string>();

            // 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.
            regSip.Profiles = locationProfiles.Intersect(userAgentProfiles).ToList();

            regSip.MetaData = GetMetaData(metaList, dbSip);
            return(regSip);
        }
        private RegisteredSipDetails MapToRegisteredSipDetails(Entities.RegisteredSipEntity rs)
        {
            if (rs == null)
            {
                return(null);
            }

            var model = new RegisteredSipDetails
            {
                Id              = rs.Id,
                Sip             = rs.SIP,
                DisplayName     = rs.DisplayName,
                Ip              = rs.IP,
                UserAgentHeader = rs.UserAgentHeader,
                Registrar       = rs.Registrar != null ? rs.Registrar : string.Empty,

                Comment             = rs.User != null ? rs.User.Comment : string.Empty,
                UserDisplayName     = rs.User != null ? rs.User.DisplayName : string.Empty,
                Api                 = rs.UserAgent != null ? rs.UserAgent.Api ?? string.Empty : string.Empty,
                Image               = rs.UserAgent?.Image ?? string.Empty,
                ActiveX             = rs.UserAgent != null && rs.UserAgent.Ax,
                Width               = rs.UserAgent?.Width ?? 1000,
                Height              = rs.UserAgent?.Height ?? 1000,
                UserInterfaceLink   = rs.UserAgent != null ? rs.UserAgent.UserInterfaceLink ?? "" : String.Empty,
                UserInterfaceIsOpen = rs.UserAgent != null && rs.UserAgent.UserInterfaceIsOpen,
                UseScrollbars       = rs.UserAgent != null && rs.UserAgent.UseScrollbars,
                Inputs              = rs.UserAgent?.Inputs ?? 0,
                NrOfGpos            = rs.UserAgent?.NrOfGpos ?? 0,
                InputGainStep       = rs.UserAgent?.InputGainStep ?? 0,
                InputMaxDb          = rs.UserAgent?.MaxInputDb ?? 0,
                InputMinDb          = rs.UserAgent?.MinInputDb ?? 0,
                Lines               = rs.UserAgent?.Lines ?? 0,

                CodecPresets = rs.UserAgent != null?rs.UserAgent.CodecPresets.Select(MapToCodecPreset).ToList() :  new List <CodecPreset>(),

                                   LocationName    = rs.Location != null ? rs.Location.Name : string.Empty,
                                   LocationComment = rs.Location != null ? rs.Location.Comment : string.Empty,
                                   CityName        = rs.Location?.City != null ? rs.Location.City.Name : string.Empty,
                                   RegionName      = rs.Location?.Region != null ? rs.Location.Region.Name : string.Empty,
            };

            return(model);
        }
Beispiel #5
0
        public RegisteredSipInfo GetRegisteredSipInfoById(Guid id)
        {
            using (var db = GetDbContext())
            {
                Entities.RegisteredSipEntity dbSip = db.RegisteredSips
                                                     .Include(rs => rs.User)
                                                     .SingleOrDefault(r => r.Id == id);

                return(dbSip == null
                    ? null
                    : new RegisteredSipInfo
                {
                    SipAddress = dbSip.SIP,
                    DisplayName = DisplayNameHelper.GetDisplayName(dbSip.DisplayName,
                                                                   dbSip.User != null ? dbSip.User.DisplayName : string.Empty, string.Empty, dbSip.Username,
                                                                   dbSip.SIP, "", _settingsManager.SipDomain)
                });
            }
        }
Beispiel #6
0
        private KamailioMessageChangeStatus GetChangeStatus(CcmDbContext cxt, Entities.RegisteredSipEntity dbSip)
        {
            var entry = cxt.Entry(dbSip);

            if (entry.State == EntityState.Added || CodecWasExpired(entry))
            {
                return(KamailioMessageChangeStatus.CodecAdded);
            }

            if (entry.State == EntityState.Modified && dbSip.Expires == 0)
            {
                return(KamailioMessageChangeStatus.CodecRemoved);
            }

            if (entry.State == EntityState.Modified && HasRelevantChange(entry))
            {
                return(KamailioMessageChangeStatus.CodecUpdated);
            }

            return(KamailioMessageChangeStatus.NothingChanged);
        }
Beispiel #7
0
        public RegisteredSip Single(Expression <Func <Entities.RegisteredSipEntity, bool> > expression)
        {
            using (var db = GetDbContext())
            {
                Entities.RegisteredSipEntity dbRegisteredSip = db.RegisteredSips.SingleOrDefault(expression);

                return(dbRegisteredSip == null
                    ? null
                    : new RegisteredSip
                {
                    Id = dbRegisteredSip.Id,
                    DisplayName = dbRegisteredSip.DisplayName,
                    Expires = dbRegisteredSip.Expires,
                    IP = dbRegisteredSip.IP,
                    Port = dbRegisteredSip.Port,
                    SIP = dbRegisteredSip.SIP,
                    ServerTimeStamp = dbRegisteredSip.ServerTimeStamp,
                    Updated = dbRegisteredSip.Updated,
                    UserAgentHead = dbRegisteredSip.UserAgentHead,
                    Username = dbRegisteredSip.Username,
                });
            }
        }
Beispiel #8
0
        public KamailioMessageHandlerResult UpdateRegisteredSip(RegisteredSip registeredSip)
        {
            // Returnerar värde som indikerar om
            // 1. Kodaren lagts till
            // 2. Kodaren fanns sedan tidigare men har på relevant sätt uppdaterad information
            // 3. Kodaren fanns sedan tidigare men registreringen i identisk. = NothingChanged

            if (registeredSip == null)
            {
                return(KamailioMessageHandlerResult.NothingChanged);
            }

            try
            {
                using (var db = GetDbContext())
                {
                    var dbSip = db.RegisteredSips.SingleOrDefault(rs => rs.SIP == registeredSip.SIP);

                    if (dbSip == null)
                    {
                        if (registeredSip.Expires == 0)
                        {
                            // Avregistrering av ej registrerad kodare. Gör ingenting.
                            return(KamailioMessageHandlerResult.NothingChanged);
                        }

                        dbSip = new Entities.RegisteredSipEntity {
                            Id = Guid.NewGuid(), Updated = DateTime.UtcNow
                        };
                        db.RegisteredSips.Add(dbSip);
                        //registeredSip.Id = dbSip.Id;
                    }
                    //else
                    //{
                    //registeredSip.Id = dbSip.Id;
                    //}

                    // Matcha och mappa
                    var user   = db.Users.FirstOrDefault(u => u.UserName == registeredSip.Username);
                    var userId = user != null ? user.Id : (Guid?)null;

                    var userAgentId = GetUserAgentId(db, registeredSip.UserAgentHead);
                    var locationId  = LocationManager.GetLocationIdByIp(registeredSip.IP);

                    registeredSip.Updated = registeredSip.Expires == 0
                        ? DateTime.UtcNow.AddSeconds(-SettingsManager.MaxRegistrationAge) // Expire immediately
                        : DateTime.UtcNow;

                    dbSip.UserAgentId         = userAgentId;
                    dbSip.Location_LocationId = locationId != Guid.Empty ? locationId : (Guid?)null;
                    dbSip.User_UserId         = userId;

                    dbSip.SIP             = registeredSip.SIP;
                    dbSip.UserAgentHead   = registeredSip.UserAgentHead;
                    dbSip.Username        = registeredSip.Username;
                    dbSip.DisplayName     = registeredSip.DisplayName;
                    dbSip.IP              = registeredSip.IP;
                    dbSip.Port            = registeredSip.Port;
                    dbSip.ServerTimeStamp = registeredSip.ServerTimeStamp;
                    dbSip.Updated         = registeredSip.Updated;
                    dbSip.Expires         = registeredSip.Expires;

                    var changeStatus = GetChangeStatus(db, dbSip);
                    db.SaveChanges();

                    return(new KamailioMessageHandlerResult {
                        ChangedObjectId = dbSip.Id, ChangeStatus = changeStatus
                    });
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Error while updating registered sip {0}", registeredSip.SIP);
                return(KamailioMessageHandlerResult.NothingChanged);
            }
        }
Beispiel #9
0
        private List <KeyValuePair <string, string> > GetMetaData(List <MetaType> metaList, Entities.RegisteredSipEntity sip)
        {
            metaList = metaList ?? new List <MetaType>();

            var userAgentMetaDataList = metaList
                                        .Select(meta => new KeyValuePair <string, string>(meta.Name, MetadataHelper.GetPropertyValue(sip, meta.FullPropertyName)))
                                        .Where(m => !string.IsNullOrEmpty(m.Value))
                                        .ToList();

            return(userAgentMetaDataList);
        }