Exemplo n.º 1
0
        public void LoadAndDownloadImages( )
        {
            // go through the news
            for (int i = 0; i < News.Count; i++)
            {
                NewsEntry newsEntry = News[i];
                if (TryLoadCachedImage(newsEntry, newsEntry.News.ImageName) == false)
                {
                    // it failed, so download it and try again.
                    string widthParam = string.Format("&width={0}", View.Bounds.Width * UIScreen.MainScreen.Scale);
                    string requestUrl = Rock.Mobile.Util.Strings.Parsers.AddParamToURL(newsEntry.News.ImageURL, widthParam);

                    FileCache.Instance.DownloadFileToCache(requestUrl, newsEntry.News.ImageName, null,
                                                           delegate
                    {
                        Rock.Mobile.Threading.Util.PerformOnUIThread(delegate
                        {
                            if (IsVisible == true)
                            {
                                TryLoadCachedImage(newsEntry, newsEntry.News.ImageName);
                            }
                        });
                    });
                }
            }
        }
Exemplo n.º 2
0
        public void UpdateNewsEntry(NewsEntryContract contract)
        {
            ParamIs.NotNull(() => contract);

            PermissionContext.VerifyPermission(PermissionToken.EditNews);

            HandleTransaction(session => {
                var user = GetLoggedUser(session);

                if (contract.Id == 0)
                {
                    var entry = new NewsEntry(contract.Text, user, contract.Anonymous, contract.Important, contract.Stickied);
                    session.Save(entry);

                    AuditLog("created " + entry, session, user);
                }
                else
                {
                    var entry       = session.Load <NewsEntry>(contract.Id);
                    entry.Anonymous = contract.Anonymous;
                    entry.Important = contract.Important;
                    entry.Stickied  = contract.Stickied;
                    entry.Text      = contract.Text;

                    session.Update(entry);

                    AuditLog("updated " + entry, session, user);
                }
            });
        }
Exemplo n.º 3
0
        public ActionResult Index(NewsEntry entry)
        {
            if (ModelState.IsValid)
            {
                if (entry.NewsId == 0)
                {
                    entry.CreatedBy   = Utility.CurrentUserName;
                    entry.CreatedTime = DateTime.UtcNow;
                    Utility.Operate(this, Operations.Add, () => _news.Add(entry), entry.Title);
                }
                else
                {
                    var info = _news.GetById(entry.NewsId);
                    info.ChangedBy   = Utility.CurrentUserName;
                    info.ChangedTime = DateTime.UtcNow;
                    info.Content     = entry.Content;
                    info.ModuleId    = entry.ModuleId;

                    Utility.Operate(this, Operations.Update, () => _news.Update(info), info.Title);
                }
            }
            else
            {
                Utility.SetErrorModelState(this);
            }

            return(Redirect("~/Admin/About/Index?MenuID=" + entry.ParentId));
        }
