Esempio n. 1
0
        public static void Run(
            [ServiceBusTrigger("atmosphere-processed-images", AccessRights.Listen, Connection = Settings.SB_CONN_NAME)] string message,
            [ServiceBus("atmosphere-images-with-faces", AccessRights.Send, Connection = Settings.SB_CONN_NAME, EntityType = EntityType.Topic)] ICollector <string> outputTopic,
            TraceWriter log)
        {
            log.Info($"Queue trigger '{nameof(FacesSplitter)}' with message: {message}");

            var processedImage = message.FromJson <ProcessedImage>();

            if (processedImage.Faces.Length == 0)
            {
                log.Info($"No faces were detected => deleting blob");
                BlobStorageClient.DeleteBlob(Settings.CONTAINER_FACES, processedImage.ImageName);
            }
            else
            {
                log.Info($"{processedImage.Faces.Length} faces detected => rasing notifications");

                processedImage
                .Faces
                .Select(r => new ProcessedFace()
                {
                    FaceId        = r.FaceId,
                    ImageName     = processedImage.ImageName,
                    Scores        = r.Scores,
                    FaceRectangle = r.FaceRectangle,
                    ClientId      = processedImage.ClientId
                })
                .ToList()
                .ForEach(f => outputTopic.Add(f.ToJson()));
            }
        }
Esempio n. 2
0
 public CodeSandboxOrchestrator(
     ContainerInstanceClient containerInstanceClient,
     BlobStorageClient blobStorageClient)
 {
     _containerInstanceClient = containerInstanceClient;
     _blobStorageClient       = blobStorageClient;
 }
Esempio n. 3
0
        public async Task <IActionResult> Upload()
        {
            foreach (var formFile in Request.Form.Files)
            {
                if (formFile.Length > 0)
                {
                    BlobStorageConfig config = _storageConfig.Copy();
                    config.ContainerName = config.UploadContainerName;

                    await BlobStorageClient.UploadBlobAsync(config,
                                                            Path.GetFileNameWithoutExtension(formFile.FileName) + "/" + formFile.FileName,
                                                            formFile.OpenReadStream());

                    var telemetryDict = new Dictionary <string, string>
                    {
                        { "FileName", formFile.FileName },
                        { "StorageAccountName", _searchConfig.ServiceName },
                        { "ContainerName", _storageConfig.ContainerName }
                    };

                    _telemetryClient.TrackEvent("FileUpload", telemetryDict);
                }
            }
            //await _searchClient.RunIndexer();
            return(new JsonResult("ok"));
        }
Esempio n. 4
0
        public async Task <IActionResult> Get()
        {
            BlobStorageConfig config = _storageConfig.Copy();

            config.ContainerName = config.FacetsFilteringContainerName;
            List <object> result = new List <object>();

            foreach (string name in _searchClient.Model.Facets.Select(f => f.Name))
            {
                var fileName = string.Format("{0}.txt", name.Replace(" ", "").ToLower());
                if (await BlobStorageClient.BlobExistsAsync(config, fileName))
                {
                    string text = await BlobStorageClient.ReadBlobAsync(config, fileName);

                    result.Add(new { name = name, restrictionList = text });
                }
                else
                {
                    await BlobStorageClient.UploadBlobAsync(config, fileName, "");

                    result.Add(new { name = name, restrictionList = "" });
                }
            }
            return(await Task.FromResult(new JsonResult(result)));
        }
Esempio n. 5
0
        private async Task <Guid> SaveFileAsync(string bucket, string fileName, IDictionary <string, object> metadata)
        {
            using (var blobStorage = new BlobStorageClient())
            {
                blobStorage.AuthorizeClient("osdr_ml_modeler", "osdr_ml_modeler_secret").Wait();

                return(await blobStorage.AddResource(bucket, fileName, metadata));
            }
        }
        public void TestInitialize()
        {
            var    r = new Random();
            string storageConnectionString = TestHelpers.GetTestSetting("StorageConnectionString");

            this.blobStorageClient = new BlobStorageClient(
                "Test00" + r.Next(0, 10000), storageConnectionString
                );
        }
