public static void CheckForFilesToBeProcessed(string productVersion, ILogger log) { FoundFile foundFile = null; while (true) { foundFile = null; try { foundFile = AzureFileHelper.ScanForANewFile(); } catch (Exception ex) { LogHelper.LogSystemError(log, productVersion, ex); } if (foundFile == null) { break; } try { string msg = "Processing the file " + foundFile.PlantName + "," + foundFile.AzureFileName; log.LogInformation("*** " + msg + $" at: {DateTime.Now}" + ":" + productVersion); LogHelper.LogMessage(foundFile.PlantName, productVersion, msg); foundFile.ProcessFile(log, productVersion); foundFile.DisposeOfFile(); foundFile.RecordSuccess(); } catch (Exception ex) { LogHelper.LogMessage(foundFile.PlantName, productVersion, "Fatal error with file " + foundFile.AzureFullPathName + " : " + ex.Message + ex.StackTrace); AzureModel.RecordFailure(foundFile.PlantName, foundFile.AzureFullPathName, foundFile.SuccessfulRecords, foundFile.FailedRecords, ex.Message); try { foundFile.DisposeOfFile(true); } catch (Exception ex2) { LogHelper.LogSystemError(log, productVersion, ex2); } } } }
private async void GetPredictions(string imageFilePath) { predictionIndicator.IsVisible = true; predictionIndicator.IsRunning = true; HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Prediction-Key", Constants.predictionKey); HttpResponseMessage response; byte[] byteData = GetImageAsByteArray(imageFilePath); using (ByteArrayContent content = new ByteArrayContent(byteData)) { content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response = await client.PostAsync(Constants.uriBase, content); string contentString = await response.Content.ReadAsStringAsync(); AzureModel model = JsonConvert.DeserializeObject <AzureModel>(contentString); var prediction = model.Predictions[0]; labelPredictionName.Text = "Obje: " + prediction.TagName; labelPrediction.Text = "Olasılık: " + prediction.Probability; } predictionIndicator.IsVisible = false; predictionIndicator.IsRunning = false; }
private OperationResult StartAzureInstance(AzureModel model) { try { string containerGroupName = SdkContext.RandomResourceName("blc-", 6); string multiContainerGroupName = containerGroupName + "-multi"; string postgresImagePath = Resources.POSTGRES_IMAGE_PATH; string mongoImagePath = Resources.MONGO_IMAGE_PATH; string blockbaseImagePath = Resources.BLOCKBASE_IMAGE_PATH; IAzure azureCon = GetAzureContext(model); if (!azureCon.ResourceGroups.CheckExistence(model.ResourceGroupName)) { azureCon.ResourceGroups.Define(model.ResourceGroupName).WithRegion(Microsoft.Azure.Management.ResourceManager.Fluent.Core.Region.USCentral).Create(); } CreateContainerGroupMulti(azureCon, model.ResourceGroupName, multiContainerGroupName, postgresImagePath, mongoImagePath, blockbaseImagePath); ViewBag.errorMessage = "Instance initiated"; return(new OperationResult() { IsSuccessful = true }); } catch (Exception e) { return(new OperationResult() { IsSuccessful = false, ErrorMessage = $"Instance failed ( Error: {e.Message} )" }); } }
public IActionResult Index() { var test = new AzureModel(); var azureForm = FormViewModel.From(test); return(View(azureForm)); }
public async Task <string> GetPowerBiAccessToken(AzureModel azureSettings) { using var client = new HttpClient(); var form = new Dictionary <string, string> { ["authorityUrl"] = azureSettings.AuthorityUrl, ["client_id"] = azureSettings.ClientId.ToString(), ["client_secret"] = azureSettings.ClientSecret, ["grant_type"] = azureSettings.GrantType, ["password"] = azureSettings.Password, ["resource"] = azureSettings.Resource, ["scope"] = azureSettings.Scope, ["username"] = azureSettings.Username }; client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded"); using var formContent = new FormUrlEncodedContent(form); using var response = await client.PostAsync(azureSettings.AuthorityUrl, formContent); var body = await response.Content.ReadAsStringAsync(); var jsonBody = JObject.Parse(body); var errorToken = jsonBody.SelectToken("error"); if (errorToken != null) { throw new Exception(errorToken.Value <string>()); } return(jsonBody.SelectToken("access_token").Value <string>()); }
public void AddingSigmaTagMappings() { string tags = File.ReadAllText(@"..\..\..\..\sampleFiles\tagMappingsWithSigma.csv"); DataTable tm = Utilities.ConvertCSVTexttoDataTable(tags); var output = AzureModel.UpdateTagMappings("GP01", tm); Console.WriteLine(output); }
public async Task <ViewResult> CreateWithModel(AzureModel model) { var instanceStartResult = StartAzureInstance(model); if (!instanceStartResult.IsSuccessful) { ViewBag.ErrorMessage = instanceStartResult.ErrorMessage; } return(View("Index", FormViewModel.From(model))); }
private static IAzure GetAzureContext(AzureModel azure) { IAzure azureContext; var credentials = new AzureCredentials(new ServicePrincipalLoginInformation { ClientId = azure.ClientId, ClientSecret = azure.ClientSecret }, azure.TenantId, AzureEnvironment.AzureGlobalCloud); azureContext = Azure.Authenticate(credentials).WithDefaultSubscription(); return(azureContext); }
public async Task <bool> TriggerLogicApp(AzureModel model) { using (var client = new HttpClient()) { var json = Newtonsoft.Json.JsonConvert.SerializeObject(model); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(logicAppUrl, content); response.EnsureSuccessStatusCode(); return(true); } }
public async void WhenCallingTheTriggerLogicAppWithBelowAzureModel(Table table) { var row = table.Rows[0]; AzureModel azureModel = new AzureModel { FirstName = row["FirstName"], LastName = row["LastName"], Email = row["Email"], PhoneNumber = row["PhoneNumber"] }; azureResult = await azureController.TriggerLogicApp(azureModel); }
internal static void ProcessModifiedTagMapping(string plant, string version) { // add/modify/delete tags mappings string suffix = "." + plant + ".csv"; string tags = AzureFileHelper.ReadFile(tagMappingFile + suffix); if (tags != null) { DataTable tm = Utilities.ConvertCSVTexttoDataTable(tags); string output = AzureModel.UpdateTagMappings(plant, tm); LogHelper.LogMessage(plant, version, "Updated the following tag mappings:\r\n" + output); AzureFileHelper.WriteFile(tagMappingFileProcessed + suffix, tags, false); AzureFileHelper.DeleteFile(tagMappingFile + suffix); } }
public async Task <PowerBIModel> GetEmbedData([FromServices] AzureModel azureSettings) { var accessToken = await _embeddedService.GetPowerBiAccessToken(azureSettings); var tokenCredentials = new TokenCredentials(accessToken, "Bearer"); var requestAccessLevel = new GenerateTokenRequest(accessLevel: "view"); using var client = new PowerBIClient(new Uri(azureSettings.ApiUrl), tokenCredentials); var report = await client.Reports.GetReportInGroupAsync(azureSettings.GroupId, azureSettings.ReportId); var tokenResponse = await client.Reports.GenerateTokenAsync(azureSettings.GroupId, azureSettings.ReportId, requestAccessLevel); var result = new PowerBIModel(tokenResponse, report.EmbedUrl); return(result); }
public void LoadProductionRecords(DataTable currentMonth, DPSFile ms, DateTime currentDay) { foreach (var row in currentMonth.AsEnumerable()) { string productionCode = row["Plant"].ToString() + "_" + row["Material Description OR Product Code in DPS"].ToString(); string uom = row["Display Unit of Measure"].ToString(); DateTime?day = row["transaction date"] as DateTime?; decimal quantity = DPSFile.ParseDecimal(row["production"].ToString()); try { quantity = AzureModel.ConvertQuantityToStandardUnit(uom, quantity); } catch (Exception ex) { ms.Warnings.Add(new WarningMessage(productionCode, ex.Message)); continue; } ms.AddTagBalance(currentDay, "DPS", productionCode, day.Value, quantity); } }
public void AddTagBalance(DateTime currentDay, string system, string productCode, DateTime day, decimal quantity) { TagBalance tb = new TagBalance(); tb.MovementType = "Production"; tb.System = system; tb.Tag = productCode; tb.Plant = this.Plant; tb.Created = DateTime.Now; tb.BalanceDate = day; tb.QuantityTimestamp = DateTime.Now; tb.CreatedBy = "STransform"; TagMap tm = AzureModel.LookupTag(tb.Tag, tb.Plant); if (tm == null) { SuncorProductionFile.Log(this.Plant, "no TagMapping found for " + tb.BalanceDate + "," + tb.Plant + "," + tb.Tag); Warnings.Add(new WarningMessage(tb.Tag, "No TagMapping")); this.FailedRecords.Add(tb); return; } tb.StandardUnit = tm.DefaultUnit; tb.Plant = tm.Plant; tb.ValType = tm.DefaultValuationType; tb.WorkCenter = tm.WorkCenter; tb.Material = tm.MaterialNumber; tb.Quantity = Math.Round(quantity, 3); tb.BatchId = this.BatchId.ToString(); if (!IsDayValid(day, currentDay)) { this.Warnings.Add(new WarningMessage(tb.Tag, "Invalid Date " + day.ToString("yyyy/MM/dd"))); this.FailedRecords.Add(tb); } else { this.Products.Add(tb); } return; }
public void CreateAllJsonR2P() { var data = AzureModel.GetAllTagBalances().Select(t => new { Date = t.BalanceDate, Tag = t.Tag, System = t.System, MovementType = t.MovementType, Material = t.Material, Plant = t.Plant, WorkCenter = t.WorkCenter, ValType = t.ValType, Tank = t.Tank, QuantityTimestamp = t.QuantityTimestamp, BalanceDate = t.BalanceDate, Quantity = t.Quantity, StandardUnit = t.StandardUnit }); string json = JsonConvert.SerializeObject(data); Assert.IsTrue(json.Length > 0); }
public void PersistBogusTagBalance() { List <TagBalance> items = new List <TagBalance>(); var tb = new TagBalance(); tb.MovementType = "Production"; tb.System = "Honeywell PB"; tb.Tag = "asdf"; tb.Created = DateTime.Now; tb.BalanceDate = DateTime.Now; tb.QuantityTimestamp = DateTime.Now; tb.CreatedBy = "cab"; tb.StandardUnit = "BBL"; tb.Plant = "cab"; tb.ValType = "cab"; tb.WorkCenter = "cab"; tb.Material = "123"; items.Add(tb); AzureModel.SaveTagBalance("aaa", new HoneywellPBFile("aaa", "CP01"), items); Assert.IsTrue(items.Count > 0); }
public void RecordSuccess(string fileName) { AzureModel.RecordStats(this, fileName, Warnings); SuncorProductionFile.LogSuccess(fileName, this, SavedRecords.Count, FailedRecords.Count); }
public void SaveRecords() { List <TagBalance> tb = this.GetTagBalanceRecords(); AzureModel.SaveTagBalance(FileName, this, tb); }
public void ReadAllTagBalance() { var items = AzureModel.GetAllTagBalances(); Assert.IsTrue(items.Count > 0); }
public async Task <bool> TriggerLogicApp([FromBody] AzureModel model) { return(await azureService.TriggerLogicApp(model)); }