public static void Run([BlobTrigger("exportedevents/{name}", Connection = "conversationstoragev2")] Stream myBlob, string name, ILogger log) { log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes"); BotFrameworkDataExtractor de = new BotFrameworkDataExtractor(); List <EventData> eds = de.ExtractFromBlob(myBlob); if (eds != null) { SearchIndexClient indexClient = new SearchIndexClient( Environment.GetEnvironmentVariable("searchServiceName"), Environment.GetEnvironmentVariable("searchIndexName"), new SearchCredentials(Environment.GetEnvironmentVariable("searchApiKey"))); List <Document> docsToPush = new List <Document>(); foreach (EventData ed in eds) { Document oldDoc = null; try { oldDoc = indexClient.Documents.Get(ed.ConversationId); } catch (Exception ex) { } List <string> messagesToAdd = new List <string>(); if (oldDoc != null) { string[] oldMessages = oldDoc["messages"] as string[]; if (oldMessages != null) { messagesToAdd = new List <string>(oldMessages); } } messagesToAdd.Add(string.Format("[{0}] {1}", ed.MessageType.ToString(), ed.MessageText)); Document newDoc = new Document(); newDoc.Add("conversation_id", ed.ConversationId); newDoc.Add("last_modified", DateTime.UtcNow.ToString("O")); newDoc.Add("messages", messagesToAdd); docsToPush.Add(newDoc); } //IndexAction.MergeOrUpload<Document>(newDoc); var batch = IndexBatch.MergeOrUpload <Document>(docsToPush); var res = indexClient.Documents.Index(batch); } }
public static void Run([BlobTrigger("conversationkm-raw/{name}", Connection = "conversationstoragev2")] Stream myBlob, string name, ILogger log) { log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes"); List <EventData> eds = null; try { BotFrameworkDataExtractor de = new BotFrameworkDataExtractor(); eds = de.ExtractFromBlob(myBlob); } catch { } if (eds != null) { BlobServiceClient blobServiceClient = new BlobServiceClient(Environment.GetEnvironmentVariable("conversationstoragev2")); BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient(Environment.GetEnvironmentVariable("outputContainerName")); foreach (EventData ed in eds) { BlobClient blobClient = blobContainerClient.GetBlobClient($"{ed.ConversationId}.json"); try { BlobDownloadInfo download = blobClient.Download(); using (StreamReader reader = new StreamReader(download.Content)) { string content = reader.ReadToEnd(); Conversation existingConversation = JsonConvert.DeserializeObject <Conversation>(content); existingConversation.Messages.Add(ed); existingConversation.Messages.Sort((x, y) => x.EventTime.CompareTo(y.EventTime)); UploadConversation(existingConversation, blobClient); } } catch (Azure.RequestFailedException ex) { if (ex.Status == 404) { Conversation conversation = new Conversation() { ConversationId = ed.ConversationId }; conversation.Messages.Add(ed); UploadConversation(conversation, blobClient); } } } } }