SIPSorcery.SIP.App.SIPCallDescriptor.CopyOf C# (CSharp) Method

CopyOf() public method

public CopyOf ( ) : SIPCallDescriptor
return SIPCallDescriptor
        public SIPCallDescriptor CopyOf()
        {
            List<string> copiedCustomHeaders = null;
            if (CustomHeaders != null)
            {
                copiedCustomHeaders = new List<string>();
                copiedCustomHeaders.InsertRange(0, CustomHeaders);
            }

            SIPCallDescriptor copy = new SIPCallDescriptor(
                Username,
                Password,
                Uri,
                From,
                To,
                RouteSet,
                copiedCustomHeaders,
                AuthUsername,
                CallDirection,
                ContentType,
                Content,
                (MangleIPAddress != null) ? new IPAddress(MangleIPAddress.GetAddressBytes()) : null);

            // Options.
            copy.DelaySeconds = DelaySeconds;
            copy.RedirectMode = RedirectMode;
            copy.CallDurationLimit = CallDurationLimit;
            copy.MangleResponseSDP = MangleResponseSDP;
            copy.FromDisplayName = FromDisplayName;
            copy.FromURIUsername = FromURIUsername;
            copy.FromURIHost = FromURIHost;
            copy.TransferMode = TransferMode;

            copy.ToSIPAccount = ToSIPAccount;

            return copy;
        }

Usage Example

        public List<SIPCallDescriptor> GetForwardsForRedirect(SIPURI redirectURI, SIPCallDescriptor callDescriptor)
        {
            Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Getting forwards for redirect to " + redirectURI.ToString() + ".", m_username));

            List<SIPCallDescriptor> redirectCalls = new List<SIPCallDescriptor>();

            string localDomain = GetCanonicalDomain_External(redirectURI.Host, false);
            if (localDomain != null)
            {
                Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Redirect is for local SIP account " + redirectURI.User + " and canonical domain " + localDomain + ", looking up bindings.", m_username));

                SIPAccount sipAccount = GetSIPAccount_External(s => s.SIPUsername == redirectURI.User && s.SIPDomain == localDomain);

                List<SIPRegistrarBinding> bindings = GetRegistrarBindings_External(b => b.SIPAccountId == sipAccount.Id, null, 0, Int32.MaxValue);

                if (bindings != null)
                {
                    Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, bindings.Count + " bindings found for local SIP account " + sipAccount.SIPUsername + "@" + sipAccount.SIPDomain + " when processing redirect.", m_username));

                    // Build list of registered contacts.
                    for (int index = 0; index < bindings.Count; index++)
                    {
                        SIPRegistrarBinding binding = bindings[index];
                        SIPURI contactURI = binding.MangledContactSIPURI;
                        SIPCallDescriptor redirectCallDescriptor = callDescriptor.CopyOf();
                        redirectCallDescriptor.Uri = contactURI.ToString();
                        redirectCalls.Add(redirectCallDescriptor);
                    }
                }
                else
                {
                    Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "No bindings were found for local SIP account " + sipAccount.SIPUsername + "@" + sipAccount.SIPDomain + " when processing redirect.", m_username));
                }
            }
            else
            {
                Log_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Redirect destination " + redirectURI.ToString() + " was determined as an external URI.", m_username));

                SIPCallDescriptor redirectCallDescriptor = callDescriptor.CopyOf();
                redirectCallDescriptor.Uri = redirectURI.ToString();
                redirectCalls.Add(redirectCallDescriptor);
            }

            return redirectCalls;
        }