Exemplo n.º 4
0
        private static void ProcessRss(string key, string rssUrl)
        {
            try
            {
                //Log.Write("Fetching News from: " + key);

                XmlReaderSettings settings = new XmlReaderSettings()
                {
                    MaxCharactersInDocument = Int32.MaxValue
                };
                XmlReader reader = XmlReader.Create(rssUrl, settings);

                SyndicationFeed feed = SyndicationFeed.Load(reader);
                foreach (var item in feed.Items)
                {
                    var entry = new NewsEntry()
                    {
                        Provider  = key,
                        Title     = item.Title.Text,
                        Summary   = item.Summary.Text,
                        Url       = item.Links.Count > 0 ? item.Links[0].Uri.AbsoluteUri : string.Empty,
                        EmailId   = Constants.NEWS_EMAIL,
                        EmailSent = false
                    };
                    NewsList.Add(entry);

                    //Log.Write("News Article: " + entry.Title);
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
Exemplo n.º 5
0
                public void UpdateNews(List <RockNews> sourceNews)
                {
                    // free existing news
                    FreeImageResources( );

                    News.Clear( );

                    // copy the new news.
                    int i;

                    for (i = 0; i < sourceNews.Count; i++)
                    {
                        NewsEntry newsEntry = new NewsEntry();
                        News.Add(newsEntry);

                        newsEntry.News = sourceNews[i];
                        // see if we can load the file
                        bool fileFound = TryLoadCachedImageAsync(newsEntry, newsEntry.News.ImageName);
                        if (fileFound == false)
                        {
                            // if not, download it
                            string widthParam = string.Format("width={0}", NavbarFragment.GetCurrentContainerDisplayWidth( ));
                            string requestUrl = Rock.Mobile.Util.Strings.Parsers.AddParamToURL(newsEntry.News.ImageURL, widthParam);

                            FileCache.Instance.DownloadFileToCache(requestUrl, newsEntry.News.ImageName, null,
                                                                   delegate
                            {
                                // and THEN load it
                                TryLoadCachedImageAsync(newsEntry, newsEntry.News.ImageName);
                            });
                        }
                    }
                }
Exemplo n.º 6
0
        public ActionResult Index(NewsEntry entry)
        {
            if (ModelState.IsValid)
            {
                if (entry.NewsId == 0)
                {
                    entry.CreatedBy = Utility.CurrentUserName;
                    entry.CreatedTime = DateTime.UtcNow;
                    Utility.Operate(this, Operations.Add, () => _news.Add(entry), entry.Title);
                }
                else
                {
                    var info = _news.GetById(entry.NewsId);
                    info.ChangedBy = Utility.CurrentUserName;
                    info.ChangedTime = DateTime.UtcNow;
                    info.Content = entry.Content;
                    info.ModuleId = entry.ModuleId;

                    Utility.Operate(this, Operations.Update, () => _news.Update(info), info.Title);
                }
            }
            else
            {
                Utility.SetErrorModelState(this);
            }

            return Redirect("~/Admin/About/Index?MenuID=" + entry.ParentId);
        }
Exemplo n.º 7
0
        public IHttpActionResult PostNews([FromBody] News news)
        {
            IDentifier.currentID += 1;
            var newsEntry = new NewsEntry(Organization.GetInstance().FindUserByID(news.AuthorId), news.CreationTime, new Rating(0, 0), IDentifier.currentID, news.Body);

            newsService.PostEntry(newsEntry);
            return(Ok("I did it"));
        }
Exemplo n.º 8
0
        public void CreateSuccess()
        {
            var newsEntry = NewsEntry.Create();

            newsEntry.AddContent(LanguageCodes.English, "title", "text");
            newsEntry.AddContent(LanguageCodes.German, "titel", "deutscher text");

            // Assert
            Assert.AreEqual("title", newsEntry.GetContentForLanguage(LanguageCodes.English).Title);
            Assert.AreEqual("titel", newsEntry.GetContentForLanguage(LanguageCodes.German).Title);
        }
Exemplo n.º 9
0
 public static bool IsDuplicate(NewsEntry entry)
 {
     using (DAC dac = new DAC())
     {
         string query = string.Format("SELECT Title FROM News WHERE Provider = '{0}' AND Title = '{1}' AND EmailId = '{2}';", entry.Provider, entry.Title, entry.EmailId);
         using (DbDataReader reader = dac.FetchRecords(query))
         {
             return(reader.HasRows);
         }
     }
 }
Exemplo n.º 10
0
        public static void Insert(NewsEntry entry)
        {
            entry.Title   = entry.Title.Replace("'", "''");
            entry.Summary = entry.Summary.Replace("'", "''");

            using (DAC dac = new DAC())
            {
                string statement = string.Format("INSERT INTO News (Provider, Title, Url, EmailId, EmailSent) VALUES ('{0}', '{1}', '{2}', '{3}', {4});", entry.Provider, entry.Title, entry.Url, entry.EmailId, entry.EmailSent ? 1 : 0);
                dac.ExecuteCommand(statement);
            }
        }
Exemplo n.º 11
0
        public void AddDuplicateContentForLanguage()
        {
            // Arrange

            // Act
            var newsEntry = NewsEntry.Create();

            newsEntry.AddContent(LanguageCodes.English, "title", "text");
            newsEntry.AddContent(LanguageCodes.English, "title2", "text2");

            // Assert
        }
Exemplo n.º 12
0
        public NewsEntryContract(NewsEntry newsEntry)
        {
            ParamIs.NotNull(() => newsEntry);

            Anonymous  = newsEntry.Anonymous;
            Author     = new UserContract(newsEntry.Author);
            CreateDate = newsEntry.CreateDate;
            Id         = newsEntry.Id;
            Important  = newsEntry.Important;
            Stickied   = newsEntry.Stickied;
            Text       = newsEntry.Text;
        }
Exemplo n.º 13
0
        public async Task GetNewsById_PlusId_ReturnsPlusElement()
        {
            var repositorystub    = new Mock <IRepository <NewsEntry> >();
            var expextedNewsEntry = new NewsEntry(new User(0, ""), DateTime.Now, new Rating(0, 0), 1, "FirstElement");

            repositorystub.Setup(stub => stub.GetEntry(1)).Returns(expextedNewsEntry);
            var newsService = new NewsService(repositorystub.Object);



            Assert.AreEqual(expextedNewsEntry, await newsService.GetNewsById(1));
        }
Exemplo n.º 14
0
        public void UpdateNews(List <RockNews> sourceNews)
        {
            // clear the existing news
            News.Clear( );

            // copy the source into our news objects
            foreach (RockNews rockEntry in sourceNews)
            {
                NewsEntry newsEntry = new NewsEntry();
                News.Add(newsEntry);

                newsEntry.News = rockEntry;
            }
        }
Exemplo n.º 15
0
    // Use this for initialization
    void Start()
    {
        // Setup random list
        randomEntries = new RandomList <NewsEntry>(startingEntries);

        // Setup current text
        NewsEntry tempEntry = randomEntries.RandomElement;

        currentText.text = tempEntry.News;

        // Cache news
        cacheEntries.Clear();
        cacheEntries.Enqueue(tempEntry);
    }
Exemplo n.º 16
0
        public async Task <ActionResult> Get(string id)
        {
            if (id == null)
            {
                return(new StatusCodeResult(400));
            }
            NewsEntry newsEntry = await _dataAccessProvider.GetNewsEntry(id);

            if (newsEntry == null)
            {
                return(new StatusCodeResult(404));
            }
            return(View(newsEntry));
        }
Exemplo n.º 17
0
        public void PostNews(DTO.News.NewsContent[] newsContents)
        {
            var newsEntry = NewsEntry.Create();

            newsEntry.CreatedById = this.userProvider.GetCurrentUserId();
            newsEntry.CreatedAt   = DateTime.UtcNow;

            foreach (var newsContent in newsContents)
            {
                newsEntry.AddContent(newsContent.Language, newsContent.Title, newsContent.Text);
            }

            this.UnitOfWork.News.Add(newsEntry);

            this.UnitOfWork.Commit();
        }
Exemplo n.º 18
0
        public ActionResult Create(NewsEntry model)
        {
            if (ModelState.IsValid)
            {
                model.CreatedBy   = Utility.CurrentUserName;
                model.CreatedTime = DateTime.UtcNow;

                Utility.Operate(this, Operations.Add, () => _news.Add(model), model.Title);
            }
            else
            {
                Utility.SetErrorModelState(this);
            }

            return(Redirect("~/Admin/News/Index?MenuID=" + model.ParentId));
        }
Exemplo n.º 19
0
        private void NewsLoaded(object sender, NewsLoadedEventArgs newsLoadedEventArgs)
        {
            UI.SetLabelText(NewsLabel, $"Wieści ({newsLoadedEventArgs.NumberOfNews})");
            UI.SetVisible(TitleLabel);
            UI.SetVisible(ForTitle);
            UI.SetVisible(authorLabel);

            // first we sort and only take the last news item

            List <NewsEntry> news   = newsLoadedEventArgs.News;
            NewsEntry        latest = news.OrderByDescending(n => n.Published).FirstOrDefault();

            UI.SetLabelText(TitleLabel, String.Format(TitleLabel.Text, latest.Title));
            UI.SetLabelText(authorLabel, String.Format(authorLabel.Text, latest.Author));

            ParseNewsAndGenerateForms(latest.NewsElements);
        }
Exemplo n.º 20
0
                bool TryLoadCachedImageAsync(NewsEntry entry, string imageName)
                {
                    // if it exists, spawn a thread to load and decode it
                    if (FileCache.Instance.FileExists(imageName) == true)
                    {
                        AsyncLoader.LoadImage(imageName, false, false,
                                              delegate(Bitmap imageBmp)
                        {
                            if (FragmentActive == true)
                            {
                                // if for some reason it loaded corrupt, remove it.
                                if (imageBmp == null)
                                {
                                    FileCache.Instance.RemoveFile(imageName);

                                    return(false);
                                }
                                else
                                {
                                    // we might be replacing an existing image, so be sure to dispose our reference to it.
                                    if (entry.Image != null)
                                    {
                                        entry.Image.Dispose( );
                                        entry.Image = null;
                                    }

                                    // flag that we do HAVE the image
                                    entry.Image = imageBmp;

                                    RefreshListView( );

                                    return(true);
                                }
                            }

                            return(false);
                        });

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
Exemplo n.º 21
0
 public static void GetMatchingAndSendEmail(string[] keywords)
 {
     for (int index = 0; index < NewsList.Count; index++)
     {
         NewsEntry entry = NewsList[index];
         if (ContainsAny(entry.Title, keywords) || ContainsAny(entry.Summary, keywords))
         {
             if (!NewsDAC.IsDuplicate(entry))
             {
                 SendNewsAlertEmail(ref entry, keywords);
                 if (entry.EmailSent)
                 {
                     NewsDAC.Insert(entry);
                 }
             }
         }
     }
 }
Exemplo n.º 22
0
        public ActionResult Edit(NewsEntry model)
        {
            if (ModelState.IsValid)
            {
                var info = _news.GetById(model.NewsId);
                info.ChangedBy   = Utility.CurrentUserName;
                info.ChangedTime = DateTime.UtcNow;
                info.Content     = model.Content;
                info.ModuleId    = model.ModuleId;
                info.Title       = model.Title;

                Utility.Operate(this, Operations.Update, () => _news.Update(model), model.Title);
            }
            else
            {
                Utility.SetErrorModelState(this);
            }

            return(Redirect("~/Admin/Cases/Show/" + model.NewsId));
        }
Exemplo n.º 23
0
        public static void SendNewsAlertEmail(ref NewsEntry entry, string[] keywords)
        {
            try
            {
                string warningText = "You are receiving this mail, because you have enabled News-based-recipes in YtoX.";

                string body = @"You might be interested in this:";
                body += "<p><a href=\"" + entry.Url + "\" target=\"_blank\">" + entry.Title + "</a></p>";
                body += "<p>Provider: <a href=\"" + Constants.AllNewsProviders[entry.Provider] + "\" target=\"_blank\">" + entry.Provider + " RSS</a></p>";
                body += "<p>Relevant Keywords: " + string.Join(", ", keywords) + "</p>";
                body += "<pre>" + warningText + "</pre>";

                string subject = "YtoX News Alert";
                EmailHelper.SendEmail(Constants.NEWS_EMAIL, subject, body);

                entry.EmailSent = true;
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
Exemplo n.º 24
0
        private static NewsEntry Fetch(DbDataReader reader)
        {
            NewsEntry entry = new NewsEntry();

            try
            {
                entry.Provider = (string)reader["Provider"];
                entry.Title    = (string)reader["Title"];
                if (!Convert.IsDBNull(reader["Summary"]))
                {
                    entry.Summary = (string)reader["Summary"];
                }
                entry.Url       = (string)reader["Url"];
                entry.EmailId   = (string)reader["EmailId"];
                entry.EmailSent = (bool)reader["EmailSent"];
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
            return(entry);
        }
Exemplo n.º 25
0
    public void NextNewsEntry(NewsEntry entry = null)
    {
        // Check if any entry is provided
        if (entry == null)
        {
            // If not, choose a random element
            entry = randomEntries.RandomElement;

            // Get an entry that isn't in the cache list
            //Debug.Log("Random Entry Selected");
            while (cacheEntries.Contains(entry) == true)
            {
                // Keep grabbing a random element
                //Debug.Log("Duplicate News found:\n" + entry.News);
                entry = randomEntries.RandomElement;
            }
        }

        // Display this news
        newText.text = entry.News;
        animator.SetTrigger(nextEntryTrigger);

        // Reset time
        if (lastStarted > 0)
        {
            Resume();
        }

        // Add entry to the list
        cacheEntries.Enqueue(entry);

        // If this exceeds the size, start removing entries
        while (cacheEntries.Count > numberOfEntriesToCache)
        {
            entry = cacheEntries.Dequeue();
            //Debug.Log("Removing News from cache:\n" + entry.News);
        }
        //Debug.Log("Cache size: " + cacheEntries.Count);
    }
Exemplo n.º 26
0
        public void Execute(NewsEntry NewsEntryModel)
        {
            var DeObj = new DAL.EntityFramework.SQL.NewsEntry();

            //var dbObj = (from entry in dc.NewsEntries where entry.Headline.StartsWith(DEM.Headline.Remove(10, DEM.Headline.Length - 10)) select entry).FirstOrDefault();
            var DBitem = context.FindHeadline(NewsEntryModel.Headline);

            if (DBitem == null)
            {
                DeObj.Headline    = NewsEntryModel.Headline;
                DeObj.HeadlineUrl = NewsEntryModel.HeadlineUrl;
                DeObj.NewsSource  = NewsEntryModel.NewsSource;
                DeObj.TimeAdded   = DateTime.UtcNow;
                DeObj.Article     = NewsEntryModel.Article;
                DeObj.Imagepath   = NewsEntryModel.Imagepath;
                DeObj.Category    = NewsEntryModel.Category;

                context.Insert(DeObj);
                context.Commit();

                _logger.Log($"Added to database", ConsoleColor.Red);
            }
        }
        public override async Task Seed(ImperaContext context)
        {
            await base.Seed(context);

            if (context.MapTemplates.FirstOrDefault(x => x.Name == "TestMap") == null)
            {
                context.MapTemplates.Add(new Domain.Map.MapTemplateDescriptor
                {
                    Name           = "TestMap",
                    LastModifiedAt = DateTime.UtcNow,
                    CreatedAt      = DateTime.UtcNow
                });
            }

            // Add dummy news entry
            var newsEntry = NewsEntry.Create();

            newsEntry.CreatedBy = context.Users.FirstOrDefault(x => x.UserName == "System");
            newsEntry.CreatedAt = DateTime.UtcNow;
            newsEntry.AddContent("en", "DB initialized", "DB has been updated");
            context.NewsEntries.Add(newsEntry);
            context.SaveChanges();
        }
Exemplo n.º 28
0
        public ActionResult Edit(NewsEntry model)
        {
            if (ModelState.IsValid)
            {
                var info = _news.GetById(model.NewsId);
                info.ChangedBy   = Utility.CurrentUserName;
                info.ChangedTime = DateTime.UtcNow;
                info.Author      = model.Author;
                info.Brief       = model.Brief;
                info.Content     = model.Content;
                info.Count       = model.Count;
                info.ModuleId    = model.ModuleId;
                info.Source      = model.Source;
                info.Title       = model.Title;

                Utility.Operate(this, Operations.Update, () => _news.Update(model), model.Title);
            }
            else
            {
                Utility.SetErrorModelState(this);
            }

            return(Redirect("~/Admin/News/Index?MenuID=" + model.ParentId));
        }
Exemplo n.º 29
0
        bool TryLoadCachedImage(NewsEntry entry, string imageName)
        {
            bool success = false;

            // check the billboard
            if (FileCache.Instance.FileExists(imageName) == true)
            {
                MemoryStream imageStream = (MemoryStream)FileCache.Instance.LoadFile(imageName);
                if (imageStream != null)
                {
                    try
                    {
                        // grab the data
                        NSData imageData = NSData.FromStream(imageStream);
                        entry.Image = new UIImage(imageData, UIScreen.MainScreen.Scale);

                        // refresh the table if it's ready. It's possible we're prepping news items before
                        // we've presented the UI (where the tableView gets created)
                        if (NewsTableView != null)
                        {
                            NewsTableView.ReloadData( );
                        }

                        success = true;
                    }
                    catch (Exception e)
                    {
                        FileCache.Instance.RemoveFile(imageName);
                        Rock.Mobile.Util.Debug.WriteLine(string.Format("Image {0} is corrupt. Removing. (Exception: {1})", imageName, e.Message));
                    }
                    imageStream.Dispose( );
                }
            }

            return(success);
        }
        bool TryLoadCachedImage( NewsEntry entry, string imageName )
        {
            bool success = false;

            // check the billboard
            if( FileCache.Instance.FileExists( imageName ) == true )
            {
                MemoryStream imageStream = (MemoryStream)FileCache.Instance.LoadFile( imageName );
                if ( imageStream != null )
                {
                    try
                    {
                        // grab the data
                        NSData imageData = NSData.FromStream( imageStream );
                        entry.Image = new UIImage( imageData, UIScreen.MainScreen.Scale );

                        // refresh the table
                        NewsTableView.ReloadData( );

                        success = true;
                    }
                    catch( Exception )
                    {
                        FileCache.Instance.RemoveFile( imageName );
                        Rock.Mobile.Util.Debug.WriteLine( string.Format( "Image {0} is corrupt. Removing.", imageName ) );
                    }
                    imageStream.Dispose( );
                }
            }

            return success;
        }
Exemplo n.º 31
0
                bool TryLoadCachedImageAsync( NewsEntry entry )
                {
                    // if it exists, spawn a thread to load and decode it
                    if ( FileCache.Instance.FileExists( entry.News.ImageName ) == true )
                    {
                        // flag that we do HAVE the image
                        entry.ImageIsDownloaded = true;

                        AsyncLoader.LoadImage( entry.News.ImageName, false, false,
                            delegate( Bitmap imageBmp )
                            {
                                if ( FragmentActive == true )
                                {
                                    // if for some reason it loaded corrupt, remove it.
                                    if ( imageBmp == null )
                                    {
                                        FileCache.Instance.RemoveFile( entry.News.ImageName );
                                    }

                                    entry.Image = imageBmp;
                                    RefreshListView( );

                                    return true;
                                }

                                return false;
                            } );

                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
Exemplo n.º 32
0
                public void UpdateNews( List<RockNews> sourceNews )
                {
                    // free existing news

                    // be sure to dump the existing news images so
                    // Dalvik knows it can use the memory
                    foreach ( NewsEntry newsEntry in News )
                    {
                        if ( newsEntry.Image != null )
                        {
                            newsEntry.Image.Dispose( );
                            newsEntry.Image = null;
                        }
                    }

                    News.Clear( );

                    // copy the new news
                    foreach ( RockNews rockEntry in sourceNews )
                    {
                        NewsEntry newsEntry = new NewsEntry();
                        News.Add( newsEntry );

                        newsEntry.News = rockEntry;

                        // see if we can load the file
                        bool fileFound = TryLoadCachedImageAsync( newsEntry );
                        if ( fileFound == false )
                        {
                            // if not, download it
                            FileCache.Instance.DownloadFileToCache( newsEntry.News.ImageURL, newsEntry.News.ImageName,
                                delegate
                                {
                                    // and THEN load it
                                    TryLoadCachedImageAsync( newsEntry );
                                } );
                        }
                    }
                }
        public void UpdateNews( List<RockNews> sourceNews )
        {
            // clear the existing news
            News.Clear( );

            // copy the source into our news objects
            foreach ( RockNews rockEntry in sourceNews )
            {
                NewsEntry newsEntry = new NewsEntry();
                News.Add( newsEntry );

                newsEntry.News = rockEntry;
            }
        }
Exemplo n.º 34
0
        public ActionResult Edit(NewsEntry model)
        {
            if (ModelState.IsValid)
            {
                var info = _news.GetById(model.NewsId);
                info.ChangedBy = Utility.CurrentUserName;
                info.ChangedTime = DateTime.UtcNow;
                info.Author = model.Author;
                info.Brief = model.Brief;
                info.Content = model.Content;
                info.Count = model.Count;
                info.ModuleId = model.ModuleId;
                info.Source = model.Source;
                info.Title = model.Title;

                Utility.Operate(this, Operations.Update, () => _news.Update(model), model.Title);
            }
            else
            {
                Utility.SetErrorModelState(this);
            }

            return Redirect("~/Admin/News/Index?MenuID=" + model.ParentId);
        }
Exemplo n.º 35
0
        public ActionResult Edit(NewsEntry model)
        {
            if (ModelState.IsValid)
            {
                var info = _news.GetById(model.NewsId);
                info.ChangedBy = Utility.CurrentUserName;
                info.ChangedTime = DateTime.UtcNow;
                info.Content = model.Content;
                info.ModuleId = model.ModuleId;
                info.Title = model.Title;

                Utility.Operate(this, Operations.Update, () => _news.Update(model), model.Title);
            }
            else
            {
                Utility.SetErrorModelState(this);
            }

            return Redirect("~/Admin/Products/Show/" + model.NewsId);
        }
Exemplo n.º 36
0
        public ActionResult Create(NewsEntry model)
        {
            if (ModelState.IsValid)
            {
                model.CreatedBy = Utility.CurrentUserName;
                model.CreatedTime = DateTime.UtcNow;

                Utility.Operate(this, Operations.Add, () => _news.Add(model), model.Title);
            }
            else
            {
                Utility.SetErrorModelState(this);
            }

            return Redirect("~/Admin/Products/Show/" + model.NewsId);
        }
Exemplo n.º 37
0
        public void Bootstrap()
        {
            var _fs = new Filesystem(Directory.GetCurrentDirectory());

            Console.WriteLine("[I] Bootstrap...");
            AccessProvider.ProviderResponse     += Handle_Provider_Event;
            ServerProvider.ProviderResponse     += Handle_Provider_Event;
            ClientProvider.ProviderResponse     += Handle_Provider_Event;
            UserProvider.ProviderResponse       += Handle_Provider_Event;
            NewsProvider.ProviderResponse       += Handle_Provider_Event;
            NavigationProvider.ProviderResponse += Handle_Provider_Event;

            if (!Directory.Exists(Path.Combine(_fs.Root, "Providers")))
            {
                Directory.CreateDirectory(Path.Combine(_fs.Root, "Providers"));
                Console.WriteLine("[I] Provider installation needed..., Bootstrapping them...");
            }

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "System",
                Level    = ulong.MaxValue,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Server-Administratoren",
                Level    = byte.MaxValue,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Server-Operatoren",
                Level    = 250,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Seiten-Administroren",
                Level    = 245,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Seiten-Operatoren",
                Level    = 240,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "News-Administratoren",
                Level    = 235,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "News-Operatoren",
                Level    = 230,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Sendeplan-Administratoren",
                Level    = 225,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Sendeplan-Operatoren",
                Level    = 220,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Stream-Administratoren",
                Level    = 215,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Stream-Operatoren",
                Level    = 210,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Seiten-Mitglied",
                Level    = 1,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Unregistriert",
                Level    = byte.MinValue,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            #region "News Provider - Installation"


            var news_user = Guid.Empty;
            var xmlDoc    = new XmlDocument();
            xmlDoc.Load(NewsProvider.InstallScript);
            var newsEntries = xmlDoc.SelectNodes("Namiono/Install/Users/User");

            for (var i = 0; i < newsEntries.Count; i++)
            {
                var res_level = ulong.MinValue;


                var user = new UserEntry <Guid>
                {
                    Id                                 = newsEntries[i].Attributes["Id"] == null?Guid.NewGuid() : Guid.Parse(newsEntries[i].Attributes["Id"].Value),
                                             Name      = newsEntries[i].Attributes["Name"].Value,
                                             Service   = bool.Parse(newsEntries[i].Attributes["Service"].Value == "0" ? "false" : "true"),
                                             Moderator = bool.Parse(newsEntries[i].Attributes["Moderator"].Value == "0" ? "false" : "true"),
                                             Locked    = bool.Parse(newsEntries[i].Attributes["Locked"].Value == "0" ? "false" : "true"),
                                             Password  = MD5.GetMD5Hash(newsEntries[i].Attributes["Password"].Value),
                                             Provider  = UserProvider.Name
                };

                if (newsEntries[i].Attributes["Level"] != null)
                {
                    ulong.TryParse(newsEntries[i].Attributes["Level"].Value, out res_level);
                    user.Level = res_level;
                }

                news_user = user.Id;

                UserProvider.Add(user.Id, user);
            }

            newsEntries = xmlDoc.SelectNodes("Namiono/Install/Entries/Entry");

            for (var i = 0; i < newsEntries.Count; i++)
            {
                var res_level = ulong.MinValue;

                var news = new NewsEntry <Guid>
                {
                    Name      = newsEntries[i].Attributes["Name"].Value,
                    Service   = bool.Parse(newsEntries[i].Attributes["Service"].Value == "0" ? "false" : "true"),
                    Moderator = bool.Parse(newsEntries[i].Attributes["Moderator"].Value == "0" ? "false" : "true"),
                    Locked    = bool.Parse(newsEntries[i].Attributes["Locked"].Value == "0" ? "false" : "true"),
                    OutPut    = newsEntries[i].Attributes["Output"].Value.Replace("[[NL]]", "<br />"),
                    Url       = newsEntries[i].Attributes["Url"].Value,
                    Author    = news_user
                };

                if (newsEntries[i].Attributes["Level"] != null)
                {
                    ulong.TryParse(newsEntries[i].Attributes["Level"].Value, out res_level);
                    news.Level = res_level;
                }


                NewsProvider.Add(Guid.NewGuid(), news);
            }

            #endregion

            #region "Navigation Provider - Installation"
            xmlDoc.Load(NavigationProvider.InstallScript);

            var navEntries = xmlDoc.SelectNodes("Namiono/Install/Entries/Entry");

            for (var i = 0; i < navEntries.Count; i++)
            {
                var res_level = ulong.MinValue;

                var nav = new NavigationEntry <Guid>
                {
                    Name      = navEntries[i].Attributes["Name"].Value,
                    Service   = bool.Parse(navEntries[i].Attributes["Service"].Value == "0" ? "false" : "true"),
                    Moderator = bool.Parse(navEntries[i].Attributes["Moderator"].Value == "0" ? "false" : "true"),
                    Locked    = bool.Parse(navEntries[i].Attributes["Locked"].Value == "0" ? "false" : "true"),
                    OutPut    = navEntries[i].Attributes["Output"].Value.Replace("[[NL]]", "<br />"),
                    Url       = navEntries[i].Attributes["Url"].Value,
                    Author    = Guid.Empty
                };

                if (navEntries[i].Attributes["Level"] != null)
                {
                    ulong.TryParse(navEntries[i].Attributes["Level"].Value, out res_level);
                    nav.Level = res_level;
                }


                NavigationProvider.Add(Guid.NewGuid(), nav);
            }


            NavigationProvider.Add(Guid.NewGuid(), new NavigationEntry <Guid>()
            {
                Name = "Mitglieder", Active = true, Locked = false, Level = 1, Frame = "#content", Provider = UserProvider.Name, Action = "show"
            });
            NavigationProvider.Add(Guid.NewGuid(), new NavigationEntry <Guid>()
            {
                Name = "News", Active = true, Locked = false, Level = 1, Frame = "#content", Provider = NewsProvider.Name, Action = "show"
            });

            #endregion
            AccessProvider.Bootstrap();
            ServerProvider.Bootstrap();
            ClientProvider.Bootstrap();
            UserProvider.Bootstrap();
            NewsProvider.Bootstrap();
            NavigationProvider.Bootstrap();



            Console.WriteLine("[I] Starting ...");
        }
Exemplo n.º 38
0
                bool TryLoadCachedImageAsync( NewsEntry entry, string imageName )
                {
                    // if it exists, spawn a thread to load and decode it
                    if ( FileCache.Instance.FileExists( imageName ) == true )
                    {
                        AsyncLoader.LoadImage( imageName, false, false,
                            delegate( Bitmap imageBmp)
                            {
                                if ( FragmentActive == true )
                                {
                                    // if for some reason it loaded corrupt, remove it.
                                    if ( imageBmp == null )
                                    {
                                        FileCache.Instance.RemoveFile( imageName );

                                        return false;
                                    }
                                    else
                                    {
                                        // we might be replacing an existing image, so be sure to dispose our reference to it.
                                        if( entry.Image != null )
                                        {
                                            entry.Image.Dispose( );
                                            entry.Image = null;
                                        }

                                        // flag that we do HAVE the image
                                        entry.Image = imageBmp;

                                        RefreshListView( );

                                        return true;
                                    }
                                }

                                return false;
                            } );

                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
Exemplo n.º 39
0
                public void UpdateNews( List<RockNews> sourceNews )
                {
                    // free existing news
                    FreeImageResources( );

                    News.Clear( );

                    // copy the new news.
                    int i;
                    for( i = 0; i < sourceNews.Count; i++ )
                    {
                        NewsEntry newsEntry = new NewsEntry();
                        News.Add( newsEntry );

                        newsEntry.News = sourceNews[ i ];

                        // if this is the top news item on a landscape device, use it's 'Header' image instead.
                        if ( MainActivity.SupportsLandscapeWide( ) && i == 0 )
                        {
                            bool fileFound = TryLoadCachedImageAsync( newsEntry, newsEntry.News.HeaderImageName );
                            if ( fileFound == false )
                            {
                                // if not, download it
                                string widthParam = string.Format( "&width={0}", NavbarFragment.GetContainerDisplayWidth_Landscape( ) );
                                FileCache.Instance.DownloadFileToCache( newsEntry.News.HeaderImageURL + widthParam, newsEntry.News.HeaderImageName, 
                                    delegate
                                    {
                                        // and THEN load it
                                        TryLoadCachedImageAsync( newsEntry, newsEntry.News.HeaderImageName );
                                    } );
                            }
                        }
                        else
                        {
                            // see if we can load the file
                            bool fileFound = TryLoadCachedImageAsync( newsEntry, newsEntry.News.ImageName );
                            if ( fileFound == false )
                            {
                                // if not, download it
                                string widthParam = string.Format( "&width={0}", NavbarFragment.GetContainerDisplayWidth_Landscape( ) );
                                FileCache.Instance.DownloadFileToCache( newsEntry.News.ImageURL + widthParam, newsEntry.News.ImageName, 
                                    delegate
                                    {
                                        // and THEN load it
                                        TryLoadCachedImageAsync( newsEntry, newsEntry.News.ImageName );
                                    } );
                            }
                        }
                    }
                }