Example #1
0
        public static String GetDisplayName(String uri)
        {
            String displayname = null;
            if (!String.IsNullOrEmpty(uri))
            {
                Contact contact = UriUtils.ServiceManager.ContactService.ContactFind(uri);
                if (contact != null && (displayname = contact.DisplayName) != null)
                {
                    return displayname;
                }

                SipUri sipUri = new SipUri(uri);
                if (sipUri.isValid())
                {
                    displayname = sipUri.getUserName();
                }
                sipUri.Dispose();
            }

            return (displayname == null ? uri : displayname);
        }
Example #2
0
        // very dirty
        public static String GetValidPhoneNumber(String uri)
        {
            if (uri != null && (uri.StartsWith("sip:") || uri.StartsWith("sip:") || uri.StartsWith("tel:")))
            {
                SipUri sipUri = new SipUri(uri);
                if (sipUri.isValid())
                {
                    String userName = sipUri.getUserName();
                    if (userName != null)
                    {
                        try
                        {
                            String scheme = sipUri.getScheme();
                            if (scheme != null && scheme.Equals("tel"))
                            {
                                userName = userName.Replace("-", "");
                            }

                            long result = Convert.ToInt64(userName.StartsWith("+") ? userName.Substring(1) : userName);
                            if (result < UriUtils.MAX_PHONE_NUMBER)
                            {
                                return userName;
                            }
                        }
                        catch (FormatException ) { }
                        catch (Exception e)
                        {
                            LOG.Error(e);
                        }
                    }
                }
                sipUri.Dispose();
            }
            else
            {
                try
                {
                    uri = uri.Replace("-", "");
                    long result = Convert.ToInt64(uri.StartsWith("+") ? uri.Substring(1) : uri);
                    if (result < UriUtils.MAX_PHONE_NUMBER)
                    {
                        return uri;
                    }
                }
                catch (FormatException ) { }
                catch (Exception e)
                {
                    LOG.Error(e);
                }
            }
            return null;
        }