//------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Sends the RFDeviceList via UDP to any connect client. /// This function is not asynchron, so the main thread is blocked when sending data. /// Maybe in oen of the next versions me make this function asynchron. /// </summary> /// <param name="devicelist">The devicelist.</param> private void SendDataUDP(RFDeviceList devicelist) { try { using (Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) { IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse(this.settings.UDPHost), this.settings.UDPPortSending); foreach (RFDevice device in devicelist) { XElement eDevice = device.ToXml(); byte[] baMessage = Encoding.Default.GetBytes(eDevice.ToDefaultString()); sender.SendTo(baMessage, endpoint); // Give the poor client some time to process the data when he need or bleed ... if (this.settings.UDPDelay > 0) { Thread.Sleep(this.settings.UDPDelay); } } sender.Close(); } } catch (Exception ex) { MB.Error(ex); } }
public void Test001_ExportRFDevices([ValueSource(nameof(aFormats))] FileFormat format, [Values(10, 50, 200, 1000)] int iCount) { SIGENCEScenarioToolTestCaseHelper.ShowTestCaseInformation(); //----------------------------------------------------------------- RFDeviceList dl = RFDeviceList.CreateRandomizedRFDeviceList(iCount, new PointLatLng(0, 0)); string strFilename = $"{Path.GetTempPath()}nunit_rfdevice.{DateTime.Now.ToString( "yyyyMMdd_HHmmssfff" )}.{format}"; switch (format) { case FileFormat.Xml: dl.SaveAsXml(strFilename); break; case FileFormat.Csv: dl.SaveAsCsv(strFilename); break; //case FileFormat.Json: // dl.SaveAsJson(strFilename); // break; } //----------------------------------------------------------------- Assert.True(File.Exists(strFilename)); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="ChartingDialog" /> class. /// </summary> public ChartingDialog(RFDeviceList lRFDevices) { this.lRFDevices = lRFDevices; InitializeComponent(); InitChart(); }
/// <summary> /// Sends the data UDP. /// </summary> private void SendDataUDP() { RFDeviceList devicelist = GetDeviceList(); if (devicelist.Count == 0) { MB.Warning("No Selected RFDevice Avaible For Sending!"); return; } SendDataUDP(devicelist); }
/// <summary> /// Exports the RFDevices. /// </summary> private void ExportRFDevices() { RFDeviceList devicelist = GetDeviceList(); if (devicelist.Count == 0) { MB.Warning("No Selected RFDevice Avaible For Export!"); return; } this.sfdExportSIGENCEScenario.FileName = this.CurrentFile != null ? new FileInfo(this.CurrentFile).GetFilenameWithoutExtension() : DateTime.Now.Fmt_YYYYMMDDHHMMSS(); if (this.sfdExportSIGENCEScenario.ShowDialog() == true) { ExportRFDevices(devicelist, new FileInfo(this.sfdExportSIGENCEScenario.FileName)); } }
/// <summary> /// Exports the RFDevices. /// </summary> /// <param name="devicelist">The devicelist.</param> /// <param name="fiExportFile">The fi export file.</param> private void ExportRFDevices(RFDeviceList devicelist, FileInfo fiExportFile) { this.Cursor = Cursors.Wait; try { switch (fiExportFile.Extension.ToLower()) { case ".csv": devicelist.SaveAsCsv(fiExportFile.FullName); MB.Information("File {0} successful created.", fiExportFile.Name); break; case ".json": devicelist.SaveAsJson(fiExportFile.FullName); MB.Information("File {0} successful created.", fiExportFile.Name); break; case ".xml": devicelist.SaveAsXml(fiExportFile.FullName); MB.Information("File {0} successful created.", fiExportFile.Name); break; //case ".sqlite": // devicelist.SaveAsSQLite( fiExportFile.FullName ); // MB.Information( "File {0} successful created." , fiExportFile.Name ); // break; case ".xlsx": SaveAsExcel(devicelist, fiExportFile.FullName); break; default: MB.Warning("The FileType '{0}' Is Currently Not Supported For Export!", fiExportFile.Extension.ToLower()); break; } } catch (Exception ex) { MB.Error(ex); } this.Cursor = Cursors.Arrow; }
/// <summary> /// Saves as excel file. /// </summary> /// <param name="dl">The dl.</param> /// <param name="strOutputFilename">The string output filename.</param> /// <exception cref="ArgumentException">Der Ausgabedateiname darf nicht leer sein! - strOutputFilename</exception> private void SaveAsExcel(RFDeviceList dl, string strOutputFilename) { if (strOutputFilename.IsEmpty()) { throw new ArgumentException("The output filename can not be empty!", nameof(strOutputFilename)); } //----------------------------------------------------------------- Excel.Application excel = new Excel.Application { SheetsInNewWorkbook = 1 }; Excel.Workbook wb = excel.Workbooks.Add(this.Missing); //----------------------------------------------------------------- Excel.Worksheet maindatasheet = wb.Sheets[1] as Excel.Worksheet; maindatasheet.Name = "RF Devices"; StringList slColumnNames = new StringList { "Time", "ID", "Lat", "Long", "Alt", "Roll", "Pitch", "Yaw", "RxTxType", "AntType", "Gain", "CenterFreq", "BandWidth", "SNR", "x", "y", "z", "Remark", "TechnicalParameters" }; // Create Header Columns { int iColumnCounter = 1; foreach (string strColumn in slColumnNames) { Excel.Range cell = maindatasheet.Cells[1, iColumnCounter++] as Excel.Range; cell.Font.Bold = true; cell.Orientation = Excel.XlOrientation.xlUpward; cell.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; cell.VerticalAlignment = Excel.XlVAlign.xlVAlignBottom; cell.Value2 = " " + strColumn; cell.Interior.Color = ColorTranslator.ToWin32(Color.CornflowerBlue); cell.Borders.Color = ColorTranslator.ToWin32(Color.Black); cell.Borders.Weight = Excel.XlBorderWeight.xlThick; } } //----------------------------------------------------------------- // Create Data Columns And Rows { int iRowCounter = 2; int iLastId = 0; bool bIdToggle = false; foreach (RFDevice device in from dev in dl orderby dev.StartTime, dev.Id select dev) { if (device.Id != iLastId) { bIdToggle = !bIdToggle; iLastId = device.Id; } Color c = bIdToggle ? Color.AliceBlue : Color.LightGoldenrodYellow; AddCell(maindatasheet, 1, iRowCounter, device.StartTime, c); AddCell(maindatasheet, 2, iRowCounter, device.Id, c); AddCell(maindatasheet, 3, iRowCounter, (double)device.Latitude, c); AddCell(maindatasheet, 4, iRowCounter, (double)device.Longitude, c); AddCell(maindatasheet, 5, iRowCounter, (int)device.Altitude, c); AddCell(maindatasheet, 6, iRowCounter, device.Roll, c); AddCell(maindatasheet, 7, iRowCounter, device.Pitch, c); AddCell(maindatasheet, 8, iRowCounter, device.Yaw, c); AddCell(maindatasheet, 9, iRowCounter, device.RxTxType * (this.SimulationMode ? 1 : -1), c); AddCell(maindatasheet, 10, iRowCounter, device.AntennaType, c); AddCell(maindatasheet, 11, iRowCounter, (double)device.Gain_dB, c); AddCell(maindatasheet, 12, iRowCounter, (double)device.CenterFrequency_Hz, c); AddCell(maindatasheet, 13, iRowCounter, (double)device.Bandwidth_Hz, c); AddCell(maindatasheet, 14, iRowCounter, (double)device.SignalToNoiseRatio_dB, c); AddCell(maindatasheet, 15, iRowCounter, device.XPos, c); AddCell(maindatasheet, 16, iRowCounter, device.YPos, c); AddCell(maindatasheet, 17, iRowCounter, device.ZPos, c); AddCell(maindatasheet, 18, iRowCounter, device.Remark, c); AddCell(maindatasheet, 19, iRowCounter, device.TechnicalParameters, c); iRowCounter++; } } maindatasheet.Columns.AutoFit(); //----------------------------------------------------------------- //if(string.IsNullOrEmpty( this.ScenarioDescription ) == false) //{ // if(wb.Sheets.Count < 2) // { // wb.Sheets.Add( this.Missing, maindatasheet ); // } // Excel.Worksheet descriptionsheet = wb.Sheets[2] as Excel.Worksheet; // descriptionsheet.Name = "Scenario Description"; // Excel.Range cell = descriptionsheet.Cells[1, 1] as Excel.Range; // Clipboard.SetDataObject( this.ScenarioDescription ); // cell.PasteSpecial(); //} //----------------------------------------------------------------- excel.Visible = true; wb.SaveAs(strOutputFilename, this.Missing, this.Missing, this.Missing, this.Missing, this.Missing, Excel.XlSaveAsAccessMode.xlNoChange, this.Missing, this.Missing, this.Missing, this.Missing, this.Missing); GC.WaitForPendingFinalizers(); GC.Collect(); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #region Specialied Excel Import /// <summary> /// Loads from excel. /// </summary> /// <param name="strInputFilename">The string input filename.</param> private void LoadFromExcel(string strInputFilename) { if (strInputFilename.IsEmpty()) { throw new ArgumentException("The input filename can not be empty!", nameof(strInputFilename)); } Excel.Application excel = new Excel.Application(); try { Excel.Workbook wb = excel.Workbooks.Open(strInputFilename); // We guess, the RF Device Data is on sheet #1, starting @ row 1 ... Excel.Worksheet maindatasheet = wb.Sheets[1] as Excel.Worksheet; Excel.Range range = maindatasheet.UsedRange; int iColumnCount = range.Columns.Count; if (iColumnCount < 17) { throw new Exception( $"The Current Excel File Can Not Be Imported Because There Are Only {iColumnCount} Columns!\nWe Need At Least 17 Columns For A Good Import."); } int iRowCount = range.Rows.Count; if (iRowCount < 2) { throw new Exception( $"The Current Excel File Can Not Be Imported Because There Are Only {iRowCount} Rows!\nWe Need At Least 2 Rows For A Good Import."); } RFDeviceList dlImportedDevices = new RFDeviceList(); for (int iRow = 2; iRow < iRowCount + 1; iRow++) { RFDevice device = new RFDevice { DeviceSource = DeviceSource.DataImport, }; for (int iColumn = 1; iColumn < 19 + 1; iColumn++) { object value = (range.Cells[iRow, iColumn] as Excel.Range).Value2; if (value == null) { continue; } // Hier ist zu überlegen wie wir das ganze generisch machen können falls sich das Model nochmal ändert ... switch (iColumn) { case 1: device.StartTime = Convert.ToDouble(value); break; case 2: device.Id = Convert.ToInt32(value); break; case 3: device.Latitude = Convert.ToDouble(value); break; case 4: device.Longitude = Convert.ToDouble(value); break; case 5: device.Altitude = Convert.ToInt32(value); break; case 6: device.Roll = Convert.ToDouble(value); break; case 7: device.Pitch = Convert.ToDouble(value); break; case 8: device.Yaw = Convert.ToDouble(value); break; case 9: device.RxTxType = RxTxTypes.FromInt(device.Id, Convert.ToInt32(value)); break; case 10: device.AntennaType = (AntennaType)Convert.ToInt32(value); break; case 11: device.Gain_dB = Convert.ToDouble(value); break; case 12: device.CenterFrequency_Hz = Convert.ToDouble(value); break; case 13: device.Bandwidth_Hz = Convert.ToDouble(value); break; case 14: device.SignalToNoiseRatio_dB = Convert.ToDouble(value); break; case 15: device.XPos = Convert.ToInt32(value); break; case 16: device.YPos = Convert.ToInt32(value); break; case 17: device.ZPos = Convert.ToInt32(value); break; case 18: device.Remark = Convert.ToString(value); break; case 19: device.TechnicalParameters = Convert.ToString(value); break; } } dlImportedDevices.Add(device); } AddRFDevices(dlImportedDevices); } catch (Exception ex) { MB.Error(ex); } excel.Quit(); excel = null; GC.WaitForPendingFinalizers(); GC.Collect(); }
/// <summary> /// Adds the rf devices. /// </summary> /// <param name="devices">The devices.</param> private void AddRFDevices(RFDeviceList devices) { devices.ForEach(d => AddRFDevice(d)); }
/// <summary> /// Displays the scenario. /// </summary> public void DisplayScenario() { dg.ItemsSource = RFDeviceList.CreateRandomizedRFDeviceList(16, new PointLatLng(49.7454, 6.6149)); wb.NavigateToString("<h1>Simple Testscenario</h1><hr/><ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul><table border=\"1\"><tr><th>Column1</th><th>Column2</th></tr><tr><td>Column1</td><td>Column2</td></tr></table><br/></br/><hr /><img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/7/7b/Geigentonspektrum.svg/262px-Geigentonspektrum.svg.png\"/><img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/5/5d/Airbus_Logo_2017.svg/200px-Airbus_Logo_2017.svg.png\"/>"); l.Content = "TestScenario Porta Nigra"; }