Esempio n. 7
0
        public async Task <IActionResult> Update(FacetFilterUpdateRequest request)
        {
            BlobStorageConfig config = _storageConfig.Copy();

            config.ContainerName = config.FacetsFilteringContainerName;
            await BlobStorageClient.WriteBlobAsync(config, string.Format("{0}.txt", request.FacetName.Replace(" ", "").ToLower()), request.Text);

            return(await Task.FromResult(new JsonResult("success")));
        }
Esempio n. 8
0
        public async Task <IActionResult> Search(SearchRequest searchRequest)
        {
            var token = await BlobStorageClient.GetContainerSasUriAsync(_storageConfig);

            var selectFilter = _searchClient.Model.SelectFilter;
            var search       = searchRequest.Query;

            if (!string.IsNullOrEmpty(search))
            {
                search = search.Replace("-", "").Replace("?", "");
            }

            var response = await _searchClient.Search(search, searchRequest.SearchFacets, selectFilter, searchRequest.CurrentPage);

            var searchId = await _searchClient.GetSearchId();

            var facetResults = new List <object>();
            var tagsResults  = new List <object>();

            if (response.Facets != null)
            {
                // Return only the selected facets from the Search Model
                foreach (var facetResult in response.Facets.Where(f => _searchClient.Model.Facets.Where(x => x.Name == f.Key).Any()))
                {
                    facetResults.Add(new
                    {
                        key   = facetResult.Key,
                        value = facetResult.Value
                    });
                }

                foreach (var tagResult in response.Facets.Where(t => _searchClient.Model.Tags.Where(x => x.Name == t.Key).Any()))
                {
                    tagsResults.Add(new
                    {
                        key   = tagResult.Key,
                        value = tagResult.Value
                    });
                }
            }
            var telemetryDict = new Dictionary <string, string>
            {
                { "SearchServiceName", _searchConfig.ServiceName },
                { "SearchId", searchId },
                { "IndexName", _searchConfig.IndexName },
                { "QueryTerms", search },
                { "ResultCount", response.Count.ToString() }
            };

            _telemetryClient.TrackEvent("Search", telemetryDict);

            return(new JsonResult(new DocumentResult {
                Results = response.Results, Facets = facetResults, Tags = tagsResults, Count = Convert.ToInt32(response.Count), Token = token, SearchId = searchId
            }));
        }
Esempio n. 9
0
        public Program()
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            Configuration = builder.Build();

            _client = new BlobStorageClient(Configuration["AppSettings:ConnectionString"]); // must be lower case

            _client.CreateContainerAsync(ContainerName).GetAwaiter().GetResult();
        }
Esempio n. 10
0
        public async Task BlobUpload_GetBlobInfo_ReturnsExpectedBlobInfo()
        {
            using (var blobStorage = new BlobStorageClient("osdr_webapi", "osdr_webapi_secret"))
            {
                await blobStorage.Authorize("john", "qqq123");

                var info = await blobStorage.GetBlobInfo(JohnId.ToString(), BlobId);

                info["fileName"].Should().Be("Aspirin.mol");
            }
        }
