Exemplo n.º 1
0
        public CurrentStatus GetCurrentStatus()
        {
            MazakAllData mazakData;

            if (!OpenDatabaseKitDB.MazakTransactionLock.WaitOne(TimeSpan.FromMinutes(2), true))
            {
                throw new Exception("Unable to obtain mazak database lock");
            }
            try
            {
                mazakData = readDatabase.LoadAllData();
            }
            finally
            {
                OpenDatabaseKitDB.MazakTransactionLock.ReleaseMutex();
            }

            return(BuildCurrentStatus.Build(jobDB, log, fmsSettings, _machineGroupName, queueFault, readDatabase.MazakType, mazakData, DateTime.UtcNow));
        }
Exemplo 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;
        }
Exemplo n.º 3
0
        private void AddFixturesPalletsParts(NewJobs newJ)
        {
            var mazakData = readDatabase.LoadAllData();

            //first allocate a UID to use for this download
            int UID = 0;

            while (UID < int.MaxValue)
            {
                //check schedule rows for UID
                foreach (var schRow in mazakData.Schedules)
                {
                    if (MazakPart.ParseUID(schRow.PartName) == UID)
                    {
                        goto found;
                    }
                }

                //check fixture rows for UID
                foreach (var fixRow in mazakData.Fixtures)
                {
                    if (MazakPart.ParseUID(fixRow.FixtureName) == UID)
                    {
                        goto found;
                    }
                }

                break;
found:
                UID += 1;
            }
            if (UID == int.MaxValue)
            {
                throw new Exception("Unable to find unused UID");
            }
            Log.Debug("Creating new schedule with UID {uid}", UID);

            var(transSet, savedParts) = BuildMazakSchedules.RemoveCompletedAndDecrementSchedules(
                mazakData, UseStartingOffsetForDueDate
                );
            if (transSet.Schedules.Any())
            {
                writeDb.Save(transSet, "Update schedules");
            }

            Log.Debug("Saved Parts: {parts}", savedParts);

            var jobErrs   = new List <string>();
            var mazakJobs = ConvertJobsToMazakParts.JobsToMazak(
                newJ.Jobs,
                UID,
                mazakData,
                savedParts,
                writeDb.MazakType,
                CheckPalletsUsedOnce,
                fmsSettings,
                LookupProgram,
                jobErrs);

            if (jobErrs.Any())
            {
                throw new BlackMaple.MachineFramework.BadRequestException(
                          string.Join(Environment.NewLine, jobErrs)
                          );
            }

            //delete everything
            transSet = mazakJobs.DeleteOldPartPalletRows();
            if (transSet.Parts.Any() || transSet.Pallets.Any())
            {
                try
                {
                    writeDb.Save(transSet, "Delete Parts Pallets");
                }
                catch (ErrorModifyingParts e)
                {
                    foreach (var partName in e.PartNames)
                    {
                        if (readDatabase.CheckPartExists(partName))
                        {
                            throw new Exception("Mazak returned an error when attempting to delete part " + partName);
                        }
                    }
                }
            }

            //have to delete fixtures after schedule, parts, and pallets are already deleted
            //also, add new fixtures
            transSet = mazakJobs.CreateDeleteFixtureAndProgramDatabaseRows(jobDB.LoadProgramContent, ProgramDirectory);
            writeDb.Save(transSet, "Fixtures");

            //now save the pallets and parts
            transSet = mazakJobs.CreatePartPalletDatabaseRows();
            writeDb.Save(transSet, "Add Parts");
        }