//ejecuta el search para cada fila recuperada de la base de datos, antes de esto, debemos encontrar el search correspondiente para el command que toca, para eso usamos reflexion
        public int RunDetector()
        {
            try
            {
                Type searcherT = Type.GetType("PlataformaPDCOnline.Editable.Searchers.Search" + this.CommandName);                                              //buscamos el tipo                                                                                         //Type commandT = Type.GetType("PlataformaPDCOnline.Editable.pdcOnline.Commands." + this.CommandName);

                if (searcherT.GetInterfaces().Contains(typeof(ISearcher)))                                                                                      //si la instancia implementa ISearcher y SearcherChangesController
                {
                    object search = searcherT == null ? throw new NullReferenceException("No se ha encontrado el typo.") : Activator.CreateInstance(searcherT); //creamos una instancia de esta clase

                    List <Dictionary <string, object> > table = ConsultasPreparadas.Singelton().GetRowData(this.SqlCommand);

                    MethodInfo method = search.GetType().GetMethod("RunSearcher");

                    foreach (Dictionary <string, object> row in table)
                    {
                        Command commandSend = (Command)method.Invoke(search, new object[] { row, this });  //invocamos el methodo con la instancia searcher y le pasamos los parametros

                        /*if (Sender.Singelton().SendCommand(commandSend)) CommandsSended++;
                         * else throw new NoCompletCommandSend("No se a podido enviar el command.");*/
                    }
                }
                else
                {
                    throw new MyNoImplementedException("Se ha encontrado la clase " + searcherT.Name + ", pero no implementa ISearcher.");  //ok
                }
            }
            catch (NullReferenceException ne)
            {
                throw new Exception(ne.ToString());
            }
            return(CommandsSended);
        }
Beispiel #2
0
 public static ConsultasPreparadas Singelton()
 {
     if (Consultas == null)
     {
         Consultas = new ConsultasPreparadas();
     }
     return(Consultas);
 }