Monday, December 19, 2011

MongoDB Experiment

This example shows how to connect to a mogoDB database using the mongo-csharp-driver (git checkout). The code below demonstrates how to insert data into a collection, and retrieve a collection and deserialize the data.


using System;
using System.Collections.Generic;
using System.Linq;
using MongoDB.Driver;

namespace Console1
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            //BsonClassMap.RegisterClassMap();
            RunCode();
        }

        private static void RunCode()
        {
            var settings = new MongoServerSettings();
            int portNumber=999;
            settings.Server = new MongoServerAddress("mongoServer.com", portNumber);
            settings.DefaultCredentials = new MongoCredentials("username", "password", false);
            MongoServer mongo = MongoServer.Create(settings);
            var dbSettings = new MongoDatabaseSettings(mongo, "databaseName");
            MongoDatabase mongoDb = mongo.GetDatabase(dbSettings);
            //this lists the names of the collections
            foreach (string collectoinName in mongoDb.GetCollectionNames())
            {
                Write(collectoinName);
            }

            
            AddCrimeTomongoDbAndReadBackTheList(mongoDb);

            Write("Press x to exit, or any other key to Loop!");
            ConsoleKeyInfo key = Console.ReadKey();
            if (key.KeyChar != 'x')
                RunCode();
        }

        private static void AddCrimeTomongoDbAndReadBackTheList(MongoDatabase db)
        {
            var crime = new Crime
                            {
                                Id = Guid.NewGuid(),
                                When = DateTime.Now,
                                Where = "Down town",
                                NatureOfCrime = "Purse snatching",
                                WitnessNames = new List {"Larry", "Curly", "Moe"}
                            };
            db.GetCollection("Crime").Save(crime);
            List crimes = db.GetCollection("Crime").FindAllAs().ToList();
            int i = 0;
            foreach (Crime c in crimes)
            {
                i++;
                Write(string.Format("item {2}: {1} (id {0})", c.Id, c.NatureOfCrime, i));
            }
        }

        private static void Write(string str)
        {
            Console.WriteLine(str);
        }
    }

    //this is a sample class which will be saved into mongoDB
    public class Crime
    {
        public Guid Id { get; set; }
        public string NatureOfCrime { get; set; }
        public string Where { get; set; }
        public DateTime When { get; set; }
        public List WitnessNames { get; set; }
    }
}

Wednesday, December 14, 2011

jsfiddle.net

If you are a javascript/html/css developer, you've got to see what these guys at jsfiddle.net have done.

Monday, November 21, 2011

Expression Blend 4 Step by Step By Elena Kosinska and Chris Leeds

A good tutorial for those who want to learn about Expression Blend and Silverlight

GetSkeleton

Skeleton is a small collection of CSS & JS files that can help you rapidly develop sites that look beautiful at any size, be it a 17" laptop screen or an iPhone. Skeleton is built on three core principles:



  1. Responsive Grid Down To Mobile
  2. Fast to Start
  3. Style Agnostic
Read more about it here: http://www.getskeleton.com/

DotNetPerls

Sunday, November 20, 2011

The Tao of Programming

If you haven't seen it yet, you should check it out here.  Beware that you don't start speaking like the book.  It might annoy some people.

Tuesday, August 16, 2011

Sample Multi-threading in ASP.NET C# console applicatoin

Do download a zip file project at my google code page.

Some notes about starting up threads:
  • Use QueueUserWorkItem to create a thread in a pool.  This has the added benefit of the .NET framework doing some checking for you to see if the CPU is able to handle more work.  If it isn't too busy, it will fire up a thread for you.  It has more overhead than ThreadStart, but is scalable.
  • Use System.ComponentModel.BackgroundWorker for cross-thread communication.  The benefits include:
    • Progress report
    • Cancellation pending property so  you can exit gracefuly.

Friday, July 15, 2011

Sunday, May 01, 2011

Online Web Service Scheduler (WSS)


On their website, the service is described as "an online cron service that can execute your important custom scripts remotely. It's easy to use. Just login and add the URL of the web service or script (PHP, ASP, CGI) and the time you would like the service to run."

http://www.wsscheduler.com

Monday, January 24, 2011

Posting to WCF Service

This example shows how to post to a WCF service. Also, for further notes on how to decorate your webmethod, see this page.

If you are having trouble accessing your WCF service, you should check your service url like so:

PathToService/NameOfYourServiceFile.svc/jsdebug

Thursday, January 20, 2011

Thursday, January 06, 2011

Read Please

This program reads to you any text you paste into it.  Great for listening to a long article while you do something else.

I was a fan of the Opera browser's read aloud feature, but it has a problem of breaking due to maintenance releases of the browser.  So ReadPlease is a great substitute.

Tuesday, January 04, 2011

Freesnap Tool Gives WinXP the SNAP of 7

FreeSnap allows Windows XP to get the snap behavriour native to Windows 7.

Visit the developer's website here.