public void Setup() { _loggedData = new LoggedData(); _loggedDatas = new List <LoggedData> { _loggedData }; _catalog = new Catalog(); _datacardPath = ""; _taskDocumentWriter = new TaskDocumentWriter(); _timeMapperMock = new Mock <ITimeMapper>(); _tlgMapperMock = new Mock <ITlgMapper>(); _taskMapper = new TaskMapper(_timeMapperMock.Object, _tlgMapperMock.Object); }
private ISOTimeLog ExportTimeLog(OperationData operation, IEnumerable <SpatialRecord> spatialRecords, string dataPath) { ISOTimeLog isoTimeLog = new ISOTimeLog(); //ID string id = operation.Id.FindIsoId() ?? GenerateId(5); isoTimeLog.Filename = id; isoTimeLog.TimeLogType = 1; // TimeLogType TLG.C is a required attribute. Currently only the value "1" is defined. ExportIDs(operation.Id, id); List <DeviceElementUse> deviceElementUses = operation.GetAllSections(); List <WorkingData> workingDatas = deviceElementUses.SelectMany(x => x.GetWorkingDatas()).ToList(); ISOTime isoTime = new ISOTime(); isoTime.HasStart = true; isoTime.Type = ISOTimeType.Effective; isoTime.DataLogValues = ExportDataLogValues(workingDatas, deviceElementUses).ToList(); //Set the timelog data definition for PTN ISOPosition position = new ISOPosition(); position.HasPositionNorth = true; position.HasPositionEast = true; position.HasPositionUp = true; position.HasPositionStatus = true; position.HasPDOP = false; position.HasHDOP = false; position.HasNumberOfSatellites = false; position.HasGpsUtcTime = false; position.HasGpsUtcTime = false; isoTime.Positions.Add(position); //Write XML TaskDocumentWriter xmlWriter = new TaskDocumentWriter(); xmlWriter.WriteTimeLog(dataPath, isoTimeLog, isoTime); //Write BIN var binFilePath = Path.Combine(dataPath, isoTimeLog.Filename + ".bin"); BinaryWriter writer = new BinaryWriter(_dataLogValueOrdersByWorkingDataID); writer.Write(binFilePath, workingDatas.ToList(), spatialRecords); return(isoTimeLog); }
private IWriter[] MapItems(LoggedData loggedData, string datacardPath, TaskDocumentWriter taskDocumentWriter) { var times = FindAndMapTimes(loggedData.TimeScopes); var tlgs = _tlgMapper.Map(loggedData.OperationData, datacardPath, taskDocumentWriter); var items = new List <IWriter>(); if (times != null) { items.AddRange(times); } if (tlgs != null) { items.AddRange(tlgs); } return(items.ToArray()); }
private TLG Map(OperationData operationData, string taskDataPath, TaskDocumentWriter taskDocumentWriter) { var tlgId = operationData.Id.FindIsoId() ?? "TLG" + operationData.Id.ReferenceId; taskDocumentWriter.Ids.Add(tlgId, operationData.Id); var tlg = new TLG { A = tlgId }; var sections = operationData.GetAllSections(); var meters = sections.SelectMany(x => x.GetWorkingDatas()).ToList(); var spatialRecords = operationData.GetSpatialRecords != null?operationData.GetSpatialRecords() : null; var timHeader = _timHeaderMapper.Map(meters); _xmlReader.WriteTlgXmlData(taskDataPath, tlg.A + ".xml", timHeader); var binFilePath = Path.Combine(taskDataPath, tlg.A + ".bin"); _binaryWriter.Write(binFilePath, meters, spatialRecords); return(tlg); }
public void ShouldWritePrescription() { // Setup var taskWriter = new TaskDocumentWriter(); var adaptDocument = TestHelpers.LoadFromJson <ApplicationDataModel>(TestData.TestData.SingleProduct); var fertilizerProduct = new CropNutritionProduct { Description = "product", ProductType = ProductTypeEnum.Fertilizer }; fertilizerProduct.Id.ReferenceId = -1; adaptDocument.Catalog.Products.Add(fertilizerProduct); // Act using (taskWriter) { var actualXml = TestHelpers.Export(taskWriter, adaptDocument, _exportPath); Assert.AreEqual(TestData.TestData.SingleProductOutputXml, actualXml); } // Verify var expectedPath = Path.Combine(_exportPath, "TASKDATA", "GRD00000.BIN"); Assert.AreEqual(TestData.TestData.SingleProductOutputTxt, TestHelpers.LoadFromFileAsHexString(expectedPath)); }
private TSK Map(WorkOrder workOrder, ApplicationDataModel.ADM.ApplicationDataModel dataModel, int taskNumber, TaskDocumentWriter taskDocumentWriter) { var taskId = "TSK" + taskNumber; taskDocumentWriter.Ids.Add(taskId, workOrder.Id); var task = new TSK { A = taskId, B = workOrder.Description, C = FindGrowerId(workOrder.GrowerId, dataModel.Catalog), G = TSKG.Item1 //TaskStatus.Planned }; if (workOrder.WorkItemIds != null && workOrder.WorkItemIds.Any()) { var workItem = dataModel.Documents.WorkItems.FirstOrDefault(item => item.Id.ReferenceId == workOrder.WorkItemIds.First()); task.D = FindFarmId(workItem.FarmId, dataModel.Catalog); task.E = FindFieldId(workItem.FieldId, dataModel.Catalog); if (workItem.WorkItemOperationIds != null && workOrder.WorkItemIds.Any()) { var operation = dataModel.Documents.WorkItemOperations.First( item => item.Id.ReferenceId == workItem.WorkItemOperationIds.First()); if (operation.PrescriptionId != null && operation.PrescriptionId != 0) { var prescription = dataModel.Catalog.Prescriptions.FirstOrDefault( p => p.Id.ReferenceId == operation.PrescriptionId); if (prescription != null) { PrescriptionWriter.WriteSingle(taskDocumentWriter, prescription); } } } } return(task); }
public IEnumerable <TSK> Map(IEnumerable <WorkOrder> workOrders, ApplicationDataModel.ADM.ApplicationDataModel dataModel, int numberOfExistingTasks, TaskDocumentWriter writer) { if (workOrders == null) { yield break; } foreach (var workOrder in workOrders) { numberOfExistingTasks++; yield return(Map(workOrder, dataModel, numberOfExistingTasks, writer)); } }
public IEnumerable <TSK> Map(IEnumerable <LoggedData> loggedData, Catalog catalog, string taskDataPath, int numberOfExistingTasks, TaskDocumentWriter writer, bool includeIfPrescription = true) { if (loggedData == null) { yield break; } var loggedDataList = null as List <LoggedData>; if (includeIfPrescription) { loggedDataList = loggedData.ToList(); } else { loggedDataList = loggedData.Where(x => x.OperationData != null && x.OperationData.All(y => y.PrescriptionId == null)).ToList(); } for (int i = 0; i < loggedDataList.Count(); ++i) { yield return(Map(loggedDataList[i], catalog, taskDataPath, numberOfExistingTasks + (i + 1), writer)); } }
private TSK Map(LoggedData loggedData, Catalog catalog, string taskDataPath, int taskNumber, TaskDocumentWriter taskDocumentWriter) { var taskId = "TSK" + taskNumber; taskDocumentWriter.Ids.Add(taskId, loggedData.Id); var tsk = new TSK { A = taskId, B = loggedData.Description, C = FindGrowerId(loggedData.GrowerId, catalog), D = FindFarmId(loggedData.FarmId, catalog), E = FindFieldId(loggedData.FieldId, catalog), G = TSKG.Item4, Items = MapItems(loggedData, taskDataPath, taskDocumentWriter) }; return(tsk); }
public IEnumerable <TLG> Map(IEnumerable <OperationData> operationDatas, string taskDataPath, TaskDocumentWriter taskDocumentWriter) { if (operationDatas == null) { return(Enumerable.Empty <TLG>()); } return(operationDatas.Select(x => Map(x, taskDataPath, taskDocumentWriter))); }
public void Setup() { _taskWriter = new TaskDocumentWriter(); _directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(_directory); }