public static void CreateRevision(DynamicTableEntity letter_entity, string board_id, string discussion_id, string letter_id, int version) { string partition_key = SandId.CombineId(board_id, discussion_id, letter_id); DynamicTableEntity entity = new DynamicTableEntity(partition_key, SandId.MakeRevisionId(version)); LetterConverter.CopyLetterRevision(letter_entity, entity, version); Warehouse.RevisionTable.Execute(TableOperation.Insert(entity)); // If an exception is thrown after revision created but before edit count in letter entity is updated, next time edit will fail because the revision already exists. }
public static void CreateActivity(string partition_key, string[] properties, object[] values) { int version = VersionCounterStore.Next(Warehouse.ActivityTable, partition_key); DynamicTableEntity entity = new DynamicTableEntity(partition_key, SandId.MakeRevisionId(version)); for (int i = 0; i < properties.Length; i++) { if (values[i] is string) { entity[properties[i]] = new EntityProperty((string)values[i]); } else { throw new ProgramLogicException(); } } Warehouse.ActivityTable.Execute(TableOperation.Insert(entity)); // 409 conflict exception if already exists. }
public static void CreateHistory(DynamicTableEntity src_entity, string partition_key, int version, params string[] properties_to_copy) { DynamicTableEntity dst_entity = new DynamicTableEntity(partition_key, SandId.MakeRevisionId(version)); CreatorConverter.CopyEntity(src_entity, CreatorConverter.Status.Editor, dst_entity, CreatorConverter.Status.Editor); foreach (string property_name in properties_to_copy) { EntityProperty ep; if (src_entity.Properties.TryGetValue(property_name, out ep)) { dst_entity[property_name] = ep /*src_entity[property_name]*/; } } Warehouse.HistoryTable.Execute(TableOperation.Insert(dst_entity)); }
public static int Next(CloudTable table, string partition_key) { TableResult result = table.Execute(TableOperation.Retrieve(partition_key, SandId.MakeRevisionId(0))); DynamicTableEntity entity = (DynamicTableEntity)result.Result; if (entity == null) { return(0); } EntityProperty ep; int version = 1; if (entity.Properties.TryGetValue("nextid", out ep)) { version = (int)ep.Int32Value; ep.Int32Value = version + 1; } else { entity["nextid"] = new EntityProperty(version + 1); } table.Execute(TableOperation.Merge(entity)); return(version); }