public static async Task DoGetNamedItemValue(IDialogContext context) { var workbookId = context.UserData.GetValue <string>("WorkbookId"); var worksheetId = context.UserData.GetValue <string>("WorksheetId"); var name = context.UserData.GetValue <string>("Name"); var type = context.UserData.GetValue <ObjectType>("Type"); // Check if the name refers to a cell if (type == ObjectType.Cell) { await CellWorker.ReplyWithValue(context, workbookId, worksheetId, name); } else { // Check if the name refers to a named item var namedItem = await GetNamedItem(context, workbookId, name); if (namedItem != null) { context.UserData.SetValue <ObjectType>("Type", ObjectType.NamedItem); await ReplyWithValue(context, workbookId, namedItem); } else { // Check if the name refers to a chart var chart = await ChartsWorker.GetChart(context, workbookId, worksheetId, name); if (chart != null) { context.UserData.SetValue <ObjectType>("Type", ObjectType.Chart); await ChartsWorker.ReplyWithChart(context, workbookId, worksheetId, chart); } else { // Check if the name refers to a table var table = await TablesWorker.GetTable(context, workbookId, name); if (table != null) { context.UserData.SetValue <string>("TableName", name); context.UserData.SetValue <ObjectType>("Type", ObjectType.Table); await TablesWorker.ReplyWithTable(context, workbookId, table); } else { await context.PostAsync($"**{name}** is not a named item, chart or table in the workbook"); } } } } }
public static async Task DoSetNamedItemValue(IDialogContext context, object value) { var workbookId = context.UserData.GetValue <string>("WorkbookId"); var type = context.UserData.GetValue <ObjectType>("Type"); var name = context.UserData.GetValue <string>("Name"); switch (type) { case ObjectType.Cell: var worksheetId = context.UserData.GetValue <string>("WorksheetId"); await CellWorker.SetCellValue(context, workbookId, worksheetId, name, value); break; case ObjectType.NamedItem: await SetNamedItemValue(context, workbookId, name, value); break; case ObjectType.Chart: await context.PostAsync($"I am not able to set the value of **{name}** because it is a chart"); break; case ObjectType.Table: var tableName = context.UserData.GetValue <string>("TableName"); int?rowIndex = null; context.UserData.TryGetValue <int?>("RowIndex", out rowIndex); if (rowIndex != null) { await TablesWorker.SetColumnValue(context, workbookId, tableName, name, (int)rowIndex, value); } else { await context.PostAsync($"I need to know about a specific table row to set the value of one of the columns. Ask me to look up a table row first"); } break; } }