Esempio n. 11
0
        public async Task CrudAndCopy_Success()
        {
            var    client         = new BlobStorageClient();
            string text           = "texto gravado";
            string sourceFilePath = CreateNewTxtFile(text);
            string filename       = Path.GetFileName(sourceFilePath);

            FilePath destination = new FilePath {
                Folder = folder,
                Path   = $"forms\\{filename}"
            };

            var response = await client.UploadToAsync(sourceFilePath, destination);

            Assert.IsTrue(((HttpFileResponse)response).HttpStatusCode == System.Net.HttpStatusCode.OK);

            var downloadStream = await client.DownloadFileStreamAsync(destination);

            using (var reader = new StreamReader(downloadStream))
            {
                var texto = reader.ReadToEnd();
                Assert.IsTrue(text == texto);
            }

            var downloadString = await client.DownloadFileStringAsync(destination);

            Assert.IsTrue(text == downloadString);

            FilePath destinationCopy = new FilePath
            {
                Folder = folder,
                Path   = $"forms\\copy\\{filename}"
            };

            var result = await client.CopyToAsync(destination, destinationCopy, true);

            var downloadStringCopy = await client.DownloadFileStringAsync(destinationCopy);

            Assert.IsTrue(text == downloadStringCopy);

            var exists = await client.ExistsAsync(destinationCopy);

            Assert.IsTrue(exists);

            var deleted = await client.DeleteAsync(destinationCopy);

            Assert.IsTrue(deleted);

            var destinationExists = await client.ExistsAsync(destination);

            Assert.IsTrue(destinationExists);

            await client.DeleteFolderAsync(destination.Folder);
        }
        public async Task BlobUpload_GetBlobInfo_ReturnsExpectedBlobInfo()
        {
            using (var blobStorage = new BlobStorageClient())
            {
                await blobStorage.AuthorizeClient("osdr_ml_modeler", "osdr_ml_modeler_secret");

                var info = await blobStorage.GetBlobInfo("CLIENT_ID", BlobId);

                info["fileName"].Should().Be("Aspirin.mol");
            }
        }
        public BlobStorageClientsTestsFixture(OsdrTestHarness harness)
        {
            using (var blobStorage = new BlobStorageClient())
            {
                blobStorage.AuthorizeClient("osdr_ml_modeler", "osdr_ml_modeler_secret").Wait();

                BlobId = blobStorage.AddResource("CLIENT_ID", "Aspirin.mol", new Dictionary <string, object>()
                {
                    { "parentId", harness.JohnId }, { "SkipOsdrProcessing", true }
                }).Result;
            }
        }
Esempio n. 14
0
        public BlobStorageUsersTestsFixture(BlobStorageTestHarness harness)
        {
            using (var blobStorage = new BlobStorageClient("osdr_webapi", "osdr_webapi_secret"))
            {
                blobStorage.Authorize("john", "qqq123").Wait();

                BlobId = blobStorage.AddResource(harness.JohnId.ToString(), "Aspirin.mol", new Dictionary <string, object>()
                {
                    { "parentId", harness.JohnId }
                }).Result;
            }
        }
        public async Task BlobUpload_UploadTooBitFile_Returns413()
        {
            using (var blobStorage = new BlobStorageClient("osdr_webapi", "osdr_webapi_secret"))
            {
                blobStorage.Authorize("john", "qqq123").Wait();

                var filePath = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "TooBig.mol");

                var response = await blobStorage.UploadFile(Harness.JohnId.ToString(), filePath, new Dictionary <string, object>() { { "parentId", Harness.JohnId } });

                response.StatusCode.Should().Be(HttpStatusCode.RequestEntityTooLarge);
            }
        }
