Esempio n. 1
0
        private void AddSchedules(IEnumerable <JobPlan> jobs)
        {
            var mazakData = readDatabase.LoadSchedulesPartsPallets();
            var transSet  = BuildMazakSchedules.AddSchedules(mazakData, jobs, UseStartingOffsetForDueDate);

            if (transSet.Schedules.Any())
            {
                writeDb.Save(transSet, "Add Schedules");
                foreach (var j in jobs)
                {
                    jobDB.MarkJobCopiedToSystem(j.UniqueStr);
                }
            }
        }
Esempio n. 2
0
        public WriteJobsSpec()
        {
            var logConn = new Microsoft.Data.Sqlite.SqliteConnection("Data Source=:memory:");

            logConn.Open();
            _logDB = new JobLogDB(new FMSSettings(), logConn);
            _logDB.CreateTables(firstSerialOnEmpty: null);

            var jobConn = new Microsoft.Data.Sqlite.SqliteConnection("Data Source=:memory:");

            jobConn.Open();
            _jobDB = new JobDB(jobConn);
            _jobDB.CreateTables();

            _writeMock = new WriteMock();

            _readMock = Substitute.For <IReadDataAccess>();
            _readMock.MazakType.Returns(MazakDbType.MazakSmooth);
            _readMock.LoadAllData().Returns(new MazakAllData()
            {
                Schedules = new[] {
                    // a completed schedule, should be deleted
                    new MazakScheduleRow()
                    {
                        Id               = 1,
                        PartName         = "part1:1:1",
                        Comment          = MazakPart.CreateComment("uniq1", new [] { 1 }, false),
                        PlanQuantity     = 15,
                        CompleteQuantity = 15,
                        Priority         = 50,
                        Processes        =
                        {
                            new MazakScheduleProcessRow()
                            {
                                MazakScheduleRowId = 1,
                                FixedMachineFlag   = 1,
                                ProcessNumber      = 1
                            }
                        }
                    },
                    // a non-completed schedule, should be decremented
                    new MazakScheduleRow()
                    {
                        Id               = 2,
                        PartName         = "part2:1:1",
                        Comment          = MazakPart.CreateComment("uniq2", new [] { 1 }, false),
                        PlanQuantity     = 15,
                        CompleteQuantity = 10,
                        Priority         = 50,
                        Processes        =
                        {
                            new MazakScheduleProcessRow()
                            {
                                MazakScheduleRowId      = 1,
                                FixedMachineFlag        = 1,
                                ProcessNumber           = 1,
                                ProcessMaterialQuantity = 3,
                                ProcessExecuteQuantity  = 2
                            }
                        }
                    },
                },
                Parts = new[] {
                    // should be deleted, since corresponding schedule is deleted
                    new MazakPartRow()
                    {
                        PartName  = "part1:1:1",
                        Comment   = MazakPart.CreateComment("uniq1", new[] { 1 }, false),
                        Processes =
                        {
                            new MazakPartProcessRow()
                            {
                                PartName      = "part1:1:1",
                                ProcessNumber = 1,
                                FixQuantity   = 5,
                                Fixture       = "fixtoremove"
                            }
                        }
                    },
                    //should be kept, since schedule is kept
                    new MazakPartRow()
                    {
                        PartName  = "part2:1:1",
                        Comment   = MazakPart.CreateComment("uniq2", new[] { 1 }, false),
                        Processes =
                        {
                            new MazakPartProcessRow()
                            {
                                PartName      = "part2:1:1",
                                ProcessNumber = 1,
                                FixQuantity   = 2,
                                Fixture       = "fixtokeep"
                            }
                        }
                    },
                },
                Fixtures = new[] {
                    new MazakFixtureRow()
                    {
                        FixtureName = "fixtoremove", Comment = "Insight"
                    },
                    new MazakFixtureRow()
                    {
                        FixtureName = "fixtokeep", Comment = "Insight"
                    }
                },
                Pallets = new[] {
                    new MazakPalletRow()
                    {
                        PalletNumber = 5, Fixture = "fixtoremove"
                    },
                    new MazakPalletRow()
                    {
                        PalletNumber = 6, Fixture = "fixtokeep"
                    }
                },
                PalletSubStatuses = Enumerable.Empty <MazakPalletSubStatusRow>(),
                PalletPositions   = Enumerable.Empty <MazakPalletPositionRow>(),
                LoadActions       = Enumerable.Empty <LoadAction>(),
                MainPrograms      =
                    Enumerable.Concat(
                        (new[] { "1001", "1002", "1003", "1004", "1005" }).Select(p => new MazakProgramRow()
                {
                    MainProgram = p, Comment = ""
                }),
                        new[] {
                    new MazakProgramRow()
                    {
                        MainProgram = System.IO.Path.Combine("theprogdir", "prog-bbb-1_rev2.EIA"),
                        Comment     = "Insight:2:prog-bbb-1"
                    },
                    new MazakProgramRow()
                    {
                        MainProgram = System.IO.Path.Combine("theprogdir", "prog-bbb-1_rev3.EIA"),
                        Comment     = "Insight:3:prog-bbb-1"
                    }
                }
                        )
            });
            _readMock.LoadSchedulesPartsPallets().Returns(x => new MazakSchedulesPartsPallets()
            {
                Schedules         = Enumerable.Empty <MazakScheduleRow>(),
                Parts             = _writeMock.AddParts.Parts,
                Pallets           = _writeMock.AddParts.Pallets,
                PalletSubStatuses = Enumerable.Empty <MazakPalletSubStatusRow>(),
                PalletPositions   = Enumerable.Empty <MazakPalletPositionRow>(),
                LoadActions       = Enumerable.Empty <LoadAction>(),
                MainPrograms      = (new[] {
                    "1001", "1002", "1003", "1004", "1005"
                }).Select(p => new MazakProgramRow()
                {
                    MainProgram = p, Comment = ""
                }),
            });

            _settings = new FMSSettings();
            _settings.Queues["castings"] = new QueueSize();
            _settings.Queues["queueAAA"] = new QueueSize();
            _settings.Queues["queueBBB"] = new QueueSize();
            _settings.Queues["queueCCC"] = new QueueSize();


            _writeJobs = new WriteJobs(
                _writeMock,
                _readMock,
                Substitute.For <IHoldManagement>(),
                _jobDB,
                _logDB,
                _settings,
                check: false,
                useStarting: true,
                progDir: "theprogdir");

            jsonSettings = new JsonSerializerSettings();
            jsonSettings.Converters.Add(new BlackMaple.MachineFramework.TimespanConverter());
            jsonSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
            jsonSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
            jsonSettings.Formatting           = Formatting.Indented;
        }