ページ

Sunday, August 29, 2010

Simple Silverlight RSS Reader. (MVVM Pattern)

As a little more useful application under MVVM Pattern, I created a silverlight RSS reader.

Silverlight RSS Reader Demo
http://demo.gehintleman.com/RssReader.html


But, as is well known, silverlight application throws System.Security.SecurityException unless the target host has a clientaccesspolicy.xml.
(Because silverlight does not allow corss domain access.)

One of the solution against that, using GAE(Google App Engine) is a workable alternative.

1.Create rssfeed.py

# -*- coding: utf-8 -*-
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import urlfetch

class GetRssFeed(webapp.RequestHandler):
  def get(self):
    u = self.request.get("u")
    if u:
      try:
        result = urlfetch.fetch(u)
        self.response.out.write(result.content)
      except:
        self.error(404)
    else:
      self.error(404)


application = webapp.WSGIApplication([('/RssFeed',GetRssFeed)], debug=False)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()


2. Create clientaccesspolicy.xml

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from>
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>


3. Add the following configurations in app.yaml

- url: /RssFeed
  script: rssfeed.py
- url: /clientaccesspolicy.xml
  static_files: clientaccesspolicy.xml
  upload: clientaccesspolicy.xml


After deploying those files to GAE, silverlight applications can fetch RSS via the python script.

http://<your application name>.appspot.com/RssFeed?u=<target RSS feed url>


* Actually, I didn't use Expression Blend to create the view. so it doesn't look good.
   but, I think, trying to code xaml must be good to deeply understand silverlight.

Wednesday, August 18, 2010

MVVM Pattern for Silverlight 4

I tried creating a simple silverlight application under some of MVVM pattern rules like followings.

・Views can do "CRUD" data only by "Data Binding" from ViewModels. ( CRUD : Create, Read, Update, Delete )
・Any events will be executed on ViewModels by "ICommand" from Views or some Behaviors on Views.
    (which means there is no code behind on the view.)

⇒ "loose coupling" between a view and a viewmodel ( ViewとViewModelの疎結合 )


MVVM Pattern for Silverlight 4  Demo
http://demo.gehintleman.com/MVVMPattern.html

・There are 4 Views (including MainView), and all the Views do not have any code behinds.
・Views and ViewModels are managed through ExportAttribute/ImportAttribute.
・Using resource files(*.resx) for the localization.


MVVM Pattern could clearly devide web application development into coding by programmers and designing by designers.

* Differently from WPF, Silverlight cannot assign(bind) ViewModels to Views in Application.Resources in APP.XAML.
   But, Managed Extensibility Framework ( a.k.a. MEF ) is so great that we can easily manage ViewModels and Views.