public static IFaceClient AuthenticateService(ISecretStore secretStore) { //Obtain Secrets from Secret Store AzureSettings azureSettings = new AzureSettings(); Secret secret = secretStore.Get(azureSettings.SecretPath); string faceRecognitionKey = secret.Data[azureSettings.FaceRecognitionKeySecretName]; string faceRecognitionEndPoint = secret.Data[azureSettings.FaceRecognitionEndpointSecretName]; return(new FaceClient(new ApiKeyServiceClientCredentials(faceRecognitionKey)) { Endpoint = faceRecognitionEndPoint }); }
private async Task ExtractInfo(ConsoleButton consoleButton) { switch (consoleButton.Name) { //Handle each Button's functionality case "Extract Info": int workspaceID = this.Helper.GetActiveCaseID(); int invoiceArtifactID = this.ActiveArtifact.ArtifactID; Guid modelGuid = Guid.Empty; string documentLocation = String.Empty; //Get Model and Document could be made a function to get doc location, but keeping for demo int modelArtifactId = (int)this.ActiveArtifact.Fields[Guids.Invoice.TRAINING_MODEL.ToString()].Value.Value; int documentArtifactId = (int)this.ActiveArtifact.Fields[Guids.Invoice.DOCUMENT.ToString()].Value.Value; if ((modelArtifactId > 0) && (documentArtifactId > 0)) { Model model = new Model(); await model.ReadModelGuid(Helper.GetServicesManager(), workspaceID, modelArtifactId); modelGuid = model.ModelGuid; IDBContext workspaceContext = Helper.GetDBContext(workspaceID); string sql = @"SELECT [Location] FROM [file] WITH(NOLOCK) WHERE [DocumentArtifactId] = @documentArtifactID AND [Type] = 0"; SqlParameter documentArtifactIdParam = new SqlParameter("@documentArtifactID", SqlDbType.Int); documentArtifactIdParam.Value = documentArtifactId; documentLocation = workspaceContext.ExecuteSqlStatementAsScalar <String>(sql, new SqlParameter[] { documentArtifactIdParam }); } //get secrets AzureSettings azureSettings = new AzureSettings(); ISecretStore secretStore = this.Helper.GetSecretStore(); Secret secret = secretStore.Get(azureSettings.SecretPath); string congnitiveServicesKey = secret.Data[azureSettings.CognitiveServicesKeySecretName]; string congnitiveServicesEndPoint = secret.Data[azureSettings.CognitiveServicesEndpointSecretName]; AzureFormRecognitionService azureFormRecognitionService = new FormRecognition.AzureFormRecognitionService(congnitiveServicesKey, congnitiveServicesEndPoint, Helper); Microsoft.Azure.CognitiveServices.FormRecognizer.Models.AnalyzeResult results = await azureFormRecognitionService.AnalyzeForm(azureFormRecognitionService.GetClient(), modelGuid, documentLocation); Invoice invoice = new Invoice(); invoice = invoice.ConvertAnalyzeResultToInvoice(results, Helper); IServicesMgr mgr = Helper.GetServicesManager(); await invoice.UpdateRelativity(mgr, workspaceID, invoiceArtifactID); break; } }
public async Task <IActionResult> Post(WeatherForecast weatherForecast) { var apiUrl = _configuration["api:url"]; // You should not be doing this but it's just to prove the point HttpClient httpClient = new HttpClient { BaseAddress = new Uri(apiUrl) }; var apiKey = await _secretStore.Get("APIs-Weather-Key"); httpClient.DefaultRequestHeaders.Add("x-api-key", apiKey); var rawForecast = JsonConvert.SerializeObject(weatherForecast); await httpClient.PostAsync("/weather/report", new StringContent(rawForecast)); return(Ok()); }
public string GetSecret(string tableName, string application, string name) { SetDependencies(tableName); return(_secretStore.Get(application, name).Value); }
private async Task SubmitDocuments(ConsoleButton consoleButton) { try { switch (consoleButton.Name) { //Handle each Button's functionality case "Submit Documents": int workspaceId = this.Helper.GetActiveCaseID(); int modelId = this.ActiveArtifact.ArtifactID; Model model = new Model(); //Get Documents In SavedSearch int savedSearchId = (int)this.ActiveArtifact.Fields[Guids.Model.SAVED_SEARCH_FIELD.ToString()].Value.Value; await model.ReadDocumentsInSavedSeach(Helper.GetServicesManager(), workspaceId, savedSearchId); //Could have made function shared with the other event handler but left here for demo Relativity.API.IDBContext workspaceContext = Helper.GetDBContext(workspaceId); string documentLocation = string.Empty; List <string> documentLocations = new List <string>(); foreach (int documentArtifactId in model.DocsInSearch) { string sql = @"SELECT [Location] FROM [file] WITH(NOLOCK) WHERE [DocumentArtifactId] = @documentArtifactID AND [Type] = 0"; SqlParameter documentArtifactIdParam = new SqlParameter("@documentArtifactID", SqlDbType.Int); documentArtifactIdParam.Value = documentArtifactId; documentLocation = workspaceContext.ExecuteSqlStatementAsScalar <String>(sql, new SqlParameter[] { documentArtifactIdParam }); documentLocations.Add(documentLocation); } //get secrets AzureSettings azureSettings = new AzureSettings(); ISecretStore secretStore = this.Helper.GetSecretStore(); Secret secret = secretStore.Get(azureSettings.SecretPath); string congnitiveServicesKey = secret.Data[azureSettings.CognitiveServicesKeySecretName]; string congnitiveServicesEndPoint = secret.Data[azureSettings.CognitiveServicesEndpointSecretName]; string storageAccountKey = secret.Data[azureSettings.StorageAccountKeySecretName]; string storageAccountName = secret.Data[azureSettings.StorageAccountNameSecretName]; //upload documents to New Container AzureStorageService azureStorageService = new FormRecognition.AzureStorageService(storageAccountKey, storageAccountName); Microsoft.Azure.Storage.Blob.CloudBlobClient client = azureStorageService.GetClient(); string containerPrefix = workspaceId.ToString() + "-" + modelId.ToString(); string sasUrl = azureStorageService.UploadFiles(client, documentLocations, containerPrefix); string containerName = azureStorageService.ContainerName; //Train model AzureFormRecognitionService azureFormRecognitionService = new FormRecognition.AzureFormRecognitionService(congnitiveServicesKey, congnitiveServicesEndPoint, Helper); Guid modeld = await azureFormRecognitionService.TrainModelAsync(azureFormRecognitionService.GetClient(), sasUrl); model.ModelGuid = modeld; model.SasUrl = sasUrl; //Update Relativity with data returned await model.UpdateRelativity(Helper.GetServicesManager(), workspaceId, modelId); break; } } catch (Exception e) { Helper.GetLoggerFactory().GetLogger().LogError(e, "Submit Documents Error"); throw; } }