aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration/IntegrationSettings.cs
blob: ce6ace32aa0120849143522413907760890faad4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Settings;
using Tango.Transport.Adapters;

namespace Tango.Integration
{
    public class IntegrationSettings : SettingsBase
    {
        /// <summary>
        /// Gets or sets the external bridge service port.
        /// </summary>
        public int ExternalBridgeServicePort { get; set; }

        /// <summary>
        /// Gets or sets the external bridge service discovery port.
        /// </summary>
        public int ExternalBridgeServiceDiscoveryPort { get; set; }

        /// <summary>
        /// Gets or sets the name of the embedded device.
        /// </summary>
        public String EmbeddedDeviceName { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether filter the detected USB machines via <see cref="EmbeddedDeviceName"/>.
        /// </summary>
        public bool FilterExternalBridgeUsbMachines { get; set; }

        /// <summary>
        /// Gets or sets the last virtual machine baud rate.
        /// </summary>
        public UsbSerialBaudRates EmbeddedSerialBaudRate { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="IntegrationSettings"/> class.
        /// </summary>
        public IntegrationSettings()
        {
            ExternalBridgeServicePort = 1984;
            ExternalBridgeServiceDiscoveryPort = 8888;
            EmbeddedDeviceName = "Tango USB Serial Port";
            FilterExternalBridgeUsbMachines = false;
            EmbeddedSerialBaudRate = UsbSerialBaudRates.BR_115200;
        }
    }
}
>>()) { _column_names.Add(name); } } } public ExcelWriter(String fileName) : this(new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { } public void WriteData<T>(IEnumerable<T> data, String sheetName) { var props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList(); WorksheetPart work_sheet_part = GetWorkSheetPart(sheetName); Worksheet workSheet = work_sheet_part.Worksheet; SheetData sheetData = workSheet.GetFirstChild<SheetData>(); List<Row> rows = sheetData.Elements<Row>().ToList(); var list = data.ToList(); for (int i = 0; i < list.Count; i++) { var item = list[i]; var last_row = sheetData.Elements<Row>().Last(); Row newRow = new Row(); newRow.RowIndex = last_row.RowIndex + 1; sheetData.InsertAfter(newRow, last_row); foreach (var prop in props) { var definedName = _column_names.SingleOrDefault(x => x.Name == prop.Name); if (definedName != null) { SetCellRow(newRow, GetCellReference(definedName, i + 2), prop.GetValue(item)); } } } } private void SetCellRow(Row row, string cellReference, object value) { Cell cell = row.Descendants<Cell>().FirstOrDefault(c => c.CellReference == cellReference); if (cell == null) { cell = new Cell(); cell.CellReference = cellReference; } cell.CellValue = new CellValue(value.ToString()); cell.DataType = CellValues.Number; if (value is String) { cell.DataType = CellValues.String; } else if (value is DateTime) { cell.DataType = CellValues.Date; } else if (value is Boolean) { cell.DataType = CellValues.Boolean; } row.Append(cell); } private WorksheetPart GetWorkSheetPart(String sheetName) { var sheet = _document.WorkbookPart.Workbook.Descendants<Sheet>().FirstOrDefault(x => x.Name.Value == sheetName); string relId = sheet.Id; return (WorksheetPart)_document.WorkbookPart.GetPartById(relId); } private string GetCellReference(DefinedName name, int rowIndex) { Regex rowPatern = new Regex("^.*\\!\\$(.*)\\$\\d*$"); Match match = rowPatern.Match(name.Text); return match.Groups[1].Value + rowIndex.ToString(); } public void Dispose() { _document.Save(); _stream.Dispose(); } } }