Esempio n. 16
0
            public async Task <SlackMessage> getMessages(string channelId, string messageTs)
            {
                string channelHistoryRequestUrl = ConfigurationManager.AppSettings["ChannelHistoryRequestUrl"];
                string slackTokenKeyName        = ConfigurationManager.AppSettings["SlackTokenKeyName"];
                AzureKeyVaultClient _client     = new AzureKeyVaultClient();
                var _slacktoken = await _client.GetSecret(slackTokenKeyName);


                var requestUrl = string.Concat(channelHistoryRequestUrl, $"?token={_slacktoken}&channel={channelId}&latest={messageTs}&inclusive=true&count=1");

                using (HttpClient client = new HttpClient())
                {
                    var response = await client.GetAsync(new Uri(requestUrl));

                    var content = await response.Content.ReadAsStringAsync();

                    var result = JsonConvert.DeserializeObject <Dictionary <string, object> >(content);

                    var message = ((JArray)result["messages"]).First.ToObject <Dictionary <string, object> >();

                    SlackMessage slackMessage = null;

                    if (message.ContainsKey("file"))
                    {
                        var filedetails = ((JToken)message["file"]).ToObject <Dictionary <string, object> >();
                        var ext         = filedetails["filetype"].ToString();
                        if (ext == "jpg")
                        {
                            //Retrieve File Content
                            var fileContent = await getFileContents(filedetails["url_private"].ToString());

                            //Upload file to Blob
                            var blobStorageClient = new BlobStorageClient();
                            var blobPath          = await blobStorageClient.UploadDocument(fileContent, Guid.NewGuid().ToString() + "." + ext);

                            slackMessage          = new SlackMessage();
                            slackMessage.isFile   = true;
                            slackMessage.filePath = blobPath;
                            slackMessage.text     = message["text"].ToString();
                        }
                    }
                    else
                    {
                        slackMessage        = new SlackMessage();
                        slackMessage.isFile = false;
                        slackMessage.text   = message["text"].ToString();
                    }
                    return(slackMessage);
                }
            }
        public BaseIntegration()
        {
            var sharedFolder = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "Example.Console");

            var builder = new ConfigurationBuilder()
                          .SetBasePath(sharedFolder)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            Configuration = builder.Build();

            ContainerName = $"my-test-container{DateTime.UtcNow.Ticks}";
            Client        = new BlobStorageClient(Configuration["AppSettings:ConnectionString"]);

            // force this to execute!
            Client.CreateContainerAsync(ContainerName).ConfigureAwait(false).GetAwaiter().GetResult();
        }
        public async Task <HttpResponseMessage> ExecuteTransform([FromBody] TransformRequest transformRequest)
        {
            try
            {
                // Get map and extension object content from blob storage
                var blobStorageClient = new BlobStorageClient(_blobStorageConnString);
                if (transformRequest.MapName == null)
                {
                    throw new ArgumentNullException("There is no map name specified.");
                }

                byte[] mapContent = await blobStorageClient.GetBlob(_mapsContainerName, transformRequest.MapName);

                byte[] extensionObjectContent = transformRequest.ExtensionObjectName == null ? null : await blobStorageClient.GetBlob(_extensionObjectsContainerName, transformRequest.ExtensionObjectName);

                // Get and load extension objects from blob storage
                var transformClient  = new TransformClient();
                var extensionObjects = new List <ExtensionObject>();

                if (extensionObjectContent != null)
                {
                    extensionObjects = await transformClient.GetExtensionObjects(Encoding.Default.GetString(extensionObjectContent));

                    foreach (var extensionObject in extensionObjects)
                    {
                        extensionObject.RawAssembly = await blobStorageClient.GetBlob(_assembliesContainerName, extensionObject.AssemblyFileName);
                    }
                }

                // Execute the transform
                var output = await transformClient.ExecuteTransform(
                    transformRequest.InputXml,
                    mapContent,
                    extensionObjects);

                return(Request.CreateResponse(HttpStatusCode.OK, new TransformResponse {
                    OutputXml = output
                }));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.ToString()));
            }
        }
Esempio n. 19
0
        public static void Run(
            [ServiceBusTrigger("atmosphere-images-with-faces", "store-rectangles", AccessRights.Listen, Connection = Settings.SB_CONN_NAME)] string message,
            TraceWriter log)
        {
            log.Info($"Topic trigger '{nameof(CreateRectangles)}' with message: {message}");

            var face = message.FromJson <ProcessedFace>();

            using (var inputStream = BlobStorageClient.DownloadBlob(Settings.CONTAINER_FACES, face.ImageName))
            {
                log.Info($"Loaded image from blob in size of {inputStream.Length}");

                using (var outputStream = cutRectangle(face.FaceRectangle, inputStream))
                {
                    var fileName = $"{face.FaceId.ToString("D")}.jpg";
                    BlobStorageClient.UploadBlob(Settings.CONTAINER_RECTANGLES, fileName, outputStream);
                    log.Info($"Uploaded image {fileName} blob in size of {outputStream.Length}");
                }
            }
        }
        public static async Task Run(
            [ServiceBusTrigger("atmosphere-face-not-identified", AccessRights.Listen, Connection = Settings.SB_CONN_NAME)] string message,
            TraceWriter log)
        {
            log.Info($"Topic trigger '{nameof(RequestTaggingOnSlack)}' with message: {message}");
            var face = message.FromJson <Face>();

            // check image size
            using (var inputStream = BlobStorageClient.DownloadBlob(Settings.CONTAINER_RECTANGLES, $"{face.Id}.jpg"))
                using (var sourceImage = Image.FromStream(inputStream))
                {
                    log.Info($"The size of face thumbnail is {sourceImage.Size}");
                    if (sourceImage.Size.Width < MIN_WIDTH || sourceImage.Size.Height < MIN_HEIGHT)
                    {
                        await SlackClient.SendMessage(getMessageImageTooSmall(face.Id, sourceImage.Size), log);
                    }
                    else
                    {
                        await SlackClient.SendMessage(getMessageForTagging(face.Id), log);
                    }
                }
        }
