/// <summary>
        /// Checks weather the connector can connect, if not it returns a status code as integer.
        /// </summary>
        /// <returns>Int: 0=Connectivity ok, 1=No connector chosen (not checked here), 2=Invalid/unreachable URL, 3=Incorrect username/password, 4=Other error</returns>
        public int CheckConnectivity(String _connector, String _url, String _username, String _password)
        {
            HttpWebRequest  CaldavRequest;
            HttpWebResponse CaldavResponse;

            if (!IsValidUrl(_url))
            {
                MessageBox.Show("Error while connecting to calendar: Wrong url.");
                return(CONNECTOR_STATUS_ERR_INVALID_URL);
            }

            try
            {
                CaldavRequest = (HttpWebRequest)WebRequest.Create(CheckSlashAtEnd(_url));
                //CaldavRequest.Method = "GET";
                CaldavRequest.Credentials     = new NetworkCredential(_username, _password);
                CaldavRequest.PreAuthenticate = true;
                CaldavResponse = (HttpWebResponse)CaldavRequest.GetResponse();
            }
            catch (WebException WebEx)
            {
                if (WebEx.Status == WebExceptionStatus.ProtocolError)
                {
                    var response = WebEx.Response as HttpWebResponse;
                    if (response != null)
                    {
                        switch (response.StatusCode)
                        {
                        case HttpStatusCode.OK:
                            return(CONNECTOR_STATUS_OK);

                        case HttpStatusCode.Forbidden:
                        case HttpStatusCode.Unauthorized:
                            MessageBox.Show("Error while connecting to calendar: Wrong credentials.");
                            return(CONNECTOR_STATUS_ERR_INVALID_CREDS);

                        case HttpStatusCode.NotFound:
                        case HttpStatusCode.NotImplemented:
                        case HttpStatusCode.MethodNotAllowed:
                            MessageBox.Show("Error while connecting to calendar: Wrong url.");
                            return(CONNECTOR_STATUS_ERR_INVALID_URL);

                        default:
                            MessageBox.Show("Error while connecting to calendar: An unknown error occured.");
                            return(CONNECTOR_STATUS_ERR_UNKNOWN);
                        }
                    }
                }
                MessageBox.Show("Error while connecting to calendar: Wrong url.");
                return(CONNECTOR_STATUS_ERR_INVALID_URL);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while connecting to calendar: An unknown error occured - " + ex.Message);
                return(CONNECTOR_STATUS_ERR_UNKNOWN);
            }
            return(CONNECTOR_STATUS_OK);
        }
        /// <summary>
        /// Helper method to query a CalDav server.
        /// </summary>
        /// <param name="requestMethod">Request mehtod to use for query.</param>
        /// <param name="headers">Headers to include into query.</param>
        /// <param name="query">The query itseld.</param>
        /// <param name="contentType">The content type to use for query.</param>
        /// <param name="url">For a REPORT request just provide NULL and the calendar URL form the settings will be used. For PUT and DELETE requests provide the relative url to the element or just its name (including .ics) and it will be combined with the settings path.</param>
        /// <returns></returns>
        private XmlDocument QueryCaldavServer(String requestMethod, WebHeaderCollection headers, String query, String contentType, String url)
        {
            System.IO.Stream       ResponseStream;
            System.Xml.XmlDocument ResponseXmlDoc = new XmlDocument();
            HttpWebRequest         CaldavRequest;

            try
            {
                if (url == null)
                {
                    CaldavRequest = (HttpWebRequest)WebRequest.Create(calendarUrl);
                }
                else
                {
                    string[] url_parts     = url.Split(new Char[] { '\\', '/' });
                    string   url_corrected = calendarUrl + url_parts.Last();
                    CaldavRequest = (HttpWebRequest)WebRequest.Create(url_corrected);
                }
                CaldavRequest.Method          = requestMethod;
                CaldavRequest.Credentials     = new NetworkCredential(username, password);
                CaldavRequest.PreAuthenticate = true;
                CaldavRequest.Headers         = headers;
                if (contentType != null)
                {
                    CaldavRequest.ContentType = contentType;
                }
                byte[] optionsArray = Encoding.UTF8.GetBytes(query);
                CaldavRequest.ContentLength = optionsArray.Length;
                System.IO.Stream requestStream = CaldavRequest.GetRequestStream();
                requestStream.Write(optionsArray, 0, optionsArray.Length);
                requestStream.Close();
                HttpWebResponse ReportResponse = (HttpWebResponse)CaldavRequest.GetResponse();
                ResponseStream = ReportResponse.GetResponseStream();
                if (!requestMethod.Equals("DELETE") && !requestMethod.Equals("PUT"))
                {
                    ResponseXmlDoc.Load(ResponseStream);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                MessageBox.Show("The following error occurred: " + e.Message);
                return(ResponseXmlDoc);
            }
            return(ResponseXmlDoc);
        }