private bool ValidateLolaXml(ParametersMachineModelXml machineModelXml, out List <string> errors)
        {
            errors = new List <string>();

            if (!(machineModelXml.ModelCodeV997 > 0))
            {
                errors.Add($"ModelCodeV997: {machineModelXml.ModelCodeV997} inesistente");
            }
            else if (!_xmlDataService.CheckMachineModelCode(machineModelXml.ModelCodeV997))
            {
                errors.Add($"ModelCodeV997: {machineModelXml.ModelCodeV997} inesistente");
            }

            if (errors.Count() == 0)
            {
                var wrongVarNumber = machineModelXml.Parameters.Parameter.Where(n => string.IsNullOrWhiteSpace(n.VAR_NUMBER) ||
                                                                                !_xmlDataService.CheckVarNumber(machineModelXml.ModelCodeV997, n.VAR_NUMBER)).ToList();
                if (wrongVarNumber.Count() > 0)
                {
                    foreach (var row in wrongVarNumber)
                    {
                        errors.Add($"VarNumber inesistente: {row.VAR_NUMBER} (keyword: {row.KEYWORD})");
                    }
                }
            }


            var wrongIdPanel = machineModelXml.Parameters.Parameter.Where(n => !_xmlDataService.CheckPanelId(n.PANEL_ID)).ToList();

            if (wrongIdPanel.Count() > 0)
            {
                foreach (var row in wrongIdPanel)
                {
                    errors.Add($"PANEL_ID inesistente: {row.PANEL_ID} (keyword: {row.KEYWORD})");
                }
            }

            var wrongMachineGroup = machineModelXml.Parameters.Parameter.Where(n => string.IsNullOrWhiteSpace(n.MACHINE_GROUP) ||
                                                                               !_xmlDataService.CheckMachineGroup(n.MACHINE_GROUP)).ToList();

            if (wrongMachineGroup.Count() > 0)
            {
                foreach (var row in wrongMachineGroup)
                {
                    errors.Add($"MACHINE_GROUP inesistente: {row.MACHINE_GROUP} (keyword: {row.KEYWORD})");
                }
            }

            if (errors.Count() > 0)
            {
                return(false);
            }
            return(true);
        }
Example #2
0
        public async Task AddOrUpdateMachineParameterAsync(ParametersMachineModelXml m)
        {
            var machineModel = _context.Set <MachineModel>().FirstOrDefault(mac => mac.ModelCodev997 == m.ModelCodeV997);

            if (machineModel != null)
            {
                var list = m.Parameters.Parameter.BuildAdapter().AddParameters("idMachineModel", machineModel.Id).AddParameters("modelCode", m.ModelCodeV997).AdaptToType <List <ParameterMachine> >();

                foreach (var i in list)
                {
                    var old = _context.Set <ParameterMachine>().FirstOrDefault(pm => pm.ModelCode == i.ModelCode && pm.VarNumber == i.VarNumber);
                    i.Id             = old?.Id ?? 0;
                    i.MachineModelId = machineModel.Id;
                    _context.Set <ParameterMachine>().AddOrUpdate(i);
                }

                //elimino i record che non esistono piĆ¹
                var curparams = _context.Set <ParameterMachine>().Where(p => p.ModelCode == m.ModelCodeV997.ToString()).ToList();
                var toDelete  = curparams.Where(c => !list.Any(a => a.VarNumber == c.VarNumber.ToString())).ToList();
                if (toDelete.Count > 0)
                {
                    var ids    = toDelete.Select(a => a.Id).ToList();
                    var values = _context.Set <ParameterMachineValue>().Where(v => ids.Contains(v.ParameterMachineId)).ToList();
                    if (values.Count > 0)
                    {
                        _context.Set <ParameterMachineValue>().RemoveRange(values);
                    }
                    var resets = _context.Set <ParameterResetValue>().Where(v => ids.Contains(v.ParameterMachineId)).ToList();
                    if (resets.Count > 0)
                    {
                        _context.Set <ParameterResetValue>().RemoveRange(resets);
                    }
                    var thresholds = _context.Set <ParameterMachineThreshold>().Where(v => ids.Contains(v.ParameterMachineId)).ToList();
                    if (thresholds.Count > 0)
                    {
                        _context.Set <ParameterMachineThreshold>().RemoveRange(thresholds);
                    }

                    _context.Set <ParameterMachine>().RemoveRange(toDelete);
                }
            }

            await _context.SaveChangesAsync();
        }
        public async Task <IHttpActionResult> Load(ParametersMachineModelXml pmm)
        {
            await _xmlDataService.AddOrUpdateMachineParameterAsync(pmm);

            return(Ok());
        }