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 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
            });
        }
Beispiel #3
0
        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 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());
        }
        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());
        }
Beispiel #6
0
        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 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();
        }
Beispiel #8
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 #9
0
        /// <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 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);
        }
Beispiel #11
0
        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 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.");
            }
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        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));
        }
Beispiel #15
0
        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);
        }
Beispiel #17
0
        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);
        }
Beispiel #19
0
        public RegisteredSipInfo GetRegisteredSipInfoById(Guid id)
        {
            using (var db = GetDbContext())
            {
                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)
                });
            }
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(ValidationResult.Success);
            }
            PropertyInfo propertyToComparePropertyInfo = validationContext.ObjectType.GetProperty(_propertyToCompare);
            object       propertyToCompareValue        = propertyToComparePropertyInfo.GetValue(validationContext.ObjectInstance, null);

            if (propertyToCompareValue == null || !propertyToCompareValue.ToString().Equals(value.ToString()))
            {
                return(ValidationResult.Success);
            }

            _propertyToCompareDisplayName = DisplayNameHelper.GetDisplayName(_propertyToCompare, propertyToComparePropertyInfo);
            string displayName = DisplayNameHelper.GetDisplayName(validationContext.DisplayName, validationContext);

            return(new ValidationResult(FormatErrorMessage(displayName)));
        }
Beispiel #21
0
        public IList <CodecStatus> GetAll(bool includeCodecsOffline = false)
        {
            List <RegisteredSipDto> allRegisteredSips = _registeredSipRepository.GetCachedRegisteredSips();

            if (includeCodecsOffline)
            {
                var sipIdsOnline      = allRegisteredSips.Select(rs => rs.Sip).ToList();
                var accounts          = _userRepository.GetAllSipUsers();
                var accountsNotOnline = accounts.Where(a => !sipIdsOnline.Contains(a.UserName)).ToList();
                var sipDomain         = _settingsManager.SipDomain;
                var notRegisteredSips = accountsNotOnline.Select(a => new RegisteredSipDto()
                {
                    Id          = Guid.Empty,
                    Sip         = a.UserName,
                    DisplayName = DisplayNameHelper.GetDisplayName("", a.DisplayName, string.Empty, "", a.UserName, "", sipDomain),
                }).ToList();
                allRegisteredSips.AddRange(notRegisteredSips);
            }

            return(allRegisteredSips.Select(CodecStatusMapper.MapToCodecStatus).ToList());
        }
Beispiel #22
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
            {
                return(ValidationResult.Success);
            }

            int callOrPutStrategyId = int.Parse(value.ToString());
            int strategyId          = int.Parse(validationContext.ObjectType.GetProperty("Id").GetValue(validationContext.ObjectInstance, null).ToString());
            int?originalCallStrategyId;
            int?originalPutStrategyId;

            IStrategyGroupService strategyGroupService = ObjectFactory.GetInstance <IStrategyGroupService>();

            if (strategyId == 0)
            {
                originalCallStrategyId = null;
                originalPutStrategyId  = null;
            }
            else
            {
                StrategyGroup strategyGroup = strategyGroupService.GetById(strategyId);
                originalCallStrategyId = strategyGroup.CallStrategyId;
                originalPutStrategyId  = strategyGroup.PutStrategyId;
            }

            List <Strategy> notGroupedStrategies  = strategyGroupService.GetNotGroupedStrategies(originalCallStrategyId, originalPutStrategyId);
            List <int>      notGroupedStrategyIds = notGroupedStrategies.Select(m => m.Id).ToList();

            if (notGroupedStrategyIds.Contains(callOrPutStrategyId))
            {
                return(ValidationResult.Success);
            }

            string displayName = DisplayNameHelper.GetDisplayName(validationContext.DisplayName, validationContext);

            return(new ValidationResult(FormatErrorMessage(displayName)));
        }
Beispiel #23
0
 public string GetDisplayName(string propertyName)
 {
     return(DisplayNameHelper.GetDisplayName(this, propertyName));
 }
Beispiel #24
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 #25
0
        public void DisplayNameHelper_GetDisplayName_Default()
        {
            string result = DisplayNameHelper.GetDisplayName(new TestClass3());

            Assert.Equal(nameof(TestClass3), result);
        }
Beispiel #26
0
        public void DisplayNameHelper_GetDisplayName_ToString()
        {
            string result = DisplayNameHelper.GetDisplayName(new TestClass2());

            Assert.Equal(TestClass2DisplayName, result);
        }
Beispiel #27
0
        public void DisplayNameHelper_GetDisplayName_DisplayNameAttribute()
        {
            string result = DisplayNameHelper.GetDisplayName(new TestClass());

            Assert.Equal(TestClassDisplayName, result);
        }