public void SendBogusTagBalanceToMuleSoft() { MulesoftPush.SetConnection("https://api-rtfdev.sequt.com/azureiot-experience-api/api/v1/azureiot-experience-api/production-posting", "20da7837f9574f03adb6fca17301f75a", "63e0E42AaDbA4815bD6B002E70E9B321"); HoneywellPBFile pf = new HoneywellPBFile("filename", "CP04"); List <TagBalance> items = new List <TagBalance>(); var tb = new TagBalance(); tb.MovementType = "Production"; tb.System = "Honeywell PB"; tb.Tag = "asdf"; tb.Quantity = 44; 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); pf.SavedRecords = new List <TagBalance>(); pf.SavedRecords.Add(tb); var json = pf.ExportR2PJson(); Console.WriteLine(json); MulesoftPush.PostProduction(json); }
public static void SaveTagBalance(String file, SuncorProductionFile pf, List <TagBalance> tb) { using (DBContextWithConnectionString context = new DBContextWithConnectionString()) { Batch batch = new Batch(); batch.Id = pf.BatchId.ToString(); batch.Created = DateTime.Now; batch.CreatedBy = "System"; batch.Filename = file; context.Batches.Add(batch); foreach (var item in tb) { TagBalance found = context.TagBalances.Find(new object[] { item.Tag, item.BalanceDate }); if (found == null) { batch.TagBalances.Add(item); } else { UpdateTagBalance(found, item); } } context.SaveChanges(); pf.SavedRecords = tb; } }
private static void UpdateTagBalance(TagBalance existing, TagBalance tb) { existing.Quantity = tb.Quantity; existing.Material = tb.Material; existing.StandardUnit = tb.StandardUnit; existing.ValType = tb.ValType; existing.WorkCenter = tb.WorkCenter; existing.Tank = tb.Tank; }
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 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); }