public void should_hide_external_numbers() { var s = "*****@*****.**"; var result = DisplayNameHelper.AnonymizePhonenumber(s); Assert.AreEqual("Externt nummer", result); }
public void should_handle_empty_string() { var s = string.Empty; var result = DisplayNameHelper.AnonymizePhonenumber(s); Assert.AreEqual(s, result); }
public void should_not_anonymize_standard_sipaddresses() { var s = "*****@*****.**"; var result = DisplayNameHelper.AnonymizePhonenumber(s); Assert.AreEqual(s, result); }
private OldCall MapToOldCall(CallHistoryEntity dbCall, bool anonymize) { return(new OldCall { CallId = GuidString(dbCall.CallId), Started = dbCall.Started.ToLocalTime(), Ended = dbCall.Ended.ToLocalTime(), Duration = dbCall.Ended.Subtract(dbCall.Started).ToString(@"dd\d\ hh\:mm\:ss"), IsPhoneCall = dbCall.IsPhoneCall, FromId = GuidString(dbCall.FromId), FromSip = anonymize ? DisplayNameHelper.AnonymizePhonenumber(dbCall.FromUsername) : dbCall.FromUsername, FromCodecTypeColor = dbCall.FromCodecTypeColor, FromCodecTypeName = dbCall.FromCodecTypeName, FromComment = dbCall.FromComment, FromDisplayName = anonymize ? DisplayNameHelper.AnonymizeDisplayName(dbCall.FromDisplayName) : dbCall.FromDisplayName, FromLocationName = dbCall.FromLocationName, FromLocationShortName = dbCall.FromLocationShortName, FromRegionName = dbCall.FromRegionName, ToId = GuidString(dbCall.ToId), ToSip = anonymize ? DisplayNameHelper.AnonymizePhonenumber(dbCall.ToUsername) : dbCall.ToUsername, ToCodecTypeColor = dbCall.ToCodecTypeColor, ToCodecTypeName = dbCall.ToCodecTypeName, ToComment = dbCall.ToComment, ToDisplayName = anonymize ? DisplayNameHelper.AnonymizeDisplayName(dbCall.ToDisplayName) : dbCall.ToDisplayName, ToLocationName = dbCall.ToLocationName, ToLocationShortName = dbCall.ToLocationShortName, ToRegionName = dbCall.ToRegionName }); }
public static RegisteredSipOverviewDto MapToDto(RegisteredSipDto regSip, string sipDomain) { return(new RegisteredSipOverviewDto { InCall = regSip.InCall, Sip = regSip.Sip, Id = regSip.Id, //DisplayName = regSip.DisplayName, DisplayName = DisplayNameHelper.GetDisplayName(regSip.DisplayName, regSip.UserDisplayName, string.Empty, regSip.UserName, regSip.Sip, "", sipDomain), Location = regSip.LocationName, LocationShortName = regSip.LocationShortName, Comment = regSip.Comment, Image = regSip.Image, CodecTypeName = regSip.CodecTypeName, CodecTypeColor = regSip.CodecTypeColor, UserName = regSip.UserName, UserDisplayName = regSip.UserDisplayName, UserComment = regSip.Comment, InCallWithId = regSip.InCallWithId, InCallWithSip = DisplayNameHelper.AnonymizePhonenumber(regSip.InCallWithSip), InCallWithName = DisplayNameHelper.AnonymizeDisplayName(regSip.InCallWithName), RegionName = regSip.RegionName, Updated = regSip.Updated }); }
private void Validate(InquireModel model, IFormFile uploadedResume) { if (_resumeValidator.UploadedResumeIsValid(uploadedResume, out var errorMessage)) { model.AttachResume(uploadedResume); } else { ModelState.AddModelError("Resume", errorMessage); } if (!model.Availability.Any(l => l.Checked)) { ModelState.AddModelError(nameof(model.Availability), "At least one value should be selected."); } else if (model.Availability.Any(l => l.Checked && string.IsNullOrWhiteSpace(l.Hours))) { ModelState.AddModelError(nameof(model.Availability), $"{DisplayNameHelper.GetDisplayName(model.GetType(), nameof(model.Availability))} is required."); } if (model.JobType == JobTypeEnum.Doctor.Description() && string.IsNullOrWhiteSpace(model.Specialty)) { ModelState.AddModelError(nameof(model.Specialty), $"{DisplayNameHelper.GetDisplayName(model.GetType(), nameof(model.Specialty))} is required."); } if (model.WorkExperience == WorkExperienceEnum.Other.ToString() && string.IsNullOrWhiteSpace(model.WorkExperienceOther)) { ModelState.AddModelError(nameof(model.WorkExperienceOther), $"{DisplayNameHelper.GetDisplayName(model.GetType(), nameof(model.WorkExperienceOther))} is required."); } }
public static string GetMessageDetail(Quote quote) { var sb = new StringBuilder(); sb.Append("<html><body><table>"); sb.Append("<tr><td>"); sb.Append(string.Format(YahooFinanceLink, quote.Symbol.Trim())); sb.Append("</td></tr></table>"); sb.Append("<table border=\"1\" style=\"border-collapse : collapse; border : 1px solid orange;\"><tr>"); var i = DisplayColumns; foreach (PropertyInfo prop in typeof(Quote).GetProperties()) { sb.Append(string.Format("<td>{0}</td><td>{1}</td>", DisplayNameHelper.GetDisplayName(prop), prop.GetValue(quote, null))); if (i % ((DisplayColumns - 1) == 0 ? 1 : (DisplayColumns - 1)) == 0) { sb.Append("</tr><tr>"); } i++; } if (i % ((DisplayColumns - 1) == 0 ? 1 : (DisplayColumns - 1)) == 1) { sb.Append("<td></td><td></td>"); } sb.Append("</tr>"); sb.Append("</table></body></html>"); return(sb.ToString()); }
/// <summary> /// 将集合导出为DataTable /// </summary> /// <typeparam name="T">泛型</typeparam> /// <param name="data">需要导出的集合</param> /// <param name="propertyNameList">需要包含显示的实体类的属性</param> /// <returns>DataTable</returns> /// 时间:2016/10/16 15:54 /// 备注: public static DataTable ToDataTable <T>(IEnumerable <T> data, string[] propertyNameList) where T : class { ValidateOperator.Begin().NotNull(data, "需要导出的集合"); ICollection <PropertyInfo> _properties = GetCacheProperties <T>(propertyNameList); DataTable _dataTable = new DataTable(typeof(T).Name); foreach (PropertyInfo prop in _properties) { _dataTable.Columns.Add(DisplayNameHelper.Get(prop)); } foreach (T item in data) { object[] _values = new object[_properties.Count]; int _index = 0; foreach (PropertyInfo prop in _properties) { _values[_index] = prop.GetValue(item, null); _index++; } _dataTable.Rows.Add(_values); } return(_dataTable); }
private OnGoingCall MapToOngoingCall(CallEntity dbCall, string sipDomain, bool anonymize) { var fromDisplayName = CallDisplayNameHelper.GetDisplayName(dbCall.FromSip, dbCall.FromDisplayName, dbCall.FromUsername, sipDomain); var toDisplayName = CallDisplayNameHelper.GetDisplayName(dbCall.ToSip, dbCall.ToDisplayName, dbCall.ToUsername, sipDomain); var onGoingCall = new OnGoingCall { CallId = GuidHelper.GuidString(dbCall.Id), Started = dbCall.Started, FromId = GuidHelper.GuidString(dbCall.FromId), FromSip = anonymize ? DisplayNameHelper.AnonymizePhonenumber(dbCall.FromUsername) : dbCall.FromUsername, FromDisplayName = anonymize ? DisplayNameHelper.AnonymizeDisplayName(fromDisplayName) : fromDisplayName, FromCodecTypeColor = dbCall.FromSip != null && dbCall.FromSip.User != null && dbCall.FromSip.User.CodecType != null ? dbCall.FromSip.User.CodecType.Color : string.Empty, FromCodecTypeName = dbCall.FromSip != null && dbCall.FromSip.User != null && dbCall.FromSip.User.CodecType != null ? dbCall.FromSip.User.CodecType.Name : string.Empty, FromComment = dbCall.FromSip != null && dbCall.FromSip.User != null ? dbCall.FromSip.User.Comment : string.Empty, FromLocationName = dbCall.FromSip != null && dbCall.FromSip.Location != null ? dbCall.FromSip.Location.Name : string.Empty, FromLocationShortName = dbCall.FromSip != null && dbCall.FromSip.Location != null ? dbCall.FromSip.Location.ShortName : string.Empty, FromRegionName = dbCall.FromSip != null && dbCall.FromSip.Location != null && dbCall.FromSip.Location.Region != null ? dbCall.FromSip.Location.Region.Name : string.Empty, ToId = GuidHelper.GuidString(dbCall.ToId), ToSip = anonymize ? DisplayNameHelper.AnonymizePhonenumber(dbCall.ToUsername) : dbCall.ToUsername, ToDisplayName = anonymize ? DisplayNameHelper.AnonymizeDisplayName(toDisplayName) : toDisplayName, ToCodecTypeColor = dbCall.ToSip != null && dbCall.ToSip.User != null && dbCall.ToSip.User.CodecType != null ? dbCall.ToSip.User.CodecType.Color : string.Empty, ToCodecTypeName = dbCall.ToSip != null && dbCall.ToSip.User != null && dbCall.ToSip.User.CodecType != null ? dbCall.ToSip.User.CodecType.Name : string.Empty, ToComment = dbCall.ToSip != null && dbCall.ToSip.User != null ? dbCall.ToSip.User.Comment : string.Empty, ToLocationName = dbCall.ToSip != null && dbCall.ToSip.Location != null ? dbCall.ToSip.Location.Name : string.Empty, ToLocationShortName = dbCall.ToSip != null && dbCall.ToSip.Location != null ? dbCall.ToSip.Location.ShortName : string.Empty, ToRegionName = dbCall.ToSip != null && dbCall.ToSip.Location != null && dbCall.ToSip.Location.Region != null ? dbCall.ToSip.Location.Region.Name : string.Empty }; return(onGoingCall); }
private static string GenerateMessageFromModel(object model) { var emailBody = new StringBuilder(); var type = model.GetType(); var properties = type.GetProperties(); emailBody.Append("<h2>Summary of the form: </h2>"); foreach (var propertyInfo in properties) { if (propertyInfo.CanRead) { if (propertyInfo.PropertyType == typeof(string) || propertyInfo.PropertyType == typeof(Boolean) || propertyInfo.PropertyType == typeof(Int32)) { if (propertyInfo.GetValue(model, null) != null) { emailBody.Append("<p><strong>" + DisplayNameHelper.GetDisplayName(propertyInfo) + ": </strong>" + propertyInfo.GetValue(model, null) + "</p>"); } } } } return(emailBody.ToString()); }
public void should_show_internal_number_without_host() { var s = "*****@*****.**"; var result = DisplayNameHelper.AnonymizePhonenumber(s); Assert.AreEqual("840200", result); }
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()); }
private string GetDisplayName(RegisteredSipDetails registeredSip) { var sipDomain = _settingsManager.SipDomain; return(DisplayNameHelper.GetDisplayName( registeredSip.DisplayName, registeredSip.UserDisplayName, string.Empty, registeredSip.Sip, string.Empty, string.Empty, sipDomain)); }
private string SaveReportInFile() { DataTable dt = new DataTable(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < DataGridName.Columns.Count; i++) { if (DataGridName.Columns[i].Visibility == Visibility.Visible) { dt.Columns.Add(DataGridName.Columns[i].Header.ToString() .Replace(" ", "_") .Replace("[", "") .Replace("]", "") .Replace("%", "procent")); } } foreach (var rowObject in DataGridName.Items) { DataRow datar = dt.NewRow(); foreach (DataGridColumn column in DataGridName.Columns) { if (column.Visibility == Visibility.Visible) { var correctRow = DisplayNameHelper.GetPropertyValues(rowObject, column.Header.ToString()); foreach (var item in correctRow) { if (item.Key == column.Header.ToString()) { datar[item.Key .Replace(" ", "_") .Replace("[", "") .Replace("]", "") .Replace("%", "procent")] = item.Value; } } } } dt.Rows.Add(datar); } IEnumerable <string> columnNames = dt.Columns.Cast <DataColumn>(). Select(column => column.ColumnName); sb.AppendLine(string.Join(";", columnNames)); foreach (DataRow row in dt.Rows) { IEnumerable <string> fields = row.ItemArray.Select(field => field.ToString()); sb.AppendLine(string.Join(";", fields)); } return(sb.ToString()); File.WriteAllText("D:\\ApkaRaporty\\test.csv", sb.ToString()); }
//public static long ToInt64(this Enum value) //{ // return Convert.ToInt64(value); //} public static string GetDisplayName(this Enum value) { var field = value.GetType().GetField(value.ToString()); return(field == null ? null : DisplayNameHelper.GetDisplayNameForProperty(field)); //var attributes = field.GetCustomAttributes(typeof(DisplayAttribute), true).ToArray(); //return attributes.Length > 0 ? ((DisplayAttribute)attributes[0]).GetName() : value.ToString(); }
private void RefreshAllSeries() { GeneticAlgorithm? algorithm = null; Population? population = null; IEnumerable <Metric>?selectedMetrics = null; this.Dispatcher.Invoke(() => { algorithm = this.Algorithm; population = this.Population; selectedMetrics = this.SelectedMetrics; }); this.PlotModel.Series.Clear(); if (algorithm != null && population != null) { IEnumerable <Metric> metrics = selectedMetrics ?? algorithm.Metrics; foreach (Metric metric in metrics) { LineSeries series = new LineSeries { Title = DisplayNameHelper.GetDisplayName(metric), ToolTip = DisplayNameHelper.GetDisplayNameWithTypeInfo(metric), DataFieldX = nameof(MetricResult.GenerationIndex), DataFieldY = nameof(MetricResult.ResultValue) }; ObservableCollection <MetricResult> results = metric.GetResults(population.Index); series.ItemsSource = results; // Verify the results contain values of types that can be converted to double // for the chart to plot. MetricResult firstResult = results.FirstOrDefault(); if (firstResult != null) { bool exceptionThrown = false; try { Convert.ToDouble(firstResult.ResultValue, CultureInfo.CurrentCulture); } catch (Exception) { exceptionThrown = true; } if (!exceptionThrown) { this.PlotModel.Series.Add(series); } } } } this.RefreshPlot(); }
/// <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); }
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)); }
public void GetTest() { string _actual = DisplayNameHelper.Get <Address>("City"); Assert.AreEqual("城市", _actual); _actual = DisplayNameHelper.Get <Address>("AddressID"); Assert.AreEqual("AddressID", _actual); _actual = DisplayNameHelper.Get <Address>(c => c.AddressID); Assert.AreEqual("AddressID", _actual); _actual = DisplayNameHelper.Get <Address>(c => c.City); Assert.AreEqual("城市", _actual); }
public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) { _propertyToCompareDisplayName = DisplayNameHelper.GetDisplayName(_propertyToCompare, metadata, context); ModelClientValidationRule rule = new ModelClientValidationRule { ValidationType = "notequalto", ErrorMessage = FormatErrorMessage(metadata.DisplayName), }; rule.ValidationParameters.Add("another", _propertyToCompare); yield return(rule); }
private void Validate(BuyPracticeModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (model.MinPurchaseAmount >= model.MaxPurchaseAmount) { ModelState.AddModelError(nameof(model.MinPurchaseAmount), $"{DisplayNameHelper.GetDisplayName(model.GetType(), nameof(model.MinPurchaseAmount))} must be less than {DisplayNameHelper.GetDisplayName(model.GetType(), nameof(model.MaxPurchaseAmount))}"); } }
private void SpecializeMembers <T>(SimpleTypeLookup <MemberAction <T> > lookup, AssemblyDefinition toTargetAssembly) where T : MemberReference, IMemberDefinition { foreach (var item in lookup[typeof(ModifiesMemberAttribute), typeof(MemberAliasAttribute)]) { item.TargetMember = GetPatchedMember(item.TypeAction.TargetType, item.YourMember, item.ActionAttribute); if (item.TargetMember == null) { var memberName = GetPatchedMemberName(item.YourMember, item.ActionAttribute); throw Errors.Missing_member_in_attribute(DisplayNameHelper.CommonNameForMemberDef <T>(), item.YourMember, memberName); } } }
public static string GetDisplayName <TModel, TProperty>(this TModel model, Expression <Func <TModel, TProperty> > expression) { if (expression == null) { throw new ArgumentNullException(nameof(expression)); } var me = expression.Body as MemberExpression; if (me == null) { throw new ArgumentException("Must be a MemberExpression.", nameof(expression)); } return(DisplayNameHelper.GetDisplayNameForProperty(me.Member)); }
private void Validate(CreateModel model) { if (!model.JobHours.Any(j => j.Checked)) { ModelState.AddModelError(nameof(model.JobHours), "At least one value should be selected."); } else if (model.JobHours.Any(m => m.Checked && string.IsNullOrWhiteSpace(m.Hours))) { ModelState.AddModelError(nameof(model.JobHours), $"{DisplayNameHelper.GetDisplayName(model.GetType(), nameof(model.JobHours))} is required."); } if (model.JobType == JobTypeEnum.Doctor.Description() && string.IsNullOrWhiteSpace(model.Specialty)) { ModelState.AddModelError(nameof(CreateModel.Specialty), "Specialty is required for doctor."); } }
private string GetInCallWith(RegisteredSipDetails registeredSip, Call call) { var sipDomain = _settingsManager.SipDomain; string inCallWith; if (call.FromSip == registeredSip.Sip) { inCallWith = call.To != null?DisplayNameHelper.GetDisplayName(call.To, sipDomain) : call.ToSip; } else { inCallWith = call.From != null?DisplayNameHelper.GetDisplayName(call.From, sipDomain) : call.FromSip; } return(DisplayNameHelper.AnonymizeDisplayName(inCallWith)); }
private static string GetDisplayValue(Expression expressionBody, string propertyName) { var memberExpression = expressionBody as MemberExpression; if (memberExpression == null) { return(propertyName); } var objectType = memberExpression.Member.ReflectedType; var displayName = DisplayNameHelper.GetDisplayName(objectType, propertyName); if (displayName != null && propertyName != displayName) { return(displayName); } if (objectType == null) { return(propertyName); } var property = objectType.GetProperty(propertyName); var t = typeof(DisplayAttribute); var first = (DisplayAttribute)property.GetCustomAttributes(t, false).FirstOrDefault(); if (first != null) { return(first.Name); } var metaAttr = (MetadataTypeAttribute[]) objectType.GetCustomAttributes(typeof(MetadataTypeAttribute), true); if (metaAttr.Length <= 0) { return(propertyName); } foreach (var attr in metaAttr) { var subType = attr.MetadataClassType; var pi = subType.GetField(propertyName); if (pi != null) { first = (DisplayAttribute)pi.GetCustomAttributes(t, false).FirstOrDefault(); } } return(first == null ? propertyName : first.Name); }
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); }
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); }
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); }
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); }