Пример #1
0
 public LogDataWeb(string path,
                   BlackMaple.MachineFramework.JobLogDB log,
                   BlackMaple.MachineFramework.JobDB jobDB,
                   BlackMaple.MachineFramework.ISendMaterialToExternalQueue sendToExternal,
                   IReadDataAccess readDB,
                   MazakQueues queues,
                   BlackMaple.MachineFramework.FMSSettings settings)
 {
     _path           = path;
     _log            = log;
     _jobDB          = jobDB;
     _readDB         = readDB;
     _queues         = queues;
     _settings       = settings;
     _sendToExternal = sendToExternal;
     _shutdown       = new AutoResetEvent(false);
     _newLogFile     = new AutoResetEvent(false);
     _recheckQueues  = new AutoResetEvent(false);
     if (System.IO.Directory.Exists(path))
     {
         _thread = new Thread(new ThreadStart(ThreadFunc));
         _thread.Start();
         _watcher          = new FileSystemWatcher(_path);
         _watcher.Filter   = "*.csv";
         _watcher.Created += (sender, evt) =>
                             _newLogFile.Set();
         //_watcher.Changed += (sender, evt) => _newLogFile.Set();
         _watcher.EnableRaisingEvents = true;
         Log.Debug("Watching {path} for new CSV files", _path);
     }
 }
Пример #2
0
        public RoutingInfo(
            IWriteData d,
            IMachineGroupName machineGroupName,
            IReadDataAccess readDb,
            IMazakLogReader logR,
            BlackMaple.MachineFramework.JobDB jDB,
            BlackMaple.MachineFramework.JobLogDB jLog,
            IWriteJobs wJobs,
            IQueueSyncFault queueSyncFault,
            IDecrementPlanQty decrement,
            bool check,
            BlackMaple.MachineFramework.FMSSettings settings)
        {
            writeDb              = d;
            readDatabase         = readDb;
            fmsSettings          = settings;
            jobDB                = jDB;
            logReader            = logR;
            log                  = jLog;
            _writeJobs           = wJobs;
            _decr                = decrement;
            _machineGroupName    = machineGroupName;
            queueFault           = queueSyncFault;
            CheckPalletsUsedOnce = check;

            _copySchedulesTimer          = new System.Timers.Timer(TimeSpan.FromMinutes(4.5).TotalMilliseconds);
            _copySchedulesTimer.Elapsed += (sender, args) => RecopyJobsToSystem();
            _copySchedulesTimer.Start();
        }
Пример #3
0
        public HoldPattern(IWriteData d, IReadDataAccess readDb, BlackMaple.MachineFramework.JobDB jdb, bool createThread)
        {
            database     = d;
            readDatabase = readDb;
            jobDB        = jdb;

            if (createThread)
            {
                _thread = new TransitionThread(this);
            }
        }
Пример #4
0
        public DecrementSpec()
        {
            var jobConn = new Microsoft.Data.Sqlite.SqliteConnection("Data Source=:memory:");

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

            _write = new WriteMock();

            _read = Substitute.For <IReadDataAccess>();
            _read.MazakType.Returns(MazakDbType.MazakSmooth);

            _decr = new DecrementPlanQty(_jobDB, _write, _read);
        }
Пример #5
0
        public WriteJobs(
            IWriteData d,
            IReadDataAccess readDb,
            IHoldManagement h,
            BlackMaple.MachineFramework.JobDB jDB,
            BlackMaple.MachineFramework.JobLogDB jLog,
            FMSSettings settings,
            bool check,
            bool useStarting,
            string progDir
            )
        {
            writeDb                     = d;
            readDatabase                = readDb;
            hold                        = h;
            jobDB                       = jDB;
            log                         = jLog;
            CheckPalletsUsedOnce        = check;
            UseStartingOffsetForDueDate = useStarting;
            fmsSettings                 = settings;
            ProgramDirectory            = progDir;

            var sch = jobDB.LoadMostRecentSchedule();

            if (sch.Jobs != null)
            {
                foreach (var j in sch.Jobs)
                {
                    for (int proc = 1; proc <= j.NumProcesses; proc++)
                    {
                        for (int path = 1; path <= j.GetNumPaths(proc); path++)
                        {
                            foreach (var stop in j.GetMachiningStop(proc, path))
                            {
                                if (!string.IsNullOrEmpty(stop.StationGroup))
                                {
                                    _machineGroupName = stop.StationGroup;
                                    goto foundGroup;
                                }
                            }
                        }
                    }
                }
                foundGroup :;
            }
        }
