Monday, December 14, 2009

Regular expressions for connection string parsing

Collection of regular expressions for parsing of connection string:
Split to parts:
string regexSplitToParts = "([^=;]*)=([^=;]*)";
RegexOptions options = RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled;
Regex reg = new Regex(regexSplitToParts, options);


Fetch specific part of connection string (e.g. DataSource):
string regexDataSource = "Data\\sSource(\\s)*=(\\s)*(?<DataSourceName>([^;]*))";
RegexOptions options = RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled;
Regex reg = new Regex(regexDataSource, options);

Technorati Tags:

Wednesday, December 02, 2009

Shakespeare - Sonnet 66 – few translations

Samuil Marshak +1 !!! :o)
 
Бессмертный Шекспир
ШЕКСПИР, Сонет 66
Original Перевод Маршака Перевод Пастернака Актуальный перевод

Tired with all these, for restful death I cry, -
As to behold desert a beggar born,
And needy nothing trimm'd in jollity,
And purest faith unhappily forsworn,
And gilded honour shamefully misplac'd,
And maiden virtue rudely strumpeted,
And right perfection wrongfully disgrac'd,
And strength by limping sway disabled,
And art made tongue-tied by autority,
And folly (doctor-like) controlling skill,
And simple truth miscall'd simplicity,
And captive good attending captain ill:

Tired with all these, from these would I be gone,
Save that, to die, I leave my love alone.

Зову я смерть. Мне видеть невтерпеж
Достоинство, что просит подаянья,
Над простотой глумящуюся ложь,
Ничтожество в роскошном одеянье,
И совершенству ложный приговор,
И девственность, поруганную грубо,
И неуместной почести позор,
И мощь в плену у немощи беззубой,
И прямоту, что глупостью слывет,
И глупость в маске мудреца, пророка,
И вдохновения зажатый рот,
И праведность на службе у порока.

Все мерзостно, что вижу я вокруг...
Но как тебя покинуть, милый друг!

Измучась всем, я умереть хочу.
Тоска смотреть, как мается бедняк,
И как шутя живется богачу,
И доверять, и попадать впросак,
И наблюдать, как наглость лезет в свет,
И честь девичья катится ко дну,
И знать, что ходу совершенствам нет,
И видеть мощь у немощи в плену,
И вспоминать, что мысли заткнут рот,
И разум сносит глупости хулу,
И прямодушье простотой слывет,
И доброта прислуживает злу.

Измучась всем, не стал бы жить и дня,
Да другу трудно будет без меня.

Когда ж я сдохну! До того достало,
Что бабки оседают у жлобов,
Что старики ночуют по вокзалам,
Что "православный" значит - бей жидов!
Что побратались мент и бандюган,
Что колесят шестерки в шестисотых,
Что в загс приходят по любви к деньгам,
Что лег народ с восторгом под сексотов.
Что делают бестселлер из говна,
Что проходимец лепит монументы,
Что музыкант играет паханам,
А быдло учит жить интеллигента.

Другой бы сдох к пятнадцати годам,
Но я вам пережить меня не дам!

(с) не я, найдено в сети


Sunday, November 22, 2009

Tuesday, November 17, 2009

Silverlight HTML Control

If you need to display a piece of HTML in your Silverlight application…
Public/open-source Silverlight HTML controls:
Commercial Silverlight HTML controls:
Technorati Tags: ,,

Wednesday, November 11, 2009

Practical tutorial on using Sgen.exe to improve performance of XML serialization startup.

There is an overhead incurred when using serialization in your application, which is caused by generation of a ‘helper’ assembly for each type that is serialized with XmlSerializer (per-process-per-domain). (Btw – this has subtle adverse effect – if you use serialization – your application should have Read/Write permissions to %windir%\temp folder).

This overhead may be avoided by using Sgen.exe tool to pre-generate serialization assemblies.
Basically it should be pretty straightforward, especially if your FooBar.dll assembly for which you pre-generating serialization assembly doesn’t has a lot of references. Unfortunately – if you do have a lot of references – you would have to add them all using /reference:c:\foo1\foo1.dll /reference:c:\foo2\foo2.dll /reference:c:\foo3\foo3.dll ……

Here is a workaround:
To generate serialization assembly manually (could be done as a post-build step):
1) Visual Studio –> Foo.csproj –> Properties –> Build –> Generate Serialization Assembly –> On
You would expect it to work automatically now – but it wouldn’t, or saying it more precisely it would create serialization assembly only if your assembly includes proxy types (e.g. web-services).
Anyway – build your assembly, open MSVC output window and look for sgen.exe line in the end of output.
2) Copy whole sgen.exe line – it would include all the references needed.
3) Remove from it /proxytypes parameter – this will cause sgen.exe to generate serializers for regular types.
4) Add /force parameter to force overwrite of previously created assembly.

Now you almost done except of following caveats:
1) If you have types with the same name in different namespaces you would get error saying something like:
Error: There was an error reflecting type ‘FooNamespace.Foo’ – Types ‘FooNamespace1.Foo’ and ‘FooNamespace2.Foo’ both use the XML type name. Use XML attributes to specify a unique XML name and/or namespace for the type.
To resolve it – differentiate your types by specifying XML namespace:
   1:  using System.Xml.Serialization;


   2:   


   3:  [XmlType(Namespace = "urn:Foo1")]


   4:  [XmlRoot(Namespace = "urn:Foo1")]


   5:  public class Foo{}





2)  If you have properties with readonly or internal properties, or internal types – you would get the following error:


Error … property or indexer cannot be assigned to it is read only.

You may either mark such property with [XmlIgnore] attribute or (for internal) – add following line to AssemblyInfo.cs file:





[assembly: InternalsVisibleTo("<AssemblyName>.XmlSerializers, PublicKeyToken=null")]






You may still add it as part of build process manually modifying MSBUILD script in .csproj file.


Look here or here for details.




Technorati Tags: ,,


Monday, November 09, 2009

How to activate Fusion logs

Technorati Tags:

Fusion.reg file:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion]
"LogPath"="C:\\FusionLogs"
"ForceLog"=dword:00000001