protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            TableStorageFieldCollection parameters = ConvertParameters();
            string         entryId;
            HttpWebRequest request = GetRequest(parameters, out entryId);

            try
            {
                WebResponse response       = request.GetResponse();
                Stream      responseStream = response.GetResponseStream();

                return(new TableStorageDataReader(responseStream));
            }
            catch (WebException we)
            {
                HttpWebResponse response = (HttpWebResponse)we.Response;

                if (response == null)
                {
                    throw new TableStorageException(we.Message, we);
                }

                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    return(new TableStorageDataReader(null));
                }

                throw TableStorageException.Parse(we);
            }
        }
        public override int ExecuteNonQuery()
        {
            TableStorageFieldCollection parameters = ConvertParameters();
            string entryId;

            HttpWebRequest request = GetRequest(parameters, out entryId);

            request.ContentType = "application/atom+xml";

            Stream requestStream = request.GetRequestStream();

            using (TableStorageDataWriter writer = new TableStorageDataWriter(requestStream))
            {
                writer.WriteStartEntry(entryId);

                foreach (TableStorageField parameter in parameters)
                {
                    writer.WriteField(parameter);
                }

                writer.WriteEndEntry();
                writer.Flush();
            }

            HttpWebResponse response = null;

            try
            {
                response = (HttpWebResponse)request.GetResponse();

                return(1);
            }
            catch (WebException we)
            {
                response = (HttpWebResponse)we.Response;

                if (response == null)
                {
                    throw new TableStorageException(we.Message, we);
                }

                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    return(0);
                }

                throw TableStorageException.Parse(we);
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }
        }
        public static TableStorageException Parse(WebException innerException)
        {
            ThrowHelper.CheckArgumentNull(innerException, "innerException");

            HttpWebResponse response = (HttpWebResponse)innerException.Response;

            if(response == null)
            {
                return new TableStorageException(innerException.Message, innerException);
            }

            Stream stream = response.GetResponseStream();

            Debug.Assert(stream != null);

            if(stream.CanSeek)
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreComments = true;
            settings.IgnoreWhitespace = true;

            XmlReader reader = XmlReader.Create(stream, settings);
            reader.ReadStartElement("error");
            reader.ReadStartElement("code");
            string tableStorageErrorCode = reader.ReadContentAsString();
            reader.ReadEndElement();
            reader.ReadStartElement("message");
            string message = reader.ReadContentAsString();
            reader.ReadEndElement();

            TableStorageException exception = new TableStorageException(tableStorageErrorCode, message, innerException);

            while(reader.IsStartElement())
            {
                string name = reader.LocalName;
                bool isEmpty = reader.IsEmptyElement;

                reader.ReadStartElement(name);

                if(!isEmpty)
                {
                    if(!exception.Data.Contains(name))
                    {
                        string value = reader.ReadContentAsString();

                        exception.Data.Add(name, value);
                    }

                    reader.ReadEndElement();
                }
            }

            reader.ReadEndElement();

            return exception;
        }
        public static TableStorageException Parse(WebException innerException)
        {
            ThrowHelper.CheckArgumentNull(innerException, "innerException");

            HttpWebResponse response = (HttpWebResponse)innerException.Response;

            if (response == null)
            {
                return(new TableStorageException(innerException.Message, innerException));
            }

            Stream stream = response.GetResponseStream();

            Debug.Assert(stream != null);

            if (stream.CanSeek)
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments   = true;
            settings.IgnoreWhitespace = true;

            XmlReader reader = XmlReader.Create(stream, settings);

            reader.ReadStartElement("error");
            reader.ReadStartElement("code");
            string tableStorageErrorCode = reader.ReadContentAsString();

            reader.ReadEndElement();
            reader.ReadStartElement("message");
            string message = reader.ReadContentAsString();

            reader.ReadEndElement();

            TableStorageException exception = new TableStorageException(tableStorageErrorCode, message, innerException);

            while (reader.IsStartElement())
            {
                string name    = reader.LocalName;
                bool   isEmpty = reader.IsEmptyElement;

                reader.ReadStartElement(name);

                if (!isEmpty)
                {
                    if (!exception.Data.Contains(name))
                    {
                        string value = reader.ReadContentAsString();

                        exception.Data.Add(name, value);
                    }

                    reader.ReadEndElement();
                }
            }

            reader.ReadEndElement();

            return(exception);
        }