/// <summary> /// Add a row data to the specified grid view using parsed bin data /// </summary> /// <param name="grid">the grid view to add a row to</param> /// <param name="bin">bin data (wz files that were parsed then saved as a bin file type)</param> public void AddGridRow(DataGridView grid, BinData bin) { string queries = SearchTextBox.Text; if (!string.IsNullOrEmpty(queries)) { string[] lines = queries.Split(new[] { "\r\n" }, StringSplitOptions.None); foreach (var query in lines) { // all queries must match if (!bin.Search(query)) { return; } } } var properties = ""; foreach (string p in bin.Properties) { properties += p + "\r\n"; } grid.Rows.Add(bin.ID, bin.Image, bin.Name, properties); }
//TODO - Implement Methods of GET/SET/UPDATE/DELETE things from the database public List <BinData> GetAllBinsData() { List <spBin_GetBinListFullDetails_Result> dbBins = null; List <BinData> bins = new List <BinData>(); try { dbBins = this.db.spBin_GetBinListFullDetails().ToList(); foreach (spBin_GetBinListFullDetails_Result dbBin in dbBins) { BinData binData = new BinData() { binId = dbBin.BinId, binTypeId = dbBin.BinTypeId, binTypeDesc = dbBin.BinTypeDesc, cityAddress = dbBin.AreaDesc, currentCapacity = dbBin.CurrentCapacity, maxCapacity = dbBin.Capacity, streetAddress = dbBin.BuildingAddress, binTrashDisposalArea = dbBin.BinTrashDisposalArea, }; bins.Add(binData); } return(bins); } catch (Exception ex) { throw ErrorHandler.Handle(ex, this); } }
public void UpsertAsync_Should_Update_Existing_Record_When_Id_Exists() { // Arrange var existingData = new BinData { Id = 1, LeftContent = "aaaaaa", RightContent = "bbbb" }; var mockSet = MockHelper.MockDbSet(existingData); this.dataEntitiesMock.Setup(_ => _.BinDataSet) .Returns(mockSet.Object); var binData = new BinData { Id = 1, LeftContent = "bGVlZWVlZmZmZnR0dA==", RightContent = "cmlnaHR0dHR0dHR0" }; // Act this.service.UpsertAsync(binData).Wait(); // Assert existingData.LeftContent.Should().Be(binData.LeftContent); existingData.RightContent.Should().Be(binData.RightContent); this.binDataSetMock.Verify(_ => _.Add(binData), Times.Never); this.dataEntitiesMock.Verify(_ => _.SaveChangesAsync(), Times.Once); }
/// <summary> /// Asserts a <see cref="BinData"/> instance and throws and exception should it be invalid. /// </summary> /// <param name="data">Instance to be validated.</param> /// <exception cref="ArgumentNullException">Thrown should <paramref name="data"/> be null.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown should <see cref="BinData.Id"/> be lower than 1.</exception> /// <exception cref="ArgumentException"> /// <para>Thrown should both <see cref="BinData.LeftContent"/> and <see cref="BinData.RightContent"/> be null/empty/white space.</para> /// <para>Thrown should either <see cref="BinData.LeftContent"/> or <see cref="BinData.RightContent"/> be an invalid base64 string.</para> /// </exception> private void AssertDataForUpsert(BinData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (data.Id <= 0) { throw new ArgumentOutOfRangeException(nameof(data), "'Id' must be greater than zero."); } if (data.LeftContent.IsBlank() && data.RightContent.IsBlank()) { throw new ArgumentException("Either 'left' or 'right' properties must be provided.", nameof(data)); } if (!data.LeftContent.IsBlank()) { this.AssertBase64String(data.LeftContent); } if (!data.RightContent.IsBlank()) { this.AssertBase64String(data.RightContent); } }
/// <summary> /// Asynchronously creates OR updates a record for the given <paramref name="data"/>. /// </summary> /// <param name="data"><see cref="BinData"/> instance containing a valid <see cref="BinData.Id"/>, /// and also either <see cref="BinData.LeftContent"/> or <see cref="BinData.RightContent"/> populated.</param> /// <returns>A task that represents the asynchronous operation.</returns> public async Task UpsertAsync(BinData data) { this.AssertDataForUpsert(data); using (this.NewDbContextScope()) { var existingRecord = await this.DbContext.BinDataSet.SingleOrDefaultAsync(_ => _.Id == data.Id); if (existingRecord == null) { existingRecord = this.DbContext.BinDataSet.Add(data); } else { if (!data.LeftContent.IsBlank()) { existingRecord.LeftContent = data.LeftContent; } if (!data.RightContent.IsBlank()) { existingRecord.RightContent = data.RightContent; } } await this.DbContext.SaveChangesAsync(); } }
public StoreBinData GetStoreBinData(int x) { var result = new StoreBinData(); result.MaxBin = new BinData(); var where = new Hashtable(); var param = new Hashtable(); param["BinStart"] = x.ToString("D2"); where["where"] = param; if (x == 99) { result.MaxBin.BinNo = getMaxBinNo(null); } else { result.MaxBin.BinNo = getMaxBinNo(where); } var dTable = this.GetDataTableByStatement("GetBinDataByBinNoStart", where); var bins = new List <BinData>(); foreach (DataRow dRow in dTable.Rows) { var bin = new BinData(); bins.Add(bin); bin.BinNo = dRow.StringValue("BIN_PLC_NO"); bin.UsedFlag = dRow.IntValue("USED_FLAG", 0); bin.BinSize = dRow.StringValue("BIN_SIZE"); bin.BinStatus = dRow.StringValue("BIN_STATUS"); bin.BinBizStatus = dRow.StringValue("BIN_BIZ_STATUS"); bin.BinWeight = dRow.IntValue("BIN_WEIGHT", 0); bin.BinArea = dRow.StringValue("BIN_AREA"); bin.CrnNo = dRow.StringValue("CRN_NO"); bin.GroupNo = dRow.StringValue("GROUP_NO"); bin.OrderLineGuid = dRow.StringValue("ORDER_LINE_GUID"); bin.BinAgvNo = dRow.StringValue("BIN_AGV_NO"); //bin.BinPlcNo = dRow.StringValue("BIN_PLC_NO"); bin.PalletNo1 = dRow.StringValue("PALLET_NO1"); bin.PalletNo2 = dRow.StringValue("PALLET_NO2"); bin.MaterNo = dRow.StringValue("MATERIAL_NO"); bin.MaterName = dRow.StringValue("MATER_NAME"); bin.BatchNo = dRow.StringValue("BATCH_NO"); bin.Grade = dRow.StringValue("GRADE"); bin.ProductDate = dRow.StringValue("PRODUCT_DATE"); bin.MaterMkind = dRow.StringValue("MATER_MKIND"); bin.MaterType = dRow.StringValue("MATER_TYPE"); bin.MaterSpec = dRow.StringValue("MATER_SPEC"); bin.MaterDesc = dRow.StringValue("MATER_DESC"); bin.Qty = dRow.StringValue("QTY"); bin.CrnNo = dRow.StringValue("CRN_NO"); } result.AllBin = bins.ToArray(); return(result); }
public void UpsertAsync_Should_Throw_Exception_When_Data_Is_Null() { // Arrange BinData data = null; // Act & Assert this.Invoking(_ => this.service.UpsertAsync(data).Wait()) .ShouldThrow <AggregateException>() .WithInnerException <ArgumentNullException>(); }
/// <summary> /// Asserts <see cref="BinData.LeftContent"/> and <see cref="BinData.RightContent"/>, and throws an exception should either of them be invalid. /// </summary> /// <param name="data"><see cref="BinData"/> to be validated.</param> /// <exception cref="InvalidOperationException">Thrown should either <see cref="BinData.LeftContent"/> or <see cref="BinData.LeftContent"/> be null/empty.</exception> private void AssertDataForComparison(BinData data) { if (data.LeftContent.IsBlank()) { throw new InvalidOperationException("'Left' content is missing."); } if (data.RightContent.IsBlank()) { throw new InvalidOperationException("'Right' content is missing."); } }
public void UpdateBin(BinData updatedBin) { try { using (BinBusinessLogic binBusinessLogic = new BinBusinessLogic()) { binBusinessLogic.UpdateBin(updatedBin, DateTime.Now); } } catch (Exception ex) { throw ex; } }
public Bin AddNewBin(BinData newBin) { try { using (BinBusinessLogic binBusinessLogic = new BinBusinessLogic()) { return(binBusinessLogic.AddNewBin(newBin)); } } catch (Exception ex) { throw ex; } }
public void UpsertAsync_Should_Throw_Exception_When_LeftContent_Is_Not_Base64() { // Arrange var data = new BinData { Id = 1, LeftContent = "123" }; // Act & Assert this.Invoking(_ => this.service.UpsertAsync(data).Wait()) .ShouldThrow <AggregateException>() .WithInnerException <ArgumentException>() .WithInnerMessage("Invalid base64 string."); }
public void UpsertAsync_Should_Create_Record_When_Id_Does_Not_Exist() { // Arrange // By default the BinDataSet is empty, so it should force the data below to be 'added'. var binData = new BinData { Id = 1, LeftContent = "aaaa" }; // Act this.service.UpsertAsync(binData).Wait(); // Assert this.binDataSetMock.Verify(_ => _.Add(binData), Times.Once); this.dataEntitiesMock.Verify(_ => _.SaveChangesAsync(), Times.Once); }
public void UpsertAsync_Should_Throw_Exception_When_Id_Is_Lower_Than_One() { // Arrange var data = new BinData { Id = 0, LeftContent = "aaaaa", RightContent = "aaaaa" }; // Act & Assert this.Invoking(_ => this.service.UpsertAsync(data).Wait()) .ShouldThrow <AggregateException>() .WithInnerException <ArgumentOutOfRangeException>() .WithInnerMessage("*'Id' must be greater than zero.*"); }
public void UpsertAsync_Should_Throw_Exception_When_LeftContent_And_RightContent_Are_White_Spaces() { // Arrange var data = new BinData { Id = 1, LeftContent = " ", RightContent = " " }; // Act & Assert this.Invoking(_ => this.service.UpsertAsync(data).Wait()) .ShouldThrow <AggregateException>() .WithInnerException <ArgumentException>() .WithInnerMessage("*Either 'left' or 'right' properties must be provided.*"); }
public BinData DbBinToBinData(spBin_GetBinListFullDetails_Result dbBin) { BinData binData = new BinData() { binId = dbBin.BinId, binTypeId = dbBin.BinTypeId, binTypeDesc = dbBin.BinTypeDesc, cityAddress = dbBin.AreaDesc, streetAddress = dbBin.BuildingAddress, currentCapacity = dbBin.CurrentCapacity, maxCapacity = dbBin.Capacity, binTrashDisposalArea = dbBin.BinTrashDisposalArea, buildingId = dbBin.BuildingId// buildingid is nullable }; return(binData); }
public void CompareLeftAndRightAsync_Should_Throw_Exception_When_RightContent_Is_Missing() { // Arrange var existingData = new BinData { Id = 1, LeftContent = "aaaaa", RightContent = null }; var mockSet = MockHelper.MockDbSet(existingData); this.dataEntitiesMock.Setup(_ => _.Set <BinData>()) .Returns(mockSet.Object); // Act & Assert this.Invoking(_ => this.service.CompareLeftAndRightAsync(1).Wait()) .ShouldThrow <AggregateException>() .WithInnerException <InvalidOperationException>() .WithInnerMessage("'Right' content is missing."); }
private async void GetData_Click(object sender, EventArgs e) { try { var Data = await _GetCovid.GetData((string)CountryList.SelectedValue); BinData.Add(Data); DataBox.DataSource = BinData; DataBox.Update(); DataBox.Refresh(); }//end try catch (Exception ex) { MessageBox.Show(ex.Message); }//end catch }
public Bin AddNewBin(BinData newBin) { Bin dbBin; try { dbBin = new Bin(); BinDataToDbBin(dbBin, newBin); this.db.Bins.Add(dbBin); this.db.SaveChanges(); } catch (Exception ex) { throw ErrorHandler.Handle(ex, this); } return(dbBin); }
public void CompareLeftAndRightAsync_Should_Return_Message_When_Left_And_Right_Are_The_Same() { // Arrange var existingData = new BinData { Id = 1, LeftContent = "SEVMTE8gV09STEQh", RightContent = "SEVMTE8gV09STEQh" }; var mockSet = MockHelper.MockDbSet(existingData); this.dataEntitiesMock.Setup(_ => _.Set <BinData>()) .Returns(mockSet.Object); // Act var result = this.service.CompareLeftAndRightAsync(1).Result; // Assert result.DiffOffsets.Should().BeNull(); result.Length.Should().BeNull(); result.Message.Should().Be("Left and Right are the same."); }
public void CompareLeftAndRightAsync_Should_Return_Message_And_Offsets_When_Left_And_Right_Have_Same_Lengths() { // Arrange var existingData = new BinData { Id = 1, LeftContent = "aGVsbG8gd29ybGQh", RightContent = "SEVMTE8gV09STEQh" }; var mockSet = MockHelper.MockDbSet(existingData); this.dataEntitiesMock.Setup(_ => _.Set <BinData>()) .Returns(mockSet.Object); // Act var result = this.service.CompareLeftAndRightAsync(1).Result; // Assert result.Message.Should().Be("Left and Right have same size, but with different content."); result.DiffOffsets.Should().NotBeNullOrEmpty(); result.Length.Should().NotBeNull(); }
public void UpdateBin(BinData updatedBin, DateTime dt) { try { Bin oldBin = this.db.Bins.Where(x => x.BinId == updatedBin.binId).SingleOrDefault(); if (oldBin == null) { throw new Exception("Bin not found."); } BinDataToDbBin(oldBin, updatedBin); AddNewBinLog(oldBin, dt); this.db.SaveChanges(); } catch (Exception ex) { throw ErrorHandler.Handle(ex, this); } }
private static List <BinData> ParseBinaryFile(string path) { using FileStream fs = new FileStream(path, FileMode.Open); using BinaryReader br = new BinaryReader(fs); var rowCount = br.ReadInt32(); var bins = new List <BinData>(rowCount); for (int i = 0; i < rowCount; i++) { var bin = new BinData { ID = br.ReadInt32(), Name = br.ReadString() }; int propCount = br.ReadInt32(); for (int p = 0; p < propCount; p++) { bin.Properties.Add(br.ReadString()); } if (br.ReadBoolean()) { int bufferLength = br.ReadInt32(); byte[] buffer = br.ReadBytes(bufferLength); using MemoryStream ms = new MemoryStream(buffer); Image image = Image.FromStream(ms); Bitmap bmp = new Bitmap(image.Width, image.Height, PixelFormat.Format16bppRgb555); bmp.MakeTransparent(); using (var g = Graphics.FromImage(bmp)) { g.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height)); } image.Dispose(); bin.Image = bmp; } bins.Add(bin); } return(bins); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj is BinaryData) { return(BinData.Equals(((BinaryData)obj).BinData)); } else if (obj is byte[]) { return(BinData.Equals(obj)); } else if (obj is string) { return(ToString().Equals(obj)); } else { return(false); } }
public static void ExportBinary(TabPage page, string folder) { string directory = $"{ExportFolder}/{folder}"; string filePath = $"{directory}/{page.Text}.bin"; Directory.CreateDirectory(directory); var gdv = (DataViewer)page.Controls[0]; var rows = gdv.GridView.Rows; using BinaryWriter bw = new BinaryWriter(new FileStream(filePath, FileMode.Create)); bw.Write(rows.Count); for (int a = 0; a < rows.Count; a++) { var cells = rows[a].Cells; BinData bin = new BinData(); for (int b = 0; b < cells.Count; b++) { var cell = cells[b]; string colName = cell.OwningColumn.Name; if (colName.Contains("ID")) { bin.ID = (int)cell.Value; } else if (colName.Contains("Bitmap")) { bin.Image = (Bitmap)cell.Value; } else if (colName.Contains("Name")) { bin.Name = (string)cell.Value; } else if (colName.Contains("Properties")) { string[] properties = ((string)cell.Value).Split(new[] { "\r\n" }, StringSplitOptions.None); foreach (string prop in properties) { bin.Properties.Add(prop); } } else { throw new Exception($"unhandled column '{colName}'"); } } bw.Write(bin.ID); bw.Write(bin.Name); bw.Write(bin.Properties.Count); foreach (string prop in bin.Properties) { bw.Write(prop); } bw.Write(bin.Image != null); if (bin.Image != null) { using MemoryStream ms = new MemoryStream(); bin.Image.Save(ms, ImageFormat.Png); byte[] buffer = ms.GetBuffer(); bw.Write(buffer.Length); bw.Write(buffer); } } }
public Task Handle(Request @event) { BinData.Switch(@event); return Task.CompletedTask; }
private void _read() { _typeByte = ((BsonType)m_io.ReadU1()); _name = new Cstring(m_io, this, m_root); switch (TypeByte) { case BsonType.NumberDouble: { _content = m_io.ReadF8le(); break; } case BsonType.CodeWithScope: { _content = new CodeWithScope(m_io, this, m_root); break; } case BsonType.ObjectId: { _content = new ObjectId(m_io, this, m_root); break; } case BsonType.String: { _content = new String(m_io, this, m_root); break; } case BsonType.RegEx: { _content = new RegEx(m_io, this, m_root); break; } case BsonType.NumberDecimal: { _content = new F16(m_io, this, m_root); break; } case BsonType.UtcDatetime: { _content = m_io.ReadS8le(); break; } case BsonType.NumberLong: { _content = m_io.ReadS8le(); break; } case BsonType.Timestamp: { _content = new Timestamp(m_io, this, m_root); break; } case BsonType.DbPointer: { _content = new DbPointer(m_io, this, m_root); break; } case BsonType.Array: { _content = new Bson(m_io); break; } case BsonType.Javascript: { _content = new String(m_io, this, m_root); break; } case BsonType.Boolean: { _content = m_io.ReadU1(); break; } case BsonType.Document: { _content = new Bson(m_io); break; } case BsonType.Symbol: { _content = new String(m_io, this, m_root); break; } case BsonType.NumberInt: { _content = m_io.ReadS4le(); break; } case BsonType.BinData: { _content = new BinData(m_io, this, m_root); break; } } }
/// <summary> /// 获取指定的包 /// </summary> /// <param name="index"></param> /// <param name="size"></param> /// <returns></returns> public byte[] GetPacket(int index, int size) { var db = BinData.Skip(index * size).Take(size).ToArray(); return(db); }
public ExampleQuery() { Bin = new BinData(); Dsl = new DslData(); }
public ValuesController(IEventBus eventBus, IHostingEnvironment env) { BinData bd = new BinData(eventBus, env.ApplicationName); var res = bd.FindLimit("uinfo"); }
public void BinDataToDbBin(Bin bin, BinData binData) { bin.BinTypeId = binData.binTypeId; bin.CurrentCapacity = binData.currentCapacity; bin.BuildingId = binData.buildingId; }