/// <summary>
        /// Removes specified SIP registration from server,
        /// </summary>
        /// <param name="registration">Registration to remove.</param>
        public void Remove(SipRegistration registration)
        {
            /* DeleteSipRegistration "<virtualServerID>" "<addressOfRecord>"
             *    Responses:
             +OK
             *      -ERR <errorText>
             */

            lock (m_pOwner.Server.LockSynchronizer){
                string id = Guid.NewGuid().ToString();

                // Call TCP DeleteSipRegistration
                m_pOwner.Server.TcpClient.TcpStream.WriteLine("DeleteSipRegistration " +
                                                              TextUtils.QuoteString(m_pOwner.VirtualServerID) + " " +
                                                              TextUtils.QuoteString(registration.AddressOfRecord)
                                                              );

                string response = m_pOwner.Server.ReadLine();
                if (!response.ToUpper().StartsWith("+OK"))
                {
                    throw new Exception(response);
                }

                m_pRegistrations.Remove(registration);
            }
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="registration">Registration what contacts to show.</param>
        public wfrm_Monitoring_SipRegistration_Contacts(SipRegistration registration)
        {
            m_pRegistration = registration;

            InitUI();

            LoadContacts();
        }
        /// <summary>
        /// Adds or updates specified SIP registration info.
        /// </summary>
        /// <param name="addressOfRecord">Registration address of record.</param>
        /// <param name="contacts">Contacts to add to the specified address of record.</param>
        public void Set(string addressOfRecord, string[] contacts)
        {
            /* SetSipRegistration "<virtualServerID>" "<addressOfRecord>" "<contacts>"
             *    Responses:
             +OK
             *      -ERR <errorText>
             */

            lock (m_pOwner.Server.LockSynchronizer){
                // Build TAB delimited contacts.
                string tabContacts = "";
                for (int i = 0; i < contacts.Length; i++)
                {
                    // Don't add TAB to last item.
                    if (i == (contacts.Length - 1))
                    {
                        tabContacts += contacts[i];
                    }
                    else
                    {
                        tabContacts += contacts[i] + "\t";
                    }
                }

                m_pOwner.Server.TcpClient.TcpStream.WriteLine("SetSipRegistration " +
                                                              TextUtils.QuoteString(m_pOwner.VirtualServerID) + " " +
                                                              TextUtils.QuoteString(addressOfRecord) + " " +
                                                              TextUtils.QuoteString(tabContacts)
                                                              );

                string response = m_pOwner.Server.ReadLine();
                if (!response.ToUpper().StartsWith("+OK"))
                {
                    throw new Exception(response);
                }

                SipRegistration registration = new SipRegistration(this, "administrator", addressOfRecord, new SipRegistrationContact[0]);
                m_pRegistrations.Add(registration);
                // Force to registration to get new registration info from server.
                registration.Refresh();
            }
        }
        /// <summary>
        /// Edit constructor.
        /// </summary>
        /// <param name="server">Reference to contact owner server.</param>
        /// <param name="registration">Registration what contacts to show.</param>
        public wfrm_Monitoring_SipRegistration(Server server,SipRegistration registration)
        {
            m_pServer = server;
            m_pRegistration = registration;
            m_pContactsToRemove = new List<string>();

            InitUI();

            // Load virtual servers
            foreach(VirtualServer virtualServer in m_pServer.VirtualServers){
                m_pVirtualServer.Items.Add(new WComboBoxItem(virtualServer.Name,virtualServer));
            }
            if(m_pVirtualServer.Items.Count > 0){
                m_pVirtualServer.SelectedIndex = 0;
            }

            m_pVirtualServer.Enabled = false;
            m_pAOR.Enabled = false;
            m_pAOR.Text = registration.AddressOfRecord;

            LoadContacts();
        }
        /// <summary>
        /// Adds or updates specified SIP registration info.
        /// </summary>
        /// <param name="addressOfRecord">Registration address of record.</param>
        /// <param name="contacts">Contacts to add to the specified address of record.</param>
        public void Set(string addressOfRecord,string[] contacts)
        {
            /* SetSipRegistration "<virtualServerID>" "<addressOfRecord>" "<contacts>"
                  Responses:
                    +OK
                    -ERR <errorText>
            */

            lock(m_pOwner.Server.LockSynchronizer){
                // Build TAB delimited contacts.
                string tabContacts = "";
                for(int i=0;i<contacts.Length;i++){
                    // Don't add TAB to last item.
                    if(i == (contacts.Length - 1)){
                        tabContacts += contacts[i];
                    }
                    else{
                        tabContacts += contacts[i] + "\t";
                    }
                }

                m_pOwner.Server.Socket.WriteLine("SetSipRegistration " +
                    TextUtils.QuoteString(m_pOwner.VirtualServerID) + " " +
                    TextUtils.QuoteString(addressOfRecord) + " " +
                    TextUtils.QuoteString(tabContacts)
                );

                string response = m_pOwner.Server.Socket.ReadLine();
                if(!response.ToUpper().StartsWith("+OK")){
                    throw new Exception(response);
                }

                SipRegistration registration = new SipRegistration(this,"administrator",addressOfRecord,new SipRegistrationContact[0]);
                m_pRegistrations.Add(registration);
                // Force to registration to get new registration info from server.
                registration.Refresh();
            }
        }
        /// <summary>
        /// Removes specified SIP registration from server,
        /// </summary>
        /// <param name="registration">Registration to remove.</param>
        public void Remove(SipRegistration registration)
        {
            /* DeleteSipRegistration "<virtualServerID>" "<addressOfRecord>"
                  Responses:
                    +OK
                    -ERR <errorText>
            */

            lock(m_pOwner.Server.LockSynchronizer){
                string id = Guid.NewGuid().ToString();

                // Call TCP DeleteSipRegistration
                m_pOwner.Server.Socket.WriteLine("DeleteSipRegistration " +
                    TextUtils.QuoteString(m_pOwner.VirtualServerID) + " " +
                    TextUtils.QuoteString(registration.AddressOfRecord)
                );

                string response = m_pOwner.Server.Socket.ReadLine();
                if(!response.ToUpper().StartsWith("+OK")){
                    throw new Exception(response);
                }

                m_pRegistrations.Remove(registration);
            }
        }