public ISOTask ExportPrescription(WorkItem workItem, int gridType, Prescription prescription) { ISOTask task = new ISOTask(); //Task ID string taskID = workItem.Id.FindIsoId() ?? GenerateId(); task.TaskID = taskID; ExportIDs(workItem.Id, taskID); //Designator task.TaskDesignator = prescription.Description; //Customer Ref if (workItem.GrowerId.HasValue) { task.CustomerIdRef = TaskDataMapper.InstanceIDMap.GetISOID(workItem.GrowerId.Value); } //Farm Ref if (workItem.FarmId.HasValue) { task.FarmIdRef = TaskDataMapper.InstanceIDMap.GetISOID(workItem.FarmId.Value); } //Partfield Ref if (workItem.CropZoneId.HasValue) { task.PartFieldIdRef = TaskDataMapper.InstanceIDMap.GetISOID(workItem.CropZoneId.Value); } else if (workItem.FieldId.HasValue) { task.PartFieldIdRef = TaskDataMapper.InstanceIDMap.GetISOID(workItem.FieldId.Value); } //Comments if (workItem.Notes.Any()) { CommentAllocationMapper canMapper = new CommentAllocationMapper(TaskDataMapper); task.CommentAllocations = canMapper.ExportCommentAllocations(workItem.Notes).ToList(); } //Worker Allocations if (workItem.PeopleRoleIds.Any()) { WorkerAllocationMapper workerAllocationMapper = new WorkerAllocationMapper(TaskDataMapper); List <PersonRole> personRoles = new List <PersonRole>(); foreach (int id in workItem.PeopleRoleIds) { PersonRole personRole = DataModel.Catalog.PersonRoles.FirstOrDefault(p => p.Id.ReferenceId == id); if (personRole != null) { personRoles.Add(personRole); } } task.WorkerAllocations = workerAllocationMapper.ExportWorkerAllocations(personRoles).ToList(); } //Guidance Allocations if (workItem.GuidanceAllocationIds.Any()) { GuidanceAllocationMapper guidanceAllocationMapper = new GuidanceAllocationMapper(TaskDataMapper); List <GuidanceAllocation> allocations = new List <GuidanceAllocation>(); foreach (int id in workItem.GuidanceAllocationIds) { GuidanceAllocation allocation = DataModel.Documents.GuidanceAllocations.FirstOrDefault(p => p.Id.ReferenceId == id); if (allocation != null) { allocations.Add(allocation); } } task.GuidanceAllocations = guidanceAllocationMapper.ExportGuidanceAllocations(allocations).ToList(); } //Connections if (workItem.EquipmentConfigurationGroup != null) { task.Connections = _connectionMapper.ExportConnections(workItem.Id.ReferenceId, workItem.EquipmentConfigurationGroup.EquipmentConfigurations).ToList(); } //Status if (workItem.StatusUpdates == null || workItem.StatusUpdates.Count == 0) { task.TaskStatus = ISOEnumerations.ISOTaskStatus.Planned; } else if (workItem.StatusUpdates.Count == 1) { StatusUpdate lastStatus = workItem.StatusUpdates.OrderByDescending(su => su.TimeStamp).Last(); task.TaskStatus = ExportStatus(lastStatus.Status); } //Prescription if (prescription is RasterGridPrescription) { ExportRasterPrescription(task, prescription as RasterGridPrescription, gridType); } else if (prescription is VectorPrescription) { ExportVectorPrescription(task, prescription as VectorPrescription); } else if (prescription is ManualPrescription) { ExportManualPresciption(task, prescription as ManualPrescription); } return(task); }
private ISOTask Export(LoggedData loggedData) { ISOTask task = null; //Try to map to a pre-existing Work Item task where appropriate if (loggedData.OperationData.All(o => o.PrescriptionId.HasValue) && loggedData.OperationData.Select(o => o.PrescriptionId.Value).Distinct().Count() == 1) { int rxID = loggedData.OperationData.First().PrescriptionId.Value; if (_taskIDsByPrescription.ContainsKey(rxID)) { task = ISOTaskData.ChildElements.OfType <ISOTask>().FirstOrDefault(t => t.TaskID == _taskIDsByPrescription[rxID]); } } if (task == null) { task = new ISOTask(); //Task ID string taskID = loggedData.Id.FindIsoId() ?? GenerateId(); task.TaskID = taskID; } if (!ExportIDs(loggedData.Id, task.TaskID)) { //Update the mapping to represent the completed task TaskDataMapper.InstanceIDMap.ReplaceADAPTID(task.TaskID, loggedData.Id.ReferenceId); } //Task Designator task.TaskDesignator = loggedData.Description; //Customer Ref if (loggedData.GrowerId.HasValue) { task.CustomerIdRef = TaskDataMapper.InstanceIDMap.GetISOID(loggedData.GrowerId.Value); } //Farm Ref if (loggedData.FarmId.HasValue) { task.FarmIdRef = TaskDataMapper.InstanceIDMap.GetISOID(loggedData.FarmId.Value); } //Partfield Ref if (loggedData.CropZoneId.HasValue) { task.PartFieldIdRef = TaskDataMapper.InstanceIDMap.GetISOID(loggedData.CropZoneId.Value); } else if (loggedData.FieldId.HasValue) { task.PartFieldIdRef = TaskDataMapper.InstanceIDMap.GetISOID(loggedData.FieldId.Value); } //Status task.TaskStatus = ISOEnumerations.ISOTaskStatus.Completed; if (loggedData.OperationData.Any()) { //Time Logs task.TimeLogs = TimeLogMapper.ExportTimeLogs(loggedData.OperationData, TaskDataPath).ToList(); //Connections IEnumerable <int> taskEquipmentConfigIDs = loggedData.OperationData.SelectMany(o => o.EquipmentConfigurationIds); if (taskEquipmentConfigIDs.Any()) { IEnumerable <EquipmentConfiguration> taskEquipmentConfigs = DataModel.Catalog.EquipmentConfigurations.Where(d => taskEquipmentConfigIDs.Contains(d.Id.ReferenceId)); task.Connections = ConnectionMapper.ExportConnections(loggedData.Id.ReferenceId, taskEquipmentConfigs).ToList(); } } //Summaries if (loggedData.SummaryId.HasValue) { Summary summary = DataModel.Documents.Summaries.FirstOrDefault(s => s.Id.ReferenceId == loggedData.SummaryId.Value); if (summary != null) { task.Times.AddRange(ExportSummary(summary)); } List <ISOProductAllocation> productAllocations = GetProductAllocationsForSummary(summary); if (productAllocations != null) { task.ProductAllocations.AddRange(productAllocations); } } //Comments if (loggedData.Notes.Any()) { CommentAllocationMapper canMapper = new CommentAllocationMapper(TaskDataMapper); task.CommentAllocations = canMapper.ExportCommentAllocations(loggedData.Notes).ToList(); } //Worker Allocations if (loggedData.PersonRoleIds.Any()) { WorkerAllocationMapper workerAllocationMapper = new WorkerAllocationMapper(TaskDataMapper); List <PersonRole> personRoles = new List <PersonRole>(); foreach (int id in loggedData.PersonRoleIds) { PersonRole personRole = DataModel.Catalog.PersonRoles.FirstOrDefault(p => p.Id.ReferenceId == id); if (personRole != null) { personRoles.Add(personRole); } } task.WorkerAllocations = workerAllocationMapper.ExportWorkerAllocations(personRoles).ToList(); } //Guidance Allocations if (loggedData.GuidanceAllocationIds.Any()) { GuidanceAllocationMapper guidanceAllocationMapper = new GuidanceAllocationMapper(TaskDataMapper); List <GuidanceAllocation> allocations = new List <GuidanceAllocation>(); foreach (int id in loggedData.GuidanceAllocationIds) { GuidanceAllocation allocation = DataModel.Documents.GuidanceAllocations.FirstOrDefault(p => p.Id.ReferenceId == id); if (allocation != null) { allocations.Add(allocation); } } task.GuidanceAllocations = guidanceAllocationMapper.ExportGuidanceAllocations(allocations).ToList(); } return(task); }