Thursday, February 28, 2013

Chronic: "Programming ASP.NET MVC 4"

I recently read a new book: Programming ASP.NET MVC 4. This interesting book has been written by Jess Chadwick, Todd Snyder and Hrusikesh Panda and is about the latest ASP.NET MVC version (4).

Here is the list of the topics (by chapter) covered in this book:
  1. Fundamentals of ASP.NET MVC: The MVC Architecture, New in ASP.NET MVC 4, ...
  2. ASP.NET MVC for Web Forms Developers: More Differences than Similarities, ...
  3. Working with Data: Building a Form, Validating Data, ...
  4. Client-Side Development: Working with JavaScript, AJAX, Client-Side Validation, ...
  5. Web Application Architecture: Architecting a Web Application, Design Principles, ...
  6. Enhancing Your Site with AJAX: Partial Rendering, Sending Data to the Server, ...
  7. The ASP.NET Web API: Building a Data Service, Exception Handling, ...
  8. Advanced Data: Data Access Patterns, Building a Data Access Layer, ...
  9. Security: Building Secure Web Applications, Guarding Against Attacks, ...
  10. Mobile Web Development: Application Mobile Friendly, Adaptive Rendering, ...
  11. Parallel, Asynchronous, and Real-Time Data Operations: Asynchronous Controllers, ...
  12. Caching: Types of Caching, Server-Side Caching Techniques, Client-Side Caching Techniques, ...
  13. Client-Side Optimization Techniques: Anatomy of a Page, Best Practices, Measuring Client-Side Performance, ...
  14. Advanced Routing: URLs and SEO, Building Routes, Route Constraints, ...
  15. Reusable UI Components: What ASP.NET MVC Offers out of the Box, Unit Testing Razor Views, ...
  16. Logging: Error Handling in ASP.NET MVC, Logging and Tracing, ...
  17. Automated Testing: Levels of Automated Testing, What Is an Automated Test Project, Testing an ASP.NET MVC Application, ...
  18. Build Automation: Creating Build Scripts, Automating the Build, Continuous Integration, ...
  19. Deployment: What Needs to Be Deployed, Deploying to Internet Information Server, Deploying to Windows Azure, ...
And some appendixes: ASP.NET MVC and Web Forms Integration, Leveraging NuGet as a Platform, Appendix Best Practices, etc.

I enjoyed reading this book: as the title says, it's really about the Real World Web Applications. My knowledge of ASP.NET MVC was already advanced, but I had to rethink my expertise in architecture development, consider tight coupling of classes, etc.
I recommend this big book (500 pages...) to people who already know the basics of  ASP.NET MVC or to the ASP.NET Webform developers.

I will soon receive another book: Exploring CQRS and Event Sourcing: A journey into high scalability, availability, and maintainability with Windows Azure. Perhaps another small chronic to come ;-)

Wednesday, February 13, 2013

Simple Chrome extension: show a counter from API

I already talked about my game "Blind Friends" (which also exists on Windows Phone)...

The game was not a great success but the number of registered players in my database increases progressively.
I had already created a simple action that sends the number of registered players (in JSON: so I can add more information if I need it):

   1:  public JsonResult playercount()
   2:  {
   3:      return Json(new { Count = Db.GetCountPlayers() }, JsonRequestBehavior.AllowGet);
   4:  }

At the beginning, I was checking that number at the URL corresponding to the action in my web app... But it was not very convenient... So I decided to create a small extension for Chrome:

The code is very simple: I just need to check an URL every two minutes.
The extension contains 4 files:

  • background.js
  • icon.png (I took the favicon of my web app)
  • jquery.js (a local copy of a recent version of Jquery)
  • manifest.json

Code of background.js:

   1:  var pollInterval = 2;  // 2 minutes
   3:  function updateCounter() {
   4:      $.getJSON('{the url which returns a json with a "Count" property...}', function(json) {
   5:          chrome.browserAction.setBadgeText({
   6:              text: json.Count.toString()
   7:          });
   8:      });
   9:  }
  11:  $(document).ready(function () {
  12:      updateCounter(); // we call the function one time here because
  13:                       // the alarm will be triggered one minute after
  15:      chrome.browserAction.setBadgeBackgroundColor({
  16:          color: "#000"
  17:      })
  19:      chrome.alarms.onAlarm.addListener(function (alarm) {
  20:          updateCounter();
  21:      });
  23:      chrome.alarms.create('blindFriendsAlarm', {periodInMinutes: pollInterval});
  24:  })

Code of manifest.json:

   1:  {
   2:    "manifest_version": 2,
   4:    "name": "Blind Friends Counter",
   5:    "description": "Count the number of Blind Friends users.",
   6:    "version": "1.0",
   8:    "permissions": [
   9:      "",
  10:      "alarms"
  11:    ],
  12:    "browser_action": {
  13:      "default_icon": "icon.png"
  14:    },
  15:    "background": {
  16:      "scripts": ["jquery.js", "background.js"],
  17:      "persistent": false
  18:    }
  19:  }

The installation is simple: you have to click on "Load unpacked extension" in the extensions page of Chrome

And you just have to select the folder which contains the previous files...