Example #1
0
        private IEnumerable <JobLogDB.EventLogMaterial> CreateUnloadMaterial(MessageState state, string pal, IReadOnlyList <LogEntry> oldEvents = null)
        {
            var    oldMat   = FindMaterial(pal, oldEvents)[0];
            var    ret      = new List <JobLogDB.EventLogMaterial>();
            string partName = "";
            int    count    = 1;

            if (state.PartCompletedMessagesBySetup.Count > 0)
            {
                // use highest setup value
                var msgs = state.PartCompletedMessagesBySetup.ElementAt(state.PartCompletedMessagesBySetup.Count - 1).Value;
                count    = msgs.Count;
                partName = msgs[0].PartName;
            }
            Log.Debug("During unload, found {cnt} parts with name {part} that were unloaded/completed",
                      count, partName);

            _log.SetDetailsForMaterialID(oldMat.MaterialID, null, partName, null);

            if (_settings.SerialType == BlackMaple.MachineFramework.SerialType.AssignOneSerialPerCycle ||
                _settings.SerialType == BlackMaple.MachineFramework.SerialType.AssignOneSerialPerMaterial
                )
            {
                _log.RecordSerialForMaterialID(oldMat, _settings.ConvertMaterialIDToSerial(oldMat.MaterialID).PadLeft(_settings.SerialLength, '0'), state.LastSeenMessage.TimeUTC);
            }
            ret.Add(oldMat);

            var oldMatDetails = _log.GetMaterialDetails(oldMat.MaterialID);

            //allocate new materials, one per completed part in addition to the existing one
            for (int i = 1; i < count; i++)
            {
                var newId  = _log.AllocateMaterialID(oldMatDetails.JobUnique, oldMatDetails.PartName, 1);
                var newMat = new JobLogDB.EventLogMaterial()
                {
                    MaterialID = newId,
                    Process    = 1,
                    Face       = ""
                };
                if (_settings.SerialType == BlackMaple.MachineFramework.SerialType.AssignOneSerialPerCycle)
                {
                    _log.RecordSerialForMaterialID(newMat, oldMatDetails.Serial, state.LastSeenMessage.TimeUTC);
                }
                else if (_settings.SerialType == BlackMaple.MachineFramework.SerialType.AssignOneSerialPerMaterial)
                {
                    _log.RecordSerialForMaterialID(newMat, _settings.ConvertMaterialIDToSerial(newId).PadLeft(_settings.SerialLength, '0'), state.LastSeenMessage.TimeUTC);
                }
                ret.Add(newMat);
            }

            return(ret);
        }