Esempio n. 21
0
        public async Task <IActionResult> Get(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                _telemetryClient.TrackEvent($"A document request with an empty Id was sent. Document Id is required.");
                return(await Task.FromResult(new NotFoundObjectResult($"A Document Id is required.")));
            }

            var token = await BlobStorageClient.GetContainerSasUriAsync(_storageConfig);

            var response = await _searchClient.Lookup(id);

            var telemetryDict = new Dictionary <string, string>
            {
                { "SearchServiceName", _searchConfig.ServiceName },
                { "ClickedDocId", id }
            };

            _telemetryClient.TrackEvent("Click", telemetryDict);

            return(await Task.FromResult(new JsonResult(new DocumentResult {
                Result = response, Token = token
            })));
        }
        public async Task <IActionResult> FilterFacets(string facetname, FacetsFilteringRequest searchRequest)
        {
            // Calculate the response for each value.
            var response = new FacetsFilteringResponse();

            response.Values = new List <FacetRecord>();

            string[] commonList = new string[] { };
            string[] list       = new string[] { };
            try
            {
                BlobStorageConfig config = _storageConfig.Copy();
                config.ContainerName = config.FacetsFilteringContainerName;
                string s = await BlobStorageClient.ReadBlobAsync(config, "commonfilters.txt");

                commonList = s.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

                s = await BlobStorageClient.ReadBlobAsync(config, string.Format("{0}.txt", facetname));

                list = s.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            }
            catch (Exception)
            {
            }
            Trace.TraceInformation("facet: " + facetname);
            Trace.TraceInformation("number of values:" + searchRequest.Values.Count);
            foreach (var record in searchRequest.Values)
            {
                if (record == null || record.RecordId == null)
                {
                    continue;
                }

                FacetRecord responseRecord = new FacetRecord();
                responseRecord.RecordId = record.RecordId;

                try
                {
                    List <string> restrictionList = new List <string>(commonList);
                    restrictionList.AddRange(list);

                    var outputRecord = new FacetData();
                    outputRecord.Facets = new List <string>();
                    Trace.TraceInformation("number of facets:" + record.Data.Facets.Count);

                    // replace all non-alphbic characters before comparision
                    Regex rgx = new Regex("[^a-zA-Z0-9 ]");

                    for (int i = 0; i < restrictionList.Count; i++)
                    {
                        restrictionList[i] = rgx.Replace(restrictionList[i], "").ToLower();
                    }

                    foreach (string phrase in record.Data.Facets)
                    {
                        var str = rgx.Replace(phrase, "").ToLower();
                        if (!string.IsNullOrEmpty(str))
                        {
                            //lower case the first letter
                            //str = Char.ToLower(str[0]) + str.Substring(1);

                            if (!restrictionList.Contains(str))
                            {
                                outputRecord.Facets.Add(phrase);
                            }
                        }
                    }

                    //UpdateGraph(outputRecord.Facets, facetname);

                    responseRecord.Data = outputRecord;
                }
                catch (Exception e)
                {
                }
                finally
                {
                    response.Values.Add(responseRecord);
                }
            }


            return(new OkObjectResult(response));
        }
        protected BlobTestBase(string containerName)
        {
            ConnectionString = GetTestConnectionString();

            _client = new BlobStorageClient(ConnectionString, containerName, true);
        }
Esempio n. 24
0
 public void WhenQueueNameIsNull_ThenThrowException()
 {
     Assert.Throws <ArgumentNullException>(() => _ = new BlobStorageClient(TestConnectionStrings.Valid, null, false));
 }
Esempio n. 25
0
 public void WhenConnectionStringIsNull_ThenThrowException()
 {
     Assert.Throws <ArgumentNullException>(() => _ = new BlobStorageClient(null, ContainerName, false));
 }