Facing new challenges everyday

ByteBuffer implementation for dotNET

August 2nd, 2009

Today I created a dotNET version of ByteBuffer class, with this class you can easily read and write data into byte array. You can get the source file here.

Here’s an example about how to use ByteBuffer class:

Program.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestCode
{
    class Program
    {
        static void Main(string[] args)
        {
            ByteBuffer buffer = new ByteBuffer(20);

            buffer.AddInt(10);
            buffer.AddString("Test");
            buffer.AddLong(10000);
            buffer.AddInt(350);
            buffer.AddChar('c');
            buffer.AddDouble(10000.325);

            Console.WriteLine(buffer.ReadInt());
            Console.WriteLine(buffer.ReadString());
            Console.WriteLine(buffer.ReadLong());
            Console.WriteLine(buffer.ReadInt());
            Console.WriteLine(buffer.ReadChar());
            Console.WriteLine(buffer.ReadDouble());

            Console.ReadLine();
        }
    }
}

My implementation doesn’t contains all features found on Java version of the same class, but can help on most cases.

DZoneGoogle BookmarksFacebookEvernoteLinkedInDeliciousShare

Working with Mongo Wire Protocol on C#

August 2nd, 2009

Last saturday I started a small C# project when I try to send a message to MongoDB, after few hours working on it I finally could see the database receiving the message sucessfully.

Here’s the code that I used to send the message to database:

Program.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;

namespace Mongo.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            //Creating a socket connection to mongodb instance
            Socket socket = new Socket(AddressFamily.InterNetwork,
                  SocketType.Stream, ProtocolType.Tcp);
            socket.Connect(Dns.GetHostAddresses("192.168.0.103"), 27017);

            //This is the message to be sent to mongodb instance
            List<byte> message = new List<byte>();
            message.AddRange(Encoding.UTF8.GetBytes("This is a test."));
            message.Add(0x00);

            //Each message to be sent to mongodb must have a header like
            //where we can specify which operation will be performed on server.
            List<byte> header = new List<byte>();
            header.AddRange(BitConverter.GetBytes(16 + message.Count));
            header.AddRange(BitConverter.GetBytes(1));
            header.AddRange(BitConverter.GetBytes(0));
            header.AddRange(BitConverter.GetBytes(1000));

            //Now we must put the message header a body together before send it
            // to the server.
            List<ArraySegment<byte>> buffer = new List<ArraySegment<byte>>();
            buffer.Add(new ArraySegment<byte>(header.ToArray()));
            buffer.Add(new ArraySegment<byte>(message.ToArray()));

            //Send the message to the server
            socket.Send(buffer);

            //Close connection
            socket.Close();
        }
    }

A very good documentation about how to write a MongoDB driver can be found here.

DZoneGoogle BookmarksFacebookEvernoteLinkedInDeliciousShare

ASP.NET Basics with Visual Studio Web Developer 2008

January 8th, 2009

ASP.NET is one of the key technologies behind .NET Framework, you can easily create web applications to collect data entered by user by placing some input controls in your page, once the data is entered and the page is submited, you can read data on server side by accessing specific properties in your controls.

This article will give an idea about how to create a simple ASP.NET project, it will have a page that contains some textboxes and a button, this button will have an event attached to it, we will add some code in this event to store user entered data into an SQLite database using its ADO.NET provider that can be downloaded here.

I’m assuming that you already have installed Visual Studio Web Developer Express 2008 in your computer, if not, you must download both from this site.

Now you must start Visual Studio Web Developer Express 2008 and then go to File->New Web Site… menu like we have in the image below:

new_project_menu
(more…)

DZoneGoogle BookmarksFacebookEvernoteLinkedInDeliciousShare

What you must avoid in LINQ to SQL one to many associations

December 8th, 2008

Last saturday I spent few hours trying to figure out the reason of a very annoying bug that was happening with my WCF Service, for several times if got the same error: “The underlying connection was closed: The connection was closed unexpectedly.”.

The root cause of this bug was a LINQ to SQL query in my WCF service that was retuning a large list of objects, I tried to set maxItemsInObjectGraph of dataContractSerializer, but with no success. My LINQ model contains some onetomany associations that was generating both child and parent properties, this setting was causing the generation of infinite number of object references in my LINQ resultset, after disabling the generation of child property of all onetomany associations the error gone.

DZoneGoogle BookmarksFacebookEvernoteLinkedInDeliciousShare

Back with Windows Mobile development

May 19th, 2008

Today I’m working with four mobile platforms:

At work:

  • Symbian

At home:

  • J2ME
  • Qtopia
  • Windows Mobile

After some years without touch in Visual Studio .NET and a little far away from Windows Mobile development, I’m finally back, now working on a small project for use in restaurants using a wi-fi connection.

I’ll post some of my challenges in this project when possible.

DZoneGoogle BookmarksFacebookEvernoteLinkedInDeliciousShare

Visitors Around the World

Polls

How Is My Site?

View Results

Loading ... Loading ...

Categories

Meta

Links

hosted by easy2use.net