Пример #6
0
 public LogDataVerE(BlackMaple.MachineFramework.JobLogDB log,
                    BlackMaple.MachineFramework.JobDB jobDB,
                    BlackMaple.MachineFramework.ISendMaterialToExternalQueue send,
                    IReadDataAccess readDB,
                    MazakQueues queues,
                    BlackMaple.MachineFramework.FMSSettings settings)
 {
     _log            = log;
     _jobDB          = jobDB;
     _readDB         = readDB;
     _queues         = queues;
     _sendToExternal = send;
     FMSSettings     = settings;
     _lock           = new object();
     _timer          = new System.Timers.Timer(TimeSpan.FromMinutes(1).TotalMilliseconds);
     _timer.Elapsed += HandleElapsed;
     _timer.Start();
 }
Пример #7
0
 public WriteJobs(
     IWriteData d,
     IReadDataAccess readDb,
     IHoldManagement h,
     BlackMaple.MachineFramework.JobDB jDB,
     BlackMaple.MachineFramework.JobLogDB jLog,
     FMSSettings settings,
     bool check,
     bool useStarting
     )
 {
     writeDb                     = d;
     readDatabase                = readDb;
     hold                        = h;
     jobDB                       = jDB;
     log                         = jLog;
     CheckPalletsUsedOnce        = check;
     UseStartingOffsetForDueDate = useStarting;
     fmsSettings                 = settings;
 }
Пример #8
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;
        }
Пример #9
0
 public DecrementPlanQty(JobDB jdb, IWriteData w, IReadDataAccess r)
 {
     _jobDB = jdb;
     _write = w;
     _read  = r;
 }
