private TableRow CheckAndGetEntity(ChangeDescription changeDescription, bool shouldExist) { UtilityRow utilityRow = this.ExecuteQuery <UtilityRow>(changeDescription); this.CheckPermissions(utilityRow, changeDescription); PointQueryTracker pointQuery = ((DbTableRowQueryProvider <UtilityRow>)changeDescription.QueryableRow.Provider).PointQuery; if (pointQuery != null) { this.CheckPartitionAndRowKeys(pointQuery.PartitionKey, pointQuery.RowKey, changeDescription.UpdateType); } if (utilityRow == null) { if (shouldExist) { throw new TableServiceGeneralException(TableServiceError.EntityNotFound, null); } return(null); } changeDescription.ExistingRow = utilityRow; TableRow sqlEntity = this.GetSqlEntity(utilityRow.PartitionKey, utilityRow.RowKey, changeDescription.EtagConditionUsed); if (sqlEntity == null) { throw new TableServiceGeneralException(TableServiceError.UpdateConditionNotSatisfied, null); } return(sqlEntity); }
public void SetValue(object targetResource, string propertyName, object propertyValue) { object obj; try { ChangeDescription changeDescription = (ChangeDescription)targetResource; if (!TableResourceContainer.IsUtilityTables(this.m_currentResourceContainer.Name)) { UtilityRow row = (UtilityRow)changeDescription.Row; if (!propertyName.Equals("Timestamp")) { if (changeDescription.UpdateType != UpdateKind.Insert && changeDescription.UpdateType != UpdateKind.InsertOrMerge && changeDescription.UpdateType != UpdateKind.InsertOrReplace && (propertyName.Equals("PartitionKey") || propertyName.Equals("RowKey"))) { throw new InvalidOperationException("Cannot update key values."); } if (!TableDataContextHelper.IsValidPropertyName(propertyName, this.ApiVersion)) { throw new TableServiceGeneralException(TableServiceError.PropertyNameInvalid, null); } if (row.ColumnValues.TryGetValue(propertyName, out obj) && obj != null) { throw new XStoreArgumentException("Multiple entries for same property specified in the input"); } row[propertyName] = propertyValue; } else { return; } } else { UtilityTable utilityTable = (UtilityTable)changeDescription.Row; if (changeDescription.UpdateType == UpdateKind.Insert) { utilityTable[propertyName] = propertyValue; if (string.Equals(propertyName, "TableName")) { if (TableResourceContainer.IsUtilityTables(propertyValue as string)) { throw new TableServiceArgumentException("Invalid table container name"); } if (!Regex.IsMatch(propertyValue as string, "^[A-Za-z][A-Za-z0-9]{2,62}$")) { throw new InvalidResourceNameException("Invalid table name"); } } } } } catch (InvalidCastException invalidCastException1) { InvalidCastException invalidCastException = invalidCastException1; CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { propertyName }; throw new XStoreArgumentException(string.Format(invariantCulture, "Invalid data type for property {0}", objArray), invalidCastException); } }
public IEnumerable <KeyValuePair <string, object> > GetOpenPropertyValues(object target) { UtilityRow utilityRow = target as UtilityRow; if (utilityRow == null) { return(null); } return(utilityRow.ColumnValues.AsEnumerable <KeyValuePair <string, object> >()); }
public object GetPropertyValue(object target, ResourceProperty resourceProperty) { string name = resourceProperty.Name; UtilityRow utilityRow = target as UtilityRow; if (utilityRow != null) { return(utilityRow[name]); } return((target as UtilityTable)[name]); }
private TableRow CreateAndPopulateSqlEntity(UtilityRow utilRow) { TableRow tableRow = new TableRow() { AccountName = this.AccountName, TableName = this.m_currentResourceContainer.Name.ToLowerInvariant(), PartitionKey = DevelopmentStorageDbDataContext.EncodeKeyString(utilRow.PartitionKey), RowKey = DevelopmentStorageDbDataContext.EncodeKeyString(utilRow.RowKey), Data = XmlUtility.GetXmlFromUtilityRow(utilRow) }; return(tableRow); }
internal static XElement MergeXmlProperties(UtilityRow deltaRow, XElement existingRowXml) { UtilityRow value = deltaRow.Clone(); UtilityRow utilityRow = new UtilityRow(); XmlUtility.AddObjectsToDictionaryFromXml(existingRowXml, utilityRow, true); foreach (KeyValuePair <string, object> columnValue in utilityRow.ColumnValues) { if (value.ColumnValues.ContainsKey(columnValue.Key) && value[columnValue.Key] != null) { continue; } value[columnValue.Key] = columnValue.Value; } return(XmlUtility.GetXmlFromUtilityRow(value)); }
public static object GetUtilityRowEnumerator(IEnumerator <TableRow> enumerator) { List <UtilityRow> utilityRows = new List <UtilityRow>(); while (enumerator.MoveNext()) { TableRow current = enumerator.Current; UtilityRow utilityRow = new UtilityRow() { PartitionKey = DevelopmentStorageDbDataContext.DecodeKeyString(current.PartitionKey), RowKey = DevelopmentStorageDbDataContext.DecodeKeyString(current.RowKey), Timestamp = current.Timestamp }; XmlUtility.AddObjectsToDictionaryFromXml(current.Data, utilityRow, false); utilityRows.Add(utilityRow); } return(utilityRows.GetEnumerator()); }
private void CheckPermissions(UtilityRow existingRow, ChangeDescription changeDescription) { string partitionKey = null; string rowKey = null; if (existingRow != null) { partitionKey = existingRow.PartitionKey; rowKey = existingRow.RowKey; } else { partitionKey = ((UtilityRow)changeDescription.Row).PartitionKey; rowKey = ((UtilityRow)changeDescription.Row).RowKey; } this.CheckPermission(this.m_currentResourceContainer.Name, false, false, changeDescription.UpdateType); XfeTableSASAuthorizationManager.CheckSignedAccessKeyBoundary(this.SignedAccountIdentifier, partitionKey, rowKey); }
internal static XElement GetXmlFromUtilityRow(UtilityRow entity) { string str; XElement xElement = new XElement("Properties"); if (entity.ColumnValues.Count > 252) { throw new TableServiceGeneralException(TableServiceError.TooManyProperties, null); } foreach (KeyValuePair <string, object> columnValue in entity.ColumnValues) { string key = columnValue.Key; string str1 = key; if (key != null && (str1 == "PartitionKey" || str1 == "RowKey")) { continue; } if (columnValue.Key.Length > 255) { throw new TableServiceGeneralException(TableServiceError.PropertyNameTooLong, null); } if (columnValue.Value is DateTime) { DateTime value = (DateTime)columnValue.Value; if (value < DevStoreTableServiceConstants.MIN_DATETIME_VALUE) { throw new ArgumentOutOfRangeException(string.Format("DateTime Current value is [{0}] but the values should be at least 1/1/1601.", value)); } } string sqlTypeFromObject = XmlUtility.GetSqlTypeFromObject(columnValue.Value, out str); XElement xElement1 = new XElement(columnValue.Key, str); xElement1.Add(new XAttribute("SqlType", sqlTypeFromObject)); if (string.IsNullOrWhiteSpace(str)) { xElement1.Add(new XAttribute(XNamespace.Xml + "space", "preserve")); } if (columnValue.Value == null) { xElement1.Add(new XAttribute("IsNull", "true")); } xElement.Add(xElement1); } return(xElement); }
internal static void AddObjectsToDictionaryFromXml(XElement xmlRoot, UtilityRow entity, bool shouldIncludeNull) { Dictionary <string, object> strs = new Dictionary <string, object>(); XmlUtility.AddObjectsToDictionaryFromXml(xmlRoot, entity.ColumnValues, shouldIncludeNull); }
private void ProcessChange(ChangeDescription changeDescription) { TableRow sqlEntity = null; PointQueryTracker pointQuery = null; DbTableDataContext failedCommandIndex = this; failedCommandIndex.FailedCommandIndex = failedCommandIndex.FailedCommandIndex + 1; switch (changeDescription.UpdateType) { case UpdateKind.Insert: { this.CheckPermissions(null, changeDescription); this.CheckPartitionAndRowKeys(((UtilityRow)changeDescription.Row).PartitionKey, ((UtilityRow)changeDescription.Row).RowKey, changeDescription.UpdateType); DateTime?nullable = null; sqlEntity = this.GetSqlEntity(((UtilityRow)changeDescription.Row).PartitionKey, ((UtilityRow)changeDescription.Row).RowKey, nullable); if (sqlEntity != null) { throw new TableServiceGeneralException(TableServiceError.EntityAlreadyExists, null); } UtilityRow row = (UtilityRow)changeDescription.Row; this.AddChangeToMap(DevelopmentStorageDbDataContext.EncodeKeyString(row.PartitionKey), DevelopmentStorageDbDataContext.EncodeKeyString(row.RowKey), changeDescription); this.m_dbContext.TableRows.InsertOnSubmit(this.CreateAndPopulateSqlEntity(row)); return; } case UpdateKind.Delete: { if (changeDescription.IfMatchHeaderMissing) { throw new XStoreArgumentException("If-Match header is mandatory when deleting an entity."); } sqlEntity = this.CheckAndGetEntity(changeDescription, true); this.AddChangeToMap(sqlEntity.PartitionKey, sqlEntity.RowKey, changeDescription); this.m_dbContext.TableRows.DeleteOnSubmit(sqlEntity); return; } case UpdateKind.Replace: { sqlEntity = this.CheckAndGetEntity(changeDescription, true); this.AddChangeToMap(sqlEntity.PartitionKey, sqlEntity.RowKey, changeDescription); sqlEntity.Data = XmlUtility.GetXmlFromUtilityRow(changeDescription.Row as UtilityRow); return; } case UpdateKind.Merge: { sqlEntity = this.CheckAndGetEntity(changeDescription, true); this.AddChangeToMap(sqlEntity.PartitionKey, sqlEntity.RowKey, changeDescription); sqlEntity.Data = XmlUtility.MergeXmlProperties(changeDescription.Row as UtilityRow, sqlEntity.Data); return; } case UpdateKind.InsertOrMerge: { this.ExecuteQuery <UtilityRow>(changeDescription); pointQuery = ((DbTableRowQueryProvider <UtilityRow>)changeDescription.QueryableRow.Provider).PointQuery; if (pointQuery == null) { throw new DataServiceException(400, "PK and RK not present in the required format"); } (changeDescription.Row as UtilityRow).PartitionKey = pointQuery.PartitionKey; (changeDescription.Row as UtilityRow).RowKey = pointQuery.RowKey; sqlEntity = this.CheckAndGetEntity(changeDescription, false); this.AddChangeToMap(DevelopmentStorageDbDataContext.EncodeKeyString(pointQuery.PartitionKey), DevelopmentStorageDbDataContext.EncodeKeyString(pointQuery.RowKey), changeDescription); if (sqlEntity != null) { sqlEntity.Data = XmlUtility.MergeXmlProperties(changeDescription.Row as UtilityRow, sqlEntity.Data); return; } this.m_dbContext.TableRows.InsertOnSubmit(this.CreateAndPopulateSqlEntity(changeDescription.Row as UtilityRow)); return; } case UpdateKind.InsertOrReplace: { this.ExecuteQuery <UtilityRow>(changeDescription); pointQuery = ((DbTableRowQueryProvider <UtilityRow>)changeDescription.QueryableRow.Provider).PointQuery; if (pointQuery == null) { throw new DataServiceException(400, "PK and RK not present in the required format"); } (changeDescription.Row as UtilityRow).PartitionKey = pointQuery.PartitionKey; (changeDescription.Row as UtilityRow).RowKey = pointQuery.RowKey; sqlEntity = this.CheckAndGetEntity(changeDescription, false); this.AddChangeToMap(DevelopmentStorageDbDataContext.EncodeKeyString(pointQuery.PartitionKey), DevelopmentStorageDbDataContext.EncodeKeyString(pointQuery.RowKey), changeDescription); if (sqlEntity != null) { sqlEntity.Data = XmlUtility.GetXmlFromUtilityRow(changeDescription.Row as UtilityRow); return; } this.m_dbContext.TableRows.InsertOnSubmit(this.CreateAndPopulateSqlEntity(changeDescription.Row as UtilityRow)); return; } default: { return; } } }