示例#1
0
        /// <summary>
        ///		Ejecuta la sentencia que comprueba si existe un valor en la tabla de datos
        /// </summary>
        private void ExecuteIfExists(SentenceIfExists sentence)
        {
            using (BlockLogModel block = Manager.Logger.Default.CreateBlock(LogModel.LogType.Info, "Start if exists"))
            {
                ProviderModel provider = GetProvider(sentence.Source);

                if (provider == null)
                {
                    AddError($"Can't find provider {sentence.Source}");
                }
                else
                {
                    CommandModel command = ConvertProviderCommand(sentence.Command, out string error);

                    // Log
                    AddDebug("ExecuteIfExists", sentence.Command);
                    // Ejecuta el comando
                    if (!string.IsNullOrWhiteSpace(error))
                    {
                        AddError($"Error when convert command. {error}");
                    }
                    else
                    {
                        bool exists = ExistsData(provider, command, sentence.Command.Timeout);

                        if (!Stopped)
                        {
                            if (exists && sentence.SentencesThen.Count > 0)
                            {
                                ExecuteWithContext(sentence.SentencesThen);
                            }
                            else if (!exists && sentence.SentencesElse.Count > 0)
                            {
                                ExecuteWithContext(sentence.SentencesElse);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        ///		Carga la sentencia que comprueba si existe un valor
        /// </summary>
        private SentenceBase LoadSentenceIfExists(MLNode rootML, string pathBase)
        {
            SentenceIfExists sentence = new SentenceIfExists();

            // Carga los parámetros de la sentencia
            sentence.Source  = rootML.Attributes[TagSource].Value;
            sentence.Command = GetProviderCommand(rootML, TagProviderCommand);
            // Carga las instrucciones a ejecutar cuando existe o no existe el dato
            foreach (MLNode nodeML in rootML.Nodes)
            {
                switch (nodeML.Name)
                {
                case TagThen:
                    sentence.SentencesThen.AddRange(LoadSentences(nodeML.Nodes, pathBase));
                    break;

                case TagElse:
                    sentence.SentencesElse.AddRange(LoadSentences(nodeML.Nodes, pathBase));
                    break;
                }
            }
            // Devuelve la sentencia
            return(sentence);
        }