Пример #10
0
        public MazakBackend(IConfiguration configuration, FMSSettings st)
        {
            var    cfg         = configuration.GetSection("Mazak");
            string localDbPath = cfg.GetValue <string>("Database Path");

            MazakType = DetectMazakType(cfg, localDbPath);

            // database settings
            string sqlConnectString = cfg.GetValue <string>("SQL ConnectionString");
            string dbConnStr;

            if (MazakType == MazakDbType.MazakSmooth)
            {
                if (!string.IsNullOrEmpty(sqlConnectString))
                {
                    dbConnStr = sqlConnectString;
                }
                else if (!string.IsNullOrEmpty(localDbPath))
                {
                    // old installers put sql server computer name in localDbPath
                    dbConnStr = "Server=" + localDbPath + "\\pmcsqlserver;" +
                                "User ID=mazakpmc;Password=Fms-978";
                }
                else
                {
                    var b = new System.Data.SqlClient.SqlConnectionStringBuilder();
                    b.UserID     = "mazakpmc";
                    b.Password   = "******";
                    b.DataSource = "(local)";
                    dbConnStr    = b.ConnectionString;
                }
            }
            else
            {
                dbConnStr = localDbPath;
                if (string.IsNullOrEmpty(dbConnStr))
                {
                    dbConnStr = "c:\\Mazak\\NFMS\\DB";
                }
            }

            // log csv
            string logPath = cfg.GetValue <string>("Log CSV Path");

            if (logPath == null || logPath == "")
            {
                logPath = "c:\\Mazak\\FMS\\Log";
            }

            if (MazakType != MazakDbType.MazakVersionE && !System.IO.Directory.Exists(logPath))
            {
                Log.Error("Log CSV Directory {path} does not exist.  Set the directory in the config.ini file.", logPath);
            }
            else if (MazakType != MazakDbType.MazakVersionE)
            {
                Log.Information("Loading log CSV files from {logcsv}", logPath);
            }

            // general config
            string useStarting  = cfg.GetValue <string>("Use Starting Offset For Due Date");
            string useStarting2 = cfg.GetValue <string>("Use Starting Offset");

            if (string.IsNullOrEmpty(useStarting))
            {
                if (string.IsNullOrEmpty(useStarting2))
                {
                    UseStartingOffsetForDueDate = true;
                }
                else
                {
                    UseStartingOffsetForDueDate = Convert.ToBoolean(useStarting2);
                }
            }
            else
            {
                UseStartingOffsetForDueDate = Convert.ToBoolean(useStarting);
            }
            //Perhaps this should be a new setting, but if you don't check for pallets used once
            //then you don't care if all faces on a pallet are full so might as well use priority
            //which causes pallet positions to go empty.
            CheckPalletsUsedOnce = !UseStartingOffsetForDueDate;

            ProgramDirectory = cfg.GetValue <string>("Program Directory");
            if (string.IsNullOrEmpty(ProgramDirectory))
            {
                ProgramDirectory = "C:\\NCProgs";
            }

            // serial settings
            string serialPerMaterial = cfg.GetValue <string>("Assign Serial Per Material");

            if (!string.IsNullOrEmpty(serialPerMaterial))
            {
                bool result;
                if (bool.TryParse(serialPerMaterial, out result))
                {
                    if (!result)
                    {
                        st.SerialType = SerialType.AssignOneSerialPerCycle;
                    }
                }
            }

            Log.Debug(
                "Configured UseStartingOffsetForDueDate = {useStarting}",
                UseStartingOffsetForDueDate);

            jobLog = new BlackMaple.MachineFramework.JobLogDB(st);
            jobLog.Open(
                System.IO.Path.Combine(st.DataDirectory, "log.db"),
                System.IO.Path.Combine(st.DataDirectory, "insp.db"),
                startingSerial: st.StartingSerial
                );

            jobDB = new BlackMaple.MachineFramework.JobDB();
            var jobInspName = System.IO.Path.Combine(st.DataDirectory, "jobinspection.db");

            if (System.IO.File.Exists(jobInspName))
            {
                jobDB.Open(jobInspName);
            }
            else
            {
                jobDB.Open(System.IO.Path.Combine(st.DataDirectory, "mazakjobs.db"));
            }

            _writeDB = new OpenDatabaseKitTransactionDB(dbConnStr, MazakType);

            if (MazakType == MazakDbType.MazakVersionE)
            {
                loadOper = new LoadOperationsFromFile(cfg, enableWatcher: true);
            }
            else if (MazakType == MazakDbType.MazakWeb)
            {
                loadOper = new LoadOperationsFromFile(cfg, enableWatcher: false); // web instead watches the log csv files
            }
            else
            {
                loadOper = null; // smooth db doesn't use the load operations file
            }
            var openReadDb = new OpenDatabaseKitReadDB(dbConnStr, MazakType, loadOper);

            if (MazakType == MazakDbType.MazakSmooth)
            {
                _readDB = new SmoothReadOnlyDB(dbConnStr, openReadDb);
            }
            else
            {
                _readDB = openReadDb;
            }

            queues = new MazakQueues(jobLog, jobDB, _writeDB);
            var sendToExternal = new SendMaterialToExternalQueue();

            hold = new HoldPattern(_writeDB, _readDB, jobDB, true);
            var writeJobs = new WriteJobs(_writeDB, _readDB, hold, jobDB, jobLog, st, CheckPalletsUsedOnce, UseStartingOffsetForDueDate, ProgramDirectory);
            var decr      = new DecrementPlanQty(jobDB, _writeDB, _readDB);

            if (MazakType == MazakDbType.MazakWeb || MazakType == MazakDbType.MazakSmooth)
            {
                logDataLoader = new LogDataWeb(logPath, jobLog, jobDB, writeJobs, sendToExternal, _readDB, queues, st);
            }
            else
            {
#if USE_OLEDB
                logDataLoader = new LogDataVerE(jobLog, jobDB, sendToExternal, writeJobs, _readDB, queues, st);
#else
                throw new Exception("Mazak Web and VerE are not supported on .NET core");
#endif
            }

            routing = new RoutingInfo(_writeDB, writeJobs, _readDB, logDataLoader, jobDB, jobLog, writeJobs, queues, decr,
                                      CheckPalletsUsedOnce, st);

            logDataLoader.NewEntries += OnNewLogEntries;
            if (loadOper != null)
            {
                loadOper.LoadActions += OnLoadActions;
            }
        }