Exemplo n.º 1
0
        internal static PrensaDato ConvertToBL(DAL.DTO.PrensaDato item)
        {
            PrensaDato dato = null;

            if (item != null)
            {
                dato = new PrensaDato
                {
                    Fecha          = item.Fecha,
                    PrensaId       = item.PrensaId,
                    TagActivaValue = item.TagActivaValue,
                    TagCVValue     = item.TagCVValue,
                    TagCicloValue  = item.TagCicloValue,
                    TagProdValue   = item.TagProdValue,
                    TagTempValue   = item.TagTempValue,
                    Cavidad        = item.Cavidad
                };
            }
            return(dato);
        }
Exemplo n.º 2
0
        private void CompruebaRegistro(PrensaDato registro)
        {
            try
            {
                if (registro == null || registro.PrensaId <= 0)
                {
                    return;
                }

                if (_valoresMemoria == null)
                {
                    _valoresMemoria = new MemoryValues();
                }

                var valoresDB = Converter.ConvertToTagValueDictionary(registro);

                if (valoresDB != null && valoresDB.Count > 0)
                {
                    foreach (TagValue valorDB in valoresDB.Values)
                    {
                        if (!_valoresMemoria.ContainsKey(valorDB.ToKey()))
                        {
                            log.Debug("Nuevo tag añadido al diccionario de valores. Prensa: [{0}]. Tipo: [{1}]. Valor: [{2}]. Fecha: [{3}]",
                                      valorDB.Id_Prensa,
                                      valorDB.Type.ToString(),
                                      !string.IsNullOrEmpty(valorDB.Value) ? valorDB.Value : "null",
                                      valorDB.Date.ToString("dd/MM/yyyy HH:mm:ss"));

                            _valoresMemoria.AddValue(valorDB.Id_Prensa, valorDB.Type, valorDB.Value, valorDB.Date);

                            //TODO: Nuevo tag añadido al diccionario de valores, ¿lanzar evento de cambio de valor?
                        }
                        else
                        {
                            var tagValue = _valoresMemoria.GetTagValue(valorDB.Id_Prensa, valorDB.Type);

                            if (tagValue == null)
                            {
                                log.Debug("Nuevo tag añadido al diccionario de valores. Prensa: [{0}]. Tipo: [{1}]. Valor: [{2}]. Fecha: [{3}]",
                                          valorDB.Id_Prensa,
                                          valorDB.Type.ToString(),
                                          !string.IsNullOrEmpty(valorDB.Value) ? valorDB.Value : "null",
                                          valorDB.Date.ToString("dd/MM/yyyy HH:mm:ss"));

                                _valoresMemoria.AddValue(valorDB.Id_Prensa, valorDB.Type, valorDB.Value, valorDB.Date);

                                //TODO: Nuevo tag añadido al diccionario de valores, ¿lanzar evento de cambio de valor?
                            }
                            else if (tagValue.Value.Equals(valorDB.Value))
                            {
                                //El valor sigue siendo el mismo, actualizo la fecha

                                tagValue.Date = valorDB.Date;
                            }
                            else
                            {
                                log.Debug("Nuevo valor para el tag [{1}] de la Prensa: [{0}]. Valor: [{2}]. Fecha: [{3}]",
                                          valorDB.Id_Prensa,
                                          valorDB.Type.ToString(),
                                          !string.IsNullOrEmpty(valorDB.Value) ? valorDB.Value : "null",
                                          valorDB.Date.ToString("dd/MM/yyyy HH:mm:ss"));

                                //Nuevo valor
                                tagValue.Date  = valorDB.Date;
                                tagValue.Value = valorDB.Value;

                                OnDataReceived(new DataReceivedEventArgs
                                {
                                    Value = tagValue
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("CompruebaRegistro()", ex);
            }
        }