internal TableStorageDataReader(Stream stream) { m_Current = new TableStorageFieldCollection(); if(stream != null) { XmlReaderSettings settings = new XmlReaderSettings(); settings.CloseInput = true; settings.IgnoreComments = true; settings.IgnoreWhitespace = true; m_Reader = XmlReader.Create(stream, settings); ReadNext(); if(m_Next != null) { m_Current = m_Next; m_HasRows = true; } } }
private HttpWebRequest GetRequest(TableStorageFieldCollection parameters, out string entryId) { if(m_Connection.State != ConnectionState.Open) { throw new TableStorageException(Resources.ConnectionNotOpen); } if(string.IsNullOrWhiteSpace(m_Connection.ConnectionString)) { throw new InvalidOperationException("The ConnectionString property has not been initialized."); } Regex queryExpression = new Regex(@"^(?<verb>GET|POST|PUT|DELETE)\s*(?<path>/(?<tablename>[a-z][a-z0-9]{2,63}).*)$", RegexOptions.IgnoreCase); Match queryMatch = queryExpression.Match(CommandText); string verb = queryMatch.Groups["verb"].Value; string tableName = queryMatch.Groups["tablename"].Value; string path = queryMatch.Groups["path"].Value; Regex parametersExpression = new Regex(@"@(?<param>[\w]{1}[\w\d]*)", RegexOptions.IgnoreCase); MatchEvaluator evaluator = delegate(Match match) { string parameterName = match.Groups["param"].Value; if(parameters.Contains(parameterName)) { TableStorageField parameter = parameters[parameterName]; object value = parameter.Value; if((value == null) || DBNull.Value.Equals(value)) { return string.Empty; } return string.Format(parameter.FormatString, parameter.Value); } throw new TableStorageException(string.Format(Resources.ParameterNotFound, parameterName)); }; path = parametersExpression.Replace(path, evaluator); CloudTableClient tableClient = m_Connection.StorageAccount.CreateCloudTableClient(); tableClient.Timeout = TimeSpan.FromSeconds(CommandTimeout); tableClient.CreateTableIfNotExist(tableName); // TODO (Matt Magurany 8/14/2012): If a transaction exists, add to existing batch Uri url = new Uri(tableClient.BaseUri.AbsoluteUri.Trim('/') + path); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Accept = "application/atom+xml,application/xml"; request.Headers["x-ms-version"] = m_Connection.ServerVersion; request.Headers["Accept-Charset"] = "UTF-8"; request.Headers["DataServiceVersion"] = "2.0;NetFx"; request.Headers["MaxDataServiceVersion"] = "2.0;NetFx"; request.Method = verb; request.Timeout = CommandTimeout * 1000; if(StringComparer.OrdinalIgnoreCase.Equals("PUT", verb) || StringComparer.OrdinalIgnoreCase.Equals("DELETE", verb)) { request.Headers["If-Match"] = "*"; entryId = url.AbsoluteUri; } else { entryId = null; } m_Connection.StorageAccount.Credentials.SignRequestLite(request); return request; }
private TableStorageFieldCollection ConvertParameters() { TableStorageFieldCollection parameters = new TableStorageFieldCollection(); foreach(DbParameter parameter in m_Parameters) { if(parameter.Direction != ParameterDirection.Input) { throw new TableStorageException(string.Format(Resources.ParamterDirectionNotSupported, ParameterDirection.Input)); } TableStorageField field = ToField(parameter); parameters.Add(field); } return parameters; }
private void ReadNext() { m_Next = null; if(m_Reader != null) { if(m_Reader.ReadToFollowing("entry", TableStorageConstants.Atom.NAMESPACE)) { m_Reader.ReadStartElement("entry", TableStorageConstants.Atom.NAMESPACE); if(m_Reader.ReadToFollowing("properties", TableStorageConstants.Edm.NAMESPACE)) { m_Reader.ReadStartElement("properties", TableStorageConstants.Edm.NAMESPACE); m_Next = new TableStorageFieldCollection(); while(m_Reader.IsStartElement()) { bool isEmpty = m_Reader.IsEmptyElement; string propertyName = m_Reader.LocalName; bool isNull; string edmType; if(m_Reader.MoveToAttribute("null", TableStorageConstants.Edm.NAMESPACE)) { isNull = m_Reader.ReadContentAsBoolean(); } else { isNull = false; } if(m_Reader.MoveToAttribute("type", TableStorageConstants.Edm.NAMESPACE)) { edmType = m_Reader.ReadContentAsString(); } else { edmType = TableStorageConstants.Edm.TYPE_STRING; } m_Reader.ReadStartElement(propertyName, TableStorageConstants.DataServices.NAMESPACE); TableStorageField field = ToObject(m_Reader, edmType, isNull, propertyName); m_Next.Add(field); if(!isEmpty) { m_Reader.ReadEndElement(); } } } } } }
public override bool Read() { if(m_Next == null) { return false; } m_Current = m_Next; ReadNext(); return true; }