/// <summary>
        /// Elimina una fuente RSS
        /// </summary>
        /// <param name="pRssSourceDTO">fuente RSS que se desea eliminar</param>
        public void Remove(RSSSourceDTO pRSSSourceDTO)
        {
            try
            {
                // Verifica si existen banners que tengan asignada la fuente
                var asociatedBanners = iUnitOfWork.RSSSourceRepository.GetBannersWithSource(pRSSSourceDTO.Id);

                if (asociatedBanners.ToList().Count == 0)
                {
                    Log.Information(String.Format("Eliminando fuente RSS con Id {0}.", pRSSSourceDTO.Id));
                    RSSSource RSSSource = iUnitOfWork.RSSSourceRepository.Get(pRSSSourceDTO.Id);
                    iUnitOfWork.RSSSourceRepository.Remove(RSSSource);
                    iUnitOfWork.Complete();
                    Log.Information("Fuente RSS Eliminada con exito.");
                }
                else
                {
                    throw new Exception("No se puede eliminar la fuente RSS ya que esta siendo usada.");
                }
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Error al eliminar fuente RSS con Id {0}. " + ex.Message, pRSSSourceDTO.Id));
                throw;
            }
        }
Beispiel #2
0
        public void UpdateRSSSourceRepository()
        {
            RSSSource sourceRSS = new RSSSource()
            {
                Description = "Fuente RSS de prueba",
                Url         = "URL de prueba",
                RSSItems    = new List <RSSItem>()
                {
                    new RSSItem()
                    {
                        Url         = "Url Item 1",
                        Title       = "Item 1",
                        Description = "Item 1 RSSSource prueba",
                        Date        = DateTime.Now
                    },
                    new RSSItem()
                    {
                        Url         = "Url Item 2",
                        Title       = "Item 2",
                        Description = "Item 2 RSSSource prueba",
                        Date        = DateTime.Now
                    },
                    new RSSItem()
                    {
                        Url         = "Url Item 3",
                        Title       = "Item 3",
                        Description = "Item 3 RSSSource prueba",
                        Date        = DateTime.Now
                    }
                }
            };

            uow.RSSSourceRepository.Add(sourceRSS);

            uow.Complete();

            //Actualizando fuente
            RSSSource source2 = new RSSSource();

            source2.Id          = sourceRSS.Id;
            source2.Description = "Fuente RSS2";
            source2.Url         = "URL2";
            source2.RSSItems    = new List <RSSItem>()
            {
                new RSSItem()
                {
                    Url         = "Url1",
                    Title       = "Item1",
                    Description = "Item 1.2",
                    Date        = DateTime.Now
                },
            };

            uow.RSSSourceRepository.Update(sourceRSS);
            uow.Complete();
            var result = uow.RSSSourceRepository.Get(source2.Id);

            Assert.IsNotNull(result);
        }
Beispiel #3
0
        public void RemoveRSSSourceRepository()
        {
            RSSSource sourceRSS = new RSSSource()
            {
                Description = "Fuente RSS de prueba",
                Url         = "URL de prueba",
                RSSItems    = new List <RSSItem>()
                {
                    new RSSItem()
                    {
                        Url         = "Url Item 1",
                        Title       = "Item 1",
                        Description = "Item 1 RSSSource prueba",
                        Date        = DateTime.Now
                    },
                    new RSSItem()
                    {
                        Url         = "Url Item 2",
                        Title       = "Item 2",
                        Description = "Item 2 RSSSource prueba",
                        Date        = DateTime.Now
                    },
                    new RSSItem()
                    {
                        Url         = "Url Item 3",
                        Title       = "Item 3",
                        Description = "Item 3 RSSSource prueba",
                        Date        = DateTime.Now
                    }
                }
            };

            uow.RSSSourceRepository.Add(sourceRSS);

            uow.Complete();

            uow.RSSSourceRepository.Remove(sourceRSS);

            uow.Complete();

            Assert.IsNull(uow.RSSSourceRepository.Get(sourceRSS.Id));
        }
        /// <summary>
        /// Actualiza una fuente RSS
        /// </summary>
        /// <param name="pRssSourceDTO">fuente RSS que se desea actualizar</param>
        public void Update(RSSSourceDTO pRSSSourceDTO)
        {
            try
            {
                Log.Information(String.Format("Actualizando fuente RSS con Id {0}.", pRSSSourceDTO.Id));
                // Fuente RSS actualizada
                var source = new RSSSource();
                AutoMapper.Mapper.Map(pRSSSourceDTO, source);

                // Fuente RSS anterior
                iUnitOfWork.RSSSourceRepository.Update(source);

                iUnitOfWork.Complete();
                Log.Information("Fuente RSS actualizada con exito.");
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Error al actualizar la fuente RSS con Id {0}. " + ex.Message, pRSSSourceDTO.Id));
                throw;
            }
        }
        /// <summary>
        /// Crea una fuente RSS
        /// </summary>
        /// <param name="pRssSourceDTO">fuente RSS que se quiere crear</param>
        public void Create(RSSSourceDTO pRSSSourceDTO)
        {
            try
            {
                Log.Information("Creando fuente RSS.");
                var source = new RSSSource();

                Campaign campaign = new Campaign();
                AutoMapper.Mapper.Map(pRSSSourceDTO, source);
                this.iUnitOfWork.RSSSourceRepository.Add(source);

                iUnitOfWork.Complete();
                Log.Information("Fuente RSS creada con exito.");
            }
            catch (Exception)
            {
                Log.Error("Error al crear la fuente RSS.");

                throw;
            }
        }
        /// <summary>
        /// Actualiza los feeds de una fuente RSS
        /// </summary>
        /// <param name="source"></param>
        private void readFeeds(RSSSource source)
        {
            try
            {
                IRSSReader rSSReader = new XMLRSSReader();
                Uri uri;
                Uri.TryCreate(source.Url, UriKind.Absolute, out uri);
                Log.Information("Leyendo fuente RSS.");
                var newRSSItems = rSSReader.Read(uri).ToList();
                // Si se pudo conectar y obtuvo al menos un feed nuevo, actualiza la lista almacenada
                if (newRSSItems != null && newRSSItems.Count > 0)
                {
                    Log.Information("Asignando items RSS a la fuente.");
                    source.RSSItems = AutoMapper.Mapper.Map<IList<RSSItemDTO>, IList<RSSItem>>(newRSSItems);
                }
            }
            catch (Exception)
            {
                Log.Error("Error al actualizar Fuentes RSS.");
            }

        }
