tag:blogger.com,1999:blog-267726132024-03-07T05:53:40.170+02:00IProgrammer<T>C#, SQL, JavaScript and more Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.comBlogger204125tag:blogger.com,1999:blog-26772613.post-75241429478906128722017-02-13T14:49:00.002+02:002017-02-13T14:49:19.334+02:00Ending the Great Debate on Enum FlagsThis <a href="https://www.codeproject.com/Articles/396851/Ending-the-Great-Debate-on-Enum-Flags?msg=5361210#xx5361210xx" target="_blank">article </a>explains how enumeration and flags work in C#.NET and how to properly use them.Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-44155968731898036552015-06-03T12:25:00.002+03:002015-06-03T12:25:47.275+03:00How do i create an InstallShield LE project to install a windows service?The main solution exist <a href="http://stackoverflow.com/a/13162618/1755451" target="_blank">here</a><br />
But real help is hiding in the comment:<br />
<blockquote class="tr_bq">
<span class="comment-copy">This option does not start the service after installation. To install service and start it, in solution explorer, select <b>3. Configure Target System > Services</b></span> </blockquote>
<span style="font-size: x-small;">Regards to <a href="http://stackoverflow.com/users/676300/rajeev" target="_blank">Rajeev</a></span>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-35439308735502513812015-05-11T13:12:00.001+03:002015-05-11T13:12:41.708+03:00RSA Key Converter - Superdry Developer<a href="https://superdry.apphb.com/tools/online-rsa-key-converter#.VVCAjGKqqNQ.blogger">RSA Key Converter - Superdry Developer</a>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-86480094720121672562014-11-06T11:09:00.000+02:002014-11-06T11:09:06.185+02:00Visual Studio 2012 Crashes at StartupThe solution for famous problem exists <a href="http://sumeetsharma84.blogspot.co.il/2013/07/visual-studio-2012-wont-start-or-it.html" target="_blank">here</a>. But my Registry not included all required keys from the article. In the 3rd page of Google search was found very small but very effective advice:<br />
<blockquote class="tr_bq">
<blockquote>
You would get above error if ieproxy.dll is not registered properly. Re register Ieproxy.dll.<br />
<div>
C:\Program Files\Internet Explorer>regsvr32 /u ieproxy.dll<br />
C:\Program Files\Internet Explorer>regsvr32 ieproxy.dll<br />
C:\Program Files (x86)\Internet Explorer>regsvr32 /u ieproxy.dll<br />
C:\Program Files (x86)\Internet Explorer>regsvr32 ieproxy.dll</div>
</blockquote>
</blockquote>
Full post exists <a href="http://www.codeovereasy.com/2013/06/visual-studio-2012-has-unexpectedly-stopped/#comment-145444" target="_blank">here</a>.<br />
Thank you, Derek Smith!Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-79245738498013094582014-10-02T12:40:00.000+03:002014-10-07T10:46:17.060+03:00Web.config and config file for every project in solutionSuppose a given project solution: core, data access layer and several "plugin" modules. In order to prevent changes in the core all configurations was moved to web.config. Also we would like that every module will use a dedicated config file because a "plugin" can be added and/or removed.<br />
<br />
<u><b>First solution:</b></u><br />
In web.config file in the section "appSettings" available attribute "file" for moving segment of web config to another file. It's nice but we need more then one config file and therefore required additional configurations.Create "sectionGroup":<br />
<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol start="2" style="background: #ffffff; margin: 0; padding: 0 0 0 5px;">
<li><span style="color: blue;"><</span><span style="color: #a31515;">configuration</span><span style="color: blue;">></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> <</span><span style="color: #a31515;">configSections</span><span style="color: blue;">></span></li>
<li><span style="color: blue;"> <</span><span style="color: #a31515;">sectionGroup</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Plugins</span>"<span style="color: blue;">></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> <</span><span style="color: #a31515;">section</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Module1</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</span>"<span style="color: blue;">/></span></li>
<li><span style="color: blue;"> <</span><span style="color: #a31515;">section</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Module2</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</span>"<span style="color: blue;">/></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> </</span><span style="color: #a31515;">sectionGroup</span><span style="color: blue;">></span></li>
<li><span style="color: blue;"> </</span><span style="color: #a31515;">configSections</span><span style="color: blue;">></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> </span>.....</li>
</ol>
</div>
</div>
<br />
<br />
Module1 and Module2 this is a names of our plugins. Create configuration section for group and define key for path of module config file in every named section:<br />
<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol start="10" style="background: #ffffff; margin: 0; padding: 0 0 0 5px;">
<li><br />
</li>
<li style="background: #f3f3f3;"><span style="color: blue;"> <</span><span style="color: #a31515;">Plugins</span><span style="color: blue;">></span></li>
<li><span style="color: blue;"> <</span><span style="color: #a31515;">Module1</span><span style="color: blue;">></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> <</span><span style="color: #a31515;">add</span><span style="color: blue;"> </span><span style="color: red;">key</span><span style="color: blue;">=</span>"<span style="color: blue;">ConfigFile</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">App1.config</span>"<span style="color: blue;">/></span></li>
<li><span style="color: blue;"> </</span><span style="color: #a31515;">Module1</span><span style="color: blue;">></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> <</span><span style="color: #a31515;">Module2</span><span style="color: blue;">></span></li>
<li><span style="color: blue;"> <</span><span style="color: #a31515;">add</span><span style="color: blue;"> </span><span style="color: red;">key</span><span style="color: blue;">=</span>"<span style="color: blue;">ConfigFile</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">App2.config</span>"<span style="color: blue;">/></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> </</span><span style="color: #a31515;">Module2</span><span style="color: blue;">></span></li>
<li><span style="color: blue;"> </</span><span style="color: #a31515;">Plugins</span><span style="color: blue;">></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> </span></li>
</ol>
</div>
</div>
<br />
Create 2 new config files "App1.config" and "App2.config". In the properties of files change "Copy to Output Directory" to "Copy always". The content of module config file look like this one:<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol start="1" style="background: #ffffff; margin: 0; padding: 0 0 0 5px;">
<li><span style="color: blue;"><?</span><span style="color: #a31515;">xml</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">1.0</span>"<span style="color: blue;"> </span><span style="color: red;">encoding</span><span style="color: blue;">=</span>"<span style="color: blue;">utf-8</span>"<span style="color: blue;"> ?></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"><</span><span style="color: #a31515;">configuration</span><span style="color: blue;">></span></li>
<li><span style="color: blue;"> <</span><span style="color: #a31515;">appSettings</span><span style="color: blue;">></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> <</span><span style="color: #a31515;">add</span><span style="color: blue;"> </span><span style="color: red;">key</span><span style="color: blue;">=</span>"<span style="color: blue;">AnyKey</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Bla-Bla-Bla</span>"<span style="color: blue;">/></span></li>
<li><span style="color: blue;"> <</span><span style="color: #a31515;">add</span><span style="color: blue;"> </span><span style="color: red;">key</span><span style="color: blue;">=</span>"<span style="color: blue;">AnyKey2</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Bla-Bla-Bla</span>"<span style="color: blue;">/></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> </</span><span style="color: #a31515;">appSettings</span><span style="color: blue;">></span></li>
<li><span style="color: blue;"></</span><span style="color: #a31515;">configuration</span><span style="color: blue;">></span></li>
</ol>
</div>
</div>
<br />
An using code:<br />
<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol start="12" style="background: #ffffff; margin: 0; padding: 0 0 0 5px; white-space: nowrap;">
<li><span style="color: blue;">class</span> <span style="color: #2b91af;">Test</span></li>
<li style="background: #f3f3f3;">{</li>
<li> <span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: blue;">readonly</span> <span style="color: #2b91af;">Configuration</span> config = <span style="color: #2b91af;">ConfigurationManager</span>.OpenMappedExeConfiguration(</li>
<li style="background: #f3f3f3;"> <span style="color: green;">//Get config file</span></li>
<li> <span style="color: blue;">new</span> <span style="color: #2b91af;">ExeConfigurationFileMap</span>()</li>
<li style="background: #f3f3f3;"> { <span style="color: green;">//Web.config part //File name </span></li>
<li> ExeConfigFilename = ((<span style="color: #2b91af;">NameValueCollection</span>)<span style="color: #2b91af;">ConfigurationManager</span>.GetSection(<span style="color: #a31515;">"Plugins/Module1"</span>))[<span style="color: #a31515;">"ConfigFile"</span>]</li>
<li style="background: #f3f3f3;"> },</li>
<li> <span style="color: #2b91af;">ConfigurationUserLevel</span>.None);</li>
<li style="background: #f3f3f3;"> </li>
<li> <span style="color: blue;">private</span> <span style="color: blue;">void</span> Foo()</li>
<li style="background: #f3f3f3;"> {</li>
<li> <span style="color: blue;">var</span> value = config.AppSettings.Settings[<span style="color: #a31515;">"AnyKey"</span>].Value;</li>
<li style="background: #f3f3f3;"> <span style="color: #2b91af;">Console</span>.WriteLine(value);</li>
<li> }</li>
<li style="background: #f3f3f3;">}</li>
</ol>
</div>
</div>
<br />
<br />
<u><b>Second solution:</b></u><br />
Add new section "Plugin". We are use the type DictionarySectionHandler in order to get values as Dictionary<span style="color: blue;">:</span><br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol start="2" style="background: #ffffff; margin: 0; padding: 0 0 0 5px;">
<li><span style="color: blue;"><</span><span style="color: #a31515;">configuration</span><span style="color: blue;">></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> <</span><span style="color: #a31515;">configSections</span><span style="color: blue;">></span></li>
<li><span style="color: blue;"> <</span><span style="color: #a31515;">section</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Plugin</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">System.Configuration.DictionarySectionHandler, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</span>"<span style="color: blue;">/></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> </</span><span style="color: #a31515;">configSections</span><span style="color: blue;">></span></li>
</ol>
</div>
</div>
<br />
Add values:<br />
<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol start="7" style="background: #ffffff; margin: 0; padding: 0 0 0 5px;">
<li><span style="color: blue;"><</span><span style="color: #a31515;">Plugin</span><span style="color: blue;">></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> <</span><span style="color: #a31515;">add</span><span style="color: blue;"> </span><span style="color: red;">key</span><span style="color: blue;">=</span>"<span style="color: blue;">ConfigFileOfModule1</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">App1.config</span>"<span style="color: blue;">/></span></li>
<li><span style="color: blue;"> <</span><span style="color: #a31515;">add</span><span style="color: blue;"> </span><span style="color: red;">key</span><span style="color: blue;">=</span>"<span style="color: blue;">ConfigFileOfModule2</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">App2.config</span>"<span style="color: blue;">/></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"></</span><span style="color: #a31515;">Plugin</span><span style="color: blue;">></span></li>
</ol>
</div>
</div>
<br />
Create 2 new config files "App1.config" and "App2.config". In the properties of files change "Copy to Output Directory" to "Copy always". The content of module config file look like this one:<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol start="1" style="background: #ffffff; margin: 0; padding: 0 0 0 5px;">
<li><span style="color: blue;"><?</span><span style="color: #a31515;">xml</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">1.0</span>"<span style="color: blue;"> </span><span style="color: red;">encoding</span><span style="color: blue;">=</span>"<span style="color: blue;">utf-8</span>"<span style="color: blue;"> ?></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"><</span><span style="color: #a31515;">configuration</span><span style="color: blue;">></span></li>
<li><span style="color: blue;"> <</span><span style="color: #a31515;">appSettings</span><span style="color: blue;">></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> <</span><span style="color: #a31515;">add</span><span style="color: blue;"> </span><span style="color: red;">key</span><span style="color: blue;">=</span>"<span style="color: blue;">AnyKey</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Bla-Bla-Bla</span>"<span style="color: blue;">/></span></li>
<li><span style="color: blue;"> <</span><span style="color: #a31515;">add</span><span style="color: blue;"> </span><span style="color: red;">key</span><span style="color: blue;">=</span>"<span style="color: blue;">AnyKey2</span>"<span style="color: blue;"> </span><span style="color: red;">value</span><span style="color: blue;">=</span>"<span style="color: blue;">Bla-Bla-Bla</span>"<span style="color: blue;">/></span></li>
<li style="background: #f3f3f3;"><span style="color: blue;"> </</span><span style="color: #a31515;">appSettings</span><span style="color: blue;">></span></li>
<li><span style="color: blue;"></</span><span style="color: #a31515;">configuration</span><span style="color: blue;">></span></li>
</ol>
</div>
</div>
<br />
An using code:<br />
<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol start="40" style="background: #ffffff; margin: 0; padding: 0 0 0 5px;">
<li><span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: blue;">readonly</span> <span style="color: #2b91af;">IDictionary</span> section = (<span style="color: #2b91af;">IDictionary</span>)<span style="color: #2b91af;">ConfigurationManager</span>.GetSection(<span style="color: #a31515;">"Plugin"</span>);</li>
<li style="background: #f3f3f3;"><span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: blue;">readonly</span> System.Configuration.<span style="color: #2b91af;">Configuration</span> config =</li>
<li> <span style="color: #2b91af;">ConfigurationManager</span>.OpenMappedExeConfiguration(</li>
<li style="background: #f3f3f3;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">ExeConfigurationFileMap</span>()</li>
<li> {</li>
<li style="background: #f3f3f3;"> ExeConfigFilename = section[<span style="color: #a31515;">"ConfigFileOfModule1"</span>].ToString()</li>
<li> }, <span style="color: #2b91af;">ConfigurationUserLevel</span>.None);</li>
<li style="background: #f3f3f3;"><span style="color: blue;">private</span> <span style="color: blue;">void</span> Foo()</li>
<li>{</li>
<li style="background: #f3f3f3;"> <span style="color: blue;">var</span> value = config.AppSettings.Settings[<span style="color: #a31515;">"AnyKey"</span>].Value;</li>
<li>}</li>
</ol>
</div>
</div>
<br />
<br />
<br />
Enjoy!<br />
<br />
<br />
<br />
<br />
<br />Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-12259407813851110942014-09-16T17:24:00.002+03:002014-09-16T17:24:47.204+03:00How to include value types AND strings in generic constraint.I'm very like to use generics in the code. Usually generic implementation is working smoothly but exists one small problem with generic value types: cannot use string typed value because System.String is a class. <br />
<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #ddd; max-height: 300px; overflow: auto;">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li>Foo<<span style="color: blue;">string</span>>(<span style="color: #a31515;">"abc"</span>);</li>
</ol>
</div>
</div>
<br />
<br />
<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #ddd; max-height: 300px; overflow: auto;">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color: blue;">private</span> <span style="color: blue;">void</span> Foo<t>(T value) <span style="color: blue;">where</span> T : <span style="color: blue;">struct</span></t></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: green;">//...</span></li>
<li style="background: #f3f3f3;">}</li>
</ol>
</div>
</div>
<br />
The simple solution is creating overwrite method:<br />
<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #ddd; max-height: 300px; overflow: auto;">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color: blue;">private</span> <span style="color: blue;">void</span> Foo<t>(T value) <span style="color: blue;">where</span> T : <span style="color: blue;">string</span></t></li>
<li>{</li>
<li><span style="color: green;">//...</span></li>
<li>}</li>
</ol>
</div>
</div>
<br />
Nice, but not perfect. The beautiful idea was offered by <a href="http://stackoverflow.com/users/436376/keiths" rel="nofollow" target="_blank">KeithS </a>instead to restrict a value to struct change it to IConvertible. Next types implemented an interface IConvertible but now String can be included in the constraint:<br />
<i>Boolean <br />Byte <br />Char <br />DateTime<br />Decimal <br />Double <br />Int16 <br />Int32 <br />Int64 <br />SByte <br />Single <br />String <br />Type <br />UInt16 <br />UInt32 <br />UInt64 </i><br />
<i><br /></i>
Final:<br />
<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #ddd; max-height: 300px; overflow: auto;">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color: blue;">private</span> <span style="color: blue;">void</span> Foo<t>(T value) <span style="color: blue;">where</span> T : <span style="color: #2b91af;">IConvertible</span></t></li>
<li>{</li>
<li><span style="color: green;">//...</span></li>
<li>}</li>
</ol>
</div>
</div>
<i><br /></i>
<br />
<br />Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-4697942610261623462014-08-26T13:24:00.000+03:002014-08-26T13:29:06.051+03:00C# generation: from '?' via '??' to '???'C# include several usable but not famous operators. Today we'll consider the generation of operator '?'.<br />
The first and known from language C old operator '?' was appeared in C# 1.0 in the Visual Studio 2002. An operator using for condition instead to block <b>if-else</b>:<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">
</div>
<div style="background: #ddd; overflow: auto;">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color: #2b91af;">Random</span> rnd = <span style="color: blue;">new</span> <span style="color: #2b91af;">Random</span>();</li>
<li style="background: #f3f3f3;"><span style="color: green;">//Long way</span></li>
<li><span style="color: blue;">bool</span> isLessTo50;</li>
<li style="background: #f3f3f3;"><span style="color: blue;">if</span> (rnd.Next(100) < 50)</li>
<li>{</li>
<li style="background: #f3f3f3;"> isLessTo50 = <span style="color: blue;">true</span>;</li>
<li>}</li>
<li style="background: #f3f3f3;"><span style="color: blue;">else</span></li>
<li>{</li>
<li style="background: #f3f3f3;"> isLessTo50 = <span style="color: blue;">false</span>;</li>
<li>}</li>
<li> </li>
<li style="background: #f3f3f3;"><span style="color: green;">//Short way</span></li>
<li><span style="color: blue;">bool</span> isLessTo50 = rnd.Next(100) < 50 ? <span style="color: blue;">true</span> : <span style="color: blue;">false</span>;</li>
</ol>
</div>
</div>
<br />
The next '??' was offered 3 years later in Visual Studio 2005. The <span class="input">??</span> operator is called the null-coalescing operator. It returns the left-hand operand if the operand is not null; otherwise it returns the right hand operand:<br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: white; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">
</div>
<div style="background: #ddd; overflow: auto;">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color: #2b91af;">DateTime</span>? dt = GetDate();<span style="color: blue;"><span style="color: black;"></span></span></li>
<li style="background: #f3f3f3;"><span style="color: green;">//Regular way</span></li>
<li><span style="color: blue;">if</span> (dt != <span style="color: blue;">null</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li> <span style="color: blue;">return</span> dt;</li>
<li style="background: #f3f3f3;">}</li>
<li><span style="color: blue;">else</span></li>
<li style="background: #f3f3f3;">{</li>
<li> <span style="color: blue;">return</span> <span style="color: #2b91af;">DateTime</span>.Now;</li>
<li style="background: #f3f3f3;">}</li>
<li><br />
</li>
<li style="background: #f3f3f3;"><span style="color: green;">//Short way</span></li>
<li><span style="color: blue;">return</span> (dt != <span style="color: blue;">null</span>) ? dt : <span style="color: #2b91af;">DateTime</span>.Now;</li>
<li style="background: #f3f3f3;"><br />
</li>
<li><span style="color: green;">//New way</span></li>
<li style="background: #f3f3f3;"><span style="color: blue;">return</span> dt ?? <span style="color: #2b91af;">DateTime</span>.Now; </li>
</ol>
</div>
</div>
<br />
The last operator '???' <span class="short_text" id="result_box" lang="en"><span class="hps">was announced in Visual Studio 2012. I'm very like it because he is cutting the validation of object:</span></span><br />
<div style="border: #000080 1px solid; color: black; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #ddd; overflow: auto;">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color: blue;">class</span> <span style="color: #2b91af;">Person</span></li>
<li style="background: #f3f3f3;">{</li>
<li> <span style="color: blue;">public</span> <span style="color: blue;">string</span> Name { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</li>
<li style="background: #f3f3f3;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span> ID { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</li>
<li>}</li>
<li style="background: #f3f3f3;"> </li>
<li><span style="color: green;">//The program</span></li>
<li style="background: #f3f3f3;"> <span style="color: #2b91af;">Person</span> person = InitPerson();</li>
<li><br />
</li>
<li style="background: #f3f3f3;"><span style="color: green;">//Old way</span></li>
<li><span style="color: blue;">if</span> (person != <span style="color: blue;">null</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li> <span style="color: blue;">return</span> person.ID;</li>
<li style="background: #f3f3f3;">}</li>
<li><span style="color: blue;">else</span></li>
<li style="background: #f3f3f3;">{</li>
<li> <span style="color: blue;">return</span> <span style="color: blue;">default</span>(<span style="color: blue;">int</span>);</li>
<li style="background: #f3f3f3;">}</li>
<li> </li>
<li style="background: #f3f3f3;"><span style="color: green;">//New way</span></li>
<li><span style="color: blue;">return</span> person.<span style="color: blue;">ID</span> ??? <span style="color: blue;">default</span>(<span style="color: blue;">int);</span></li>
</ol>
</div>
</div>
<br />
In Visual Studio 2014 the operator '?..' <span class="short_text" id="result_box" lang="en"><span class="hps">did not receive</span> <span class="hps">renewal but maybe in next versions we'll see '????' and even '?????' :-).</span></span>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-38335436107379326662014-08-05T16:42:00.000+03:002014-08-05T16:42:02.902+03:00Dependency injection using Castle Windsor<br />
<h4 class="pagetitle">
Castle Windsor :</h4>
<div class="pagetitle">
<a href="https://github.com/castleproject/Windsor/releases" target="_blank">Download page </a></div>
<div class="pagetitle">
<a href="http://docs.castleproject.org/Windsor.MainPage.ashx" target="_blank">Main page</a> </div>
<div class="pagetitle">
<a href="http://docs.castleproject.org/Windsor.Factory-Support-Facility.ashx" target="_blank">Factory Support Facility </a></div>
<div class="pagetitle">
<a href="http://docs.castleproject.org/Windsor.Registering-components.ashx" target="_blank">XML configuration</a> </div>
<div class="pagetitle">
<br /></div>
<h4 class="pagetitle">
Articles: </h4>
<div class="pagetitle">
</div>
<div class="pagetitle">
Excellent <a href="http://app-code.net/wordpress/?p=641" target="_blank">article</a> for beginner. </div>
<div class="header-post-title-class">
A quick <a href="http://mookid.dk/oncode/archives/10" target="_blank">introduction.</a></div>
<div class="header-post-title-class">
<a href="http://codebetter.com/davidhayden/2007/12/13/factory-method-support-in-castle-windsor-and-spring-net/" target="_blank">Factory Method Support in Castle Windsor</a>. </div>
<div class="pagetitle">
<a href="http://mookid.dk/oncode/archives/10" target="_blank"></a> </div>
<div class="pagetitle">
</div>
<h4 class="pagetitle">
</h4>
<div class="pagetitle">
<br /></div>
<h2 class="pagetitle">
</h2>
Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-64538757415077754862013-10-15T13:00:00.001+03:002013-10-15T13:00:14.827+03:00Repair IE8 (IE7) and IE9Unbelievable! After 2 days of research in Microsoft's sites why IE doesn't work the solution was found in non-Microsoft site.<br />
Thank you very much Mr Kai Schätzl!<br />
<br />
<a href="http://iefaq.info/index.php?action=artikel&cat=48&id=133&artlang=en" target="_blank">Link to article</a>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-12434793649426148382013-09-30T17:15:00.002+03:002013-09-30T17:17:53.611+03:00How to blink text in all browsers<b>Javascript:</b><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><pre style="line-height: 125%; margin: 0;"><span style="color: #333333;"><</span>script type<span style="color: #333333;">=</span><span style="background-color: #fff0f0;">"text/javascript"</span> language<span style="color: #333333;">=</span><span style="background-color: #fff0f0;">"javascript"</span><span style="color: #333333;">></span>
<span style="color: #007020;">window</span>.onload<span style="color: #333333;">=</span>blinkOn;
<span style="color: #008800; font-weight: bold;">function</span> blinkOn()
{ <span style="color: #007020;">document</span>.getElementById(<span style="background-color: #fff0f0;">"blink"</span>).style.color<span style="color: #333333;">=</span><span style="background-color: #fff0f0;">"Red"</span>;
setTimeout(<span style="background-color: #fff0f0;">"blinkOff()"</span>,<span style="color: #0000dd; font-weight: bold;">1000</span>);
}
<span style="color: #008800; font-weight: bold;">function</span> blinkOff()
{ <span style="color: #007020;">document</span>.getElementById(<span style="background-color: #fff0f0;">"blink"</span>).style.color<span style="color: #333333;">=</span><span style="background-color: #fff0f0;">""</span>;
setTimeout(<span style="background-color: #fff0f0;">"blinkOn()"</span>,<span style="color: #0000dd; font-weight: bold;">1000</span>);
}
<span style="color: #333333;"><</span><span >/script></span>
</pre></div><br />
<br />
<b>HTML</b><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><pre style="line-height: 125%; margin: 0;"><span style="color: #007700;"><div</span> <span style="color: #0000cc;">id=</span><span style="background-color: #fff0f0;">"blink"</span><span style="color: #007700;">></span>Hello, World!<span style="color: #007700;"></div></span>
</pre></div><br />
<span style="font-size: x-small;"><span style="font-weight: normal;">Thanks to</span> <a href="http://stevenmcconnon.com/blog/2011/01/07/how-to-blink-text-in-all-browsers/" target="_blank">Steven McConnon</a></span>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-17088820941598829982013-09-18T10:03:00.001+03:002013-09-18T10:03:23.597+03:00Simple Tooltip with jQuery<a href="http://www.alessioatzeni.com/blog/simple-tooltip-with-jquery-only-text/">Link</a>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-6667903628456859062013-02-26T10:19:00.003+02:002013-02-26T10:20:47.362+02:00C# property names without hardcoded strings<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; background: white; border-width: .1em .1em .1em .8em; border: solid gray; color: black; overflow: auto; padding: .2em .6em; width: auto;"><pre style="line-height: 125%; margin: 0;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Person</span>
{
<span style="color: blue;">public</span> <span style="color: #2b91af;">int</span> Id { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }
<span style="color: blue;">public</span> <span style="color: #2b91af;">string</span> Name { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }
}
<span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Test</span>
{
<span style="color: blue;">protected</span> <span style="color: blue;">void</span> InitDropDownList()
{
DropDownList ddl = <span style="color: blue;">new</span> DropDownList();
ddl.DataSource = <span style="color: blue;">new</span> List<Person> {
<span style="color: blue;">new</span> Person{ Id = 1, Name = <span style="color: #a31515;">"John Smith"</span> },
<span style="color: blue;">new</span> Person{ Id = 2,Name = <span style="color: #a31515;">"Moshe Perez"</span> } };
<span style="color: green;">//Old and bad way</span>
ddl.DataValueField = <span style="color: #a31515;">"Id"</span>;
ddl.DataTextField = <span style="color: #a31515;">"Name"</span>;
<span style="color: green;">//New way</span>
ddl.DataValueField = GetPropertyName(() => <span style="color: blue;">new</span> Person().Id);
ddl.DataValueField = GetPropertyName(() => <span style="color: blue;">new</span> Person().Name);
ddl.DataBind();
}
<span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">string</span> GetPropertyName<T></pre><pre style="line-height: 125%; margin: 0;">(Expression<Func<T>> expression)
{
MemberExpression body = (MemberExpression)expression.Body;
<span style="color: blue;">return</span> body.Member.Name;
}
}</pre></div><br />
<br />
<br />
<pre style="line-height: 125%; margin: 0;">From <a href="http://handcraftsman.wordpress.com/2008/11/11/how-to-get-c-property-names-without-magic-strings/" target="_blank">here</a></pre>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com1tag:blogger.com,1999:blog-26772613.post-21038152305314472042013-01-02T12:38:00.001+02:002013-01-02T13:10:14.923+02:00Test value generatorFrequently in the test time required to set random values to variables. The simple class will help you to save a time in the future:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; background: white; border-width: .1em .1em .1em .8em; border: solid gray; color: black; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Generator</span>
{
<span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">readonly</span> Random RND = <span style="color: blue;">new</span> Random();
<span style="color: green;">// Generate IP address</span>
<span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">string</span> GetIP(<span style="color: #2b91af;">bool</span> isIPv6 = <span style="color: blue;">false</span>)
{
<span style="color: blue;">if</span> (isIPv6)
{
<span style="color: blue;">return</span> <span style="color: #2b91af;">string</span>.Format(<span style="color: #a31515;">"{0}.{1}.{2}.{3}.{4}.{5}"</span>, RND.Next(0,256), RND.Next(0,256), RND.Next(0,256), RND.Next(0,256), RND.Next(0,256), RND.Next(0,256));
}
<span style="color: blue;">return</span> <span style="color: #2b91af;">string</span>.Format(<span style="color: #a31515;">"{0}.{1}.{2}.{3}"</span>, RND.Next(0,256), RND.Next(0,256), RND.Next(0,256), RND.Next(0,256));
}
<span style="color: green;">// Generate GPS coordinate</span>
<span style="color: blue;">public</span> <span style="color: blue;">static</span> System.Device.Location.GeoCoordinate GetGeo()
{
<span style="color: blue;">return</span> <span style="color: blue;">new</span> System.Device.Location.GeoCoordinate
{
Latitude = GetDouble(90),
Longitude = GetDouble(90),
};
}
<span style="color: green;">// Generate string</span>
<span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">string</span> GetString(<span style="color: #2b91af;">int</span> size, <span style="color: #2b91af;">int</span> percentOfSymbols = 30, <span style="color: #2b91af;">int</span> percentOfDigits = 30)
{
StringBuilder builder = <span style="color: blue;">new</span> StringBuilder();
<span style="color: #2b91af;">int</span>[] symbol = <span style="color: blue;">new</span>[] { 33, 36, 38, 64, 94 };
<span style="color: #2b91af;">int</span>[] digits = <span style="color: blue;">new</span>[] { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 };
<span style="color: #2b91af;">int</span> symbolsAmount = (<span style="color: #2b91af;">int</span>) size * percentOfSymbols /100;
<span style="color: #2b91af;">int</span> digitAmount = (<span style="color: #2b91af;">int</span>)size * percentOfDigits / 100;
<span style="color: blue;">for</span> (<span style="color: #2b91af;">int</span> i = 0; i < size; i++)
{
<span style="color: #2b91af;">int</span> switcher = RND.Next(3);
<span style="color: #2b91af;">char</span> ch;
<span style="color: blue;">if</span> (switcher == 0 && symbolsAmount > 0)
{
<span style="color: #2b91af;">int</span> id = RND.Next(symbol.Length);
ch = Convert.ToChar(symbol[id]);
symbolsAmount--;
}
<span style="color: blue;">else</span> if (switcher == 1 && digitAmount > 0)
{
<span style="color: #2b91af;">int</span> id = RND.Next(digits.Length);
ch = Convert.ToChar(digits[id]);
digitAmount--;
}
<span style="color: blue;">else</span>
{
<span style="color: #2b91af;">bool</span> isLower = RND.Next(2) == 0 ? <span style="color: blue;">false</span> : <span style="color: blue;">true</span>;
ch = Convert.ToChar(
Convert.ToInt32(
Math.Floor(26 * RND.NextDouble() + ((isLower) ? 65 : 97))
)
);
}
builder.Append(ch);
}
<span style="color: blue;">return</span> builder.ToString();
}
<span style="color: green;">// Generate Date</span>
<span style="color: blue;">public</span> <span style="color: blue;">static</span> DateTime GetDate()
{
<span style="color: blue;">return</span> DateTime.Now.AddMinutes( RND.Next(10000000) * (RND.Next() % 2 == 0 ? -1 : 1));
}
<span style="color: green;">//Get double</span>
<span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">double</span> GetDouble(<span style="color: #2b91af;">int</span> limit = <span style="color: blue;">default</span>(<span style="color: #2b91af;">int</span>))
{
<span style="color: blue;">return</span> <span style="color: #2b91af;">double</span>.Parse(<span style="color: #2b91af;">string</span>.Format(<span style="color: #a31515;">"{0}.{1}"</span>, limit == <span style="color: blue;">default</span>(<span style="color: #2b91af;">int</span>) ? RND.Next() : RND.Next(90), RND.Next())) * (RND.Next() % 2 == 0 ? -1 : 1);
}
}
</pre>
</div>
<br />
<a href="http://www.dotnetkicks.com/kick/?url=http://gaaton.blogspot.co.il/2013/01/test-value-generator.html"><img alt="kick it on DotNetKicks.com" border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://gaaton.blogspot.co.il/2013/01/test-value-generator.html" /></a>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-43131071883679728012012-12-23T16:38:00.002+02:002012-12-23T16:38:33.996+02:00Password in SQL<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; background: white; border-width: .1em .1em .1em .8em; border: solid gray; color: black; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: green; font-weight: bold;">DECLARE</span> <span style="color: #303030;">@</span>PWD <span style="color: #303090; font-weight: bold;">varbinary</span>(<span style="color: #0000d0; font-weight: bold;">128</span>)
<span style="color: green; font-weight: bold;">SELECT</span> <span style="color: #303030;">@</span>PWD <span style="color: #303030;">=</span> <span style="color: #0060b0; font-weight: bold;">PWDENCRYPT</span> ( <span style="background-color: #fff0f0;">'password'</span> )
<span style="color: green; font-weight: bold;">SELECT</span> <span style="color: #303030;">@</span>PWD
<span style="color: grey;">-- Correct</span>
<span style="color: green; font-weight: bold;">SELECT</span> <span style="color: #0060b0; font-weight: bold;">PWDCOMPARE</span>(<span style="background-color: #fff0f0;">'password'</span>, <span style="color: #303030;">@</span>Pwd ) <span style="color: grey;">-- 1</span>
<span style="color: grey;">-- Failed</span>
<span style="color: green; font-weight: bold;">SELECT</span> <span style="color: #0060b0; font-weight: bold;">PWDCOMPARE</span>(<span style="background-color: #fff0f0;">'bla-bla-bla'</span>, <span style="color: #303030;">@</span>Pwd ) <span style="color: grey;">-- 0</span></pre>
</div>
<br />Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-6811315237753785602012-12-18T11:13:00.000+02:002016-01-11T10:26:58.436+02:00Shrink DB log file<div style="background: #ffffff; background: white; border-width: .1em .1em .1em .8em; border: solid gray; color: black; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: green; font-weight: bold;">USE</span> dbname;
GO
<span style="color: grey;">-- Truncate the log by changing the database recovery model to SIMPLE.</span>
<span style="color: green; font-weight: bold;">ALTER</span> <span style="color: green; font-weight: bold;">DATABASE</span> dbname
<span style="color: #303090; font-weight: bold;">SET</span> RECOVERY SIMPLE;
GO
<span style="color: grey;">-- Shrink the truncated log file to 1 MB.</span>
DBCC <span style="color: #0060b0; font-weight: bold;">SHRINKFILE</span> (<span style="color: #0000d0; font-weight: bold;">2</span>, <span style="color: #0000d0; font-weight: bold;">1</span>); <span style="color: grey;">-- here 2 is the file ID for trasaction log file,you can also mention the log file name (dbname_log)</span>
GO
<span style="color: grey;">-- Reset the database recovery model.</span>
<span style="color: green; font-weight: bold;">ALTER</span> <span style="color: green; font-weight: bold;">DATABASE</span> dbname
<span style="color: #303090; font-weight: bold;">SET</span> RECOVERY FULL;
GO
</pre>
</div>
<br />
<div>
<span style="font-size: xx-small;">Thanks to <a href="http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/54e6e281-005a-4b07-8c85-3685441f4f3d/#e43f01e7-7008-4681-832c-0d586285f564" target="_blank"> Amit kulkarni hubli</a></span></div>
Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-87894065349530379432012-10-28T11:51:00.001+02:002012-10-28T12:08:16.320+02:00Validation is a boxing value is defaultI very like my lovely extension <a href="http://csharp-extension.blogspot.co.il/2011/07/isdefault-extension.html">IsDefault</a> but unpossible to use it where a value is boxing. A cool feature of C# default(...) cannot help because a argument required Type. After long research was created small solution:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; background: white; border-width: .1em .1em .1em .8em; border: solid gray; color: black; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: blue;">static</span> <span style="color: #2b91af;">bool</span> IsDefault(<span style="color: #2b91af;">object</span> o)
{
<span style="color: blue;">if</span> (o == <span style="color: blue;">null</span>)
{
<span style="color: blue;">return</span> <span style="color: blue;">true</span>;
}
<span style="color: green;">//Check is type os object is ValueType</span>
<span style="color: blue;">if</span> (o.GetType().IsValueType)
{
<span style="color: blue;">return</span> Activator.CreateInstance(o.GetType()).Equals(o);
}
<span style="color: green;">//ReferenceType</span>
<span style="color: blue;">return</span> <span style="color: blue;">false</span>;
}
</pre>
</div>
<br />
<br />
Also can be implemented as <a href="http://csharp-extension.blogspot.co.il/2012/10/validation-is-boxing-value-is-default.html">extension</a>.Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-84301192033939933202012-10-18T10:20:00.004+02:002012-10-18T10:20:53.290+02:00An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'XXX' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions.A web.config of project include next rows:<br />
<div style="background: #ffffff; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">...
<span style="color: #007000"><extensions></span>
<span style="color: #007000"><behaviorExtensions></span>
<span style="color: #007000"><add</span> <span style="color: #0000C0">name=</span><span style="background-color: #fff0f0">"ELEMENT"</span> <span style="color: #0000C0">type=</span><span style="background-color: #fff0f0">"YYY.ZZZ,YYY.XXX, Version=1.0.0.0,Culture=neutral, PublicKeyToken=null"</span> <span style="color: #007000">/></span>
<span style="color: #007000"></behaviorExtensions></span>
<span style="color: #007000"></extensions></span>
...
<span style="color: #007000"><behavior</span> <span style="color: #0000C0">name=</span><span style="background-color: #fff0f0">"BehaviorName"</span><span style="color: #007000">></span>
<span style="color: #007000">ELEMENT</span> <span style="color: #007000">/></span>
<span style="color: #007000"></behavior></span>
</pre></div><br />
In the start project WCF is throwing exception and message: <br />
<b>"An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'ELEMENT' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions."<br />
</b><br />
A problem exists in file AssemblyInfo of YYY.XXX and not in config.<br />
YYY.XXX change build number in every compilation but WCF is require a full name of assembly (AssemblyQualifiedName) and exact assembly file version number.<br />
<br />
Open AssemblyInfo and see last 2 rows:<br />
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #0000C0">[assembly: AssemblyVersion(...)]</span>
<span style="color: #0000C0">[assembly: AssemblyFileVersion(...)]</span>
</pre></div><br />
If a code looks like this:<br />
<div style="background: #ffffff; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #0000C0">[assembly: AssemblyVersion(5.0.1.0)]</span>
<span style="color: #0000C0">[assembly: AssemblyFileVersion(5.0.1.0)]</span>
</pre></div><br />
You not reading current article but if acode looks like this:<br />
<br />
<div style="background: #ffffff; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #0000C0">[assembly: AssemblyVersion(5.0.1.0)]</span>
<span style="color: #0000C0">[assembly: AssemblyFileVersion(5.0.1.*)]</span>
</pre></div><br />
This is a time to change it and resolve a problem. Enjoy. <br />
<br />
<br />
<br />
Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-55315307275317316512012-08-12T10:36:00.000+03:002012-08-12T10:36:19.555+03:00Disable the Browser Back Button<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizv9kXsVD4xRUcidlMXinItF7uvsPqKPeSqxZGXlK5k4CrtzeGq4mRffyEurHIhZCDKYzUw-vLNualTljOD1qlwmq_nSoEW9JytNws03nWMFJGFnxsuQMLYH6x2zG0vX-RVJNtwQ/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> if (window.history) {
window.history.forward(1);
}
</code></pre>
A script tested in IE 9, Chrome and FireFox.<br />
<br />
<br />
<span style="font-size: xx-small;">From <a href="http://www.harelmalka.com/?p=46" target="_blank">here</a></span>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-11679011446110514602012-08-05T13:05:00.000+03:002012-08-05T13:05:24.221+03:00Culture in .NET. All in oneBy inspiration from article <a href="http://deanhume.com/Home/BlogPost/hidden-gems-inside--net-classes/74" target="_blank">Hidden Gems inside .Net Classes </a>I created static class that include short methods for q<span class="short_text" id="result_box" lang="en"><span class="hps">uick</span> <span class="hps">retrieval object or properties of Cultures and Time Zones. All data based on build-in functionality of Framework 4.0</span></span><br />
<!-- code formatted by http://manoli.net/csharpformat/ --><br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: Consolas, "Courier New", Courier, Monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #a31515; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><br />
<pre class="csharpcode"> <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> Culture
{
<span class="preproc">#region</span> Consts
<span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">readonly</span> StringDictionary cultureDetails;
<span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">readonly</span> ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
<span class="preproc">#endregion</span>
<span class="rem">/// <summary></span>
<span class="rem">/// Ctor</span>
<span class="rem">/// </summary></span>
<span class="kwrd">static</span> Culture()
{
<span class="preproc">#region</span> Init culture datails
cultureDetails = <span class="kwrd">new</span> StringDictionary();
<span class="kwrd">foreach</span> (CultureInfo cultureInfo <span class="kwrd">in</span> CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo regionInfo = <span class="kwrd">new</span> RegionInfo(cultureInfo.Name);
<span class="kwrd">if</span> (!cultureDetails.ContainsKey(regionInfo.EnglishName))
{
cultureDetails.Add(regionInfo.EnglishName, regionInfo.Name);
}
}
<span class="preproc">#endregion</span>
}
<span class="rem">/// <summary></span>
<span class="rem">/// Get culture name by Country</span>
<span class="rem">/// </summary></span>
<span class="rem">/// <param name="countryName"></param></span>
<span class="rem">/// <returns></returns></span>
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span> GetCulture(<span class="kwrd">string</span> countryName)
{
<span class="kwrd">return</span> cultureDetails.ContainsKey(countryName) ? cultureDetails[countryName] : <span class="kwrd">string</span>.Empty;
}
<span class="rem">/// <summary></span>
<span class="rem">/// Get Culture info by culture name</span>
<span class="rem">/// </summary></span>
<span class="rem">/// <param name="cultureName"></param></span>
<span class="rem">/// <returns></returns></span>
<span class="kwrd">public</span> <span class="kwrd">static</span> CultureInfo GetCultureInfo(<span class="kwrd">string</span> cultureName)
{
<span class="kwrd">return</span> CultureInfo.GetCultures(CultureTypes.SpecificCultures).FirstOrDefault(item => item.Name == cultureName);
}
<span class="rem">/// <summary></span>
<span class="rem">/// Get month names by culture</span>
<span class="rem">/// </summary></span>
<span class="rem">/// <param name="cultureName"></param></span>
<span class="rem">/// <returns></returns></span>
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span>[] GetMonths(<span class="kwrd">string</span> cultureName)
{
<span class="kwrd">var</span> region = GetCultureInfo(cultureName);
<span class="kwrd">return</span> region == <span class="kwrd">null</span> ? <span class="kwrd">null</span> : region.DateTimeFormat.MonthNames;
}
<span class="rem">/// <summary></span>
<span class="rem">/// Get day names by culture</span>
<span class="rem">/// </summary></span>
<span class="rem">/// <param name="cultureName"></param></span>
<span class="rem">/// <returns></returns></span>
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span>[] GetDays(<span class="kwrd">string</span> cultureName)
{
<span class="kwrd">var</span> region = GetCultureInfo(cultureName);
<span class="kwrd">return</span> region == <span class="kwrd">null</span> ? <span class="kwrd">null</span> : region.DateTimeFormat.DayNames;
}
<span class="rem">/// <summary></span>
<span class="rem">/// Get first day of week by culture</span>
<span class="rem">/// </summary></span>
<span class="rem">/// <param name="cultureName"></param></span>
<span class="rem">/// <returns></returns></span>
<span class="kwrd">public</span> <span class="kwrd">static</span> DayOfWeek GetFirstDayOfWeek(<span class="kwrd">string</span> cultureName)
{
<span class="kwrd">var</span> region = GetCultureInfo(cultureName);
<span class="kwrd">return</span> region == <span class="kwrd">null</span> ? <span class="kwrd">default</span>(DayOfWeek) : region.DateTimeFormat.FirstDayOfWeek;
}
<span class="rem">/// <summary></span>
<span class="rem">/// Get datetime format by culture</span>
<span class="rem">/// </summary></span>
<span class="rem">/// <param name="cultureName"></param></span>
<span class="rem">/// <returns></returns></span>
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span> GetDateTimeFormat(<span class="kwrd">string</span> cultureName)
{
<span class="kwrd">var</span> region = GetCultureInfo(cultureName);
<span class="kwrd">return</span> region == <span class="kwrd">null</span> ? <span class="kwrd">string</span>.Empty : region.DateTimeFormat.FullDateTimePattern;
}
<span class="rem">/// <summary></span>
<span class="rem">/// Get TimeZone info by DisplayName</span>
<span class="rem">/// </summary></span>
<span class="rem">/// <param name="displayName"></param></span>
<span class="rem">/// <returns></returns></span>
<span class="kwrd">public</span> <span class="kwrd">static</span> TimeZoneInfo GetTimeZoneByDisplayName(<span class="kwrd">string</span> name)
{
<span class="kwrd">return</span> timeZones.FirstOrDefault(item => item.DisplayName == name);
}
<span class="rem">/// <summary></span>
<span class="rem">/// Get TimeZone info by Standart Name</span>
<span class="rem">/// </summary></span>
<span class="rem">/// <param name="displayName"></param></span>
<span class="rem">/// <returns></returns></span>
<span class="kwrd">public</span> <span class="kwrd">static</span> TimeZoneInfo GetTimeZoneByStandartName(<span class="kwrd">string</span> name)
{
<span class="kwrd">return</span> timeZones.FirstOrDefault(item => item.StandardName == name);
}
}</pre>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-31798047023700285632012-05-15T16:59:00.001+03:002012-05-15T16:59:11.926+03:00Caching in WCFFull article exists <a href="http://pieterderycke.wordpress.com/2012/04/09/caching-in-wcf-services-part-1/" target="_blank">HERE</a>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-17113844299730041252012-01-22T14:02:00.002+02:002012-01-22T14:02:38.707+02:00Schedule Daily backup of database in MS-SQL Server 20081. Open Management Studio.<br />
2. Under "Mangement" select Maintenance Plans.<br />
3. Right click and choose New Plan (it will ask for name).<br />
4. Double click on Subplan_1 and change it to your name.<br />
5. Drag from toolbox "Back Up Database Task" control.<br />
6. Right click on it and choose Edit.<br />
7. Choose Backup Type, Databases and change more fields.<br />
8.OK<br />
9. Click on Job Schedule (in end of row) and set backup date/time.<br />
10. Save plan. <br />
11. Under "Mangement" right click on your job and choose "Execute" for validation.<br />
<br />
<br />
Enjoy!<br />
<br />
<br />
<br />
<br />
<br />
<br />Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-90455689358442244992012-01-19T09:10:00.000+02:002012-01-19T09:10:09.478+02:00Is my code Fluent?<a href="http://www.smelser.net/blog/post/2009/11/12/Is-my-code-Fluent.aspx">http://www.smelser.net/blog/post/2009/11/12/Is-my-code-Fluent.aspx</a>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-75138603079517412832012-01-19T09:06:00.003+02:002012-01-19T09:06:28.044+02:00Activator or Lambda Expressions<a href="http://www.smelser.net/blog/post/2010/03/05/When-Activator-is-just-to-slow.aspx">http://www.smelser.net/blog/post/2010/03/05/When-Activator-is-just-to-slow.aspx</a>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-31094454768932780802012-01-19T08:59:00.002+02:002012-01-19T08:59:35.461+02:00Log4Net... Friend or Foe?<a href="http://www.smelser.net/blog/post/2011/08/16/Log4Net-Friend-or-Foe.aspx">http://www.smelser.net/blog/post/2011/08/16/Log4Net-Friend-or-Foe.aspx</a>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0tag:blogger.com,1999:blog-26772613.post-41972850387054603672012-01-18T09:29:00.003+02:002012-01-18T09:29:24.996+02:00Hidden Features of C#?<a href="http://stackoverflow.com/q/9033">http://stackoverflow.com/q/9033</a>Geverhttp://www.blogger.com/profile/11201018491765487271noreply@blogger.com0