Beispiel #1
0
        public async Task FlowMessage(StorageFile file, string analysisResult, bool readText, bool completeAnalysis = false)
        {
            var flowNotificationMessage = new FlowMessage
            {
                HoloDescription = analysisResult,
                HoloReadText    = readText.ToString(),
                HoloImage       = GetDefaultImage()
            };

            if (file != null)
            {
                if (completeAnalysis)
                {
                    await PerformCompleteImageAnalysis(file, flowNotificationMessage);
                }

                try
                {
                    var uriName = await AzureBlobUploader.UploadFiletoAzureBlobReturnUri(file);

                    flowNotificationMessage.HoloImage = uriName;
                    Debug.WriteLine(flowNotificationMessage.HoloImage);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }

            var         jsonBody    = Newtonsoft.Json.JsonConvert.SerializeObject(flowNotificationMessage);
            var         client      = new HttpClient();
            HttpContent contentPost = new StringContent(jsonBody, Encoding.UTF8, "application/json");
            await client.PostAsync(new Uri(Config.FlowUrl), contentPost).ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode());
        }
        public static async Task processZIPfile(Document _doc)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Settings.Default.AzureConnString);
            CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer  container      = blobClient.GetContainerReference("");

            WebClient wc = new WebClient();

            using (var zipBlobFileStream = new MemoryStream(wc.DownloadData(_doc.downloadURL)))
            {
                byte[] bytes;
                await zipBlobFileStream.FlushAsync();

                zipBlobFileStream.Position = 0;

                using (var zip = new ZipArchive(zipBlobFileStream))
                {
                    foreach (var entry in zip.Entries)
                    {
                        CloudBlockBlob blob = container.GetBlockBlobReference(_doc.RowKey + "/" + entry.FullName);
                        using (var entryStream = entry.Open())
                        {
                            if (entry.Length > 0)
                            {
                                using (var md5 = MD5.Create())
                                {
                                    using (var stream = entry.Open())
                                    {
                                        using (var ms = new MemoryStream())
                                        {
                                            stream.CopyTo(ms);
                                            bytes = ms.ToArray();
                                        }
                                    }
                                }

                                AzureBlobUploader _abu = new AzureBlobUploader();
                                await _abu.UploadAsync(_doc, bytes, entry.FullName);
                            }
                        }
                    }
                }
            }
        }