<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tamir Khason - Just code &#187; Work process</title>
	<atom:link href="http://khason.net/tag/work-process/feed/" rel="self" type="application/rss+xml" />
	<link>http://khason.net</link>
	<description>Take care of the sense, and the sounds will take care of themselves.</description>
	<lastBuildDate>Sun, 08 Nov 2009 18:24:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Quick IT tip: How to build bootable USB stick</title>
		<link>http://khason.net/itpro/quick-it-tip-how-to-build-bootable-usb-stick/</link>
		<comments>http://khason.net/itpro/quick-it-tip-how-to-build-bootable-usb-stick/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 11:55:12 +0000</pubDate>
		<dc:creator>Tamir</dc:creator>
				<category><![CDATA[ITPRO]]></category>
		<category><![CDATA[DEV]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Windows Embedded]]></category>
		<category><![CDATA[Work process]]></category>

		<guid isPermaLink="false">http://khason.net/itpro/quick-it-tip-how-to-build-bootable-usb-stick/</guid>
		<description><![CDATA[Because of my main job and lack of human resources there, I invest less and less in community. Thus I lost my MVP title. Sorry, guys. Also a ton of management tasks in big company prevents me from actual coding. However I am still able to find some time for doing “real” things such as [...]

<p/>]]></description>
			<content:encoded><![CDATA[<p>Because of my main job and <a href="/tag/better-place/" target="_blank">lack of human resources</a> there, I invest less and less in community. Thus I <a href="http://twitter.com/tamir/status/4638500894" target="_blank">lost my MVP title</a>. Sorry, guys. Also a ton of management tasks in big company prevents me from actual coding. However I am still able to find some time for doing “real” things such as <a href="http://connect.microsoft.com/windowsembedded" target="_blank">Windows Embedded Standard 2011</a> image building. Thus today I will explain how to build <a href="http://www.bootdisk.com/pendrive.htm" target="_blank">bootable flash USB disk</a> with a couple of simple commands and without <a href="http://www.askvg.com/a-bootable-usb-utility-to-create-bootable-usb-drive-to-install-windows-vista-server-2008-and-7/" target="_blank">using special utilities</a>. </p>
<p>&#160;<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="World first USB drive by Trek Technology" border="0" alt="World first USB drive by Trek Technology" src="http://khason.net/images/2009/10/image.png" width="186" height="150" /> </p>
<p>Why to use bootable USB instead of regular <a href="http://en.wikipedia.org/wiki/Polycarbonate" target="_blank">CD or DVD ROM</a>? Well, it is more convenience, takes less storage, faster and fully recycle. So let’s start.</p>
<p>1. Insert USB flash drive <img src='http://khason.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />     <br />2. Run command prompt shell as Administrator (just in case the keyboard shortcut for “Run as Administrator” is Ctrl+Alt+Shift)     <br />3. Type “<strong>diskpart</strong>” to run Microsoft DiskPart utility. </p>
<blockquote><p>C:\Windows\system32&gt;diskpart </p>
<p>Microsoft DiskPart version 6.1.7600      <br />Copyright (C) 1999-2008 Microsoft Corporation.       <br />On computer: TAMIRK-DEV</p>
</blockquote>
<p>4. List your disks by typing in “<strong>list disk</strong>” or for those who like it shorter (like me) “<strong>list dis</strong>”</p>
<blockquote><p>DISKPART&gt; lis dis </p>
<p>&#160; Disk ###&#160; Status&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Size&#160;&#160;&#160;&#160; Free&#160;&#160;&#160;&#160; Dyn&#160; Gpt      <br />&#160; &#8212;&#8212;&#8211;&#160; &#8212;&#8212;&#8212;&#8212;-&#160; &#8212;&#8212;-&#160; &#8212;&#8212;-&#160; &#8212;&#160; &#8212;       <br />&#160; Disk 0&#160;&#160;&#160; Online&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 149 GB&#160; 1024 KB       <br />&#160; Disk 1&#160;&#160;&#160; Online&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 75 GB&#160;&#160;&#160;&#160; 2 GB       <br />&#160; Disk 2&#160;&#160;&#160; Online&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 3814 MB&#160;&#160;&#160;&#160;&#160; 0 B       <br />&#160; Disk 3&#160;&#160;&#160; No Media&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0 B&#160;&#160;&#160;&#160;&#160; 0 B       <br />&#160; Disk 4&#160;&#160;&#160; No Media&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0 B&#160;&#160;&#160;&#160;&#160; 0 B       <br />&#160; Disk 5&#160;&#160;&#160; Online&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 14 GB&#160;&#160;&#160;&#160;&#160; 0 B</p>
</blockquote>
<p>5. Identify your flash drive (in my case it is Disk 5)    <br />6. Select this drive to mark it for work by using “<strong>select disk</strong> 5” or “<strong>sel dis</strong> 5” command</p>
<blockquote><p>DISKPART&gt; sel dis 5</p>
<p>Disk 5 is now the selected disk.</p>
</blockquote>
<p>7. Clean it (this will delete everything on your disk drive, so be careful) by using “<strong>clean</strong>” or “<strong>cle</strong>” command.</p>
<blockquote><p>DISKPART&gt; cle</p>
<p>DiskPart succeeded in cleaning the disk.</p>
</blockquote>
<p>8. Create primary partition &#8211; “<strong>create partition primary</strong>” or “<strong>cre par pri</strong>”</p>
<blockquote><p>DISKPART&gt; cre par pri</p>
<p>DiskPart succeeded in creating the specified partition.</p>
</blockquote>
<p>9. Select new partition &#8211; “<strong>select partition 1</strong>” or “<strong>sel par 1</strong>”</p>
<blockquote><p>DISKPART&gt; sel par 1</p>
<p>Partition 1 is now the selected partition.</p>
</blockquote>
<p>10. Mark it as Active partition &#8211; “<strong>active</strong>” or “<strong>act</strong>”</p>
<blockquote><p>DISKPART&gt; act</p>
<p>DiskPart marked the current partition as active.</p>
</blockquote>
<p>11. Format &#8211; “<strong>format fs=ntfs quick</strong>” or “<strong>for fs=ntfs quick</strong>”</p>
<blockquote><p>DISKPART&gt; for fs=ntfs quick</p>
<p>&#160; 100 percent completed </p>
<p>DiskPart successfully formatted the volume.</p>
</blockquote>
<p>12. And finally my favorite command &#8211; “<strong>assign</strong>” or “<strong>ass</strong>” to mark it ready and create mount point</p>
<blockquote><p>DISKPART&gt; ass</p>
<p>DiskPart successfully assigned the drive letter or mount point.</p>
</blockquote>
<p>13. Exit &#8211; “exit” or “exi” to return to command shell</p>
<blockquote><p>DISKPART&gt; exi</p>
<p>Leaving DiskPart&#8230;</p>
</blockquote>
<p>Now your thumb drive is ready and bootable. So you can start copying files from ISO image into it.</p>
<p>Other option is to work with volumes rather than with disks. The all difference is in steps 4-6. Instead of “<strong>lis dis</strong>” use “<strong>lis vol</strong>” and instead of “<strong>sel dis</strong>” use “<strong>sel vol</strong>”. Maybe it is more convenience way of work because in this case you can identify partitions by labels and sizes rather than by sizes only.</p>
<blockquote><p>DISKPART&gt; lis vol </p>
<p>&#160; Volume ###&#160; Ltr&#160; Label&#160;&#160;&#160;&#160;&#160;&#160;&#160; Fs&#160;&#160;&#160;&#160; Type&#160;&#160;&#160;&#160;&#160;&#160;&#160; Size&#160;&#160;&#160;&#160; Status&#160;&#160;&#160;&#160; Info      <br />&#160; &#8212;&#8212;&#8212;-&#160; &#8212;&#160; &#8212;&#8212;&#8212;&#8211;&#160; &#8212;&#8211;&#160; &#8212;&#8212;&#8212;-&#160; &#8212;&#8212;-&#160; &#8212;&#8212;&#8212;&#160; &#8212;&#8212;&#8211;       <br />&#160; Volume 0&#160;&#160;&#160;&#160; E&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DVD-ROM&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0 B&#160; No Media       <br />&#160; Volume 1&#160;&#160;&#160;&#160; G&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DVD-ROM&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0 B&#160; No Media       <br />&#160; Volume 2&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System Rese&#160; NTFS&#160;&#160; Partition&#160;&#160;&#160; 100 MB&#160; Healthy&#160;&#160;&#160; System       <br />&#160; Volume 3&#160;&#160;&#160;&#160; C&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; NTFS&#160;&#160; Partition&#160;&#160;&#160;&#160; 68 GB&#160; Healthy&#160;&#160;&#160; Boot       <br />&#160; Volume 4&#160;&#160;&#160;&#160; D&#160;&#160; DATA&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; NTFS&#160;&#160; Partition&#160;&#160;&#160;&#160; 80 GB&#160; Healthy       <br />&#160; Volume 5&#160;&#160;&#160;&#160; F&#160;&#160; READYBOOST&#160;&#160; FAT&#160;&#160;&#160; Removable&#160;&#160; 3812 MB&#160; Healthy       <br />&#160; Volume 6&#160;&#160;&#160;&#160; H&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Removable&#160;&#160;&#160;&#160;&#160;&#160; 0 B&#160; No Media       <br />&#160; Volume 7&#160;&#160;&#160;&#160; I&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Removable&#160;&#160;&#160;&#160;&#160;&#160; 0 B&#160; No Media       <br />&#160; Volume 8&#160;&#160;&#160;&#160; K&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; NTFS&#160;&#160; Removable&#160;&#160;&#160;&#160; 14 GB&#160; Healthy</p>
</blockquote>
<p>If you already copied your image into disk, you can mark MBR by using special utility called <a href="http://technet.microsoft.com/en-us/library/cc749177(WS.10).aspx" target="_blank">BootSect.exe</a> shipped with WAIK. In our case (with Windows 7 embedded), you’ll have to update master boot code to use BOOTMGR (Vista and up) rather than NTLDR (XP and down)</p>
<blockquote><p>BOOTSECT.EXE /NT60 K: /mbr</p>
</blockquote>
<p>We done, have a good day and be good people. Additional information regarding USB core guys from MS can be archived from <a href="http://blogs.msdn.com/usbcoreblog/" target="_blank">their brand new blog</a> (hope it will be up to date).</p>
<p>At the end, just you to know how are CDs make by Discovery Channel    </p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/O3FQzwNzUE4&amp;hl=en&amp;fs=1&amp;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/O3FQzwNzUE4&amp;hl=en&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>


<p/>]]></content:encoded>
			<wfw:commentRss>http://khason.net/itpro/quick-it-tip-how-to-build-bootable-usb-stick/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>INotifyPropertyChanged auto wiring or how to get rid of redundant code</title>
		<link>http://khason.net/dev/inotifypropertychanged-auto-wiring-or-how-to-get-rid-of-redundant-code/</link>
		<comments>http://khason.net/dev/inotifypropertychanged-auto-wiring-or-how-to-get-rid-of-redundant-code/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 19:43:41 +0000</pubDate>
		<dc:creator>Tamir</dc:creator>
				<category><![CDATA[DEV]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Work process]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://khason.net/dev/inotifypropertychanged-auto-wiring-or-how-to-get-rid-of-redundant-code/</guid>
		<description><![CDATA[For the last week most of WPF disciples are discussing how to get rid of hardcoded property name string inside INotifyPropertyChanged implementation and how to keep using automatic properties implementation but keep WPF binding working. The thread was started by Karl Shifflett, who proposed interesting method of using StackFrame for this task. During this thread [...]


Related posts:<ol><li><a href='http://khason.net/dev/read-singleton-approach-in-wpf-application/' rel='bookmark' title='Permanent Link: Real singleton approach in WPF application'>Real singleton approach in WPF application</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>For the last week most of <a title="RSS feed of all disciples" href="http://pipes.yahoo.com/pipes/pipe.run?_id=Jp_ob_fn3RGFP6DnBRNMsA&amp;_render=rss" rel="rss" target="_blank">WPF disciples</a> are discussing how to get rid of hardcoded property name string inside <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx" target="_blank">INotifyPropertyChanged</a> implementation and how to keep using automatic properties implementation but keep WPF binding working. The thread was started by Karl Shifflett, <a href="http://karlshifflett.wordpress.com/2009/08/02/inotifypropertychanged-how-to-remove-the-property-name-string-code-smell/" target="_blank">who proposed interesting method</a> of using <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stackframe.aspx" target="_blank">StackFrame</a> for this task. During this thread other methods were proposed including code snippets, R#, <a href="http://ayende.com/Blog/archive/2009/08/08/an-easier-way-to-manage-inotifypropertychanged.aspx" target="_blank">Observer Pattern</a>, <a href="http://www.codeproject.com/KB/WPF/CinchII.aspx#Better_INPC" target="_blank">Cinch framework</a>, <a href="http://mbrownchicago.spaces.live.com/blog/cns!2221DC39E0C749A4!1285.entry" target="_blank">Static Reflection</a>, <a href="http://danielvaughan.orpius.com/post/Property-Change-Notification-using-a-Weak-Referencing-Strategy.aspx" target="_blank">Weak References</a> and others. I also proposed the method we’re using for our classes and promised to blog about it. So the topic today is how to use <a href="http://www.postsharp.org" target="_blank">PostSharp</a> to wire automatic implementation of INotifyPropertyChanged interface based on automatic setters only.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="My 5 ¢" border="0" alt="My 5 ¢" src="http://khason.net/images/2009/08/image1.png" width="483" height="337" /> </p>
<p>So, I want my code to looks like this:</p>
<blockquote><p>public class AutoWiredSource {      <br />&#160;&#160; public double MyProperty { get; set; }       <br />&#160;&#160; public double MyOtherProperty { get; set; }       <br />}</p>
</blockquote>
<p>while be fully noticeable about any change in any property and makes me able to bind to those properties.</p>
<blockquote><p>&lt;StackPanel DataContext=&quot;{Binding Source={StaticResource source}}&quot;&gt;      <br />&#160;&#160;&#160; &lt;Slider Value=&quot;{Binding Path=MyProperty}&quot; /&gt;       <br />&#160;&#160;&#160; &lt;Slider Value=&quot;{Binding Path=MyProperty}&quot; /&gt;       <br />&lt;/StackPanel&gt;</p>
</blockquote>
<p>How to achieve it? How to make compiler to replace my code with following?:</p>
<blockquote><p>private double _MyProperty;      <br />public double MyProperty {       <br />&#160;&#160; get { return _MyProperty; }       <br />&#160;&#160; set {       <br />&#160;&#160;&#160;&#160;&#160; if (value != _MyProperty) {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _MyProperty = value; OnPropertyChanged(&quot;MyProperty&quot;);       <br />&#160;&#160;&#160;&#160;&#160; }       <br />&#160;&#160; }       <br />}       <br />public event PropertyChangedEventHandler PropertyChanged;       <br />internal void OnPropertyChanged(string propertyName) {       <br />&#160;&#160; if (string.IsNullOrEmpty(propertyName)) throw new ArgumentNullException(&quot;propertyName&quot;); </p>
<p>&#160;&#160; var handler = PropertyChanged as PropertyChangedEventHandler;      <br />&#160;&#160; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));       <br />}</p>
</blockquote>
<p>Simple: to use aspect oriented programming to inject set of instructions into pre-compiled source.</p>
<p>First of all we have to build some attribute will be used for marking classes requires change tracking. This attribute should be combined (compound) aspect to include all aspects used for change tracking. All we’re doing here is to get all set methods to add composition aspect to</p>
<blockquote><p>[Serializable, DebuggerNonUserCode, AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class, AllowMultiple = false, Inherited = false),      <br />MulticastAttributeUsage(MulticastTargets.Class, AllowMultiple = false, Inheritance = MulticastInheritance.None, AllowExternalAssemblies = true)]       <br />public sealed class NotifyPropertyChangedAttribute : CompoundAspect {       <br />&#160;&#160; public int AspectPriority { get; set; } </p>
<p>&#160;&#160; public override void ProvideAspects(object element, LaosReflectionAspectCollection collection) {      <br />&#160;&#160;&#160;&#160;&#160; Type targetType = (Type)element;       <br />&#160;&#160;&#160;&#160;&#160; collection.AddAspect(targetType, new PropertyChangedAspect { AspectPriority = AspectPriority });       <br />&#160;&#160;&#160;&#160;&#160; foreach (var info in targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(pi =&gt; pi.GetSetMethod() != null)) {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; collection.AddAspect(info.GetSetMethod(), new NotifyPropertyChangedAspect(info.Name) { AspectPriority = AspectPriority });       <br />&#160;&#160;&#160;&#160;&#160; }       <br />&#160;&#160; }       <br />}</p>
</blockquote>
<p>Next aspect is change tracking composition aspect. Which is used for marking only</p>
<blockquote><p>[Serializable]      <br />internal sealed class PropertyChangedAspect : CompositionAspect {       <br />&#160;&#160; public override object CreateImplementationObject(InstanceBoundLaosEventArgs eventArgs) {       <br />&#160;&#160;&#160;&#160;&#160; return new PropertyChangedImpl(eventArgs.Instance);       <br />&#160;&#160; } </p>
<p>&#160;&#160; public override Type GetPublicInterface(Type containerType) {      <br />&#160;&#160;&#160;&#160;&#160; return typeof(INotifyPropertyChanged);       <br />&#160;&#160; } </p>
<p>&#160;&#160; public override CompositionAspectOptions GetOptions() {      <br />&#160;&#160;&#160;&#160;&#160; return CompositionAspectOptions.GenerateImplementationAccessor;       <br />&#160;&#160; }       <br />}</p>
</blockquote>
<p>And the next which is most interesting one, we will put onto method boundary for tracking. There are some highlights here. First we do not want to fire PropertyChanged event if the actual value did not changed, thus we’ll handle the method on it entry and on it exit for check.</p>
<blockquote><p>[Serializable]      <br />internal sealed class NotifyPropertyChangedAspect : OnMethodBoundaryAspect {       <br />&#160;&#160; private readonly string _propertyName; </p>
<p>&#160;&#160; public NotifyPropertyChangedAspect(string propertyName) {      <br />&#160;&#160;&#160;&#160;&#160; if (string.IsNullOrEmpty(propertyName)) throw new ArgumentNullException(&quot;propertyName&quot;);       <br />&#160;&#160;&#160;&#160;&#160; _propertyName = propertyName;       <br />&#160;&#160; } </p>
<p>&#160;&#160; public override void OnEntry(MethodExecutionEventArgs eventArgs) {      <br />&#160;&#160;&#160;&#160;&#160; var targetType = eventArgs.Instance.GetType();       <br />&#160;&#160;&#160;&#160;&#160; var setSetMethod = targetType.GetProperty(_propertyName);       <br />&#160;&#160;&#160;&#160;&#160; if (setSetMethod == null) throw new AccessViolationException();       <br />&#160;&#160;&#160;&#160;&#160; var oldValue = setSetMethod.GetValue(eventArgs.Instance,null);       <br />&#160;&#160;&#160;&#160;&#160; var newValue = eventArgs.GetReadOnlyArgumentArray()[0];       <br />&#160;&#160;&#160;&#160;&#160; if (oldValue == newValue) eventArgs.FlowBehavior = FlowBehavior.Return;       <br />&#160;&#160; } </p>
<p>&#160;&#160; public override void OnSuccess(MethodExecutionEventArgs eventArgs) {      <br />&#160;&#160;&#160;&#160;&#160; var instance = eventArgs.Instance as IComposed&lt;INotifyPropertyChanged&gt;;       <br />&#160;&#160;&#160;&#160;&#160; var imp = instance.GetImplementation(eventArgs.InstanceCredentials) as PropertyChangedImpl;       <br />&#160;&#160;&#160;&#160;&#160; imp.OnPropertyChanged(_propertyName);       <br />&#160;&#160; }       <br />}</p>
</blockquote>
<p>We almost done, all we have to do is to create class which implements INotifyPropertyChanged with internal method to useful call</p>
<blockquote><p>[Serializable]      <br />internal sealed class PropertyChangedImpl : INotifyPropertyChanged {       <br />&#160;&#160; private readonly object _instance; </p>
<p>&#160;&#160; public PropertyChangedImpl(object instance) {      <br />&#160;&#160;&#160;&#160;&#160; if (instance == null) throw new ArgumentNullException(&quot;instance&quot;);       <br />&#160;&#160;&#160;&#160;&#160; _instance = instance;       <br />&#160;&#160; } </p>
<p>&#160;&#160; public event PropertyChangedEventHandler PropertyChanged; </p>
<p>&#160;&#160; internal void OnPropertyChanged(string propertyName) {      <br />&#160;&#160;&#160;&#160;&#160; if (string.IsNullOrEmpty(propertyName)) throw new ArgumentNullException(&quot;propertyName&quot;); </p>
<p>&#160;&#160;&#160;&#160;&#160; var handler = PropertyChanged as PropertyChangedEventHandler;      <br />&#160;&#160;&#160;&#160;&#160; if (handler != null) handler(_instance, new PropertyChangedEventArgs(propertyName));       <br />&#160;&#160; }       <br />}</p>
</blockquote>
<p>We done. The last thing is to reference to PostSharp Laos and Public assemblies and mark compiler to use Postsharp targets (inside your project file (*.csproj)</p>
<blockquote><p>&lt;Import Project=&quot;$(MSBuildToolsPath)\Microsoft.CSharp.targets&quot; /&gt;      <br />&lt;PropertyGroup&gt;       <br />&#160; &lt;DontImportPostSharp&gt;True&lt;/DontImportPostSharp&gt;       <br />&lt;/PropertyGroup&gt;       <br />&lt;Import Project=&quot;PostSharp\PostSharp-1.5.targets&quot; /&gt;</p>
</blockquote>
<p>Now we done. We can use clear syntax like following to make all our properties has public setter to be traceable. The only disadvantage is that you’ll have to drag two Post Sharp files with your project. But after all it much more convenience than manual notify change tracking all over your project.</p>
<blockquote><p>[NotifyPropertyChanged]      <br />public class AutoWiredSource {       <br />&#160;&#160; public double MyProperty { get; set; }       <br />}</p>
</blockquote>
<p>Have a nice day and be good people. Also try to thing what other extremely useful things can be done with PostSharp (or any other aspect oriented engine)</p>
<p><a href="http://khason.net/images/2009/08/AutoPropertyChangedWiring.zip" rel="enclosure" target="_blank">Source code for this article (1,225 KB)&gt;&gt;</a></p>


<p>Related posts:<ol><li><a href='http://khason.net/dev/read-singleton-approach-in-wpf-application/' rel='bookmark' title='Permanent Link: Real singleton approach in WPF application'>Real singleton approach in WPF application</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://khason.net/dev/inotifypropertychanged-auto-wiring-or-how-to-get-rid-of-redundant-code/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Visual Studio debugger related attributes cheat sheet</title>
		<link>http://khason.net/dev/visual-studio-debugger-related-attributes-cheat-sheet/</link>
		<comments>http://khason.net/dev/visual-studio-debugger-related-attributes-cheat-sheet/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 16:20:54 +0000</pubDate>
		<dc:creator>Tamir</dc:creator>
				<category><![CDATA[DEV]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[soft]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[VSTS]]></category>
		<category><![CDATA[Work process]]></category>

		<guid isPermaLink="false">http://khason.net/dev/visual-studio-debugger-related-attributes-cheat-sheet/</guid>
		<description><![CDATA[There are some debugger-oriented attributes in .Net, however 70% of developers not even know that they exist and 95% of them has no idea what they doing and how to use it. Today we’ll try to lid light on what those attributes doing and how to achieve the best of using it.
First of all let’s [...]


Related posts:<ol><li><a href='http://khason.net/dev/inotifypropertychanged-auto-wiring-or-how-to-get-rid-of-redundant-code/' rel='bookmark' title='Permanent Link: INotifyPropertyChanged auto wiring or how to get rid of redundant code'>INotifyPropertyChanged auto wiring or how to get rid of redundant code</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>There are some debugger-oriented attributes in .Net, however 70% of developers not even know that they exist and 95% of them has no idea what they doing and how to use it. Today we’ll try to lid light on what those attributes doing and how to achieve the best of using it.</p>
<p>First of all let’s define what we want to get from debugger in VS</p>
<table border="1" cellspacing="1" cellpadding="2" width="600">
<tbody>
<tr>
<td valign="top" width="116">Term</td>
<td valign="top" width="484">What it actually does</td>
</tr>
<tr>
<td valign="top" width="116">Step Into</td>
<td valign="top" width="484">Steps into immediate child (that is what F11 does for standard VS layout)         <br /><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://khason.net/images/2009/04/image1.png" width="240" height="17" /> </td>
</tr>
<tr>
<td valign="top" width="116">Step Over</td>
<td valign="top" width="484">Skips to any depth (that is what F10 does)         <br /><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://khason.net/images/2009/04/image2.png" width="238" height="19" /> </td>
</tr>
<tr>
<td valign="top" width="116">Step Deeper</td>
<td valign="top" width="484">Steps into bypassing code, using certain attribute</td>
</tr>
<tr>
<td valign="top" width="116">Run Through</td>
<td valign="top" width="484">Steps into, but only one level. All lower lavels will be Stepped Over</td>
</tr>
</tbody>
</table>
<p>Now, when we have our set of terms, we can learn what JMC means. It is not famous whisky brand or another car company. It Just My Code option, checked in or out in “Option” dialog inside Visual Studio</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://khason.net/images/2009/04/image3.png" width="749" height="437" /> </p>
<p> Next turn is for attributes, there are four (I know about) attributes, related to debugger and used by me for efficient programming: <a title="Read more in MSDN about this" href="http://msdn.microsoft.com/en-us/library/system.diagnostics.debuggerhiddenattribute.aspx" target="_blank">DebuggerHidden</a>, <a title="Read more in MSDN about this attribute" href="http://msdn.microsoft.com/en-us/library/system.diagnostics.debuggernonusercodeattribute.aspx" target="_blank">DebuggerNonUserCode</a>, <a title="Read more in MSDN about this attribute" href="http://msdn.microsoft.com/en-us/library/system.diagnostics.debuggerstepthroughattribute.aspx" target="_blank">DebuggerStepThrough</a> and <a title="Read more in MSDN about this attribute" href="http://msdn.microsoft.com/en-us/library/system.diagnostics.debuggerstepperboundaryattribute.aspx" target="_blank">DebuggerStepperBoundary</a>. We will use only three first. DebuggerStepperBoundary is the most secret attribute, which is related to debugging only in multithreaded environment. It used to avoid delusive effect, might appears when a context switch is made on a <a title="Read MSDN documentation about System.Threading.Thread class" href="http://msdn.microsoft.com/en-us/library/system.threading.thread.aspx" rel="tag" target="_blank">thread</a> within DebuggerNonUserCode applied. Other words, when you need to Step Through in Thread A and keep running at the same time in Thread B.</p>
<p>So let’s see the effects occurred when using those debugger attributes in case, you are trying to Step Into place, this attribute applied or set a Breakpoint there. When Just My Code (JMC) is checked all those attributes behaviors the same – they Step Deeper. However, when JMC is turned off (as in my picture) they begin to behavior differently.</p>
<table border="1" cellspacing="1" cellpadding="2" width="600">
<tbody>
<tr>
<td valign="top" width="200">Attribute</td>
<td valign="top" width="200">Step Into</td>
<td valign="top" width="200">Breakpoint</td>
</tr>
<tr>
<td valign="top" width="200">DebuggerHidden</td>
<td valign="top" width="200">Step Deeper</td>
<td valign="top" width="200">Step Deeper</td>
</tr>
<tr>
<td valign="top" width="200">DebuggerNonUserCode</td>
<td valign="top" width="200">Step Into</td>
<td valign="top" width="200">Step Into</td>
</tr>
<tr>
<td valign="top" width="200">DebuggerStepThrough</td>
<td valign="top" width="200">Step Deeper</td>
<td valign="top" width="200">Step Into</td>
</tr>
</tbody>
</table>
<p>As you can see, in this case </p>
<ul>
<li>DebuggerNonUserCode respects both for F11 (Step Into) and Breakpoints</li>
<li>DebuggerStepThrough respects only for Breakpoints</li>
<li>DebuggerHidden does not respects at all – just like when JMC is checked.</li>
</ul>
<p><strong>Bottom line</strong>: if you want people to manage whether to enter or not into your hidden methods – use DebuggerNonUserCode attribute. If you prefer them not to even know that those methods exists, use DebuggerHidden. If you want them to be able to put Breakpoints and stop on them, but keep running without explicit action – use&#160; DebuggerStepThrough</p>
<p>Have a nice day and be good people.&#160; Happy other developers friendly debugging.</p>
<p><em>Small bonus</em>: To visualize your struct, class, delegate, enum, field, property or even assembly for user debugger, you can use <a title="Read more on MSDN about this attribute" href="http://msdn.microsoft.com/en-us/library/system.diagnostics.debuggerdisplayattribute.aspx" target="_blank">DebuggerDisplay</a> attribute (you need to put executable code into {} for example (“Value = {X}:{Y}”)]</p>
<p><em>Thanks to <a title="Boris unleashed with huge passover gift" href="http://twitpic.com/2yivn" target="_blank">Boris</a> for deep investigation</em></p>


<p>Related posts:<ol><li><a href='http://khason.net/dev/inotifypropertychanged-auto-wiring-or-how-to-get-rid-of-redundant-code/' rel='bookmark' title='Permanent Link: INotifyPropertyChanged auto wiring or how to get rid of redundant code'>INotifyPropertyChanged auto wiring or how to get rid of redundant code</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://khason.net/dev/visual-studio-debugger-related-attributes-cheat-sheet/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to calculate CRC in C#?</title>
		<link>http://khason.net/dev/how-to-calculate-crc-in-c/</link>
		<comments>http://khason.net/dev/how-to-calculate-crc-in-c/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 19:38:15 +0000</pubDate>
		<dc:creator>Tamir</dc:creator>
				<category><![CDATA[DEV]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Work process]]></category>

		<guid isPermaLink="false">http://khason.net/dev/how-to-calculate-crc-in-c/</guid>
		<description><![CDATA[First of all, I want to beg your pardon about the frequency of posts last time. I’m completely understaffed and have a ton of things to do for my job. This why, today I’ll just write a quick post about checksum calculation in C#. It might be very useful for any of you, working with [...]


Related posts:<ol><li><a href='http://khason.net/dev/read-singleton-approach-in-wpf-application/' rel='bookmark' title='Permanent Link: Real singleton approach in WPF application'>Real singleton approach in WPF application</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>First of all, I want to beg your pardon about the frequency of posts last time. I’m completely understaffed and have a ton of things to do for my job. This why, today I’ll just write a quick post about checksum calculation in C#. It might be very useful for any of you, working with devices or external systems.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="BIOS CRC Error for old thinkpad" src="http://khason.net/images/2009/04/image.png" border="0" alt="BIOS CRC Error for old thinkpad" width="636" height="53" /></p>
<p><a href="http://en.wikipedia.org/wiki/Cyclic_redundancy_check" target="_blank">CRC – Cyclic Redundancy Check</a> is an algorithm, which is widely used in different communication protocols, packing and packaging algorithms for assure robustness of data. The idea behind it is simple – calculate unique checksum (frame check sequence) for each data frame, based on it’s content and stick it at the end of each meaningful message. Once data received it’s possible to perform the same calculating and compare results – if results are similar, message is ok.</p>
<p>There are two kinds of CRC – 16 and 32 bit. There are also less used checksums for 8 and 64 bits. All this is about appending a string of zeros to the frame equal in number of frames and modulo two device by using generator polynomial containing one or more bits then checksum to be generated. This is very similar to performing a bit-wise XOR operation in the frame, while the reminder is actually our CRC.</p>
<p>In many industries first polynomial is in use to create CRC tables and then apply it for performance purposes. The default polynomial, defined by IEEE 802.3 which is 0xA001 for 16 bit and 0&#215;04C11DB7 for 32 bit. We’re in C#, thus we should use it inversed version which is 0&#215;8408 for 16 bit and 0xEDB88320 for 32 bit. Those polynomials we’re going to use also in our sample.</p>
<p>So let’s start. Because CRC is HashAlgorithm after all, we can derive our classes from System.Security.Cryptography.HashAlgorithm class.</p>
<blockquote><p>public class CRC16 : HashAlgorithm {<br />
public class CRC32 : HashAlgorithm {</p>
</blockquote>
<p>Then, upon first creation we’ll generate hashtables with CRC values to enhance future performance. It’s all about values table for bytes from 0 to 255 , so we should calculate it only once and then we can use it statically.</p>
<blockquote><p>[CLSCompliant(false)]<br />
public CRC16(ushort polynomial) {<br />
HashSizeValue = 16;<br />
_crc16Table = (ushort[])_crc16TablesCache[polynomial];<br />
if (_crc16Table == null) {<br />
_crc16Table = CRC16._buildCRC16Table(polynomial);<br />
_crc16TablesCache.Add(polynomial, _crc16Table);<br />
}<br />
Initialize();<br />
}</p>
<p>[CLSCompliant(false)]<br />
public CRC32(uint polynomial) {<br />
HashSizeValue = 32;<br />
_crc32Table = (uint[])_crc32TablesCache[polynomial];<br />
if (_crc32Table == null) {<br />
_crc32Table = CRC32._buildCRC32Table(polynomial);<br />
_crc32TablesCache.Add(polynomial, _crc32Table);<br />
}<br />
Initialize();<br />
}</p>
</blockquote>
<p>Then let’s calculate it</p>
<blockquote><p>private static ushort[] _buildCRC16Table(ushort polynomial) {<br />
// 256 values representing ASCII character codes.<br />
ushort[] table = new ushort[256];<br />
for (ushort i = 0; i &lt; table.Length; i++) {<br />
ushort value = 0;<br />
ushort temp = i;<br />
for (byte j = 0; j &lt; 8; j++) {<br />
if (((value ^ temp) &amp; 0&#215;0001) != 0) {<br />
value = (ushort)((value &gt;&gt; 1) ^ polynomial);<br />
} else {<br />
value &gt;&gt;= 1;<br />
}<br />
temp &gt;&gt;= 1;<br />
}<br />
table[i] = value;<br />
}<br />
return table;<br />
}</p>
<p>private static uint[] _buildCRC32Table(uint polynomial) {<br />
uint crc;<br />
uint[] table = new uint[256];</p>
<p>// 256 values representing ASCII character codes.<br />
for (int i = 0; i &lt; 256; i++) {<br />
crc = (uint)i;<br />
for (int j = 8; j &gt; 0; j&#8211;) {<br />
if ((crc &amp; 1) == 1)<br />
crc = (crc &gt;&gt; 1) ^ polynomial;<br />
else<br />
crc &gt;&gt;= 1;<br />
}<br />
table[i] = crc;<br />
}</p>
<p>return table;<br />
}</p>
</blockquote>
<p>The result will looks like this for 32 bits</p>
<blockquote>
<pre>        0x00, 0x31, 0x62, 0x53, 0xC4, 0xF5, 0xA6, 0x97,
        0xB9, 0x88, 0xDB, 0xEA, 0x7D, 0x4C, 0x1F, 0x2E,
        0x43, 0x72, 0x21, 0x10, 0x87, 0xB6, 0xE5, 0xD4,
        0xFA, 0xCB, 0x98, 0xA9, 0x3E, 0x0F, 0x5C, 0x6D,
        0x86, 0xB7, 0xE4, 0xD5, 0x42, 0x73, 0x20, 0x11,
        0x3F, 0x0E, 0x5D, 0x6C, 0xFB, 0xCA, 0x99, 0xA8,
        0xC5, 0xF4, 0xA7, 0x96, 0x01, 0x30, 0x63, 0x52,
        0x7C, 0x4D, 0x1E, 0x2F, 0xB8, 0x89, 0xDA, 0xEB,
        0x3D, 0x0C, 0x5F, 0x6E, 0xF9, 0xC8, 0x9B, 0xAA,
        0x84, 0xB5, 0xE6, 0xD7, 0x40, 0x71, 0x22, 0x13,
        0x7E, 0x4F, 0x1C, 0x2D, 0xBA, 0x8B, 0xD8, 0xE9,
        0xC7, 0xF6, 0xA5, 0x94, 0x03, 0x32, 0x61, 0x50,
        0xBB, 0x8A, 0xD9, 0xE8, 0x7F, 0x4E, 0x1D, 0x2C,
        0x02, 0x33, 0x60, 0x51, 0xC6, 0xF7, 0xA4, 0x95,
        0xF8, 0xC9, 0x9A, 0xAB, 0x3C, 0x0D, 0x5E, 0x6F,
        0x41, 0x70, 0x23, 0x12, 0x85, 0xB4, 0xE7, 0xD6,
        0x7A, 0x4B, 0x18, 0x29, 0xBE, 0x8F, 0xDC, 0xED,
        0xC3, 0xF2, 0xA1, 0x90, 0x07, 0x36, 0x65, 0x54,
        0x39, 0x08, 0x5B, 0x6A, 0xFD, 0xCC, 0x9F, 0xAE,
        0x80, 0xB1, 0xE2, 0xD3, 0x44, 0x75, 0x26, 0x17,
        0xFC, 0xCD, 0x9E, 0xAF, 0x38, 0x09, 0x5A, 0x6B,
        0x45, 0x74, 0x27, 0x16, 0x81, 0xB0, 0xE3, 0xD2,
        0xBF, 0x8E, 0xDD, 0xEC, 0x7B, 0x4A, 0x19, 0x28,
        0x06, 0x37, 0x64, 0x55, 0xC2, 0xF3, 0xA0, 0x91,
        0x47, 0x76, 0x25, 0x14, 0x83, 0xB2, 0xE1, 0xD0,
        0xFE, 0xCF, 0x9C, 0xAD, 0x3A, 0x0B, 0x58, 0x69,
        0x04, 0x35, 0x66, 0x57, 0xC0, 0xF1, 0xA2, 0x93,
        0xBD, 0x8C, 0xDF, 0xEE, 0x79, 0x48, 0x1B, 0x2A,
        0xC1, 0xF0, 0xA3, 0x92, 0x05, 0x34, 0x67, 0x56,
        0x78, 0x49, 0x1A, 0x2B, 0xBC, 0x8D, 0xDE, 0xEF,
        0x82, 0xB3, 0xE0, 0xD1, 0x46, 0x77, 0x24, 0x15,
        0x3B, 0x0A, 0x59, 0x68, 0xFF, 0xCE, 0x9D, 0xAC</pre>
</blockquote>
<p>Now, all we have to do is to upon request to lookup into this hash table for related value and XOR it</p>
<blockquote><p>protected override void HashCore(byte[] buffer, int offset, int count) {</p>
<p>for (int i = offset; i &lt; count; i++) {</p>
<p>ulong ptr = (_crc &amp; 0xFF) ^ buffer[i];</p>
<p>_crc &gt;&gt;= 8;</p>
<p>_crc ^= _crc32Table[ptr];</p>
<p>}</p>
<p>}</p>
<p>new public byte[] ComputeHash(Stream inputStream) {</p>
<p>byte[] buffer = new byte[4096];</p>
<p>int bytesRead;</p>
<p>while ((bytesRead = inputStream.Read(buffer, 0, 4096)) &gt; 0) {</p>
<p>HashCore(buffer, 0, bytesRead);</p>
<p>}</p>
<p>return HashFinal();</p>
<p>}</p>
<p>protected override byte[] HashFinal() {</p>
<p>byte[] finalHash = new byte[4];</p>
<p>ulong finalCRC = _crc ^ _allOnes;</p>
<p>finalHash[0] = (byte)((finalCRC &gt;&gt; 0) &amp; 0xFF);</p>
<p>finalHash[1] = (byte)((finalCRC &gt;&gt; <img src='http://khason.net/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> &amp; 0xFF);</p>
<p>finalHash[2] = (byte)((finalCRC &gt;&gt; 16) &amp; 0xFF);</p>
<p>finalHash[3] = (byte)((finalCRC &gt;&gt; 24) &amp; 0xFF);</p>
<p>return finalHash;</p>
<p>}</p>
</blockquote>
<p>We done. Have a good time and be good people. Also, I want to thank Boris for helping me with this article. He promised to write here some day…</p>
<p><a href="http://khason.net/images/2009/04/crc-source.zip" target="_blank">Source code for this article</a></p>


<p>Related posts:<ol><li><a href='http://khason.net/dev/read-singleton-approach-in-wpf-application/' rel='bookmark' title='Permanent Link: Real singleton approach in WPF application'>Real singleton approach in WPF application</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://khason.net/dev/how-to-calculate-crc-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
<enclosure url="http://khason.net/images/2009/04/crc-source.zip" length="" type="" />
		</item>
		<item>
		<title>Finally I can reveal stuff I working for last half year!</title>
		<link>http://khason.net/blog/finally-i-can-reveal-stuff-i-working-for-last-half-year/</link>
		<comments>http://khason.net/blog/finally-i-can-reveal-stuff-i-working-for-last-half-year/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 17:19:39 +0000</pubDate>
		<dc:creator>Tamir</dc:creator>
				<category><![CDATA[BLOG]]></category>
		<category><![CDATA[blogging general]]></category>
		<category><![CDATA[demos]]></category>
		<category><![CDATA[My tools]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[promo]]></category>
		<category><![CDATA[soft]]></category>
		<category><![CDATA[Work process]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://khason.net/blog/finally-i-can-reveal-stuff-i-working-for-last-half-year/</guid>
		<description><![CDATA[A couple of days ago WordFocus exposed one of our (frankly old   ) WPF prototypes for in-car energy assistant system, so today I can exclusively show you some of screens from this state of art WPF work. Real time performance of WPF touch screen application, running on low power automotive grade PC, which [...]


Related posts:<ol><li><a href='http://khason.net/blog/how-to-pass-technical-interview-in-better-place/' rel='bookmark' title='Permanent Link: How to pass technical interview in Better Place'>How to pass technical interview in Better Place</a></li>
<li><a href='http://khason.net/blog/book-review-c-2008-and-2005-threaded-programming/' rel='bookmark' title='Permanent Link: Book review: C# 2008 and 2005 Threaded Programming'>Book review: C# 2008 and 2005 Threaded Programming</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago <a href="http://worldfocus.org/blog/2009/02/09/israeli-company-builds-infrastructure-for-worlds-electric-cars/3977/" target="_blank">WordFocus exposed</a> one of <a href="http://www.betterplace.com/" target="_blank">our</a> (frankly old <img src='http://khason.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) <a title="See all WPF related posts" rel="tag" href="http://khason.net/tag/wpf/" target="_blank">WPF</a> prototypes for in-car energy assistant system, so today I can exclusively show you some of screens from this state of art WPF work. Real time performance of WPF touch screen application, running on low power automotive grade PC, which <a href="http://khason.net/blog/what-boots-faster-%e2%80%93-netbook-powered-windows-xp-or-nokia-e71-mobile-phone/" target="_blank">boots faster, then Nokia phone</a>. Huge respect for all developers and P-defs.</p>
<p><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="Map overview" src="http://khason.net/images/2009/02/c1.jpg" border="0" alt="Map overview" width="640" height="432" /></p>
<p><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="Planning screen" src="http://khason.net/images/2009/02/c2.jpg" border="0" alt="Planning screen" width="640" height="434" /> <img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="Navigation draving state" src="http://khason.net/images/2009/02/c9.jpg" border="0" alt="Navigation draving state" width="640" height="430" /></p>
<p><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="Applications" src="http://khason.net/images/2009/02/c6.jpg" border="0" alt="Applications" width="640" height="436" /></p>
<p>Full video report by <a href="http://worldfocus.org/" target="_blank">WorldFocus.org</a></p>


<p>Related posts:<ol><li><a href='http://khason.net/blog/how-to-pass-technical-interview-in-better-place/' rel='bookmark' title='Permanent Link: How to pass technical interview in Better Place'>How to pass technical interview in Better Place</a></li>
<li><a href='http://khason.net/blog/book-review-c-2008-and-2005-threaded-programming/' rel='bookmark' title='Permanent Link: Book review: C# 2008 and 2005 Threaded Programming'>Book review: C# 2008 and 2005 Threaded Programming</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://khason.net/blog/finally-i-can-reveal-stuff-i-working-for-last-half-year/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Quick how to: Reduce number of colors programmatically</title>
		<link>http://khason.net/dev/quick-how-to-reduce-number-of-colors-programmatically/</link>
		<comments>http://khason.net/dev/quick-how-to-reduce-number-of-colors-programmatically/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 18:46:50 +0000</pubDate>
		<dc:creator>Tamir</dc:creator>
				<category><![CDATA[DEV]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[DirectX]]></category>
		<category><![CDATA[Interop]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Work process]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPF crossbow]]></category>

		<guid isPermaLink="false">http://khason.net/dev/quick-how-to-reduce-number-of-colors-programmatically/</guid>
		<description><![CDATA[My colleague just asked me about how to reduce a number of colors in image programmatically. This is very simple task and contains of 43   steps:

First of all, you have to read a source image
using (var img = Image.FromFile(name)) {
var bmpEncoder = ImageCodecInfo.GetImageDecoders().FirstOrDefault(e =&#62; e.FormatID == ImageFormat.Bmp.Guid);
Then create your own encoder with certain [...]


Related posts:<ol><li><a href='http://khason.net/dev/read-singleton-approach-in-wpf-application/' rel='bookmark' title='Permanent Link: Real singleton approach in WPF application'>Real singleton approach in WPF application</a></li>
<li><a href='http://khason.net/dev/inotifypropertychanged-auto-wiring-or-how-to-get-rid-of-redundant-code/' rel='bookmark' title='Permanent Link: INotifyPropertyChanged auto wiring or how to get rid of redundant code'>INotifyPropertyChanged auto wiring or how to get rid of redundant code</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>My colleague just asked me about how to reduce a number of colors in image programmatically. This is very simple task and contains of 43 <img src='http://khason.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  steps:</p>
<p><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="Simple color matrix" src="http://khason.net/images/2009/02/image2.png" border="0" alt="Simple color matrix" width="383" height="366" /></p>
<p>First of all, you have to read a source image</p>
<blockquote><p>using (var img = Image.FromFile(name)) {<br />
var bmpEncoder = ImageCodecInfo.GetImageDecoders().FirstOrDefault(e =&gt; e.FormatID == ImageFormat.Bmp.Guid);</p></blockquote>
<p>Then create your own encoder with certain color depth (32 bits in this case)</p>
<blockquote><p>var myEncoder = System.Drawing.Imaging.Encoder.ColorDepth;<br />
var myEncoderParameter = new EncoderParameter(myEncoder, 32L);<br />
var myEncoderParameters = new EncoderParameters(1) { Param = new EncoderParameter[] { myEncoderParameter } };</p></blockquote>
<p>Then save it</p>
<blockquote><p>img.Save(name.Replace(&#8220;.png&#8221;, &#8220;.bmp&#8221;), bmpEncoder, myEncoderParameters);</p></blockquote>
<p>It it enough? Not really, because if you’re going to loose colors (by reducing color depth), it makes sense to avoid letting default WIX decoder to do this, thus you have to find nearest base colors manually. How to do this? By using simple math</p>
<blockquote><p>Color GetNearestBaseColor(Color exactColor) {<br />
Color nearestColor = Colors.Black;<br />
int cnt = baseColors.Count;<br />
for (int i = 0; i &lt; cnt; i++) {<br />
int rRed = baseColors[i].R &#8211; exactColor.R;<br />
int rGreen = baseColors[i].G &#8211; exactColor.G;<br />
int rBlue = baseColors[i].B &#8211; exactColor.B;</p>
<p>int rDistance =<br />
(rRed * rRed) +<br />
(rGreen * rGreen) +<br />
(rBlue * rBlue);<br />
if (rDistance == 0.0) {<br />
return baseColors[i];<br />
} else if (rDistance &lt; maxDistance) {<br />
maxDistance = rDistance;<br />
nearestColor = baseColors[i];<br />
}<br />
}<br />
return nearestColor;<br />
}</p></blockquote>
<p>Now, you can either change colors on base image directly</p>
<blockquote><p>unsafe {<br />
uint* pBuffer = (uint*)hMap;<br />
for (int iy = 0; iy &lt; (int)ColorMapSource.PixelHeight; ++iy)<br />
{<br />
for (int ix = 0; ix &lt; nWidth; ++ix)<br />
{<br />
Color nc = GetNearestBaseColor(pBuffer[0].FromOle());</p>
<p>pBuffer[0] &amp;= (uint)((uint)nc.A &lt;&lt; 24) | //A<br />
(uint)(nc.R &lt;&lt; 16 ) | //R<br />
(uint)(nc.G &lt;&lt; 8 ) | //G<br />
(uint)(nc.B ); //B<br />
++pBuffer;<br />
}<br />
pBuffer += nOffset;<br />
}<br />
}</p></blockquote>
<p>Or, if you’re in WPF and .NET 3.5 <a title="HLSL (Pixel shader) effects tutorial" href="http://khason.net/blog/hlsl-pixel-shader-effects-tutorial/" target="_blank">create simple pixel shader effect</a> to do it for you in hardware. Now, my colleague can do it himself in about 5 minutes <img src='http://khason.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  . Have a nice day and be good people.</p>


<p>Related posts:<ol><li><a href='http://khason.net/dev/read-singleton-approach-in-wpf-application/' rel='bookmark' title='Permanent Link: Real singleton approach in WPF application'>Real singleton approach in WPF application</a></li>
<li><a href='http://khason.net/dev/inotifypropertychanged-auto-wiring-or-how-to-get-rid-of-redundant-code/' rel='bookmark' title='Permanent Link: INotifyPropertyChanged auto wiring or how to get rid of redundant code'>INotifyPropertyChanged auto wiring or how to get rid of redundant code</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://khason.net/dev/quick-how-to-reduce-number-of-colors-programmatically/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bootstrapper for .NET framework version detector</title>
		<link>http://khason.net/tech/bootstrapper-for-net-framework-version-detector/</link>
		<comments>http://khason.net/tech/bootstrapper-for-net-framework-version-detector/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 17:22:26 +0000</pubDate>
		<dc:creator>Tamir</dc:creator>
				<category><![CDATA[TECH]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DEV]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[Interop]]></category>
		<category><![CDATA[My tools]]></category>
		<category><![CDATA[promo]]></category>
		<category><![CDATA[soft]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Vista]]></category>
		<category><![CDATA[VSTS]]></category>
		<category><![CDATA[Work process]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://khason.net/tech/bootstrapper-for-net-framework-version-detector/</guid>
		<description><![CDATA[You wrote your .NET program, that can be used as stand alone portable application (such as it should be for Smart Client Apps), however you have to be sure, that necessary prerequisites (such as .NET framework) are installed on client’s machine. What to do? How to detect .NET framework version installed on target machine before [...]


Related posts:<ol><li><a href='http://khason.net/tech/some-new-in-mix-downloads/' rel='bookmark' title='Permanent Link: Some new in-mix downloads'>Some new in-mix downloads</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>You wrote your .NET program, that can be used as stand alone portable application (such as it should be for Smart Client Apps), however you have to be sure, that necessary prerequisites (such as .NET framework) are installed on client’s machine. What to do? How to detect .NET framework version installed on target machine before running .NET application. The answer is – to use unmanaged C++ bootstrapper, that invoke your application if correct version of framework is installed.</p>
<p><a title=".NET Framework Detector" href="http://khason.net/images/2009/02/whoooot.exe" target="_blank" rel="enclosure"><img title=".NET framework vrsion detector" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="212" alt=".NET framework vrsion detector" src="http://khason.net/images/2009/02/image.png" width="310" border="0" /></a> </p>
<p>Until now there are 15 possible .NET frameworks can be installed on client’s machine. Here the table of possible and official supported versions, <a href="http://support.microsoft.com/kb/318785" target="_blank">as appears in Q318785</a></p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="200">.NET version</td>
<td valign="top" width="200">Actual version</td>
</tr>
<tr>
<td valign="top" width="200">3.5 SP1</td>
<td valign="top" width="200">3.5.30729.1</td>
</tr>
<tr>
<td valign="top" width="200">3.5</td>
<td valign="top" width="200">3.5.21022.8</td>
</tr>
<tr>
<td valign="top" width="200">3.0 SP2</td>
<td valign="top" width="200">3.0.4506.2152</td>
</tr>
<tr>
<td valign="top" width="200">3.0 SP1</td>
<td valign="top" width="200">3.0.4506.648</td>
</tr>
<tr>
<td valign="top" width="200">3.0</td>
<td valign="top" width="200">3.0.4506.30</td>
</tr>
<tr>
<td valign="top" width="200">2.0 SP2</td>
<td valign="top" width="200">2.0.50727.3053</td>
</tr>
<tr>
<td valign="top" width="200">2.0 SP1</td>
<td valign="top" width="200">2.0.50727.1433</td>
</tr>
<tr>
<td valign="top" width="200">2.0</td>
<td valign="top" width="200">2.0.50727.42</td>
</tr>
<tr>
<td valign="top" width="200">1.1 SP1</td>
<td valign="top" width="200">1.1.4322.2032</td>
</tr>
<tr>
<td valign="top" width="200">1.1 SP1 (in 32 bit version of Windows 2003)</td>
<td valign="top" width="200">1.1.4322.2300</td>
</tr>
<tr>
<td valign="top" width="200">1.1</td>
<td valign="top" width="200">1.1.4322.573</td>
</tr>
<tr>
<td valign="top" width="200">1.0 SP3</td>
<td valign="top" width="200">1.0.3705.6018</td>
</tr>
<tr>
<td valign="top" width="200">1.0 SP2</td>
<td valign="top" width="200">1.0.3705.288</td>
</tr>
<tr>
<td valign="top" width="200">1.0 SP1</td>
<td valign="top" width="200">1.0.3705.209</td>
</tr>
<tr>
<td valign="top" width="200">1.0</td>
<td valign="top" width="200">1.0.3705.0</td>
</tr>
</tbody>
</table>
<p>All of those versions are detectible by queering specific registry keys. However, in some cases, you need to load mscoree.dll and call “GETCOREVERSION” API to determine whether specific version of .NET is installed. You can read more about it <a href="http://msdn2.microsoft.com/library/ydh6b3yb.aspx" target="_blank">in MSDN</a>.</p>
<p>So it’s really simple to write small C++ application (or PowerShell applet), that queries registry and invoke your managed application. How to do this? You can either read about it in outstanding blog of <a href="http://blogs.msdn.com/astebner/archive/2009/01/31/9387659.aspx" target="_blank">Aaron Stebner</a>, who is Project Manager in XNA platform deployment team or <a href="http://khason.net/blog/action-required-smart-client-development-present-and-future/" target="_blank">attend my session next week</a> to learn do it yourself. We’ll speak about nifty ways to do it also. </p>
<p>Anyway, by now, you can use small stand alone program, I wrote a while ago, that will tell you all versions of .NET frameworks installed in target machine without any prerequisites. It can be run even from shared network location <img src='http://khason.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://khason.net/images/2009/02/whoooot.exe" target="_blank"><strong>Download whoooot.exe (13K) &gt;&gt;</strong></a></p>
<p>See you next week. </p>
<p>PS: Do not forget to <a href="http://www.codeplex.com/SnippetEditor/" target="_blank">download and install the new version</a> of <a href="http://khason.net/blog/visual-studio-snippet-designer/" target="_blank">Visual Studio Snippet Designer</a>, which is extremely useful tool by MVP <a href="http://msmvps.com/blogs/bill/" target="_blank">Bill McCarthy</a>, you’ll need it later next week…</p>
<p>Have a nice day and be good people.</p>


<p>Related posts:<ol><li><a href='http://khason.net/tech/some-new-in-mix-downloads/' rel='bookmark' title='Permanent Link: Some new in-mix downloads'>Some new in-mix downloads</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://khason.net/tech/bootstrapper-for-net-framework-version-detector/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Brilliant, yet simple technical questions, can be used for work interview</title>
		<link>http://khason.net/tech/brilliant-yet-simple-technical-questions-can-be-used-for-work-interview/</link>
		<comments>http://khason.net/tech/brilliant-yet-simple-technical-questions-can-be-used-for-work-interview/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 12:24:21 +0000</pubDate>
		<dc:creator>Tamir</dc:creator>
				<category><![CDATA[TECH]]></category>
		<category><![CDATA[blogging general]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[jobs]]></category>
		<category><![CDATA[promo]]></category>
		<category><![CDATA[quiz]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Work process]]></category>

		<guid isPermaLink="false">http://khason.net/tech/brilliant-yet-simple-technical-questions-can-be-used-for-work-interview/</guid>
		<description><![CDATA[Few days ago, a friend of mine, sent me set of demonstration questions for 11th grade computer science students from Russia. I throw eye on this exam and decided to use some of those questions to test candidates in my company for hardware engineer position (we’re looking for). If you’re good candidate for this position, [...]


Related posts:<ol><li><a href='http://khason.net/blog/how-to-pass-technical-interview-in-better-place/' rel='bookmark' title='Permanent Link: How to pass technical interview in Better Place'>How to pass technical interview in Better Place</a></li>
<li><a href='http://khason.net/dev/how-to-calculate-crc-in-c/' rel='bookmark' title='Permanent Link: How to calculate CRC in C#?'>How to calculate CRC in C#?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Few days ago, a friend of mine, sent me set of demonstration questions for <a href="http://www.fipi.ru/" target="_blank">11th grade computer science students from Russia</a>. I throw eye on this exam and decided to use some of those questions to test candidates in my company for hardware engineer position (we’re looking for). If you’re good candidate for this position, you should be able to answer all those questions without even think a minute.</p>
<p><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="image" src="http://khason.net/images/2009/01/image29.png" border="0" alt="image" width="374" height="255" /></p>
<p><em>Following those questions</em>:</p>
<p>Automatic system recoded informational message in Russian from Unicode (16-bit) into KOI-8 (8 bit). After recoding the length of the message decreased by 480 bits. What was the length of the original message in characters?<br />
1) 30          2) 60          3) 120          4) 480</p>
<p>There are 119 participants in bicycle race. Special designed system registers cyclers passing waypoint by writing his serial number with minimum possible number of bits. What will be the size of temporary message, recorded by the system after 70 cyclers passed the waypoint?<br />
1) 70 bits          2) 70 bytes          3) 490 bits          4) 119 bytes</p>
<p><strong>а</strong>=D7<sub>16</sub>, <strong>b</strong>=331<sub>8</sub>. What the value of <strong>c</strong> if <strong>a&lt;c&lt;b</strong>?<br />
1) 11011001          2) 11011100          3) 11010111          4) 11011000</p>
<p>Please calculate 43<sub>8</sub>+56<sub>16</sub>?<br />
1) 121<sub>8</sub> 2) 171<sub>8</sub> 3) 69<sub>16</sub> 4) 1000001<sub>2</sub></p>
<p>What logical expression equals to: &amp; !( !B | C ), while &amp;: logical AND, !: logical NOT and |:logical OR<br />
1) !A | !B | !C          2) A &amp; !B &amp; !C          3) A &amp; B &amp; !C          4) A &amp; !B &amp;C</p>
<p>F is a result of logical expression execution with arguments A, B and C</p>
<table border="1" cellspacing="0" cellpadding="2" width="102">
<tbody>
<tr>
<td width="21" valign="top">A</td>
<td width="26" valign="top">B</td>
<td width="27" valign="top">C</td>
<td width="26" valign="top">F</td>
</tr>
<tr>
<td width="21" valign="top">1</td>
<td width="26" valign="top">0</td>
<td width="27" valign="top">0</td>
<td width="26" valign="top">1</td>
</tr>
<tr>
<td width="21" valign="top">0</td>
<td width="26" valign="top">0</td>
<td width="27" valign="top">0</td>
<td width="26" valign="top">1</td>
</tr>
<tr>
<td width="21" valign="top">1</td>
<td width="26" valign="top">1</td>
<td width="27" valign="top">1</td>
<td width="26" valign="top">0</td>
</tr>
</tbody>
</table>
<p>What is the expression for F?<br />
1) !A &amp; !B &amp; !C          2) A &amp; B &amp; C         3) A | B | C         4) !A | !B | !C</p>
<p>For encoding characters A, B, C and D we decided to use two bits numbers sequence (from 00 to 11). What was the result of coding sequence <strong>BACD</strong> on base 16?<br />
1) 4A          2) 411          3) BACD          4) 1023</p>
<p>Led table contains of number of leds. Each led can be in one of following states: “On”, “Off”, “Blinking”. What is the minimal number of leds should be on table in order to display 18 difference signals?</p>
<p>Please calculate 25<sub>14</sub> + 11<sub>-4</sub> – 21<sub>10</sub>?</p>
<p>To calculator there are only two commands 1: “add 3”, 2: “multiply by 4”. Please write down the sequence of the calculator command in order to convert number <strong>3</strong> to number <strong>57</strong> while using not more, then <strong>6</strong> commands. For example to convert 2 into 50 you should write following: “21211” (X4,+3,X4,+3,+3)</p>
<p>The speed of data transfer over network is 128000 bits/sec. Please calculate the time (in seconds) will take to transfer 625 kBytes in this network.</p>
<p>Write a simple program (by using your favorite programming language) to convert the array of 30 integers into array of modulus of items from input array without using modulus calculation special function.</p>
<hr />Good luck!</p>
<p>For people, currently employed in my company (hardware devs) it took less, then10 minutes to solve all those questions. However, I was shocked, that at least half of new candidates, come to interview failed to solve it.</p>


