コード例 #1
0
 public TimedService(IServiceProvider services, ILogger <TimedService> logger)
 {
     _logger     = logger;
     Services    = services;                                                        // Get Service Provider
     Scope       = Services.CreateScope();                                          // Create Scope
     _context    = Scope.ServiceProvider.GetRequiredService <RaportareDbContext>(); // Get DbContext
     _plcService = Scope.ServiceProvider.GetRequiredService <PlcService>();         // Get PlcService
     // log
     _logger.LogInformation("{data}<=>{Messege}", DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss"), "A pornit TimedkService din TimedService Constructor");
 }
コード例 #2
0
        // Function make report and send mail if it is time
        public bool MakeReport(RaportareDbContext context, PlcService plcService)
        {
            int nrOfAvailablePlc = plcService.ListPlcs.Where(p => p.IsEnable).Count();

            SetVarIsReportTime(nrOfAvailablePlc); // Set Variable for report tile
            SetNumberOfCheckedPlc();

            if (NumberOfCheckedPlc == nrOfAvailablePlc)
            {
                SendReportOnMail(context); // Send Mail with report
            }
            return(VarIsReportTime);
        }
コード例 #3
0
        // Get MotivStationare from Plc Tag
        public string GetMotivStationare(PlcService plcService, PlcModel plc)
        {
            // Check if plc is not connected and return messege Plc DEconectat
            try
            {
                if (!plcService.IsAvailableIpAdress(plc))
                {
                    return("Plc Deconectat");
                }
                // AddedException for GaddaF2, GaddaF4 and DunkePRess: not Get Motiv Stationare
                if (plc.Name == "GaddaF2" || plc.Name == "GaddaF4" || plc.Name == "PresaDunke")
                {
                    return("Stationeaza");
                }

                // If Plc Connected return a type of breakdown messege
                if (Convert.ToBoolean(plc.TagsList.Where(tag => tag.Name == "MechanicalBreakDown").ToList().FirstOrDefault().Value))
                {
                    return("Defect mecanic");
                }
                else if (Convert.ToBoolean(plc.TagsList.Where(tag => tag.Name == "ElectricalBreakDown").ToList().FirstOrDefault().Value))
                {
                    return("Defect electric");
                }
                else if (Convert.ToBoolean(plc.TagsList.Where(tag => tag.Name == "ProgrammedBreakDown").ToList().FirstOrDefault().Value))
                {
                    return("Oprire programata");
                }
                else if (Convert.ToBoolean(plc.TagsList.Where(tag => tag.Name == "TechnologicalBreakDown").ToList().FirstOrDefault().Value))
                {
                    return("Oprire tehnologica");
                }
                else if (Convert.ToBoolean(plc.TagsList.Where(tag => tag.Name == "NoCraneReadyBreakDown").ToList().FirstOrDefault().Value))
                {
                    return("Lipsa pod rulant / Lipsa material");
                }
            }
            catch (PlcException exPlc)
            {
                Console.WriteLine(String.Format("{0} <=> {1} <=> PlcaName: {2}", DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss"), exPlc.Message, plc.Name));
                return("Plc Deconectat");
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine(String.Format("{0} <=> {1} <=> PlcaName: {2}. Din GetMotivStationare", DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss"), ex.Message, plc.Name));
                return("Nu s-a apasat cauza");
            }

            // If none of the predefined causes are not set return none was pressed
            return("Nu s-a apasat cauza");
        }
コード例 #4
0
        // Logic IfBrackDownInProgrss Add Defect, Update It, Add Second Defect
        public void LogicBrackDowns(RaportareDbContext context, PlcModel plc, PlcService plcService, ReportService reportService)
        {
            Defect lastDefect = GetLastElementByPlc(context, plc); // Get Last defect from Plc

            // If is time of report finalise last defect and send mail (added for report excel file)
            if (lastDefect != null && lastDefect.DefectFinalizat == false)
            {                                                         //if list is not empty and last defect is not finalised
                // make report if it is time TODO
                if (reportService.MakeReport(context, plcService))    // make report to excel
                {
                    UpdateLastNotFinishedDefect(context, lastDefect); // finished not finalised defect
                }
            }
            // Add PlcViewModel
            foreach (var plcViewModel in plcService.ListPlcViewModels)
            {
                if (lastDefect != null)
                {
                    if (plcViewModel.PlcModel.Name == plc.Name)
                    {
                        plcViewModel.MapDefect(plcService, lastDefect, plc, context.Defects.Where(def => def.PlcModelID == plc.PlcModelID).ToList());
                        break;
                    }
                }
            }

            // If is Breakdown in progress and list of defects is empty or last defect is finished Add Defect to list
            if (IsBreakDownInProgress(plc))
            {                                                                         // if is brackdown
                if (lastDefect == null)                                               // if list is empty
                {
                    AddNewDefectForPlc(context, plc);                                 // Add Defect
                }
                else if (lastDefect.DefectFinalizat == true)                          // if list is not empty and last defect is finalised
                {
                    AddNewDefectForPlc(context, plc);                                 // Add defect
                }
                else if (lastDefect.DefectFinalizat == false)                         // if last defect is not finalised add Motiv Stationare
                {
                    lastDefect.MotivStationare = GetMotivStationare(plcService, plc); // Add Motiv Stationare to lastDefect when it is pressed the button
                    lastDefect.TimpStopDefect  = DateTime.Now;                        // Add Stop time defect dynamic
                    // Catch overflow error to IntervalStationare
                    try
                    {
                        lastDefect.IntervalStationare = LimitMaxTimeSpan(lastDefect.TimpStartDefect, lastDefect.TimpStopDefect);// Add dynamic interval stationare
                        // Limit the Interval Stationare Max Value
                    }
                    catch (OverflowException ex)
                    {
                        Console.WriteLine(String.Format("{0} <=> {1} <=> PlcaName: {2}", DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss"), ex.Message, lastDefect.PlcModel.Name));
                        lastDefect.IntervalStationare = new TimeSpan(23, 59, 00);
                    }

                    context.Update(lastDefect); // Update DbContext with motiv stationare
                }
            }
            else // when machine start work again finished defect
            {
                if (lastDefect != null && lastDefect.DefectFinalizat == false) //if list is not empty and last defect is not finalised
                {
                    UpdateLastNotFinishedDefect(context, lastDefect); // finished not finalised defect
                }
            }
        }