private static string createAction(string vote_id, string user_name, ActionData mat_data) { int next_id = NextIdStore.Next(Warehouse.PapersTable, vote_id); string row_key = Consts.ACTION_ID_CHAR + next_id.ToString("D" + Consts.ACTION_ID_DIGITS); DynamicTableEntity entity = new DynamicTableEntity(vote_id, row_key); entity[Consts.MAT_PROP_NAME] = new EntityProperty(mat_data.mat); entity[Consts.WHO_PROP_NAME] = new EntityProperty(user_name); entity[Consts.TIME_PROP_NAME] = new EntityProperty(DateTimeOffset.UtcNow); if (mat_data.value != null) { entity[Consts.VALUE_PROP_NAME] = new EntityProperty(mat_data.value); } if (mat_data.type != null) { entity[Consts.TYPE_PROP_NAME] = new EntityProperty(mat_data.type); } if (mat_data.pare != null) { entity[Consts.PARE_PROP_NAME] = new EntityProperty(mat_data.pare); } string hp = PaperPond.Get(vote_id).AddMat(entity); // If put this line after inserting into db, when cache miss and the roll is initialized from db, the mat will be added twice. Warehouse.PapersTable.Execute(TableOperation.Insert(entity)); return(hp); }
public static int GetLastPageId(string tag) { string partition_key = Consts.TAG_NAME_KEY_PREFIX + tag.ToLowerInvariant(); int last_id = NextIdStore.GetLastId(Warehouse.TagScrollsTable, partition_key); if (last_id == -1) { return(-1); } int page_id = (int)(last_id / Consts.NUM_VOTES_IN_A_PAGE); return(page_id); }
public static void AddVote(string vote_id, string tag, string title, string user_name) { string partition_key = Consts.TAG_NAME_KEY_PREFIX + tag.ToLowerInvariant(); NextIdStore.CreateIfNotExists(Warehouse.TagScrollsTable, partition_key, 0); int next_id = NextIdStore.Next(Warehouse.TagScrollsTable, partition_key); DynamicTableEntity entity = buildEntity(tag, next_id); entity["voteid"] = new EntityProperty(vote_id); entity["title"] = new EntityProperty(title); entity[Consts.WHO_PROP_NAME] = new EntityProperty(user_name); entity[Consts.TIME_PROP_NAME] = new EntityProperty(DateTimeOffset.UtcNow); Warehouse.TagScrollsTable.Execute(TableOperation.Insert(entity)); Warehouse.TagScrollsPond.AddOrUpdate(entity.PartitionKey, entity.RowKey, entity); }
public static string CreatePaper(string user_name) { for (; ;) { string vote_id = Util.RandomAlphaNumericString(8); if (NextIdStore.CreateIfNotExists(Warehouse.PapersTable, vote_id, 0)) { createAction(vote_id, user_name, new ActionData() { mat = "infos-create" }); return(vote_id); } } }