/// <summary> /// 获取浏览器用户信息 /// </summary> /// <returns></returns> public UserAgentDto UserAgent() { string agent = this.HttpRequest.Headers["User-Agent"]; if (string.IsNullOrEmpty(agent)) { return(null); } try { var uaParser = UAParser.Parser.GetDefault(); ClientInfo c = uaParser.Parse(agent); if (c == null) { return(null); } var model = new UserAgentDto(); model.Browser = $"{c.UA.Family} {c.UA.Major}"; model.Device = c.Device.Family; model.OS = $"{c.OS.Family} {c.OS.Major}"; model.Ip = GetClientIp(); return(model); } catch { return(null); } }
/// <summary> /// Intersects registered callees profiles and callerProfiles to return a list with available /// user agents to call for a certain caller. /// </summary> private UserAgentsResultDto MatchProfilesAndUserAgents(IEnumerable <RegisteredUserAgentAndProfilesDiscovery> registeredUserAgents, IList <ProfileDto> callerProfiles) { //TODO: Verify speed var userAgents = new List <UserAgentDto>(); try { if (!callerProfiles.Any()) { log.Error("CallerProfiles is null, can not intersect callerProfiles with callees. Expecting empty result."); } var callerProfileNames = callerProfiles.Select(p => p.Name).ToList(); // INFO: The order of common profiles is be based on callee's (destinations) profile order // INFO: The profiles has been sorted by first User-Agent Profiles Order -> Location Profile Group Order -> Callee Profiles Order foreach (var callee in registeredUserAgents) { // Match profiles from callee with the callers var matchingProfiles = callee.OrderedProfiles.Intersect(callerProfileNames).ToList(); if (matchingProfiles.Any()) { var displayName = DisplayNameHelper.GetDisplayName(callee.DisplayName, callee.UserDisplayName, "", callee.SipUri, "", "", _settingsManager.SipDomain); // TODO: WARNING!! Why is this DisplayNameHelper here.. just get something from the class ... var userAgent = new UserAgentDto { SipId = string.Format("{0} <{1}>", displayName, callee.SipUri), PresentationName = displayName, ConnectedTo = callee.InCallWithName ?? string.Empty, InCall = callee.InCall, MetaData = callee.MetaData?.Select(meta => new KeyValuePair <string, string>(meta.Key, meta.Value)).ToList(), // TODO: needs to be in a new list again? Profiles = matchingProfiles, }; userAgents.Add(userAgent); } } } catch (Exception ex) { log.Error(ex, "Error while matching registered user agents with caller profiles."); return(new UserAgentsResultDto()); } var allMatchingProfileNames = userAgents.SelectMany(ua => ua.Profiles.Select(p => p)).Distinct().ToList(); var result = new UserAgentsResultDto { UserAgents = userAgents.OrderBy(ua => ua.SipId).ToList(), Profiles = callerProfiles.Where(p => allMatchingProfileNames.Contains(p.Name)).ToList() }; return(result); }
private UserAgentsResultDto ProfilesAndUserAgents(IEnumerable <RegisteredSipDto> callees, IList <ProfileDto> callerProfiles) { var userAgents = new List <UserAgentDto>(); try { var callerProfileNames = callerProfiles.Select(p => p.Name).ToList(); foreach (var callee in callees) { // INFO: Viktigt att ordningen på gemensamma profiler baseras på callee's profilordning. var matchingProfiles = callee.Profiles.Intersect(callerProfileNames).ToList(); if (matchingProfiles.Any()) { var displayName = DisplayNameHelper.GetDisplayName(callee, _settingsManager.SipDomain); var userAgent = new UserAgentDto { SipId = string.Format("{0} <{1}>", displayName, callee.Sip), PresentationName = displayName, ConnectedTo = callee.InCallWithName ?? string.Empty, InCall = callee.InCall, MetaData = callee.MetaData.Select(meta => new KeyValuePair <string, string>(meta.Key, meta.Value)).ToList(), Profiles = matchingProfiles, }; userAgents.Add(userAgent); } } } catch (Exception ex) { log.Error(ex, "Error while getting user agents."); return(new UserAgentsResultDto()); } var allMatchingProfileNames = userAgents.SelectMany(ua => ua.Profiles.Select(p => p)).Distinct().ToList(); var result = new UserAgentsResultDto { UserAgents = userAgents.OrderBy(ua => ua.SipId).ToList(), Profiles = callerProfiles.Where(p => allMatchingProfileNames.Contains(p.Name)).ToList() }; return(result); }
private UserAgentsResultDto ProfilesAndUserAgents(IEnumerable <CachedRegisteredSip> sipsOnline, IList <ProfileDto> callerProfiles) { var allMatchingProfiles = new List <string>(); // Lista med samtliga matchande profiler var userAgents = new List <UserAgentDto>(); try { var callerProfileNames = callerProfiles.Select(p => p.Name).ToList(); foreach (var sip in sipsOnline) { var matchingProfiles = callerProfileNames.Intersect(sip.Profiles).ToList(); allMatchingProfiles.AddRange(matchingProfiles); if (matchingProfiles.Any()) { var displayName = DisplayNameHelper.GetDisplayName(sip, _settingsManager.SipDomain); var userAgent = new UserAgentDto { SipId = string.Format("{0} <{1}>", displayName, sip.Sip), PresentationName = displayName, ConnectedTo = sip.InCallWithName ?? string.Empty, InCall = sip.InCall, MetaData = sip.MetaData.Select(meta => new KeyValuePairDto(meta.Key, meta.Value)).ToList(), Profiles = matchingProfiles, }; userAgents.Add(userAgent); } } } catch (Exception ex) { Log.Error("Error while getting user agents.", ex); return(new UserAgentsResultDto()); } var result = new UserAgentsResultDto { UserAgents = userAgents.OrderBy(ua => ua.SipId).ToList(), Profiles = callerProfiles.Where(p => allMatchingProfiles.Distinct().Contains(p.Name)).ToList() }; return(result); }