Friday, October 06, 2006

Interested On How These Invisible Little Things Look Like?

When I was a child I really enjoyed studying different little things like leaves, insects and spores with microscope.

To pity that there were no such sites like this in that time.

Windows Live Writer Team Appears To Be Of Non Microsoft Origin

Rob Mensching recently met Windows Live Writer team. And it appears that this team was acquired by Microsoft.

Microsoft tries its best to enhance its Live initiative. Well, with such brilliant teams we can expect more interesting stuff to be released under Live.

Tuesday, September 19, 2006

Does your network application support IPv6?

One of the ways to find out about this is to add an IPv6 address to you computer, and make the application use it. If you observe no crashes and connectivity is fine, then you're okay and there is no need to read further :8-).

What can you do to be IPv6 "compatible"? At first start from here.

If your application is managed one and you use sockets for network I/O then the only thing you should remeber is to check IpAddress.AddressFamily property.

In code this can look like this (error checking is removed for simplicity's sake)

public void Connect(string host, int port)


{

IPHostEntry ipHostEntry = Dns.GetHostEntry(host);

//and now we're creating socket with appropriate address family

IPEndPoint ipEP = new IPEndPoint(ipHostEntry.AddressList[0], port);

Socket socket = new Socket(ipEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

socket.Connect(ipEP);

}



Many developers are creating sockets assuming that there will always be IPv4. Generally this works as IPv6 addresses are not common these days. But times are changing and we have to be prepared...

Wednesday, September 06, 2006

Finance news from Ukraine

Once again I had to use Feedburner to convert feed fomat. The trick is the same as described here. This time it was http://news.finance.ua/ua/rss. I'm using IE7 RC1 and it doesn't recognize format of this feed.

So, here is new feed http://feeds.feedburner.com/Financeua in the RSS 2.0 format.

.NET: tricky enums with custom attributes

Sometimes, when we want to serialize data type we use attributes to give additional description for type itself and its fields.

Imagine that the type we want to serialize has enum field (SampleEnum)


public class ExtendedInfoAttribute : Attribute
{
string description;

public string Description
{
get { return description; }
set { description = value; }
}

}



public enum SampleEnum
{
[ExtendedInfo(Description="First value")]
EnumValueOne,
[ExtendedInfo(Description = "Second value")]
EnumValueTwo
}



ExtendedInfo attribute provides additional info about enum fields. When serializing this attribute value can be used to provide some additional info about enum fields.


So, what's so special about getting these attribute values? Well, nothing special if you known where to look for :8-)

//errors checking is omitted for clarity
SampleEnum sEnum = SampleEnum.EnumValueTwo;

Type type = sEnum.GetType();
FieldInfo fieldInfo = type.GetField(Enum.GetName(type, sEnum));
ExtendedInfoAttribute[] attrs = (ExtendedInfoAttribute[])fieldInfo.GetCustomAttributes(
typeof(ExtendedInfoAttribute), false);
Console.WriteLine(attrs[0].Description);

Sunday, September 03, 2006

Saturday, August 19, 2006

HTTP: Proxy Design Considerations.

At first let’s make short description of what HTTP proxy does.

Basically, it receives HTTP requests and routes them to remote web server or another proxy.

How does proxy know where to send requests?
Well, in order to known that proxy has to parse incoming HTTP requests and obtain URI part of the HTTP request.

Note:
HTTP request consists of header line, headers and values and possibly content. Header line with headers is terminated with double CRLF sequence ( CRLF stands for carriage return and line feed or  \r\n escape characters). Then may or may not come content (it depends on request type GET, POST etc).

So, the workflow will be: proxy receives HTTP request, parses/analyzes it and routes to appropriate server or another proxy.

How efficient is that?

Well, if we want proxy with ability to process HTTP content, then we'll design it in such a way that whole HTTP request's content will be received by proxy and then parsed/analyzed ( I will not cover that in this post). But if we want our proxy to merely route requests then the approach described above will be very inefficient. Because total size of HTTP request can be quite large, receiving it completely can lead to great memory consumption.

Solution here can be quite simple. HTTP header contains all the info proxy needs to route the request. So, proxy can be designed in such a way that it will receive only full HTTP header, parse/analyze it.  And if there is content pending it will be immediately routed to destination pointed out by request's header.
An indication of that fact that content is pending is: we have HTTP POST request, Content-Length header is bigger then 0. 

 This approach will be more efficient, since it assumes that less memory will be allocated to process one HTTP request. Also this approach will speed up traffic through proxy.

Thursday, August 10, 2006

Windows Service Start Issues. .NET ServiceBase class

In .NET world Windows Service is represented by ServiceBase class
from System.ServiceProcess namespace. Service developer inherits her
own class from ServiceBase and overrides OnStart and OnStop methods.

Then to start service ServiceBase.Run(...) call is needed and here comes
an interesting part...

Usually process-wide initialization occurs in OnStart overload.
But what will happen if that initialization takes longer than 30 seconds?
( 30 sec. is the default time that Service Control Manager - SCM will wait
for the service to start ).

There are to ways not to get in troubles here:
(1) ask for more time to finish initialization, or
(2) do process-wide initialization in separate thread.

Both ways have advantages and disadvantages.
In first approach to ask for more time ServiceBase.RequestAdditionalTime(...) is used. Benefit here is that the code that starts service will know
for sure that service is up and running.

Second approach will give the illusion that service is up and running, while
internal initialization may not be finished. This can cause strange behavior.

First approach can be used when service is interacting with something (sends/receives data etc.).
While second approach will suit best for scenarios where service is a standalone application that is not communicating with anything except SCM :8-)

Monday, July 31, 2006

Back from the army

Finally I'm back from military vacations :8-)

After 2 years of studying in the military faculty, every student has to go to the army. Hopefully, the term is 1 month.

So, I'm back, healty, sun-burnt and ready to work.

Friday, June 30, 2006

Converting RSS feed to different formats using FeedBurner services

So, why should anyone bother converting RSS feed format? The answer is that RSS feeds can have various formats: RSS 1.0, RSS 2.0, Atom 0.3, Atom 1.0, etc. RSS reader has to know these formats and display the feed normally as if its format is the same for all feeds.

At present I’m using SharpReader as my primary RSS reading tool and there is one thing that I’m annoyed with – its memory consumption. I have smth around 180 feeds in my feed list. After SharpReader refreshes them all, its memory consumption rises to more then 200 Mb. It is not appropriate for me.

Recently I've obtained link that lead me to the download page of Internet Explorer 7 Beta3.
Though there was Beta2 out there already for quite long, I didn’t want to bother myself with “raw” product, especially if it is Internet Explorer :8-).

However, now it is Beta3 and I thought why not? Installation was okay. Then I exported RSS feeds from SharpReader into OPML file and imported it into IE.
Import was also fine, feeds hierarchy was preserved, what I really appreciate.

I’ll omit describing some inconveniences with feeds browsing I experienced with IE, and focus myself on the issue that can explain the title of this post :8-).

IE 7 Beta3 supports only several RSS formats!!! I was surprised. Namely, IE doesn’t have support for RDF format.

So, if RDF is not supported I have to convert it to something that is supported, for example RSS 2.0. How to resolve? FeedBurner comes to rescue!

Here are the steps do obtain converted feed:
1) go to http://www.feedburner.com
2) if you have an account there - sign in, if not – register and sign in
3) burn a feed. Put in the url of the feed that has unsupported format
4) after feed is burnt, go to main page, select it and then select “Optimize” tab
5) then select “Convert Format Burner”. This option will let you select appropriate RSS format. Choose “Save” and that’s it, you can use new feed url instead of the old one.

Example of such converted feed is
RDF: http://www.ixbt.com/export/articles.rdf
RSS 2.0: http://feeds.feedburner.com/Ixbt