Пример #1
0
        private void LoadEvents(string sampleDataPath, TimeSpan offset)
        {
            var files = System.IO.Directory.GetFiles(sampleDataPath, "events-*.json");
            var evts  = new List <BlackMaple.MachineWatchInterface.LogEntry>();

            foreach (var f in files)
            {
                using (var file = System.IO.File.OpenRead(f))
                {
                    var reader = new System.IO.StreamReader(file);
                    while (reader.Peek() >= 0)
                    {
                        var evtJson = reader.ReadLine();
                        var e       = (BlackMaple.MachineWatchInterface.LogEntry)JsonConvert.DeserializeObject(
                            evtJson,
                            typeof(BlackMaple.MachineWatchInterface.LogEntry),
                            _jsonSettings
                            );
                        evts.Add(e);
                    }
                }
            }

            foreach (var e in evts.OrderBy(e => e.EndTimeUTC))
            {
                foreach (var m in e.Material)
                {
                    var matDetails = LogDB.GetMaterialDetails(m.MaterialID);
                    if (matDetails == null && !string.IsNullOrEmpty(m.JobUniqueStr))
                    {
                        LogDB.CreateMaterialID(m.MaterialID, m.JobUniqueStr, m.PartName, m.NumProcesses);
                    }
                }
                if (e.LogType == LogType.PartMark)
                {
                    foreach (var m in e.Material)
                    {
                        LogDB.RecordSerialForMaterialID(JobLogDB.EventLogMaterial.FromLogMat(m), e.Result, e.EndTimeUTC.Add(offset));
                    }
                }
                else if (e.LogType == LogType.OrderAssignment)
                {
                    foreach (var m in e.Material)
                    {
                        LogDB.RecordWorkorderForMaterialID(JobLogDB.EventLogMaterial.FromLogMat(m), e.Result, e.EndTimeUTC.Add(offset));
                    }
                }
                else if (e.LogType == LogType.FinalizeWorkorder)
                {
                    LogDB.RecordFinalizedWorkorder(e.Result, e.EndTimeUTC.Add(offset));
                }
                else
                {
                    if (e.LogType == LogType.InspectionResult && e.Material.Any(m => m.MaterialID == 2965))
                    {
                        // ignore inspection complete
                        continue;
                    }
                    var e2 = new BlackMaple.MachineWatchInterface.LogEntry(
                        cntr: e.Counter,
                        mat: e.Material,
                        pal: e.Pallet,
                        ty: e.LogType,
                        locName: e.LocationName,
                        locNum: e.LocationNum,
                        prog: e.Program,
                        start: e.StartOfCycle,
                        endTime: e.EndTimeUTC.Add(offset),
                        result: e.Result,
                        endOfRoute: e.EndOfRoute,
                        elapsed: e.ElapsedTime,
                        active: e.ActiveOperationTime
                        );
                    if (e.ProgramDetails != null)
                    {
                        foreach (var x in e.ProgramDetails)
                        {
                            e2.ProgramDetails.Add(x.Key, x.Value);
                        }
                    }
                    if (e.Tools != null)
                    {
                        foreach (var x in e.Tools)
                        {
                            e2.Tools[x.Key] = x.Value;
                        }
                    }
                    LogDB.AddLogEntryFromUnitTest(e2);
                }
            }
        }