Click here to Skip to main content
Click here to Skip to main content

C# Snippet Sharing with Roslyn and SignalR

, 5 Jun 2013
Rate this:
Please Sign up or sign in to vote.
Share code online with Visual Studio-like interactive features.

Please note

This article is an entry in our Windows Azure Developer Challenge. Articles in this sub-section are not required to be full articles so care should be taken when voting. Create your free Azure Trial Account to Enter the Challenge.

Update :  

The site has launched at http://csharp.io/#/About 

Unfortunately, I was building the site instead of writing.  I don't have time to go back and re-do the completed parts of the contest (which stinks because I'd love to write about knockout.js/SignalR/Azure Websites/Azure SQL).   Also, the app doesn't even apply to the last 2 challenges since I'm not a virtual machine and I don't support mobile.  Needless to say the contest is a wrap for me! 

I just wanted to make an update for anyone interested in the initial idea; I think I've delivered what I promised and more!   

Introduction  

There isn't really a killer code snippet sharing site, and definitely not one that has as many language integrated features as what I'm planning to build in a specifically C# snippet sharing site.  The initial release will have syntax highlighting, intellisense-like documentation on hovering for built in types and methods, and real time updates with WebSockets.   

The goal is to make a code snippet sharing site for C# with enough C# specific features to stand above other snippet sharing sites.  

The Application    

Here's an example of a bit of pasted code with code formatting.  All of the data is sent to a SignalR hub, run through Roslyn, and the nicely formatted HTML is sent back.   

Snippet sites like github's gist are excellent, but I'd like to expand upon the code snippet uploading model by adding features that work specifically with C#. I'm hoping this will allow users to analyze short pieces of code more easily than sites that are no more than a text dump of the code you pasted in.   Being able to hover over a Base Class Library or Framework Class Library type and seeing the documentation is something I've never seen on any site. 

There will be enough social features to make it an enjoyable site to spend some time on (and hopefully learn) but not so social it's overbearing on the experience of reading useful code.   

I'd also like to be able to allow users to search by language feature / usage. (Example : show me  all snippets that use implicitly typed local variables by utilizing 'var') 

Background

A snippet sharing site (with Visual Studio-like features) would not be very feasible without the creation of Roslyn.  Roslyn is the white-boxing of the C# compiler to  allow you to write code that makes sense of C# code. I've used Roslyn in the past to write a Visual Studio plugin that will find opportunities to make your code more concise and refactor out methods.     

Why Windows Azure

WebSocket support, no upfront cost, and no server configuration are the major reasons I chose Azure. Having to worry about security only at the application level is a major plus for me as well.

Azure SQL Database 

Azure SQL Database will be utilized as the data store. The confidence of security out of the box (IP restricted by default), hot standbys in the same data center, and the fact that Azure SQL database is mostly compatible with SQL Server 2012 sold me on it.  Being able to deploy to a non-Azure environment gives peace of mind, even if it will likely never happen. 

Libraries/Frameworks to be utilized  

  • ASP.NET MVC 4 
  • SignalR (hubs) 
  • Knockout.js 
  • Metro UI CSS 
  • Entity Framework 5
  • ELMAH 

Update : 

Now that the contest has been extended, here are a few screenshots showcasing more design.  I also forgot to mention that I'm using CoffeeScript for the JavaScript!   Recent snippets update in real time (and as time goes on, older ones fall off the front page) 

Okay Final Update screenshot before the next leg of the contest.  Can't wait to deploy to Azure!  


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

BrianRosamilia

United States United States
.NET Developer and blogger at newmodifier.com
Follow on   Twitter

Comments and Discussions

 
GeneralMy vote of 5 Pinprofessionalroscler5-May-13 0:08 
GeneralMy vote of 5 PinmemberRumnha27-Apr-13 17:31 
GeneralRe: My vote of 5 PinmemberBrianRosamilia29-Apr-13 14:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 5 Jun 2013
Article Copyright 2013 by BrianRosamilia
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid