Пример #1
0
        private IEnumerable <ScheduleWithQueues> LoadSchedules(MazakSchedulesAndLoadActions mazakData)
        {
            var loadOpers    = mazakData.LoadActions;
            var schs         = new List <ScheduleWithQueues>();
            var pending      = _log.AllPendingLoads();
            var skippedParts = new HashSet <string>();

            foreach (var schRow in mazakData.Schedules.OrderBy(s => s.DueDate).ThenBy(s => s.Priority))
            {
                if (!MazakPart.IsSailPart(schRow.PartName))
                {
                    continue;
                }

                MazakPart.ParseComment(schRow.Comment, out string unique, out var procToPath, out bool manual);

                var job = _jobDB.LoadJob(unique);
                if (job == null)
                {
                    continue;
                }

                // only if no load or unload action is in process
                bool foundJobAtLoad = false;
                foreach (var action in loadOpers)
                {
                    if (action.Unique == job.UniqueStr && action.Path == procToPath.PathForProc(action.Process))
                    {
                        foundJobAtLoad = true;
                        skippedParts.Add(job.PartName);
                        log.Debug("Not editing queued material because {uniq} is in the process of being loaded or unload with action {@action}", job.UniqueStr, action);
                        break;
                    }
                }
                foreach (var pendingLoad in pending)
                {
                    var s = pendingLoad.Key.Split(',');
                    if (schRow.PartName == s[0])
                    {
                        skippedParts.Add(job.PartName);
                        foundJobAtLoad = true;
                        log.Debug("Not editing queued material because found a pending load {@pendingLoad}", pendingLoad);
                        break;
                    }
                }
                if (foundJobAtLoad)
                {
                    continue;
                }

                // start building the schedule
                var sch = new ScheduleWithQueues()
                {
                    SchRow = schRow,
                    Unique = unique,
                    Job    = job,
                    LowerPriorityScheduleMatchingPartSkipped = skippedParts.Contains(job.PartName),
                    Procs = new Dictionary <int, ScheduleWithQueuesProcess>(),
                };
                bool missingProc = false;
                for (int proc = 1; proc <= job.NumProcesses; proc++)
                {
                    MazakScheduleProcessRow schProcRow = null;
                    foreach (var row in schRow.Processes)
                    {
                        if (row.ProcessNumber == proc)
                        {
                            schProcRow = row;
                            break;
                        }
                    }
                    if (schProcRow == null)
                    {
                        log.Error("Unable to find process {proc} for job {uniq} and schedule {schid}", proc, job.UniqueStr, schRow.Id);
                        missingProc = true;
                        break;
                    }
                    var path = procToPath.PathForProc(proc);
                    sch.Procs.Add(proc, new ScheduleWithQueuesProcess()
                    {
                        SchProcRow = schProcRow,
                        PathGroup  = job.GetPathGroup(process: proc, path: path),
                        InputQueue = job.GetInputQueue(process: proc, path: path)
                    });
                }
                if (!missingProc)
                {
                    schs.Add(sch);
                }
            }
            return(schs);
        }