0x01 Preface because every day commuting, before lunch break, are to look at the news, but a wide variety, but also find their own interest, so it will certainly take a lot of time.
Although there are a lot of software now can subscribe to some of their favorite news, to install to the phone, or very troublesome. So it's a whim to put some news resources
Integration, save time and effort, based on RSS subscriptions, with H5 with ASP. NET core to do a small site, convenient for yourself, by the way dotnet core training practiced hand.
Development environment: Win10+vs2015+sqlite+redis (Windows)
Deployment environment: Centos7+.net core Sdk+jexus+redis (Linux)
0x02 Development
Because the amount of data will not be large, so the choice of SQLite, it is very convenient to use.
RSS content is from the major news sites, not every visit to request once, so to cache up.
Database operation selection dapper, UI framework selected Jquery-weui, also used a JS template engine art-template.
Xunit.net for unit testing.
In order to create a project, I didn't add too many things, so I built the project with Xamarin Studio and then developed it on the VS2015,
Need something, add it yourself, load it on demand. Here is the overall structure diagram:
RSS feeds under normal conditions are in XML form and are basically very regular: Rss/channel/item The following is the specific news.
So simply use XDocument to deal with these things:
1 Public AsyncTask<ilist<models.item>> GetItems (stringUrlintcount)2 {3 stringXmlstr =awaitgetxmlstringbyurl (URL);4XDocument doc =Xdocument.parse (XMLSTR);5 //The channel image6 stringImgurl = doc. Element ("RSS"). Element ("Channel"). Element ("Image"). Element ("URL"). Value;7 //The RSS Item8 varResults = doc. Element ("RSS"). Element ("Channel"). Elements ("Item"). Select (x =NewModels.item9 {Tentitle = X.element ("title"). Value, Onelink = x.element ("Link"). Value, ADescription = X.element ("Description"). Value, -PubDate = X.element ("pubDate"). Value, -GUID = X.element ("GUID"). Value, theImgurl =Imgurl - }); - - returnresults. Take (count). ToList (); +}
In the process of dependency injection, the use of Microsoft's own, and did not use AUTOFAC, as follows.
1 Public voidconfigureservices (iservicecollection services)2 { 3 Services. Addmvc ();4Services. Addscoped<irssitemrepository, rssitemrepository>();5Services. Addscoped<iuserrepository, userrepository>();6Services. Addscoped<irsssourcerepository, rsssourcerepository>();7 //The cache8Services. Addscoped<icache, rediscache>();9}These two can be said to be the most important two places for this RSS feed. One from the network to get the data back, one from the database to take the data out.
Development, due to the use of Redis, I personally installed a Windows version of the computer, easy to debug.
The operation is using Stackexchange.redis, who has simply encapsulated some basic usage, but this is not the official version.
Other parts should be relatively simple, so it is not explained.
Here's a look at deploying under CentOS7.
0X03 deployment
The previous article Dotnetcore taste, the deployment method used is purely the way of the. NET Core SDK.
Try the Jexus+.net Core SDK for deployment today in a different way (of course, there is no way to install. NET Core Deployment).
Let's just post the project:
This assembly is not too many Ah, I hope Microsoft can improve this in the next version.
To upload these things.
/var/www/easyrssIn
Add a configuration in the Siteconf folder below Jexus Easyrss
Add a line of apphost, you can let Jexus support ASP. NET core, more about this introduction can refer to http://linuxdot.net/bbsfile-4459
With this sentence, you can start the site.
Apphost={cmdline=dotnet/var/www/easyrss/catcher.easyrss.website.dll; approot=/var/www/easyrss;port=5000}
Start Easyrss this site:./jws start Easyrss
Another important step is to start Redis, or you'll never get away with it.
Start Redis:./redis-server
Open the browser and you'll see the effect.
The operation is quite simple. Give it a try.
Put a few more (after all, it took a half day)
0X04 Summary
1. A problem has been encountered after successful deployment, and the styles and scripts do not load properly. Request the external network resources more time-consuming (network slag), had to the production environment style
It was loaded locally, and then it was normal.
2, ASP. NET core and ASP. In the development of the time, there is no big difference, it should be easy to transition, you should slowly also have more with the dotnet core to develop.
Save time by making a simple RSS feed (ASP. NET Core)