<p>Related posts:<ol><li><a href='http://khason.net/blog/how-to-pass-technical-interview-in-better-place/' rel='bookmark' title='Permanent Link: How to pass technical interview in Better Place'>How to pass technical interview in Better Place</a></li>
<li><a href='http://khason.net/dev/how-to-calculate-crc-in-c/' rel='bookmark' title='Permanent Link: How to calculate CRC in C#?'>How to calculate CRC in C#?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://khason.net/tech/brilliant-yet-simple-technical-questions-can-be-used-for-work-interview/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>My favorite gadget arrived&#8230;</title>
		<link>http://khason.net/offtopic/my-favorite-gadget-arrived/</link>
		<comments>http://khason.net/offtopic/my-favorite-gadget-arrived/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 09:44:31 +0000</pubDate>
		<dc:creator>Tamir</dc:creator>
				<category><![CDATA[OFFTOPIC]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[gadgets]]></category>
		<category><![CDATA[promo]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[Work process]]></category>

		<guid isPermaLink="false">http://khason.net/offtopic/my-favorite-gadget-arrived/</guid>
		<description><![CDATA[If you’re smoking, you know how it to flight more, then two hours when you cannot smoke. Also, you know hw it feels when outside is cold or rainy, but you should come outside to smoke. When you’re in pub with friends and a pint of good beer, but you cannot satisfy with your drink, [...]

<p/>]]></description>
			<content:encoded><![CDATA[<p>If you’re smoking, you know how it to flight more, then two hours when you cannot smoke. Also, you know hw it feels when outside is cold or rainy, but you should come outside to smoke. When you’re in pub with friends and a pint of good beer, but you cannot satisfy with your drink, when each 10 minutes you need to go outside to smoke. This why, I ordered <a href="http://gamucci.com/" target="_blank">electronic cigarette</a>, that so far become my favorite gadget.</p>
<p><img src="http://media.share.ovi.com/m1/large/0598/dce8916d90aa4d35a727e673698ae07a.jpg" /> </p>
<p>It’s absolutely perfect device. It produce odorless warm smoke and filled with real nicotine. It much healthier, then real cigarette, while you have a feeling of real smoke. And the most important thing, that you can smoke it in all places, where smoking prohibited. </p>
<p><img src="http://media.share.ovi.com/m1/large/0598/34467e19fa794cbcb99fc94972d4ec25.jpg" /> </p>
<p>The pack&#160; contains of two rechargeable batteries, charger, inhaler and nicotine cartridges. All you have to do it so mount cartridge and start smoking</p>
<p><img src="http://media.share.ovi.com/m1/large/0598/86d377fbb18542718f0762917795baa4.jpg" /> </p>
<p>It feels like regular cigarette, tastes like regular cigarette, smells (for smoker, not for all around) like regular cigarette, but it is not regular cigarette, thus you can smoke whenever you want and where ever you want.</p>
<p><img src="http://media.share.ovi.com/m1/large/0598/2fc9b8e8e72f49d2a39d65cf738f939e.jpg" /> </p>
<p>Absolutely incredible and very useful gadget. Happy smoking and thanks to <a href="http://gamucci.com/" target="_blank">Gamucci</a> for such innovation. Now I can smoke during 12 hours flight to <a href="http://mvp.support.microsoft.com/gp/MVPsummit" target="_blank">MVP summit</a>.</p>
<p><img src="http://media.share.ovi.com/m1/large/0598/584cec533806444499987f37f11206e0.jpg" /></p>


<p/>]]></content:encoded>
			<wfw:commentRss>http://khason.net/offtopic/my-favorite-gadget-arrived/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Nifty time savers for WPF development</title>
		<link>http://khason.net/dev/nifty-time-savers-for-wpf-development/</link>
		<comments>http://khason.net/dev/nifty-time-savers-for-wpf-development/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 18:23:04 +0000</pubDate>
		<dc:creator>Tamir</dc:creator>
				<category><![CDATA[DEV]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[soft]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Work process]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://khason.net/dev/nifty-time-savers-for-wpf-development/</guid>
		<description><![CDATA[I just published an article on Code Project, that explains how to use my latest FM USB library for building real world software radio receiver with WPF. There I referenced to some nifty WPF time savers, I’m using for everyday development. So, today I want to share those code pieces with you.
 
Binding time savers
Want [...]


Related posts:<ol><li><a href='http://khason.net/dev/read-singleton-approach-in-wpf-application/' rel='bookmark' title='Permanent Link: Real singleton approach in WPF application'>Real singleton approach in WPF application</a></li>
<li><a href='http://khason.net/dev/inotifypropertychanged-auto-wiring-or-how-to-get-rid-of-redundant-code/' rel='bookmark' title='Permanent Link: INotifyPropertyChanged auto wiring or how to get rid of redundant code'>INotifyPropertyChanged auto wiring or how to get rid of redundant code</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" href="http://www.codeproject.com/KB/WPF/fmradio.aspx">I just published an article</a> on Code Project, that explains how to use my latest <a target="_blank" href="http://www.codeplex.com/FM">FM USB library</a> for building real world software radio receiver with WPF. There I referenced to some nifty WPF time savers, I’m using for everyday development. So, today I want to share those code pieces with you.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Software radio reciever screenshot" border="0" alt="Software radio reciever screenshot" src="http://khason.net/images/2009/01/radio.jpg" width="500" height="199" /> </p>
<h3>Binding time savers</h3>
<p>Want to use following syntax for set binding in code?</p>
<blockquote><p>Presets.SetBinding(ListBox.ItemsSourceProperty, _device, &quot;Presets&quot;);</p>
</blockquote>
<p>This piece of code sets binding to Preset DependencyObject, which is Listbox and connects ListBox.ItemsSource dependency property with “Presets” property of CLR object _device. How it done? Simple, as usual</p>
<blockquote><p>[DebuggerStepThrough]     <br />public static BindingExpressionBase SetBinding(this DependencyObject target, DependencyProperty dp, object source, string path) {      <br />&#160;&#160; Binding b = new Binding(path);      <br />&#160;&#160; b.Source = source;      <br />&#160;&#160; return BindingOperations.SetBinding(target, dp, b);      <br />}</p>
</blockquote>
<p>But what to do when we need a converter? Simple:</p>
<blockquote><p>[DebuggerStepThrough]     <br />public static BindingExpressionBase SetBinding(this DependencyObject target, DependencyProperty dp, object source, string path, IValueConverter converter) {      <br />&#160;&#160; Binding b = new Binding(path);      <br />&#160;&#160; b.Source = source;      <br />&#160;&#160; b.Converter = converter;      <br />&#160;&#160; return BindingOperations.SetBinding(target, dp, b);      <br />}</p>
</blockquote>
<p>However to use this method, we need to create special object, which implements IValueConverter. Whey not to do it generically? Like this:</p>
<blockquote><p>SignalTransform.SetBinding(ScaleTransform.ScaleYProperty, _device.RDS,&quot;SignalStrength&quot;, new ValueConverter&lt;byte, double&gt;(b =&gt; { return 1-(b / 36d); }));</p>
</blockquote>
<p>But we need this special handy ValueConverter class. What’s the problem? Here come the king:</p>
<blockquote><p>public class ValueConverter&lt;TIN, TOUT&gt; : IValueConverter { </p>
<p>&#160;&#160; public ValueConverter(Func&lt;TIN, TOUT&gt; forwardConversion) {     <br />&#160;&#160;&#160;&#160;&#160; ForwardConversion = forwardConversion;      <br />&#160;&#160; } </p>
<p>&#160;&#160; public ValueConverter(Func&lt;TIN, TOUT&gt; forwardConversion, Func&lt;TOUT, TIN&gt; reverseConversion) {     <br />&#160;&#160;&#160;&#160;&#160; ForwardConversion = forwardConversion;      <br />&#160;&#160;&#160;&#160;&#160; ReverseConversion = reverseConversion;      <br />&#160;&#160; } </p>
<p>&#160;&#160; public Func&lt;TIN, TOUT&gt; ForwardConversion { get; set; } </p>
<p>&#160;&#160; public Func&lt;TOUT, TIN&gt; ReverseConversion { get; set; }     <br />&#160;&#160; public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {      <br />&#160;&#160;&#160;&#160;&#160; try {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var in1 = Object.ReferenceEquals(value, DependencyProperty.UnsetValue) ? default(TIN) : (TIN)value;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return ForwardConversion(in1);      <br />&#160;&#160;&#160;&#160;&#160; } catch {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return Binding.DoNothing;      <br />&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160; } </p>
<p>&#160;&#160; public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {     <br />&#160;&#160;&#160;&#160;&#160; try {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var out1 = Object.ReferenceEquals(value, DependencyProperty.UnsetValue) ? default(TOUT) : (TOUT)value;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return ReverseConversion(out1);      <br />&#160;&#160;&#160;&#160;&#160; } catch {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return Binding.DoNothing;      <br />&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160; } </p>
<p>}</p>
</blockquote>
<p>Isn’t it really simple? But what to do with ugly App.Current.Dispatcher.BeginInvoke((SendOrPostCallback)delegate(object o)…? Use dispatcher time savers. </p>
<h3>Dispatcher time savers</h3>
<p>Don’t you ever want to do this in order to make context switching between UI thread and other application thread in WPF?</p>
<blockquote><p>this.Dispatch(() =&gt; {… DO SOMETHING IN UI THREAD …};</p>
</blockquote>
<p>Now you can (with default and preset DispatcherPriority:</p>
<blockquote><p>public static DispatcherOperation Dispatch(this DispatcherObject sender, Action callback) { return sender.Dispatch(DispatcherPriority.Normal, callback); } </p>
<p>public static DispatcherOperation Dispatch(this DispatcherObject sender,&#160; DispatcherPriority priority, Action callback) {     <br />&#160;&#160; if (sender.Dispatcher == null) return null;      <br />&#160;&#160; if (sender.Dispatcher.CheckAccess()) {      <br />&#160;&#160;&#160;&#160;&#160; callback();      <br />&#160;&#160;&#160;&#160;&#160; return null;      <br />&#160;&#160; } else {      <br />&#160;&#160;&#160;&#160;&#160; return sender.Dispatcher.BeginInvoke(priority, callback);      <br />&#160;&#160; }      <br />}</p>
</blockquote>
<p>Nice, isn’t it? But what to do if we do not want to set binding, but we do want to be notified about property change of dependency objects? </p>
<h3>Bindingless handlers time saver</h3>
<p>Let’s assume, that we have “Tune” UIelement, which has Angle property, but not exposes PropertyChanged event (like it done with <a target="_blank" href="http://blogs.msdn.com/expression/archive/2007/10/13/rotary-custom-control.aspx">Rotary custom control by Expression Blend team</a>… Designers, you know… <img src='http://khason.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>However I want to be able to add handler for Angle dependency property changed event and do something when it changed. Like this:</p>
<blockquote><p>Tune.AddValueChanged(RotaryControl.RotaryControl.AngleProperty, (s, ex) =&gt; {     <br />&#160;&#160; _device.Tune(Tune.Angle &gt; _prevTune);      <br />&#160;&#160; _prevTune = Tune.Angle;      <br />});</p>
</blockquote>
<p>Here comes our time saver for this purpose:</p>
<blockquote><p>public static void AddValueChanged(this DependencyObject sender, DependencyProperty property, EventHandler handler) {     <br />&#160;&#160; DependencyPropertyDescriptor.FromProperty(property, sender.GetType()).AddValueChanged(sender, handler);      <br />}</p>
</blockquote>
<p>But if we add handler we should be able to remove it too.</p>
<blockquote><p>public static void RemoveValueChanged(this DependencyObject sender, DependencyProperty property, EventHandler handler) {     <br />&#160;&#160; DependencyPropertyDescriptor.FromProperty(property, sender.GetType()).RemoveValueChanged(sender, handler);      <br />}</p>
</blockquote>
<p>Now we done with some of my nifty helpers. And last, but not the least: </p>
<h3>All times question: how to scale ranges</h3>
<p>Here is how <img src='http://khason.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<blockquote><p>public static double ToRange(this double value, double minSource, double maxSource, double minTarget, double maxTarget) {     <br />&#160;&#160; var sr = maxSource &#8211; minSource;      <br />&#160;&#160; var tr = maxTarget &#8211; minTarget;      <br />&#160;&#160; var ratio = sr / tr;      <br />&#160;&#160; return minTarget+(value / ratio);      <br />}</p>
</blockquote>
<p>Now we can connect them and get something like this:</p>
<blockquote><p>Volume.AddValueChanged(RotaryControl.RotaryControl.AngleProperty, (s, ex) =&gt; {     <br />&#160;&#160; DirectSoundMethods.Volume = (int)Volume.Angle.ToRange(Volume.CounterClockwiseMostAngle, Volume.ClockwiseMostAngle, -4000, 0);      <br />});</p>
</blockquote>
<p>Isn’t it brilliant? </p>
<p>Have a good day and <a target="_blank" href="http://www.codeproject.com/KB/WPF/fmradio.aspx">be sure to read and rate my last article on Code Project</a> <img src='http://khason.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Be good people.</p>


<p>Related posts:<ol><li><a href='http://khason.net/dev/read-singleton-approach-in-wpf-application/' rel='bookmark' title='Permanent Link: Real singleton approach in WPF application'>Real singleton approach in WPF application</a></li>
<li><a href='http://khason.net/dev/inotifypropertychanged-auto-wiring-or-how-to-get-rid-of-redundant-code/' rel='bookmark' title='Permanent Link: INotifyPropertyChanged auto wiring or how to get rid of redundant code'>INotifyPropertyChanged auto wiring or how to get rid of redundant code</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://khason.net/dev/nifty-time-savers-for-wpf-development/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
