Skip to content

Instantly share code, notes, and snippets.

View follesoe's full-sized avatar
📱

Jonas Follesø follesoe

📱
View GitHub Profile
@follesoe
follesoe / ToJSON.cs
Created December 24, 2010 14:57
Bridging windows and web applications using JSON
public static string ToJSON<T>(this T obj)
{
MemoryStream ms = new MemoryStream();
try
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
serializer.WriteObject(ms, obj);
return Encoding.UTF8.GetString(ms.ToArray());
}
finally
@follesoe
follesoe / AsyncUnitTestManualResetEvent.cs
Created December 24, 2010 14:50
Unit testing event-based asynchronous code
[Test]
public void TestCalculations()
{
// A simple web service offering basic aritmetich operations
Service service = new Service();
// Test data...
int a = 10;
int b = 10;
@follesoe
follesoe / VirtualEarthInterop.cs
Created December 24, 2010 14:45
Integrating Virtual Earth with Outlook 2007
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Outlook.ContactItem currentContact = (Outlook.ContactItem)this.OutlookItem;
string address = currentContact.BusinessAddress.Replace("\r\n", ",");
ExecuteScript("FindLocation", address, currentContact.FullName, currentContact.BusinessAddress);
}
private void ExecuteScript(string scriptName, params object[] parameters)
{
webBrowser.Document.InvokeScript(scriptName, parameters);
@follesoe
follesoe / VirtualEarthOutlook.html
Created December 24, 2010 14:43
Integrating Virtual Earth with Outlook 2007
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Virtual Earth</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body
{
margin: 0px;
padding: 0px;
@follesoe
follesoe / ProtocolListener.cs
Created December 24, 2010 14:42
Using protocol handlers as a ultra thin layer of integration
/// <summary>
/// Starts the Http Listener on a background thread.
/// </summary>
private void StartHttpListener()
{
if (HttpListener.IsSupported)
{
try
{
//Creates a HttpListener with two urls for RSS and HTML.
@follesoe
follesoe / ProtocolHandlerDemoClient.cs
Created December 24, 2010 14:39
Using protocol handlers as a ultra thin layer of integration
/// <summary>
/// The Main class of the application.
/// </summary>
static class Program
{
// Private members
private static MainForm mainForm;
/// <summary>
/// The main entry point for the application.
@follesoe
follesoe / RegistryCode.cs
Created December 24, 2010 14:37
Using protocol handlers as a ultra thin layer of integration
RegistryKey helpDesk = Registry.ClassesRoot.CreateSubKey("HelpDesk");
helpDesk.SetValue("", "URL:HelpDesk Protocol");
helpDesk.SetValue("URL Protocol", "");
RegistryKey defaultIcon = helpDesk.CreateSubKey("DefaultIcon");
defaultIcon.SetValue("", Path.GetFileName(Application.ExecutablePath));
RegistryKey shell = helpDesk.CreateSubKey("shell");
RegistryKey open = shell.CreateSubKey("open");
RegistryKey command = open.CreateSubKey("command");
@follesoe
follesoe / JavaScriptIntellisense.js
Created December 24, 2010 14:34
JavaScript IntelliSense for the Vista Sidebar Object Model
System.Gadget = function()
{
/// <summary>Defines methods, events, and properties that are used to specify gadget configuration options in the Windows Sidebar environment.</summary>
/// <field name="background" type="String">Used in a gadget to set the background image using a file path or to get the file name of the current background image.</field>
/// <field name="docked" type="Boolean">Called from within a gadget to determine if the gadget making the script call is docked.</field>
/// <field name="name" type="String">Used from within a gadget as a means to determine the gadget name as specified in the gadget manifest file.</field>
/// <field name="opacity" type="Number" integer="true">Called from within a gadget to specify the percentage of opacity as an integer.</field>
/// <field name="path" type="String">Called from within a gadget to display the file path for the gadget.</field>
/// <field name="platformVersion" type="String">Called from within a gadget to retrieve the vers
@follesoe
follesoe / SqlCodeSnippet.xml
Created December 24, 2010 14:33
Re-discovering code snippets
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Execute Sql Data Reader</Title>
<Author>Jonas Follesø</Author>
<Description>A standard way to execute a stored procedure returning a reader</Description>
<HelpUrl>http://jonas.follesoe.no</HelpUrl>
<Shortcut>reader</Shortcut>
<SnippetTypes>
@follesoe
follesoe / SimpleSqlCode.cs
Created December 24, 2010 14:32
Re-discovering code snippets
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString))
{
SqlCommand command = new SqlCommand("GetItems", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@author", "Jonas Folleso");
using (command)
{
command.Connection.Open();
using (SqlDataReader reader = command.ExecuteReader())