Пример #1
0
        public async Task Save(PersonalStoryEntity entity)
        {
            var table = new TableStorage("userprofile", tableConnection);

            if (!storyTableCreated)
            {
                storyTableCreated = await table.CreateIfNotExists();
            }

            await table.CreateIfNotExists();

            await table.InsertOrReplace(entity);
        }
Пример #2
0
        public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            PersonalStory story;

            context.PrivateConversationData.TryGetValue <PersonalStory>(key, out story);
            story = story ?? new PersonalStory();

            var message = await argument;

            var msg = new Message()
            {
                PartitionKey = message.Recipient.Id,
                RowKey       = $"{message.From.Id}_{DateTime.UtcNow}",
                Timestamp    = DateTime.UtcNow,
                Content      = message.Text,
                Task         = (int)story.Task
            };

            var storage = new Storage();
            await storage.Save(msg);

            switch (story.Task)
            {
            case PersonalStoryTask.Theme:
                story.Theme = message.Text;
                story.Task  = PersonalStoryTask.Description;
                break;

            case PersonalStoryTask.Description:
                story.Content = message.Text;
                story.Task    = PersonalStoryTask.Images;
                break;
            }

            if (null != message.Attachments && 0 < message.Attachments.Count)
            {
                story.Images = new string[message.Attachments.Count];
                for (var i = 0; i < message.Attachments.Count; i++)
                {
                    story.Images[i] = message.Attachments[i].ContentUrl;
                }
            }

            if (!string.IsNullOrWhiteSpace(story.Theme) && !string.IsNullOrWhiteSpace(story.Content) && null != story.Images && 0 < story.Images.Length)
            {
                var a      = await argument;
                var entity = new PersonalStoryEntity()
                {
                    PartitionKey = a.Recipient.Id,
                    RowKey       = a.From.Id,
                    Content      = story.Content,
                    Theme        = story.Theme,
                    Images       = string.Join(", ", story.Images),
                    Timestamp    = DateTime.UtcNow,
                };
                await storage.Save(entity);

                story.Task = PersonalStoryTask.Done;
            }

            var replyToConversation = await CreateResponse(context, story);

            await context.PostAsync(replyToConversation);

            context.PrivateConversationData.SetValue <PersonalStory>(key, story);

            context.Wait(MessageReceivedAsync);
        }