Beispiel #7
0
        protected override void Seed(DigitalSignageDbContext pContext)
        {
            Campaign campaign = new Campaign()
            {
                Name        = "Prueba",
                Description = "Prueba de una campaña",
                InitialTime = new TimeSpan(0, 0, 1),
                EndTime     = new TimeSpan(0, 0, 30),
                InitialDate = new DateTime(2018, 02, 07),
                EndDate     = new DateTime(2019, 08, 08),
                Images      = new List <Image>
                {
                    new Image()
                    {
                        Description = "Imagen 1",
                        Duration    = 1,
                        Position    = 1,
                        Data        = File.ReadAllBytes("../../../assets/images/1.jpg")
                    },
                    new Image()
                    {
                        Description = "Imagen 2",
                        Duration    = 2,
                        Position    = 2,
                        Data        = File.ReadAllBytes("../../../assets/images/2.jpg")
                    },
                    new Image()
                    {
                        Description = "Imagen 3",
                        Duration    = 3,
                        Position    = 3,
                        Data        = File.ReadAllBytes("../../../assets/images/3.jpeg")
                    },
                }
            };

            pContext.Campaigns.Add(campaign);

            RSSSource sourceRSS = new RSSSource()
            {
                Description = "Prueba de source",
                Url         = "http://www.bbc.co.uk/mundo/temas/tecnologia/index.xml",
                RSSItems    = new List <RSSItem>
                {
                    new RSSItem()
                    {
                        Date        = DateTime.Now,
                        Url         = "https://www.bbc.com/mundo/internacional/2016/06/160603_sociedad_corea_del_sur_miedo_ventiladores_causa_muerte_ps",
                        Title       = "Por qué en Corea del Sur tanta gente tiene pánico de los ventiladores",
                        Description = "¿Qué pasa si duermes en una habitación cerrada con un ventilador encendido?",
                    }
                }
            };

            pContext.RSSSources.Add(sourceRSS);

            Banner banner1 = new Banner()
            {
                Name        = "Prueba",
                Description = "Prueba de banner",
                InitialTime = new TimeSpan(0, 0, 1),
                EndTime     = new TimeSpan(0, 0, 30),
                InitialDate = new DateTime(2018, 02, 07),
                EndDate     = new DateTime(2019, 08, 08),
                Source      = sourceRSS,
                SourceId    = sourceRSS.Id
            };

            pContext.Banners.Add(banner1);

            TextSource textSource = new TextSource()
            {
                Data = "Prueba de texto",
            };

            pContext.TextSources.Add(textSource);

            Banner banner2 = new Banner()
            {
                Name        = "Prueba",
                Description = "Prueba de banner",
                InitialTime = new TimeSpan(0, 0, 1),
                EndTime     = new TimeSpan(0, 0, 30),
                InitialDate = new DateTime(2018, 02, 07),
                EndDate     = new DateTime(2019, 08, 08),
                Source      = textSource
            };

            pContext.Banners.Add(banner2);

            base.Seed(pContext);
        }