Beispiel #1
0
        private static void TestRetrieveUsuariosMasActivos(IApplicationContext ctx)
        {
            IEscuchaService escuchaService = (IEscuchaService)ctx.GetObject("escuchaService");
            Artista         a = new Artista();

            a.Id = 4;
            IList list = escuchaService.RetrieveUsuariosMasActivos(a);

            foreach (ItemRanking item in list)
            {
                Console.WriteLine("{0} - {1}", item.Id, item.Nombre);
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!this.IsPostBack)
            {
                if (this.Request.QueryString["id"] == null)
                {
                    this.MostrarNoEncontrado();
                    return;
                }
                int id = 0;
                try
                {
                    id = int.Parse(this.Request.QueryString["id"]);
                }
                catch (Exception)
                {
                    this.MostrarNoEncontrado();
                }
                ModelArtista artista = this.GetMusicaService().RetrieveArtista(id);
                if (artista == null)
                {
                    this.MostrarNoEncontrado();
                    return;
                }

                this.lblNombre.Text = artista.Nombre;

                IEscuchaService escuchaService = this.GetEscuchaService();
                this.RatingTemasMusicales.DataSource = escuchaService.RetrieveTemasMusicalesMasEscuchados(artista);
                this.RatingTemasMusicales.DataBind();

                this.RatingUsuarios.DataSource = escuchaService.RetrieveUsuariosMasActivos(artista);
                this.RatingUsuarios.DataBind();

                this.RatingAlbumes.DataSource = escuchaService.RetrieveAlbumesMasEscuchados(artista);
                this.RatingAlbumes.DataBind();

                this.rtgArtistasSimilares.DataSource = this.GetMusicaService().GetArtistasSimilaresA(artista);
                this.rtgArtistasSimilares.DataBind();
            }
        }
        private static void Main(string[] args)
        {
            log.Info("Comenzando la ejeución...");
            IDictionary parameters = GetParameters(args);

            if (parameters == null)
            {
                // No se enviaron los parámetros mínimos indispensables
                // No se debe seguir con la ejecución
                return;
            }

            log.InfoFormat("Configurado con parámetros: {0}", parameters);

            try {
                using (IApplicationContext ctx = ContextRegistry.GetContext()) {
                    IEscuchaService escuchaService = (IEscuchaService)ctx.GetObject("escuchaService");

                    DirectoryInfo fd        = new DirectoryInfo((string)parameters[PATH_KEY]);
                    FileInfo[]    fileInfos = fd.GetFiles((string)parameters[FILE_PATTERN_KEY]);
                    log.InfoFormat("Importando {0} archivos de {1}.", fileInfos.Length, fd.Name);
                    foreach (FileInfo fileInfo in fileInfos)
                    {
                        log.InfoFormat("Leyendo archivo {0}.", fileInfo.Name);
                        FileStream   fs             = fileInfo.OpenRead();
                        StreamReader sr             = new StreamReader(fs);
                        string[]     datosDeEscucha = sr.ReadLine().Split((char)parameters[SEPARATOR_CHAR_KEY]);
                        // HACK Si tiene mas de 7 comas (8 partes el split) es que los datos no son válidos
                        // porque hay un título, nombre de album o artista que tiene comas !!!
                        if (datosDeEscucha.Length != 8)
                        {
                            sr.Close();
                            fileInfo.Delete();
                            continue;
                        }

                        string   inicio        = datosDeEscucha[0] + " " + datosDeEscucha[1];
                        DateTime momentoInicio = DateTime.ParseExact(inicio, (string)parameters[DATE_PARSING_MASK_KEY], CultureInfo.CurrentCulture);

                        log.InfoFormat("Registrando escucha: {0}.", datosDeEscucha);
                        try {
                            escuchaService.RegistrarEscucha(datosDeEscucha[2], datosDeEscucha[3], datosDeEscucha[4], datosDeEscucha[6], datosDeEscucha[5], momentoInicio, 1);
                        } catch (ZonicaBaseException e) {
                            log.WarnFormat("Error de procesamiento de escucha {0}: {1}", datosDeEscucha, e.Message);
                        }

                        log.InfoFormat("Eliminando archivo {0}.", fileInfo.Name);
                        sr.Close();
                        fileInfo.Delete();
                    }
                }
            } catch (Exception e) {
                log.ErrorFormat("ERROR FATAL: {0}", e);
            }

            // Verifica si debe reejecutarse
            if ((bool)parameters[IS_RERUN_KEY])
            {
                int sleepTime = (int)parameters[SLEEP_TIME_KEY];
                log.InfoFormat("Sleeping importador por {0} millis.", sleepTime);
                Thread.Sleep(sleepTime);
                Main(args);
            }
        }