/// <summary> /// Aggregates all the machine events from the processed TAG files into a single collection, and /// maintains last known values for location, hardware ID and machine type /// </summary> /// <param name="processedTasks">The collated set tasks ready for aggregation</param> /// <param name="task">The 'seed' task used as a hold all for aggregated machines</param> private EventIntegrator AggregateAllMachineEvents(List <AggregatedDataIntegratorTask> processedTasks, AggregatedDataIntegratorTask task) { _log.LogDebug("Aggregation Task Process --> Aggregate machine events"); var eventIntegrator = new EventIntegrator(); // Iterate through the tasks to integrate the machine events for (var i = 1; i < processedTasks.Count; i++) // Zeroth item in the list is Task { var processedTask = processedTasks[i]; // 'Include' the extents etc of each site model being merged into 'task' into its extents and design change events task.IntermediaryTargetSiteModel.Include(processedTask.IntermediaryTargetSiteModel); // Iterate over all the machine events collected in the task foreach (var machine in processedTask.IntermediaryTargetMachines) { // Integrate the machine events eventIntegrator.IntegrateMachineEvents (processedTask.AggregatedMachineEvents[machine.InternalSiteModelMachineIndex], task.AggregatedMachineEvents[machine.InternalSiteModelMachineIndex], false, processedTask.IntermediaryTargetSiteModel, task.IntermediaryTargetSiteModel); //Update current DateTime with the latest one if (machine.LastKnownPositionTimeStamp.CompareTo(machine.LastKnownPositionTimeStamp) == -1) { machine.LastKnownPositionTimeStamp = machine.LastKnownPositionTimeStamp; machine.LastKnownX = machine.LastKnownX; machine.LastKnownY = machine.LastKnownY; } if (string.IsNullOrEmpty(machine.MachineHardwareID)) { machine.MachineHardwareID = machine.MachineHardwareID; } if (machine.MachineType == 0) { machine.MachineType = machine.MachineType; } } } return(eventIntegrator); }
/// <summary> /// Integrates all the machine events from the processed TAG files into the matching machines in the live site model /// </summary> /// <param name="siteModelFromDatamodel">The persistent site model the events will be integrated into</param> /// <param name="task">The 'seed' task used as a hold all for aggregated machines</param> /// <param name="eventIntegrator">The event integrator to perform the mechanical insertion of the new events</param> private bool IntegrateMachineEventsIntoLiveSiteModel(ISiteModel siteModelFromDatamodel, AggregatedDataIntegratorTask task, EventIntegrator eventIntegrator) { // Perform machine event integration outside of the SiteModel write access interlock as the // individual event lists have independent exclusive locks event integration uses. _log.LogDebug($"Aggregation Task Process --> Integrating machine events into the live site model for {task.IntermediaryTargetMachines.Count} intermediary machines"); // Iterate over all the machine events collected in the task foreach (var machineFromTask in task.IntermediaryTargetMachines) { var machineFromDatamodel = siteModelFromDatamodel.Machines.Locate(machineFromTask.ID, machineFromTask.Name, machineFromTask.IsJohnDoeMachine); var siteModelMachineTargetValues = siteModelFromDatamodel.MachinesTargetValues[machineFromDatamodel.InternalSiteModelMachineIndex]; eventIntegrator.IntegrateMachineEvents(task.AggregatedMachineEvents[machineFromTask.InternalSiteModelMachineIndex], siteModelMachineTargetValues, true, task.IntermediaryTargetSiteModel, siteModelFromDatamodel); // Integrate the machine events into the main site model. This requires the // site model interlock as aspects of the site model state (machine) are being changed. if (siteModelMachineTargetValues != null) { //Update machine last known value (events) from integrated model before saving var comparison = machineFromDatamodel.LastKnownPositionTimeStamp.CompareTo(machineFromDatamodel.LastKnownPositionTimeStamp); if (comparison == -1) { machineFromDatamodel.LastKnownDesignName = siteModelFromDatamodel.SiteModelMachineDesigns[siteModelMachineTargetValues.MachineDesignNameIDStateEvents.LastStateValue()].Name; machineFromDatamodel.LastKnownLayerId = siteModelMachineTargetValues.LayerIDStateEvents.Count() > 0 ? siteModelMachineTargetValues.LayerIDStateEvents.LastStateValue() : (ushort)0; machineFromDatamodel.LastKnownPositionTimeStamp = machineFromDatamodel.LastKnownPositionTimeStamp; machineFromDatamodel.LastKnownX = machineFromDatamodel.LastKnownX; machineFromDatamodel.LastKnownY = machineFromDatamodel.LastKnownY; } } else { _log.LogError("SiteModelMachineTargetValues not located in aggregate machine events integrator"); return(false); } // Use the synchronous command to save the machine events to the persistent store into the deferred (asynchronous model) siteModelMachineTargetValues.SaveMachineEventsToPersistentStore(_storageProxyMutable); } return(true); }