示例#1
0
        private async Task SaveChannel(string id)
        {
            Console.WriteLine("Save Channel started for " + id);
            var client   = new AmazonDynamoDBClient();
            var response = await client.ScanAsync(new ScanRequest("channel"));

            var channelFromDb = response.Items?.Find(i => (i["id"].S == id));

            if (channelFromDb == null)
            {
                //get channel name from slack
                var slackMsg = new SlackMessage(new DynamoRepository());
                List <AwsDotnetCsharp.Models.Channel> channels = slackMsg.GetChannels(new List <string>()
                {
                    id
                }).ToList();

                //add channel to channel table
                if (channels?.Count > 0)
                {
                    Console.WriteLine("Adding new channel to db : Name " + channels[0]?.name);
                    var newChannel = new Document
                    {
                        ["guid"] = Guid.NewGuid().ToString(),
                        ["id"]   = id,
                        ["name"] = channels[0]?.name
                    };
                    var table = Table.LoadTable(client, "channel");
                    await table.PutItemAsync(newChannel);

                    Console.WriteLine("Channel saved");
                }
            }
        }