Saturday, December 15, 2007

Annotation on XObject from LINQ to XML

Annotation is something like tag or helper object on XML node. You could register multiple annotations. It is registered under signature of method which was used for registration. So when you are registering some classes with common interface, cast the registered instance to the interface first!
To get annotation of value type you will need to use typeof() as parameter.
interface IHandler { void Handle(XElement e);}
class CatHandler : IHandler
{
    public void Handle(XElement e) 
    { Console.WriteLine(e.Attribute("Food").Value); }
}
class DogHandler : IHandler
{
    public void Handle(XElement e) 
    { Console.WriteLine(e.Element("Friend").Value); }
}

class Test
{
static void Main(string[] args)
{
    List<XElement> list=new List<XElement>()
    {
        new XElement("Creature", 
            new XElement("Name", "Bijou"), 
            new XAttribute("Food", "milk"),
            new XAttribute("Type", "Cat")),
        new XElement("Creature", 
            new XElement("Name", "Goro"),
            new XElement("Friend", "Reiko"),
            new XAttribute("Type", "Dog"))
    };

    //registration
    foreach (XElement element in list)
    {
        switch(element.Attribute("Type").Value)
        {
        case "Cat" : 
            element.AddAnnotation((IHandler)new CatHandler());
            break;
        case "Dog" : 
            element.AddAnnotation((IHandler)new DogHandler());
            break;
        }
    }

    //usage
    foreach (XElement element in list)
    {
        element.Annotation<IHandler>().Handle(element);
    }
}
}

Thursday, December 6, 2007

Jabber behind corporate firewall at 443

Maybe everyone know it. Until recently I had open all ports to the Internet so I used 5222 and 5223. But now I'm behind some rude firewall. I realized that both Jabber servers I'm using are listening also on port 443! This is conn443.netlab.cz:443 for jabber.cz and talk.google.com:443 for GTalk. So, I'm online again.

Saturday, December 1, 2007

Paranoid Android

By 446F75676C6173204164616D73
2249207468696E6B20796F75206F7567687420746F206B6E6F772049276D2066
65656C696E672076657279206465707265737365642C2220697420736169642E
0A49747320766F69636520776173206C6F7720616E6420686F70656C6573732E
0A224F6820476F642C22206D75747465726564205A6170686F6420616E642073
6C756D70656420696E746F206120736561742E0A2257656C6C2C222073616964
205472696C6C69616E20696E20612062726967687420636F6D70617373696F6E
61746520746F6E652C202268657265277320736F6D657468696E6720746F206F
636375707920796F7520616E64206B65657020796F7572206D696E64206F6666
207468696E67732E220A22497420776F6E277420776F726B2C222064726F6E65
64204D617276696E2C202249206861766520616E20657863657074696F6E616C
6C79206C61726765206D696E642E220A224D617276696E2122207761726E6564
205472696C6C69616E2E0A22416C72696768742C222073616964204D61727669
6E2C20227768617420646F20796F752077616E74206D6520746F20646F3F220A
22476F20646F776E20746F206E756D6265722074776F20656E74727920626179
20616E64206272696E67207468652074776F20616C69656E7320757020686572
6520756E646572207375727665696C6C616E63652E220A576974682061206D69
63726F7365636F6E642070617573652C20616E6420612066696E656C79206361
6C63756C61746564206D6963726F6D6F64756C6174696F6E206F662070697463
6820616E642074696D627265202D206E6F7468696E6720796F7520636F756C64
2061637475616C6C792074616B65206F6666656E6365206174202D204D617276
696E206D616E6167656420746F20636F6E766579206869732075747465722063
6F6E74656D707420616E6420686F72726F72206F6620616C6C207468696E6773
2068756D616E2E0A224A75737420746861743F2220686520736169642E0A2259
65732C222073616964205472696C6C69616E206669726D6C792E0A224920776F
6E277420656E6A6F792069742C222073616964204D617276696E2E