Retrieving stock quotes in C#

 

I’ve been playing with the idea of writing an currency converter for my new Windows Phone 7. Stumbled across a tweet by Scot Hanselman regarding http://channel9.msdn.com/coding4fun. Turns out someone else beat me to it with the BING “api” (more of a url naming convention really).

So I got a little diverted and write a little app to get stock quotes from google.

Here’s how enjoy…(Using a default ticker of vodafone (.net 4.0)

image

WP7

 

Received my first windows phone today, just had to try an app after finishing work..
Wrote a little app to search the subnet looking for some jboss application servers, works just as well on my phone connected to wifi Rolling on the floor laughing

Pretty chuffed with myself, the effort over the last number of years learning xaml has really paid off..

it’s helped in

* WF4 Activity designers
* WPF application
* Silverlight web
And now…. Mobile phone apps

image

Get the windows phone sdk here

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=04704acf-a63a-4f97-952c-8b51b34b00ce

VS2010 Script chooser

In a visual studio 2010 asp page, start typing

<script src=

You’ll get presented with the following screen.

image

 

Choose the Pick URL … option and you’ll be presented with the following screen

image

I think you’ll figure out the rest Ninja

SQL Server 2008 Calculation Variables

SqlServer 2008 has a short hand/compact way of assigning calculation variables.

 

e.g

Sql2005

DECLARE @val    INT
set @val = 1;
set @val = @val + 1;

 

Sql2008

DECLARE @val    INT
set @val = 1;
set @val += 1;

 

Same applies to other operators,  *=, –=, /=

Thread starvation in MVC

 

On IIS, the .NET Framework maintains a pool of threads that are used to service ASP.NET requests. When a request arrives, a thread from the pool is dispatched to process that request. If the request is processed synchronously, the thread that processes the request is blocked while the request is being processed, and that thread cannot service another request.

This is generally not a problem insofar as ASP.net may have enough threads (depending on version) to accommodate a few blocked threads, however when all threads are blocked you’ll see a 503 http error presented – now in thread starvation.

Firstly, lets talk about standard asp.NET, how can we overcome this problem?

Seasoned .NET developers may attempt to begin invoke on a delegate (using lambdas these days Hot smile) or use the ThreadPool.QueueUserWorkItem, however both these approaches are futile as the both draw from the same thread pool as asp.NET Confused smile

Another naïve approach would be to serve up your own thread,  think about this for a second, your website is there to handle multiple requests…! Needless to say it could promptly run out of resources as a new thread would be created for each request.

The asp.NET solution is to use async pages , <%@ Page Async=”true” …>  / Page.AddOnPreRenderCompleteAsync 

So what about mvc?

MVC – Async Actions

clip_image001

 

  1. The Web server gets a thread from the thread pool (the worker thread) and schedules it to handle an incoming request. This worker thread initiates an asynchronous operation.
  1. The worker thread is returned to the thread pool to service another Web request.
  1. When the asynchronous operation is complete, it notifies ASP.NET.
  2. The Web server gets a worker thread from the thread pool (which might be a different thread from the thread that started the asynchronous operation) to process the remainder of the request, including rendering the response.

 

SYNC

public class PortalController: Controller {
   
public ActionResult News(string
city) {
        NewsService newsService =
new
NewsService();
        ViewStringModel headlines = newsService.GetHeadlines(city);
       
return
View(headlines);
    }
}

ASYNC

public class PortalController : AsyncController {
   
public void NewsAsync(string
city) {

AsyncManager.OutstandingOperations.Increment();
        NewsService newsService =
new
NewsService();
        newsService.GetHeadlinesCompleted += (sender, e) =>
        {
            AsyncManager.Parameters[
"headlines"
] = e.Value;
            AsyncManager.OutstandingOperations.Decrement();
        };
        newsService.GetHeadlinesAsync(city);
    }

public ActionResult NewsCompleted(string[] headlines) {
       
return View("News", new
ViewStringModel
        {
            NewsHeadlines = headlines
        });
    }
}

Note:

  1. New derivation
  2. Matching Async/Completed calls

The future is live

 

Probably like a lot of other computer people I find myself working with more than one computer. There in lies the problem, is it worth the overhead of manually having to synchronize all these pcs?

Sure source code is and always has been handled by a source control repository, tfs/svn etc.

But what about documents; during the week I started setting up a new desktop machine, tonight while working on a java project (i know i know) i found that i needed to copy a few strings into the clipboard as I was developing, now I usually do this from within vs2010 but I’m not sure how to do this from the Java Netbeans IDE so i though I’d use MS Onenote.. there in lied the problem. I wanted to access the notebook I had on my laptop but I didn’t want to start an import/export process (so 90ies Rolling on the floor laughing).

Turns out that onenote 2010 allows me to save my notebook on a network share (not so exciting because i could do this with UNC paths); but moreover it allows you to keep your notebook synchronized with windows live office space.

So now I‘ve got my notebooks sitting in the cloud and cached and accessed locally on different computers. Now I’ve not really invested much if any time in could services, but I think it’s time to start, I’ve a sneaky suspicion that going forward operating systems will become more and more cloud integrated. I can’t see anyone choosing to manually upload and download documents to servers when this can now easily be managed by hitting that save button.

Not just a new look for 2011

Have updated a host of new features on my blog, (running Blog Engine 2.0 released on 1st January)

I’m now writing my blogs offline with Wndows Live Writer, and click of the mouse posting them to www.briankeating.net, no more manually fighting with rich text markup formatting  and html.

New features:

  • Upgraded to .NET 3.5
  • New Control Panel - complete makeover
  • Recaptcha, captcha to reduce spam for Comments and Contact Form
  • SimpleCaptcha, captcha to reduce spam
  • TypePadFilter, anti-spam comment filter
  • Disqus, optionally replace the normal comment system with Disqus
  • SQL CE 4.0 support - standalone DB storage in the App_Data directory
  • Recycle bin for Posts, Pages and Comments
  • New Dashboard in control panel
  • Posts list and Pages list - grid of all Posts and Pages in one easy to see area
  • Added jQuery, automatically included and available in pages
  • Security improvements - related to external content the blog may download
  • New Media Elements JS library extension for HTML5 video support
  • Themeable Widget Containers & Newsletter widget Notification Emails
  • New Syntax Highlighter extension - most popular syntax highlighting library
  • Roles & Rights system - create Roles and assign Rights to each role
  • Private blog feature - require users to be logged in to access the blog
  • Option to allow self-registration for visitors
  • Support for Unicode characters in the URL for Posts and Pages.
  • Improved JS/CSS minification speed and size
  • Latest version of tinyMCE WYSIWYG editor

Hello IIS 7.5 Express

Cassini; We’ve all used it and loved it, now it’s the end of the road for the visual studio webserver.

It gets replaced by  IIS 7.5 Express

  • You can install it on its own. It's IIS, except it runs as a user process rather than a service. Cassini (Visual Developer Web Server) is dead! It's "just in time" IIS. There when you need it, and not running when it's not used.
  • This is the web server that Web Matrix uses today, but it'll be enabled in Visual Studio 2010 when SP1 comes out.

MVC3 Released

Today Microsoft announced the (actual, final, honest) releases of:

  • ASP.NET MVC3 with Razor
    • Lots of new features, the new Razor syntax, more extensibility hooks, new JavaScript features, better validation, easier caching, better dynamic support, and lots more, check it out Hot smile